From fad8b9df0fe28240da967db7b316d92050321e8d Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 9 Aug 2024 18:47:38 -0400 Subject: [PATCH] Improved filter for notifications --- .../service/NostrAccountDataSource.kt | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt index a0fa38d7f..a97351b5c 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/NostrAccountDataSource.kt @@ -68,6 +68,7 @@ import com.vitorpamplona.quartz.events.SearchRelayListEvent import com.vitorpamplona.quartz.events.StatusEvent import com.vitorpamplona.quartz.events.TextNoteEvent import com.vitorpamplona.quartz.utils.TimeUtils +import kotlinx.coroutines.flow.filter // TODO: Migrate this to a property of AccountVi object NostrAccountDataSource : AmethystNostrDataSource("AccountData") { @@ -179,12 +180,26 @@ object NostrAccountDataSource : AmethystNostrDataSource("AccountData") { ) fun createNotificationFilter(): TypedFilter { - val since = + var since = latestEOSEs.users[account.userProfile()] ?.followList ?.get(account.defaultNotificationFollowList.value) ?.relayList - ?: account.connectToRelays.value.associate { it.url to EOSETime(TimeUtils.oneWeekAgo()) } + ?.toMutableMap() + + if (since == null) { + since = + account.connectToRelays.value + .associate { it.url to EOSETime(TimeUtils.oneWeekAgo()) } + .toMutableMap() + } else { + account.connectToRelays.value.forEach { + val eose = since.get(it.url) + if (eose == null) { + since.put(it.url, EOSETime(TimeUtils.oneWeekAgo())) + } + } + } return TypedFilter( types = COMMON_FEED_TYPES,