diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index 1b5e29729..364e675fe 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -449,11 +449,10 @@ class Account( val liveKind3Follows = liveKind3FollowsFlow.stateIn(scope, SharingStarted.Eagerly, LiveFollowLists(usersPlusMe = setOf(keyPair.pubKeyHex))) @OptIn(ExperimentalCoroutinesApi::class) - private val liveHomeList: Flow by lazy { + private val liveHomeList: Flow = defaultHomeFollowList.flatMapLatest { listName -> loadPeopleListFlowFromListName(listName) } - } @OptIn(ExperimentalCoroutinesApi::class) fun loadPeopleListFlowFromListName(listName: String): Flow = @@ -490,7 +489,7 @@ class Account( } val liveHomeFollowListFlow: Flow by lazy { - combinePeopleListFlows(liveKind3FollowsFlow, liveHomeList) + combinePeopleListFlows(liveKind3Follows, liveHomeList) } val liveHomeFollowLists: StateFlow by lazy { @@ -544,31 +543,27 @@ class Account( fun authorsPerRelay( followsNIP65RelayLists: Array, defaultRelayList: List, - ): Map> { - val test = - assembleAuthorsPerWriteRelay( - followsNIP65RelayLists - .mapNotNull - { - val author = (it.note as? AddressableNote)?.address?.pubKeyHex - val event = (it.note.event as? AdvertisedRelayListEvent) + ): Map> = + assembleAuthorsPerWriteRelay( + followsNIP65RelayLists + .mapNotNull + { + val author = (it.note as? AddressableNote)?.address?.pubKeyHex + val event = (it.note.event as? AdvertisedRelayListEvent) - if (event != null) { - event.pubKey to event.writeRelays() + if (event != null) { + event.pubKey to event.writeRelays() + } else { + if (author != null) { + author to defaultRelayList } else { - if (author != null) { - author to defaultRelayList - } else { - Log.e("Account", "This author should NEVER be null. Note: ${it.note.idHex}") - null - } + Log.e("Account", "This author should NEVER be null. Note: ${it.note.idHex}") + null } - }.toMap(), - hasOnionConnection = proxy != null, - ) - - return test - } + } + }.toMap(), + hasOnionConnection = proxy != null, + ) @OptIn(ExperimentalCoroutinesApi::class) val liveHomeFollowListAdvertizedRelayListFlow: Flow?> = diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt index 62fc9489c..3972f4a74 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrHomeDataSource.kt @@ -55,6 +55,7 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") { val latestEOSEs = EOSEAccount() var job: Job? = null + var job2: Job? = null override fun start() { job?.cancel() @@ -68,12 +69,25 @@ object NostrHomeDataSource : AmethystNostrDataSource("HomeFeed") { } } } + + job2?.cancel() + job2 = + scope.launch(Dispatchers.IO) { + // creates cache on main + withContext(Dispatchers.Main) { account.userProfile().live() } + account.liveHomeListAuthorsPerRelay.collect { + if (this@NostrHomeDataSource::account.isInitialized) { + invalidateFilters() + } + } + } super.start() } override fun stop() { super.stop() job?.cancel() + job2?.cancel() } fun createFollowAccountsFilter(): TypedFilter {