Commit 35a75978 authored by Leonardo Aramaki's avatar Leonardo Aramaki

Return hostname along with its logo URI when fetched for logged in servers

parent c0ff4aba
...@@ -15,6 +15,7 @@ import java.util.List; ...@@ -15,6 +15,7 @@ import java.util.List;
import java.util.UUID; import java.util.UUID;
import chat.rocket.android.log.RCLog; import chat.rocket.android.log.RCLog;
import chat.rocket.core.utils.Pair;
import io.reactivex.BackpressureStrategy; import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable; import io.reactivex.Flowable;
import io.reactivex.annotations.NonNull; import io.reactivex.annotations.NonNull;
...@@ -60,16 +61,17 @@ public class RocketChatCache { ...@@ -60,16 +61,17 @@ public class RocketChatCache {
} }
} }
public List<String> getServerList() { public List<Pair<String, String>> getServerList() {
String json = getString(KEY_HOSTNAME_LIST, null); String json = getString(KEY_HOSTNAME_LIST, null);
if (json == null) { if (json == null) {
return Collections.emptyList(); return Collections.emptyList();
} }
try { try {
JSONObject jsonObj = new JSONObject(json); JSONObject jsonObj = new JSONObject(json);
List<String> serverList = new ArrayList<>(); List<Pair<String, String>> serverList = new ArrayList<>();
for (Iterator<String> iter = jsonObj.keys(); iter.hasNext();) { for (Iterator<String> iter = jsonObj.keys(); iter.hasNext();) {
serverList.add(iter.next()); String hostname = iter.next();
serverList.add(new Pair<>(hostname,"http://" + hostname + "/" + jsonObj.getString(hostname)));
} }
return serverList; return serverList;
} catch (JSONException e) { } catch (JSONException e) {
......
package chat.rocket.android; package chat.rocket.android;
import android.content.Context import android.content.Context
import chat.rocket.core.utils.Pair
import org.hamcrest.CoreMatchers.equalTo import org.hamcrest.CoreMatchers.equalTo
import org.json.JSONObject import org.json.JSONObject
import org.junit.Assert.assertThat import org.junit.Assert.assertThat
...@@ -26,16 +27,16 @@ class RocketChatCacheTest { ...@@ -26,16 +27,16 @@ class RocketChatCacheTest {
@Test @Test
fun getServerList_ShouldReturnHostnameList() { fun getServerList_ShouldReturnHostnameList() {
val hostnameList = JSONObject() val hostnameList = JSONObject()
.put("demo.rocket.chat", "imageuri") .put("http://demo.rocket.chat", "images/logo/logo.png")
.put("192.168.0.6:3000", "imageuri") .put("http://192.168.0.6:3000", "images/icon.svg")
.toString() .toString()
doReturn(hostnameList).`when`(cache).getString("KEY_HOSTNAME_LIST", null) doReturn(hostnameList).`when`(cache).getString("KEY_HOSTNAME_LIST", null)
val expectedServerList = mutableListOf("demo.rocket.chat", "192.168.0.6:3000") val expectedServerList = mutableListOf(
Pair("http://192.168.0.6:3000", "http://192.168.0.6:3000/images/icon.svg"),
Pair("http://demo.rocket.chat", "http://demo.rocket.chat/images/logo/logo.png"))
val serverList = cache.serverList val serverList = cache.serverList
expectedServerList.sort() assertThat(serverList, equalTo(expectedServerList))
serverList.sort()
assertThat(cache.serverList, equalTo(expectedServerList))
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment