From a10ed03ef380e32da1a5d8cc6253088576039577 Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 2 May 2026 23:02:26 +0200 Subject: [PATCH] Improve stability for following accounts --- .../ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt | 2 +- .../cord/auxiliary/compose/ui/view/model/FeedListViewModel.kt | 2 +- .../auxiliary/compose/ui/view/model/FollowersListViewModel.kt | 3 ++- .../auxiliary/compose/ui/view/model/FollowingListViewModel.kt | 3 ++- .../compose/ui/view/model/MetadataEventDetailViewModel.kt | 1 + 5 files changed, 7 insertions(+), 4 deletions(-) diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt index c2dde988..f634157f 100644 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/database/dao/NostrEventDao.kt @@ -65,7 +65,7 @@ interface NostrEventDao { @Query("SELECT * FROM NostrEvent WHERE id = :id") fun getNostrEventById(id: String): NostrEvent? - @Query("SELECT * FROM NostrEvent WHERE pubKey = :publicKey AND kind = :kind") + @Query("SELECT * FROM NostrEvent WHERE pubKey = :publicKey AND kind = :kind ORDER BY createdAt DESC") fun getNostrEventByPublicKeyAndKind(publicKey: HexKey, kind: Kind): NostrEvent? @Upsert diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FeedListViewModel.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FeedListViewModel.kt index 7c358642..35da6ae4 100755 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FeedListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FeedListViewModel.kt @@ -91,7 +91,7 @@ class FeedListViewModel( fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount() { logger.d("observeSynchronizeNostrEventRequestByPurposeAndStatusCount") viewModelScope.launch(Dispatchers.IO) { - nostrRepository.observeSynchronizeNostrEventRequestByPurposeAndStatusCount("feed").collect { count -> + nostrRepository.observeSynchronizeNostrEventRequestByPurposeAndStatusCount("feed").distinctUntilChanged().collect { count -> logger.d("Pending/Processing Synchronization Request: $count") isSynchronizationPending.value = count > 0 } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowersListViewModel.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowersListViewModel.kt index 478d69aa..0f379b83 100755 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowersListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowersListViewModel.kt @@ -35,6 +35,7 @@ import androidx.lifecycle.viewmodel.viewModelFactory import co.touchlab.kermit.Logger import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch class FollowersListViewModel( @@ -91,7 +92,7 @@ class FollowersListViewModel( fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount() { logger.d("observeSynchronizeNostrEventRequestByPurposeAndStatusCount") viewModelScope.launch(Dispatchers.IO) { - nostrRepository.observeSynchronizeNostrEventRequestByPurposeAndStatusCount("feed").collect { count -> + nostrRepository.observeSynchronizeNostrEventRequestByPurposeAndStatusCount("feed").distinctUntilChanged().collect { count -> logger.d("Pending/Processing Synchronization Request: $count") isSynchronizationPending.value = count > 0 } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowingListViewModel.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowingListViewModel.kt index e03af8cb..d5d064cc 100755 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowingListViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/FollowingListViewModel.kt @@ -35,6 +35,7 @@ import androidx.lifecycle.viewmodel.viewModelFactory import co.touchlab.kermit.Logger import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO +import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.launch class FollowingListViewModel( @@ -90,7 +91,7 @@ class FollowingListViewModel( fun observeSynchronizeNostrEventRequestByPurposeAndStatusCount() { logger.d("observeSynchronizeNostrEventRequestByPurposeAndStatusCount") viewModelScope.launch(Dispatchers.IO) { - nostrRepository.observeSynchronizeNostrEventRequestByPurposeAndStatusCount("feed").collect { count -> + nostrRepository.observeSynchronizeNostrEventRequestByPurposeAndStatusCount("feed").distinctUntilChanged().collect { count -> logger.d("Pending/Processing Synchronization Request: $count") isSynchronizationPending.value = count > 0 } diff --git a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt index a7f1ee96..dcb96625 100755 --- a/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt +++ b/composeApp/src/commonMain/kotlin/ac/cord/auxiliary/compose/ui/view/model/MetadataEventDetailViewModel.kt @@ -240,6 +240,7 @@ class MetadataEventDetailViewModel( kind = ContactListEvent.KIND ) + logger.d("ContactListEvent: $contactListEvent") val followUsers: TagArray = if (contactListEvent != null) { if (contactListEvent.tags.isTaggedUser(publicKey)) {