Skip to content

fix(threads): notify the parent author when someone starts a thread - #8151

Open
jrainville wants to merge 6 commits into
developfrom
fix/first-thread-reply-standalone
Open

jrainville wants to merge 6 commits into
developfrom
fix/first-thread-reply-standalone

Conversation

@jrainville

Copy link
Copy Markdown
Member

Summary

Needed for status-im/status-app#23479

When someone else starts a thread on the user's message, the user now gets an Activity Center notification. Before, the app made this happen by sending the first thread message with the parent's ID as responseTo. That made the first message show as a quoted reply (status-im/status-app#23479). status-go now creates the notification itself from the message's threadId, so the app no longer needs responseTo.

Changes

  • Notification: in addNewActivityCenterNotification, a new message in a thread on the user's message, sent by someone else, creates a Reply notification. Its ReplyMessage is the parent message, so existing clients show it without changes.

  • Only once per thread: a new ClaimThreadStartNotification sets the threads.parent_author_notified flag in a single SQL update. It only succeeds if all of these hold:

    • the parent message is the user's and isn't deleted;
    • the user didn't create the thread;
    • the thread isn't deleted;
    • no earlier message from someone else exists in the thread.

    So the first message from someone else triggers it, even when messages arrive out of order or come from restored history.

  • No duplicates: if the first message already mentions or replies to the user, only that notification is created. The flag is still set, so nothing extra fires later.

  • Same rules as other notifications: muted and inactive chats, and community messages from before the user joined, are handled as for Mention and Reply. The chat check is moved into chatShowsMentionAndReplyActivityCenterNotifications so both paths share it.

  • Migration 1796213200_add_thread_parent_author_notified: adds the column and marks existing threads as already notified, so nobody gets a notification for an old thread.

Nothing changes in the messages sent between clients: no protobuf or wire changes.

Tests

  • TestMessengerActivityCenterMessageSuite/TestThreadStartNotifiesParentAuthorOnce, with two messengers in a group chat:
    • the first message from someone else creates one Reply notification pointing to the parent, without responseTo, and a second message creates none;
    • a first message that mentions the parent's author creates only a Mention notification;
    • no notification when the parent's author created the thread.
  • TestClaimThreadStartNotification: checks the ordering, parent-ownership, creator and "only once" rules.
  • The existing TestThreadMentionAndReplyNotifications, TestMutedThreadPreservesMentionAndReplyActivity and TestThreadMuteSuppressesOnlyOrdinaryThreadActivity still pass.

make test-single PKG=./internal/protocol TEST='TestMessengerActivityCenterMessageSuite': passes. The new "first message" test fails without the change in messenger.go.

Risk

  • Each installation decides on its own whether to notify, so a user with several devices may get the notification on each of them, the same as for other Mention and Reply notifications.
  • If creating this notification fails, the error is returned as for other notification errors, and the received batch is dropped. That is the existing behavior.

@jrainville
jrainville requested review from a team, friofry and micieslak and a balanced review from Copilot and removed request for a team December 3, 2026 21:13

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved thread-notification defects can notify thread creators, trigger notifications when Threads is disabled, and lose or misidentify parent context during edits or backup restoration.

4 open issues
What changed in this PR

Moves thread-start notifications into status-go, so clients no longer need a quoted reply to notify the parent author.

Changes:

  • Adds once-per-thread Reply notifications using shared notification eligibility rules.
  • Persists notification claims and marks existing threads as already notified.
  • Adds notification and persistence tests.
File Description
internal/​protocol/​migrations/​sqlite/​1796213200_add_thread_parent_author_notified.up.sql Adds and backfills the notification flag.
internal/​protocol/​messenger.go Creates thread-start notifications with parent context.
internal/​protocol/​messenger_activity_center_threads_test.go Tests notifications, deduplication, and claim eligibility.
internal/​protocol/​message_persistence.go Adds the atomic notification claim.
internal/​protocol/​activity_center.go Extracts shared chat eligibility checks.

Review effort: Balanced

Comment thread internal/protocol/messenger.go Resolved
Comment thread internal/protocol/messenger.go Resolved
Comment thread internal/protocol/messenger.go Resolved
@jrainville
jrainville force-pushed the fix/first-thread-reply-standalone branch from 2a9fdd6 to f976bb0 Compare December 4, 2026 15:36
@jrainville
jrainville requested a balanced review from Copilot December 4, 2026 15:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved thread-notification bugs can replace reply targets, overwrite mention and read state, generate incorrect legacy-thread notifications, and miss notifications when the parent arrives late.

4 open issues
4 resolved since last review

Review effort: Balanced

Comment thread internal/protocol/messenger.go Resolved
Comment thread internal/protocol/messenger.go Resolved
Comment thread internal/protocol/messenger_handler.go Resolved
Part of status-im/status-app#23479

When someone else starts a thread on the user's message, the first
message from another member now creates a Reply notification in the
Activity Center that points to the parent message. The first thread
message no longer has to set `responseTo` to the parent, so it is not
shown as a quoted reply.

- Add `threads.parent_author_notified` so the parent author is notified
  only once per thread. Existing threads are marked as already notified.
- Only the earliest message from another member can set the flag.
  Out-of-order delivery and restored history do not notify again.
- Skip the notification when the user created the thread, or when the
  first message already mentions or replies to them.
- Keep the existing rules for muted and inactive chats and for
  community messages sent before the user joined.
- Only notify the parent author when the Threads feature is enabled.
- Load the parent from the thread's stored parent message ID, since
  restored threads can use a different thread ID.
- Keep the parent message when the first thread message is edited
  while its notification is unread.
… author

A thread message received before the thread's creation metadata has no
known creator yet. Notifying then could tell the parent author that
someone else started a thread they created on another device.

- Skip the thread start claim while the thread's creator is pending.
- When the creation metadata sets the creator, notify the parent author
  for the earliest message from someone else, if the thread was not
  created by them and that message did not already mention or reply to
  them.
- Share the notification building between the received message and the
  creation metadata paths.
@jrainville
jrainville force-pushed the fix/first-thread-reply-standalone branch from f976bb0 to ac0bf00 Compare December 4, 2026 18:00
@jrainville
jrainville requested a lite review from Copilot December 4, 2026 18:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate active findings remain: the clock-only predicate can choose the wrong tied message, and the notification claim can suppress retries when post-claim work fails.

2 open issues
4 resolved since last review

Review effort: Lite

Comment thread internal/protocol/messenger.go Resolved
…lace their parent on edit

- Only claim the thread start notification when the thread's creator is
  recorded and is someone else. Restored threads without a creator may
  have been created by the parent author.
- Keep the thread's parent in a thread start notification when the first
  message is edited, also when that message quotes another message.
When the thread creation metadata arrives after the first message, check
whether that message already has a notification instead of inferring it
from its current content. Edits can add or remove a mention before the
metadata arrives.
Match claim ordering to the earliest-message lookup when clocks tie, and
persist the notification with its claim so failed saves remain retryable.
@jrainville
jrainville force-pushed the fix/first-thread-reply-standalone branch from ac0bf00 to d2a1f0a Compare December 4, 2026 18:44
@jrainville
jrainville requested a lite review from Copilot December 4, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two moderate active findings identify notification paths that can permanently miss thread-start alerts when messages or creation metadata arrive through different sync and archive orders.

2 open issues
2 resolved since last review

Review effort: Lite

Comment on lines +3312 to +3315
parent, err := m.persistence.MessageByID(thread.ParentMessageID)
if errors.Is(err, common.ErrRecordNotFound) {
return nil
}
Comment on lines +1975 to +1977
// Messages from others may have arrived before the creator was known.
if creatorResolved && !state.CurrentMessageState.FromArchive {
if err := m.notifyThreadStartAfterCreation(state.Response, chat, metadata.ThreadId); err != nil {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants