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() .toList()
.reversed() .reversed()
} }
fun isDifferentAccount(account: Account): Boolean {
return this::account.isInitialized && this.account != account
}
} }

View File

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

View File

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