Skip to content

feat: keep the chosen notification kinds on the user, so the API counts them too - #1592

Draft
simonhamp wants to merge 1 commit into
dev-null-sh:productionfrom
simonhamp:feat/stored-notification-types
Draft

simonhamp wants to merge 1 commit into
dev-null-sh:productionfrom
simonhamp:feat/stored-notification-types

Conversation

@simonhamp

Copy link
Copy Markdown
Contributor

Summary

The notifications page remembers which kinds you want to see (Replies, Quotes, Stars, Mentions, Follows, Moderation) in a cookie per user. The API can't read that cookie, so every unread_notifications_count the API sends counts every kind. In the mobile app (NativePHP/dev-null-app#178) you pick the kinds on a settings screen, but the badge on the Notifications tab still counts the ones you turned off.

This keeps the choice on the user instead, so the web, the API and every browser see the same one.

Changes

  • New nullable users.notification_types column. It holds the same value ?type= takes: all, none or a comma list. null means never chosen and shows everything.
  • ListNotificationsRequest::type() saves the choice through a new UpdateUserNotificationTypes action instead of queuing a cookie. rememberedType() reads the column. If the column is still empty and the browser has a valid old cookie, it takes that value over and expires the cookie, so nobody loses their filter on deploy.
  • The action only writes and sends UsersUpdated (UserUpdate::Notifications) when the value actually changes, so paging through the list with the same ?type= does nothing extra. When it does change, other open tabs refresh their count.
  • NotificationGroupsQuery::unreadCount() now defaults to the user's saved kinds instead of all. That covers every API controller that adds unread_notifications_count, without touching each one. Passing a type still overrides it.
  • GET /api/v1/notifications?type=... now saves the type too, the same as the web. Without ?type= it lists the saved kinds, as the web does.
  • GET /api/v1/me/settings has notification_types, and the data export has it under profile.
  • One line in the signed API list in KNOWLEDGE_BASE.md, and the notifications paragraph now says the filter follows the account.

API

PUT /api/v1/me/notification-types, signed like the rest of /api/v1/me.

{ "type": "replies,mentions" }

type is required and takes the same values as the list's ?type=. It answers 200 with the saved value and the unread count, which now only counts those kinds:

{ "data": { "type": "replies,mentions" }, "unread_notifications_count": 3 }

A bad value gets 422 with errors.type. Unsigned requests get 401.

Validation

Local, PHP 8.5.12, PostgreSQL with its own test database:

  • vendor/bin/pint --test on the changed files: pass
  • rector --dry-run: pass
  • phpstan: pass, no errors
  • pest --type-coverage --min=100: 100%
  • Relevant files (NotificationInboxTest, the new UserNotificationTypesControllerTest, ExportControllerTest, HandleInertiaRequestsTest, NotificationGroupsQueryTest, all of tests/Feature/Controllers/Api): 1158 passed
  • Whole suite, serially with --ci: 6126 tests, 6107 passed and 19 failed. All 19 are in tests/Feature/CommitScriptTest.php and fail the same way on unchanged production here (the shell script sandbox doesn't run on this machine), so they are not from this change. The suite ran with all three of my API PRs merged together.
  • Coverage: not run, there is no coverage driver (pcov or Xdebug) on this machine. Every new branch has a test, but CI is the real check.
  • bun run test:unit, test:lint, test:types: not run, no JS or TS changed.

Independent review

A read-only Claude review agent with the repo's .ai/guidelines and the diff against production at 2ef29e7, head 7df935e: CODE: PASS. It pointed out two things to decide on, both covered above: the API list now saves ?type=, and the first cookie takeover writes during a GET (once per user). Visual review doesn't apply, the web UI is unchanged.

Limitations

  • An older app build that never sends ?type= will now get the user's saved kinds instead of everything. The app's next release reads and sets them.
  • If someone's first visit after deploy is to the list with a new ?type=, their old cookie stays until it expires. It is never read again.

…ts them too

The web kept the Replies/Quotes/Stars/Mentions/Follows/Moderation choice in a
cookie per browser, so the API could not read it and every
unread_notifications_count it sent counted every kind. The choice now lives
in users.notification_types, a browser's old cookie is taken over the first
time it is seen, and PUT /api/v1/me/notification-types lets apps change it.
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

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.

1 participant