Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<RoomsModel> {
return Transformations.switchMap(query) { query ->

Expand All @@ -69,33 +62,26 @@ 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<CharSequence>()
val repoSearchRoomNames = ArrayList<CharSequence>()
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

val spotlight = spotlight(query.query)?.let { mapper.map(it, showLastMessage = this.showLastMessage) }
val spotlightFiltered = ArrayList<ItemHolder<*>>()
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)
Expand Down