Files
buzz/docs/adr/0004-notification-reply.md
Tom Brow d1236080eb fix(mobile): bind notification replies to the account they were typed for (#9845)
A notification reply goes out as whatever account its community signs
with when the reply is sent. No sign-in path replaces a community's
account in place today: signing in again as another account adds a new
community, and hosted re-entry refuses a different key. But nothing tied
a reply to the account its notification was for, so a future in-place
credential replacement would let a reply typed for the earlier account
go out as the new one, or land in its drafts.

Each reply is now tied to the account its notification was for:

- The notification service extension records that account in the reply
context, and iOS carries it through the reply journal, so a reply
recovered on a later launch keeps it too.
- The app sends a reply, or keeps it as a draft, only while the
community still signs as that account (the key it signs with). It checks
again after connecting.
- Otherwise the reply ends as lost: iOS shows "Reply not sent" with the
text, and no draft is kept. This is the same path a reply takes when its
community has been removed ([ADR
0004](docs/adr/0004-notification-reply.md), updated here).
- A reply to a notification posted by an earlier build has no recorded
account, so it is checked only by its community, as before.

### Regressions

- A community whose notification snapshot has no account key offers no
reply action. Every signed-in community has one, since the snapshot
falls back to the key derived from its secret.
- No extra work on the send path beyond a key comparison.

### Validation

-
[notification_reply_test.dart](https://github.com/block/buzz/blob/notification-reply-account/mobile/test/features/channels/notification_reply_test.dart):
a live reply for another account and a recovered one for another
community end as lost with their text kept nowhere; a reply whose
community's signing key is replaced while the relay connects (same
community and stored key) is neither sent nor drafted; a reply from an
earlier build without an account is sent.
-
[BuzzNotificationReplyTests.swift](https://github.com/block/buzz/blob/notification-reply-account/mobile/ios/BuzzPushKit/Tests/BuzzPushKitTests/BuzzNotificationReplyTests.swift):
the resolver records the notification's account, lowercased. An empty
account is rejected, and the account survives the journal round trip.
- No simulator run: the reply action needs a real push resolved by the
notification service extension, which the simulator can't receive. The
change is covered at both layers by the tests above, and the iOS app
builds.

---------

Signed-off-by: Tom Brow <tomb@block.xyz>
2026-11-20 20:23:59 -08:00

29 lines
6.8 KiB
Markdown

# Replying from a notification
A [mobile push notification](../../CONTEXT.md#mobile-push-notification) that shows a message offers a [notification reply](../../CONTEXT.md#notification-reply): the user types a reply in the notification, and the app sends it without opening.
The reply goes in a new subthread rooted at the notified message: its parent is that message, and its thread root is the message's own thread root, or the message itself when it is top-level. A Solo chat takes no thread replies, so there the reply goes at the same level as the notified message, the chat's top level.
The reply mentions the notified message's sender, in every kind of conversation including DMs and Solo chats, so the person or agent being answered is notified. A sender who has since left the conversation can't be mentioned, so the reply goes without the mention rather than failing. A notification has no mention autocomplete, so it adds no other mentions; text typed as `@name` stays plain text.
After the reply is accepted, the app marks the conversation read up to the notified message and removes the delivered notifications that read marker covers (for a message in a thread, that thread's earlier ones; for a top-level message, the whole conversation's, threads included), because replying means the user has seen that message. Newer messages stay unread: the user may not have seen them. When the reply can't be sent (offline, a channel the user isn't in, no time left), the app shows a "Reply not sent" notification instead; tapping it opens the subthread the reply would have gone in, with the typed text in its composer after any draft already there, so nothing typed is lost, unless the reply's community is gone (see below). A recovered draft doesn't carry the automatic mention. iOS keeps each reply on disk from the moment it's typed until the app reports what happened to it, or until the app has saved its draft, so the text survives even when the app never got to the reply, or was stopped partway. A later launch never sends a reply an earlier one was given: it makes it a draft, unless the earlier launch had reached the point where the reply could go out, which iOS records before the app publishes; then it only says the reply may not have sent, so it can't be posted twice. A reply whose community has since been removed, including by signing out, keeps no draft: its text survives only in its "Reply not sent" notification, which a later launch posts too for a reply an earlier one was given. iOS forgets the reply only once that notification is posted; if iOS refuses it, the next launch tries again. Signing back in to the same community doesn't bring it back, because the community is added again under a new identity. Each reply also remembers the account its notification was for, and is sent or kept as a draft only while its community still signs as that account. No sign-in path today replaces a community's account in place (signing in again as another account adds a new community), so this guards that invariant against a future one: a reply typed for the earlier account would survive only in its "Reply not sent" notification, never sent or kept as the new account's draft. A reply to a notification from a build that didn't record its account is checked only by its community. A community this build hides but still stores ([ADR 0001](0001-internal-and-public-mobile-builds.md)) is not gone: its reply stays with iOS for a build that shows it.
A reply has one deadline, set when iOS hands it to the app, about 25 seconds later. The app checks the deadline at the moment the message goes out, after any wait including a rate limit's, and publishes only while there's still time to hear the relay's answer before it. iOS also refuses to let a reply go out once it has ended it as not sent. So a reply reported as not sent was never published, or the relay refused it, and retrying its draft can't post it twice. A reply that was published but got no answer may have gone out: the app says so ("Reply may not have sent") and keeps no draft, so iOS forgets it only once that notification is posted. iOS says the same when the deadline passes after the app recorded that the reply could go out.
Only a notification that shows a resolved channel or DM message offers Reply. A fallback notification that shows no message (for example "Open Buzz to view this message") offers none, whatever the reason for the fallback. There is no other per-account rule. Forum posts and comments don't offer Reply yet: a forum reply is a different kind of event with its own threading rules.
The reply is sent by the same app code as a reply typed in the app, so mentions, read state and drafts behave the same. That code runs only while the app's Flutter engine runs, and on iOS the engine starts only once the app creates its screen, which a background launch for a notification action doesn't do. So a reply typed while the app isn't running ends as "Reply not sent", and its text becomes a draft when the app next opens. The app closes its relay connection soon after going to the background, so a reply reopens it and waits a bounded time for it before sending. The connection stays open until the reply finishes, within a fixed limit, and then closes after the usual background grace period.
For now, only notifications from the community selected in the app offer Reply. Replying must not switch the selected community, and the app can currently reach only the selected community, so a notification from another one offers none. If the selection changes between the notification arriving and the reply being sent, the reply is treated as not sent, and its text is kept in the drafts of the community it came from. Ideally the selected community would decide only what the interface shows, not which writes are possible; replying in other communities can follow once the app can reach them without switching.
## Considered options
- **Reply at the same level as the notified message.** Rejected: a reply to a top-level message would then land in the channel's main flow, where it can read as a new topic and reach people who weren't part of the exchange. A subthread keeps it attached to the message it answers.
- **No automatic mention, typed `@name` resolved against channel members.** Rejected: typing an exact name without autocomplete is error-prone, and the person being answered is nearly always the one who should be notified.
- **Opening the app to send.** Rejected: it loses the main benefit of replying from the notification.
- **Sending from native code, without Flutter.** Rejected: it would duplicate the app's send, membership, read-state and draft logic in a second language for the sake of a background wake that the app's Flutter engine can handle once it's started.
## Consequences
A reply sent from a notification always notifies the sender of the message it answers, even in a DM, where the sender would be notified anyway.