Remove unnecessary try catch

parent 5fab419e
......@@ -23,7 +23,6 @@ import com.shopify.livedataktx.nonNull
import kotlinx.coroutines.experimental.*
import kotlinx.coroutines.experimental.android.UI
import timber.log.Timber
import java.lang.IllegalArgumentException
class ChatRoomsViewModel(
private val connectionManager: ConnectionManager,
......@@ -43,23 +42,19 @@ class ChatRoomsViewModel(
return@switchMap if (query.isSearch()) {
this@ChatRoomsViewModel.query.wrap(runContext) { _, data: MutableLiveData<RoomsModel> ->
try {
val string = (query as Query.Search).query
// debounce, to not query while the user is writing
delay(200)
val rooms = repository.search(string).let { mapper.map(it, showLastMessage = this.showLastMessage) }
data.postValue(rooms.toMutableList() + LoadingItemHolder())
yield()
val spotlight = spotlight(query.query)?.let { mapper.map(it, showLastMessage = this.showLastMessage) }
yield()
spotlight?.let {
data.postValue(rooms.toMutableList() + spotlight)
}.ifNull {
data.postValue(rooms)
}
} catch (ignore: CancellationException) {
val string = (query as Query.Search).query
// debounce, to not query while the user is writing
delay(200)
val rooms = repository.search(string).let { mapper.map(it, showLastMessage = this.showLastMessage) }
data.postValue(rooms.toMutableList() + LoadingItemHolder())
yield()
val spotlight = spotlight(query.query)?.let { mapper.map(it, showLastMessage = this.showLastMessage) }
yield()
spotlight?.let {
data.postValue(rooms.toMutableList() + spotlight)
}.ifNull {
data.postValue(rooms)
}
}
} else {
......
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