Makes sure it doesn't crash on starting.

This commit is contained in:
Vitor Pamplona 2023-11-21 14:17:32 -05:00
parent c8365439ee
commit 7246a545af
5 changed files with 15 additions and 5 deletions

View File

@ -29,7 +29,9 @@ object NostrDiscoveryDataSource : NostrDataSource("DiscoveryFeed") {
job?.cancel()
job = scope.launch(Dispatchers.IO) {
account.liveDiscoveryFollowLists.collect {
invalidateFilters()
if (this@NostrDiscoveryDataSource::account.isInitialized) {
invalidateFilters()
}
}
}
super.start()

View File

@ -35,7 +35,9 @@ object NostrHomeDataSource : NostrDataSource("HomeFeed") {
job?.cancel()
job = account.scope.launch(Dispatchers.IO) {
account.liveHomeFollowLists.collect {
invalidateFilters()
if (this@NostrHomeDataSource::account.isInitialized) {
invalidateFilters()
}
}
}
super.start()

View File

@ -24,7 +24,9 @@ object NostrVideoDataSource : NostrDataSource("VideoFeed") {
job?.cancel()
job = scope.launch(Dispatchers.IO) {
account.liveStoriesFollowLists.collect {
invalidateFilters()
if (this@NostrVideoDataSource::account.isInitialized) {
invalidateFilters()
}
}
}
super.start()

View File

@ -55,7 +55,7 @@ fun HomeScreen(
WatchAccountForHomeScreen(homeFeedViewModel, repliesFeedViewModel, accountViewModel)
WatchLifeCycleChanges()
WatchLifeCycleChanges(accountViewModel)
AssembleHomeTabs(homeFeedViewModel, repliesFeedViewModel) { pagerState, tabItems ->
AssembleHomePage(pagerState, tabItems, accountViewModel, nav)
@ -109,11 +109,12 @@ fun ResolveNIP47(
}
@Composable
private fun WatchLifeCycleChanges() {
private fun WatchLifeCycleChanges(accountViewModel: AccountViewModel) {
val lifeCycleOwner = LocalLifecycleOwner.current
DisposableEffect(lifeCycleOwner) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_RESUME) {
NostrHomeDataSource.account = accountViewModel.account
NostrHomeDataSource.invalidateFilters()
}
}
@ -219,6 +220,7 @@ fun WatchAccountForHomeScreen(
val homeFollowList by accountViewModel.account.liveHomeFollowLists.collectAsStateWithLifecycle()
LaunchedEffect(accountViewModel, homeFollowList) {
NostrHomeDataSource.account = accountViewModel.account
NostrHomeDataSource.invalidateFilters()
homeFeedViewModel.checkKeysInvalidateDataAndSendToTop()
repliesFeedViewModel.checkKeysInvalidateDataAndSendToTop()

View File

@ -86,6 +86,7 @@ fun NotificationScreen(
DisposableEffect(lifeCycleOwner) {
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_RESUME) {
NostrAccountDataSource.account = accountViewModel.account
NostrAccountDataSource.invalidateFilters()
}
}
@ -144,6 +145,7 @@ fun WatchAccountForNotifications(
val listState by accountViewModel.account.liveStoriesFollowLists.collectAsStateWithLifecycle()
LaunchedEffect(accountViewModel, listState) {
NostrAccountDataSource.account = accountViewModel.account
NostrAccountDataSource.invalidateFilters()
notifFeedViewModel.checkKeysInvalidateDataAndSendToTop()
}