Store the ntfy notification a card came from

A card from an ntfy subscription now carries its notification,
"<topic>/<sequence ID>", in its Meta, and the queue stores it with the
job. ntfy's sequence IDs are per topic and one subscription reads
several topics, so the topic is part of the key; a message without a
sequence_id is its own sequence. Digests and jobs from the routes carry
none.

Nothing reads it yet: it lets an ntfy message_delete find the waiting
job of its notification, also after a restart, once cancelling comes.

Part of stage 1c of docs/plans/job-store.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
57_WolveandClaude Opus 5.5 committed 2026-12-01 13:47:03 -06:00
1 parent 8031135508
commit 792ee26af5
6 files changed
+73 -8

No files matched your search

+11
View File
@@ -97,6 +97,17 @@ func (m Message) Sequence() string {
return m.ID
}
// Notification names the notification m belongs to across topics,
// "<topic>/<sequence>", since sequences are per topic. It is empty when m
// has neither a sequence nor an ID.
func (m Message) Notification() string {
seq := m.Sequence()
if seq == "" {
return ""
}
return m.Topic + "/" + seq
}
// Action is a button on a notification. View actions open URL; http
// actions send a request with Method, Headers and Body; broadcast actions
// send an Android intent with Extras; copy actions copy Value to the
+18
View File
@@ -47,3 +47,21 @@ func TestDecodeMessage(t *testing.T) {
t.Errorf("attachment %+v", m.Attachment)
}
}
// Notification joins the topic and the sequence, which falls back to the
// ID, and is empty for an event with neither.
func TestNotification(t *testing.T) {
for _, tt := range []struct {
m ntfy.Message
want string
}{
{ntfy.Message{ID: "m1", SequenceID: "backup", Topic: "alerts"}, "alerts/backup"},
{ntfy.Message{ID: "m1", Topic: "alerts"}, "alerts/m1"},
{ntfy.Message{Event: ntfy.EventMessageDelete, SequenceID: "backup", Topic: "jobs"}, "jobs/backup"},
{ntfy.Message{Event: ntfy.EventKeepalive, Topic: "alerts"}, ""},
} {
if got := tt.m.Notification(); got != tt.want {
t.Errorf("%+v: Notification() = %q, want %q", tt.m, got, tt.want)
}
}
}