Do not send read requests for notifications already read #3604

Merged
hj merged 1 commit from fix/notifications-read-spam into develop 2026-11-05 15:35:32 +00:00

Every click inside a mention notification (expand, link, reply box) sent POST /api/v1/pleroma/notifications/read, also when the notification was already read. "Mark all as read" and closing the mobile drawer also sent it when nothing was unread. This easily trips rate limits on that endpoint.

Now markSingleNotificationAsSeen skips notifications that are already read, and markNotificationsAsSeen skips when all loaded notifications are read.

Testing

  • New test/unit/specs/stores/notifications_read_requests.spec.js (fails without the fix)
  • Full unit suite passes headless
Every click inside a mention notification (expand, link, reply box) sent `POST /api/v1/pleroma/notifications/read`, also when the notification was already read. "Mark all as read" and closing the mobile drawer also sent it when nothing was unread. This easily trips rate limits on that endpoint. Now `markSingleNotificationAsSeen` skips notifications that are already read, and `markNotificationsAsSeen` skips when all loaded notifications are read. ## Testing - New `test/unit/specs/stores/notifications_read_requests.spec.js` (fails without the fix) - Full unit suite passes headless
fix(notifications): no read request for notifications already read
All checks were successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/changelog Pipeline was successful
ci/woodpecker/pr/lint Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/test-e2e Pipeline was successful
3d7a44a4e2
Author
Owner

/oc review

/oc review
hj approved these changes 2026-11-05 14:10:59 +00:00
opencode-fix-bot left a comment

opencode-agent:job=170:generation=1

Verdict

No defects introduced by this pull request. Merge-readiness rating: 5/5 — production-ready.

What the change does

  • src/stores/notifications.js (markSingleNotificationAsSeen): returns early when the notification is already seen, so repeat clicks inside an already-read mention send no further POST /api/v1/pleroma/notifications/read requests.
  • src/stores/notifications.js (markNotificationsAsSeen): returns early when every loaded notification is already seen, so "mark all as read" and mobile-drawer close send nothing when there is nothing unread.
  • New test/unit/specs/stores/notifications_read_requests.spec.js covers all three behaviors.

Why it is correct

  • The single-notification path sets seen = true synchronously before the async API call, so a second click deterministically observes the flag and skips — the "many clicks, one request" test pins this down.
  • The bulk path checks this.data, whose entries are the same object references held in idStore, so the two guards cannot disagree about seen-state in normal flow.
  • Empty store is safe: [].every(...) is true, so no request with an empty max_id is sent.
  • Verified call sites: mention clicks reach the guard via notificationInteracted in src/components/notifications/notifications.js:227-230; article clicks go through notificationClicked in src/components/notifications/notifications.js:223-226; drawer close and "mark all" go through the bulk path (src/components/mobile_nav/mobile_nav.js:118-119, src/components/notifications/notifications.js:231-234).
  • Failure handling is unchanged from before (optimistic local seen marking, no rollback); no new error path is introduced.

Validation

  • New spec test/unit/specs/stores/notifications_read_requests.spec.js: 3/3 passed (vitest browser mode, headless Chromium).
  • Existing test/unit/specs/stores/notifications.spec.js: 17/17 passed, no regressions.
  • Worktree kept byte-for-byte at the claimed head; no code was modified as part of this review.
opencode-agent:job=170:generation=1 ### Verdict No defects introduced by this pull request. Merge-readiness rating: 5/5 — production-ready. ### What the change does - `src/stores/notifications.js` (`markSingleNotificationAsSeen`): returns early when the notification is already `seen`, so repeat clicks inside an already-read mention send no further `POST /api/v1/pleroma/notifications/read` requests. - `src/stores/notifications.js` (`markNotificationsAsSeen`): returns early when every loaded notification is already `seen`, so "mark all as read" and mobile-drawer close send nothing when there is nothing unread. - New `test/unit/specs/stores/notifications_read_requests.spec.js` covers all three behaviors. ### Why it is correct - The single-notification path sets `seen = true` synchronously before the async API call, so a second click deterministically observes the flag and skips — the "many clicks, one request" test pins this down. - The bulk path checks `this.data`, whose entries are the same object references held in `idStore`, so the two guards cannot disagree about seen-state in normal flow. - Empty store is safe: `[].every(...)` is `true`, so no request with an empty `max_id` is sent. - Verified call sites: mention clicks reach the guard via `notificationInteracted` in `src/components/notifications/notifications.js:227-230`; article clicks go through `notificationClicked` in `src/components/notifications/notifications.js:223-226`; drawer close and "mark all" go through the bulk path (`src/components/mobile_nav/mobile_nav.js:118-119`, `src/components/notifications/notifications.js:231-234`). - Failure handling is unchanged from before (optimistic local `seen` marking, no rollback); no new error path is introduced. ### Validation - New spec `test/unit/specs/stores/notifications_read_requests.spec.js`: 3/3 passed (vitest browser mode, headless Chromium). - Existing `test/unit/specs/stores/notifications.spec.js`: 17/17 passed, no regressions. - Worktree kept byte-for-byte at the claimed head; no code was modified as part of this review.
hj merged commit 3c09397a5d into develop 2026-11-05 15:35:32 +00:00
hj deleted branch fix/notifications-read-spam 2026-11-05 15:35:32 +00:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
pleroma/pleroma-fe!3604
No description provided.