From 9574f4b68d00cbb9911cb805a45f4cc567453994 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 24 Apr 2026 01:54:48 +0000 Subject: [PATCH] fix: align WakeUp handling with spec semantics (p-tags = authors) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A previous commit misread the spec: p-tags on a WakeUp identify the AUTHORS of the referenced events (the people whose events are the subject of the wake-up), not the recipients. The consumer's existing npub-in-p-tag match is therefore correct — "is this logged-in account the author of a referenced event?". - Revert WakeUpEvent.build() back to notify(about.toPTag()) and replace the comment with a spec-accurate one. - In wakeUpFor, source author pubkeys from event.authorKeys() (p-tags, canonical) first, merge in the e-tag author hints, and fall back to the WakeUp signer only when both are empty. Bound by MAX_WAKEUP_REFS. computeReplyTo and the referenced-event fetch path remain untouched — those fixes are orthogonal to the p-tag semantic. --- .../notifications/EventNotificationConsumer.kt | 15 ++++++++------- .../notifications/wake/WakeUpEvent.kt | 12 ++++++------ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt index 62dfa359d..c64f4005a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/notifications/EventNotificationConsumer.kt @@ -204,16 +204,17 @@ class EventNotificationConsumer( return } - // The referenced event's author is who the user will see in the final - // notification ("Alice zapped you"). The WakeUp's own pubKey is typically - // a push bot and not useful. Fall back to it only when the `e` tag omits - // the author hint. + // Per spec, p-tags on a WakeUp are the authors of the referenced + // events; those are whose metadata we need to render the notification. + // Fall back to e-tag author hints and finally to the WakeUp signer. val referencedNotes = referencedTags.map { LocalCache.getOrCreateNote(it.eventId) } - val authorCandidates = - referencedTags - .mapNotNull { it.author } + val authorKeys = + (event.authorKeys() + referencedTags.mapNotNull { it.author }) .distinct() .ifEmpty { listOf(event.pubKey) } + val authorCandidates = + authorKeys + .take(MAX_WAKEUP_REFS) .map { LocalCache.getOrCreateUser(it) } coroutineScope { diff --git a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/notifications/wake/WakeUpEvent.kt b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/notifications/wake/WakeUpEvent.kt index 925efbf85..5fc6ee712 100644 --- a/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/notifications/wake/WakeUpEvent.kt +++ b/quartz/src/commonMain/kotlin/com/vitorpamplona/quartz/experimental/notifications/wake/WakeUpEvent.kt @@ -35,7 +35,7 @@ import com.vitorpamplona.quartz.nip01Core.tags.kinds.kind import com.vitorpamplona.quartz.nip01Core.tags.people.PTag import com.vitorpamplona.quartz.nip01Core.tags.people.PTag.Companion.parse import com.vitorpamplona.quartz.nip01Core.tags.people.PTag.Companion.parseKey -import com.vitorpamplona.quartz.nip01Core.tags.people.taggedUsers +import com.vitorpamplona.quartz.nip01Core.tags.people.toPTag import com.vitorpamplona.quartz.nip31Alts.alt import com.vitorpamplona.quartz.utils.TimeUtils import kotlinx.serialization.json.JsonNull.content @@ -68,10 +68,10 @@ class WakeUpEvent( const val KIND = 23903 const val ALT_DESCRIPTION = "WakeUp" - // Tags the audience of [about] (its `p` tags) as the recipients to wake up. - // The about event's author is NOT tagged: a WakeUp about a zap from Alice - // to Bob should notify Bob, not Alice. Callers can add more recipients via - // [initializer]. + // p-tags on a WakeUp identify the AUTHORS of the referenced events — + // the people whose events are the subject of the wake-up and who should + // come online to handle new activity on them. Callers can add extra + // e/p tags via [initializer] when waking up about multiple events. fun build( about: EventHintBundle, createdAt: Long = TimeUtils.now(), @@ -79,7 +79,7 @@ class WakeUpEvent( ) = eventTemplate(KIND, content, createdAt) { alt(ALT_DESCRIPTION) about(about) - notify(about.event.tags.taggedUsers()) + notify(about.toPTag()) kind(about.event.kind) initializer() }