Skip to content

Add the notification activity remote and service - #26076

Merged
crazytonyli merged 3 commits into
trunkfrom
task/notification-activity-remote
Oct 13, 2026
Merged

crazytonyli merged 3 commits into
trunkfrom
task/notification-activity-remote

Conversation

@crazytonyli

@crazytonyli crazytonyli commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Description

applicationIconBadgeNumber is deprecated. The Notifications bell and tab badge need shared account-scoped state so they no longer depend on reading the app icon badge count. The next PR connects this service to the UI.

WordPress.com's has_unseen_notes flag indicates notification activity since the account last marked Notifications as seen, including on another client. It supplies the new-activity state for the bell and tab badge. “Seen” records a visit to Notifications; individual notifications keep their read/unread status.

  1. NotificationActivityService fetches this flag and preserves the last known value when a request fails.
  2. The service supports clearing the local indicator and submitting the newest notification timestamp to notifications/seen when Notifications opens. Pending updates survive restarts and retry after transient failures. A timestamp the server rejects is dropped, because retrying the same value cannot succeed.
  3. Account changes discard saved state and late responses from the previous session.

The existing iOS client sends an ISO 8601 date string, but notifications/seen expects Unix seconds. The server converts a string beginning with "2026-" to 2026, so it can report success without advancing the last-seen timestamp. NotificationActivityServiceRemote converts the date to Unix seconds before submitting it. The next PR switches callers to the new service and removes the old implementation.

Scenarios

Each item is a situation a user can hit, what the service does, and why.

New activity arrives while the app is open. A push, a PingHub event, or a completed notification sync is a reason to refresh, not proof of new activity: an edited old note or a mark-seen from another device produces the same signals. The service re-fetches has_unseen_notes instead of setting the bell directly.

The user opens Notifications. The bell clears immediately and locally, before any network call. The newest timestamp the list actually shows is sent to notifications/seen. Opening a list that has not loaded yet clears locally but sends nothing; a fabricated timestamp could mark unseen content seen.

A refresh that started before the user opened Notifications finishes afterwards. A revision counter advances on every local clear and activity event. A fetch whose starting revision is stale is discarded and repeated, so a slow response carrying the pre-visit true cannot relight a bell the user just cleared. This is the regression that reverted the earlier badge migration (#24877, #24928).

Notifications stays on screen. No fetch runs while a list is visible, because the bell is held clear regardless. Leaving the screen triggers the refresh. On iPad a new list can appear before the old one disappears, so visibility is counted per list.

The user opened Notifications while offline. The local clear and the pending seen timestamp are persisted and survive a relaunch. The next foreground, reconnect, or activity trigger retries the write, with no attempt limit for transient failures. No fetch runs while the write is pending: the server would still report the pre-visit true.

The server rejects the seen timestamp. The timestamp is dropped after one rejection and the flag is re-fetched. Retrying the same value cannot succeed, and a timestamp kept pending would block every refresh forever, even after a relaunch.

The visible list loads newer content. The newer timestamp replaces the pending one. Seen only moves forward: anything at or before the acknowledged timestamp is skipped, and one write is in flight at a time.

The seen write succeeds. The acknowledged timestamp advances, a newer pending timestamp drains first, and then the flag is re-fetched, so activity newer than the visit can light the bell again.

The user viewed Notifications on the web or another device. has_unseen_notes is account-wide, so the next refresh clears this device's bell.

A refresh fails. Transport, authentication, and decoding errors keep the last known state. A missing or non-Boolean has_unseen_notes is an error rather than false, so a bad response cannot invent a cleared bell.

Push notifications or app badges are disabled. The bell is driven by the WordPress.com flag and does not depend on either.

The app relaunches. The saved snapshot restores only when its account UUID matches the current default account, so the last known bell state is available before the first fetch, including offline.

The user signs out or switches accounts. Saved state and the pending write are discarded, and the per-account session is replaced. A late response or a list callback still bound to the previous account is ignored, so it cannot mark the new account seen with the old account's timestamp. Signing back into the same account starts fresh.

The token is invalidated without an account change. WPAccount.handleInvalidToken posts the same notification as an account change. The service sees the same account UUID and keeps the session, including the pending seen write; network work pauses until credentials return. A same-account re-auth posts nothing the service observes, so every account-gated entry point re-resolves credentials itself.

The app is in the background. Refreshes and seen retries wait for the foreground.

@dangermattic

dangermattic commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator
1 Warning
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.

Generated by 🚫 Danger

@crazytonyli crazytonyli changed the title task/notification activity remote Add a WordPress.com remote for notification activity Sep 24, 2026
@crazytonyli crazytonyli changed the title Add a WordPress.com remote for notification activity Add the notification activity remote and service Sep 24, 2026
@wpmobilebot

wpmobilebot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number34949
VersionPR #26076
Bundle IDorg.wordpress.alpha
Commita06319d
Installation URL5ttkgd47pfs28
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number34949
VersionPR #26076
Bundle IDcom.jetpack.alpha
Commita06319d
Installation URL3gu2c17m24t8g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli
crazytonyli removed this pull request from stack #26079 September 24, 2026 09:22
@crazytonyli
crazytonyli force-pushed the task/notification-activity-remote branch 2 times, most recently from a35bf26 to 07b84ed Compare September 25, 2026 03:59
@crazytonyli crazytonyli added this to the 27.4 milestone Sep 25, 2026
@crazytonyli
crazytonyli marked this pull request as ready for review September 25, 2026 04:50
Base automatically changed from bugfix/notification-sync-account-guard to trunk October 13, 2026 04:38
Callers can then tell a client error from a server error when the error code is unrecognized.
Add NotificationActivityServiceRemote to WordPressKit: a focused GET me?fields=has_unseen_notes for the account-wide unseen-notifications flag and a POST notifications/seen. A missing or malformed has_unseen_notes is an error, not false, so callers can preserve the last known state. The seen time is sent as Unix seconds, because the endpoint casts it to an integer. Only success true acknowledges a seen write; client errors that a retry cannot fix are reported as rejections.
Introduce NotificationActivityService, the single main-actor owner of the in-app Notifications bell: an observable has_unseen_notes flag, the local clear on opening Notifications, and the sole notifications/seen submit-and-retry. It refreshes on foreground, sync updates, and PingHub activity and reconnects. Per-account work lives in a private session object that the service replaces on sign-out or account change, so a stale result cannot reach the new account; a revision guard discards a fetch that raced a local clear. Seen timestamps never move backward, and only rejected seen writes count toward a persisted cap. NotificationActivityStore persists an account-scoped snapshot.
@crazytonyli
crazytonyli force-pushed the task/notification-activity-remote branch from 07b84ed to a06319d Compare October 13, 2026 04:39
@crazytonyli
crazytonyli added this pull request to the merge queue Oct 13, 2026
Merged via the queue into trunk with commit 2c5d8a7 Oct 13, 2026
28 checks passed
@crazytonyli
crazytonyli deleted the task/notification-activity-remote branch October 13, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants