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;
import java.util.UUID;
import chat.rocket.android.log.RCLog;
import chat.rocket.core.utils.Pair;
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.annotations.NonNull;
......@@ -60,16 +61,17 @@ public class RocketChatCache {
}
}
public List<String> getServerList() {
public List<Pair<String, String>> getServerList() {
String json = getString(KEY_HOSTNAME_LIST, null);
if (json == null) {
return Collections.emptyList();
}
try {
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();) {
serverList.add(iter.next());
String hostname = iter.next();
serverList.add(new Pair<>(hostname,"http://" + hostname + "/" + jsonObj.getString(hostname)));
}
return serverList;
} catch (JSONException e) {
......
package chat.rocket.android;
import android.content.Context
import chat.rocket.core.utils.Pair
import org.hamcrest.CoreMatchers.equalTo
import org.json.JSONObject
import org.junit.Assert.assertThat
......@@ -26,16 +27,16 @@ class RocketChatCacheTest {
@Test
fun getServerList_ShouldReturnHostnameList() {
val hostnameList = JSONObject()
.put("demo.rocket.chat", "imageuri")
.put("192.168.0.6:3000", "imageuri")
.put("http://demo.rocket.chat", "images/logo/logo.png")
.put("http://192.168.0.6:3000", "images/icon.svg")
.toString()
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
expectedServerList.sort()
serverList.sort()
assertThat(cache.serverList, equalTo(expectedServerList))
assertThat(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