feat(notifications): dispatch from LocalCache for all delivery sources
The NotificationRelayService consumes events directly into LocalCache, which made EventNotificationConsumer's hasConsumed dedup check short-circuit every subsequent push-notification path. As a result, no notifications fired while the service was active. Rework the notification pipeline so every delivery source (FCM, UnifiedPush, Pokey, active relay subscriptions, NotificationRelayService) feeds LocalCache and a single dispatcher observes it for notification-relevant kinds. Foreground suppression is scoped to MainActivity (PiP/Call activities keep notifying), with carve-outs for CallOffer and WakeUp so time-sensitive events always fire. - Add NewEventMatchingFilter observable primitive alongside EventListMatchingFilter for per-event emission (no list accumulation). - Add LocalCache.observeNewEvents<T>(filter) backed by the new observable. - Add MainActivity.isResumed flag flipped in onResume/onPause. - Add NotificationDispatcher that observes LocalCache for GiftWrap, EphemeralGiftWrap, PrivateDm, LnZap, Reaction, Chess, and WakeUp. - Replace EventNotificationConsumer.consume / findAccountAndConsume with consumeFromCache, which skips the hasConsumed check (the observer itself provides first-delivery semantics) and gates non-priority kinds on MainActivity.isResumed. - Rewire FCM/UnifiedPush/Pokey receivers to feed LocalCache directly. - Wire the dispatcher into AppModules lifecycle.
This commit is contained in:
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2025 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.commons.model.observables
|
||||
|
||||
import com.vitorpamplona.amethyst.commons.model.Note
|
||||
import com.vitorpamplona.quartz.nip01Core.core.Event
|
||||
import com.vitorpamplona.quartz.nip01Core.relay.filters.Filter
|
||||
|
||||
/**
|
||||
* Emits each new event that matches the given Nostr filter, one at a time.
|
||||
*
|
||||
* Unlike [EventListMatchingFilter] / [NoteListMatchingFilter], this does not
|
||||
* accumulate a list — it simply calls [onNew] per matching event as it is
|
||||
* inserted into the cache. Useful for reactive event-triggered pipelines
|
||||
* (e.g. notifications) that need per-event delivery without list overhead.
|
||||
*/
|
||||
class NewEventMatchingFilter<T : Event>(
|
||||
private val filter: Filter,
|
||||
private val onNew: (T) -> Unit,
|
||||
) : Observable {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun new(
|
||||
event: Event,
|
||||
note: Note,
|
||||
) {
|
||||
if (filter.match(event)) {
|
||||
onNew(event as T)
|
||||
}
|
||||
}
|
||||
|
||||
override fun remove(note: Note) {}
|
||||
}
|
||||
Reference in New Issue
Block a user