BugFix Sticky notifications on account change

This commit is contained in:
Vitor Pamplona
2023-03-29 18:06:19 -04:00
parent a66f001033
commit 8f14ccda86
3 changed files with 13 additions and 0 deletions

View File

@@ -40,4 +40,8 @@ object NotificationFeedFilter : FeedFilter<Note>() {
.toList()
.reversed()
}
fun isDifferentAccount(account: Account): Boolean {
return this::account.isInitialized && this.account != account
}
}

View File

@@ -53,9 +53,13 @@ fun AppNavigation(
GlobalFeedFilter.account = account
val searchFeedViewModel: NostrGlobalFeedViewModel = viewModel()
val restartNotificationList = NotificationFeedFilter.isDifferentAccount(account)
NotificationFeedFilter.account = account
val notifFeedViewModel: NotificationViewModel = viewModel()
if (restartNotificationList) notifFeedViewModel.clear()
NavHost(navController, startDestination = Route.Home.route) {
Route.Search.let { route ->
composable(route.route, route.arguments, content = {

View File

@@ -160,7 +160,12 @@ open class CardFeedViewModel(val dataSource: FeedFilter<Note>) : ViewModel() {
LocalCache.live.observeForever(cacheListener)
}
fun clear() {
lastNotes = null
}
override fun onCleared() {
clear()
LocalCache.live.removeObserver(cacheListener)
super.onCleared()
}