forked from upstream-mirrors/quik
Fix conversation search not clearing properly
This commit is contained in:
@@ -65,9 +65,14 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
|||||||
private val menuUnarchive by lazy { MenuItem(context.getString(R.string.menu_unarchive), 1) }
|
private val menuUnarchive by lazy { MenuItem(context.getString(R.string.menu_unarchive), 1) }
|
||||||
private val menuDelete by lazy { MenuItem(context.getString(R.string.menu_delete), 2) }
|
private val menuDelete by lazy { MenuItem(context.getString(R.string.menu_delete), 2) }
|
||||||
|
|
||||||
|
private val conversations by lazy { messageRepo.getConversations() }
|
||||||
|
|
||||||
init {
|
init {
|
||||||
appComponent.inject(this)
|
appComponent.inject(this)
|
||||||
|
|
||||||
|
// Now the conversations can be loaded
|
||||||
|
conversations
|
||||||
|
|
||||||
disposables += deleteConversation
|
disposables += deleteConversation
|
||||||
disposables += markAllSeen
|
disposables += markAllSeen
|
||||||
disposables += markArchived
|
disposables += markArchived
|
||||||
@@ -86,8 +91,6 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
|||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.subscribe { syncing -> newState { it.copy(syncing = syncing) } }
|
.subscribe { syncing -> newState { it.copy(syncing = syncing) } }
|
||||||
|
|
||||||
newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
|
||||||
|
|
||||||
// Migrate the preferences from 2.7.3 if necessary
|
// Migrate the preferences from 2.7.3 if necessary
|
||||||
migratePreferences.execute(Unit)
|
migratePreferences.execute(Unit)
|
||||||
|
|
||||||
@@ -110,14 +113,14 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
|||||||
super.bindView(view)
|
super.bindView(view)
|
||||||
|
|
||||||
view.queryChangedIntent
|
view.queryChangedIntent
|
||||||
.skip(1)
|
|
||||||
.debounce(200, TimeUnit.MILLISECONDS)
|
.debounce(200, TimeUnit.MILLISECONDS)
|
||||||
.withLatestFrom(state, { query, state ->
|
.withLatestFrom(state, { query, state ->
|
||||||
if (state.page is Inbox) {
|
if (state.page is Inbox) {
|
||||||
val conversations = state.page.data
|
val filteredConversations = if (query.isEmpty()) conversations
|
||||||
?.map { conversations -> conversations.filter { conversationFilter.filter(it, query) } }
|
else conversations
|
||||||
|
.map { conversations -> conversations.filter { conversationFilter.filter(it, query) } }
|
||||||
|
|
||||||
val page = state.page.copy(showClearButton = query.isNotEmpty(), data = conversations)
|
val page = state.page.copy(showClearButton = query.isNotEmpty(), data = filteredConversations)
|
||||||
newState { it.copy(page = page) }
|
newState { it.copy(page = page) }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -144,7 +147,7 @@ class MainViewModel : QkViewModel<MainView, MainState>(MainState()) {
|
|||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.doOnNext {
|
.doOnNext {
|
||||||
when (it) {
|
when (it) {
|
||||||
DrawerItem.INBOX -> newState { it.copy(page = Inbox(data = messageRepo.getConversations())) }
|
DrawerItem.INBOX -> newState { it.copy(page = Inbox()) }
|
||||||
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
DrawerItem.ARCHIVED -> newState { it.copy(page = Archived(messageRepo.getConversations(true))) }
|
||||||
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
DrawerItem.SCHEDULED -> newState { it.copy(page = Scheduled()) }
|
||||||
else -> {
|
else -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user