From 203830b421008187eaed70cb66854a7df538943d Mon Sep 17 00:00:00 2001 From: Shailesh Baldaniya Date: Tue, 27 Aug 2019 00:03:03 +0530 Subject: [PATCH] fix: Spotlight long delay --- .../chatrooms/viewmodel/ChatRoomsViewModel.kt | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt b/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt index 9e704a7d8b..a8b6db32b8 100644 --- a/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt +++ b/app/src/main/java/chat/rocket/android/chatrooms/viewmodel/ChatRoomsViewModel.kt @@ -20,7 +20,6 @@ import chat.rocket.core.model.SpotlightResult import com.shopify.livedataktx.distinct import com.shopify.livedataktx.map import com.shopify.livedataktx.nonNull -import com.shopify.livedataktx.observe import kotlinx.coroutines.async import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope @@ -50,12 +49,6 @@ class ChatRoomsViewModel( private var loaded = false var showLastMessage = true - private var status: State? = null - - init { - connectionManager.statusLiveData.observe { status = it } - } - fun getChatRooms(): LiveData { return Transformations.switchMap(query) { query -> @@ -69,18 +62,11 @@ class ChatRoomsViewModel( if (!coroutineContext.isActive) return@wrap val rooms = repository.search(string).let { mapper.map(it, showLastMessage = this.showLastMessage) } - - if (status !is State.Connected) { - data.postValue(rooms.toMutableList()) - connectionManager.connect() - return@wrap - } - data.postValue(rooms.toMutableList() + LoadingItemHolder()) - var repoSearchRoomNames = ArrayList() + val repoSearchRoomNames = ArrayList() rooms.forEach { room -> - var thisRoom: RoomUiModel = room.data as RoomUiModel + val thisRoom: RoomUiModel = room.data as RoomUiModel repoSearchRoomNames.add(thisRoom.name) } if (!coroutineContext.isActive) return@wrap @@ -88,14 +74,14 @@ class ChatRoomsViewModel( val spotlight = spotlight(query.query)?.let { mapper.map(it, showLastMessage = this.showLastMessage) } val spotlightFiltered = ArrayList>() spotlight?.forEach { room -> - var thisRoom: RoomUiModel = room.data as RoomUiModel + val thisRoom: RoomUiModel = room.data as RoomUiModel if (thisRoom.name !in repoSearchRoomNames) { spotlightFiltered.add(room) } } if (!coroutineContext.isActive) return@wrap - spotlightFiltered?.let { + spotlight?.let { data.postValue(rooms.toMutableList() + spotlightFiltered) }.ifNull { data.postValue(rooms)