From a996065c0532e3c6b976851b66c08db6458f8358 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Fri, 7 Nov 2025 17:27:41 -0500 Subject: [PATCH] Creates new observer for events with null option --- .../reqCommand/event/EventObservers.kt | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt index cf04ed4b2..50cdad965 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt @@ -130,6 +130,32 @@ fun observeNoteEventAndMapNotNull( return flow.collectAsStateWithLifecycle((note.event as? T)?.let { map(it) }) } +@OptIn(ExperimentalCoroutinesApi::class) +@Suppress("UNCHECKED_CAST") +@Composable +fun observeNoteEventAndMap( + note: Note, + accountViewModel: AccountViewModel, + map: (T?) -> U, +): State { + // Subscribe in the relay for changes in this note. + EventFinderFilterAssemblerSubscription(note, accountViewModel) + + // Subscribe in the LocalCache for changes that arrive in the device + val flow = + remember(note) { + note + .flow() + .metadata.stateFlow + .mapLatest { map(it.note.event as? T) } + .distinctUntilChanged() + .flowOn(Dispatchers.IO) + } + + // Subscribe in the LocalCache for changes that arrive in the device + return flow.collectAsStateWithLifecycle(map(note.event as? T)) +} + @OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeNoteHasEvent(