Commit 6bd5c27
fix(notifications): personalize embedded users in related response (#14366)
## Summary
- Regenerate `@audius/sdk` to pick up the new `user_id` query parameter
and renamed path placeholder on `GET /notifications/{id}` and `GET
/notifications/{id}/playlist_updates` (api PRs
[AudiusProject/api#837](AudiusProject/api#837) +
[AudiusProject/api#838](AudiusProject/api#838),
both merged).
- Pass the current user id through every call site so the backend
personalizes embedded `related.users` in the response
(`does_current_user_follow`, etc.).
## Why
The notifications endpoint embeds user objects in `related.users`. The
backend personalizes those via `MyID: app.getMyId(c)` in
[`api/v1_notifications.go:336`](https://github.com/AudiusProject/api/blob/main/api/v1_notifications.go#L336),
and
[`getMyId`](https://github.com/AudiusProject/api/blob/main/api/resolve_middleware.go#L30)
reads from the **query string** `?user_id=`, not the URL path. The SDK
only put the id in the path, so on the backend `MyID = 0` and the SQL
[short-circuited](https://github.com/AudiusProject/api/blob/main/api/dbv1/get_users.sql.go#L129-L136)
`does_current_user_follow` to `false` for every embedded user.
On a cold app boot, `useNotifications` fires early and
`primeRelatedData` writes those un-personalized users into the tan-query
cache. `primeUserData` only writes when the slot is empty (no
`forceReplace`), so the bad entries stick until the user navigates to
that profile and a personalized `getUser` fetch overwrites the cache.
That's why visiting `@audius` directly and refreshing makes the
Following state appear correct.
A backend-only fix would collapse two semantically distinct ids
(notifications owner vs. requester) — incorrect when a manager reads a
managed user's notifications. The fix is client-side: send the requester
id as `?user_id=`, keep the path id for whose notifications.
## Changes
| File | Change |
| --- | --- |
| `packages/sdk/src/sdk/api/generated/default/apis/NotificationsApi.ts`
| Regenerated. Path field renames `userId` → `id`; new `userId?: string`
query field carries the requester id. |
| `packages/sdk/src/sdk/api/generated/default/apis/UsersApi.ts` |
Incidental drift: `getUserForYouFeed` was removed upstream and the
generated copy was stale. |
| `packages/common/src/api/tan-query/notifications/useNotifications.ts`
| Pass `{ id, userId }` to the SDK. |
|
`packages/common/src/api/tan-query/notifications/useNotificationUnreadCount.ts`
| Update local cast type and call site to use `id` as the path field.
(No requester id passed here — the unread count doesn't hydrate
`related.users`.) |
|
`packages/common/src/api/tan-query/playlist-updates/usePlaylistUpdates.ts`
| Pass `{ id, userId }` to the SDK; widen the local cast type. |
## Breaking SDK change (external consumers)
The path field on `GetNotificationsRequest` and
`GetPlaylistUpdatesRequest` renames from `userId` to `id`. External
`@audius/sdk` consumers of these two methods will need to rename the
field. Wire format and server behaviour are unchanged.
## Test plan
- [ ] CI green (typecheck/lint/tests).
- [ ] On a fresh app load with a signed-in account that follows
`@audius`: confirm Following state renders correctly on lists hydrated
from notification responses (e.g. notification panel actor avatars,
recommended profiles surfaced from related users) without first having
to navigate to `@audius`'s profile.
- [ ] Network inspector on the notifications request shows
`?user_id=<hashed-current-user-id>` and `does_current_user_follow: true`
for users actually followed in `related.users`.
- [ ] Manager flow: read notifications while acting as a managed user.
`?user_id=` carries whatever the app treats as "current user" (the
managed user in normal manager-switched state); personalization in the
response reflects that perspective.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>1 parent a80d544 commit 6bd5c27
6 files changed
Lines changed: 51 additions & 75 deletions
File tree
- .changeset
- packages
- common/src/api/tan-query
- notifications
- playlist-updates
- sdk/src/sdk/api/generated/default/apis
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
79 | 83 | | |
80 | 84 | | |
81 | 85 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| 41 | + | |
| 42 | + | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | | - | |
| 46 | + | |
| 47 | + | |
45 | 48 | | |
46 | 49 | | |
47 | 50 | | |
| 51 | + | |
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
| |||
Lines changed: 18 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
| 29 | + | |
| 30 | + | |
30 | 31 | | |
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
| 38 | + | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
| |||
47 | 49 | | |
48 | 50 | | |
49 | 51 | | |
50 | | - | |
51 | | - | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
56 | 62 | | |
57 | 63 | | |
58 | 64 | | |
| |||
72 | 78 | | |
73 | 79 | | |
74 | 80 | | |
75 | | - | |
| 81 | + | |
76 | 82 | | |
77 | 83 | | |
78 | 84 | | |
| |||
94 | 100 | | |
95 | 101 | | |
96 | 102 | | |
97 | | - | |
98 | | - | |
| 103 | + | |
| 104 | + | |
99 | 105 | | |
100 | 106 | | |
101 | 107 | | |
102 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
103 | 113 | | |
104 | 114 | | |
105 | 115 | | |
106 | | - | |
| 116 | + | |
107 | 117 | | |
108 | 118 | | |
109 | 119 | | |
| |||
Lines changed: 0 additions & 64 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
686 | 686 | | |
687 | 687 | | |
688 | 688 | | |
689 | | - | |
690 | | - | |
691 | | - | |
692 | | - | |
693 | | - | |
694 | | - | |
695 | | - | |
696 | | - | |
697 | 689 | | |
698 | 690 | | |
699 | 691 | | |
| |||
4175 | 4167 | | |
4176 | 4168 | | |
4177 | 4169 | | |
4178 | | - | |
4179 | | - | |
4180 | | - | |
4181 | | - | |
4182 | | - | |
4183 | | - | |
4184 | | - | |
4185 | | - | |
4186 | | - | |
4187 | | - | |
4188 | | - | |
4189 | | - | |
4190 | | - | |
4191 | | - | |
4192 | | - | |
4193 | | - | |
4194 | | - | |
4195 | | - | |
4196 | | - | |
4197 | | - | |
4198 | | - | |
4199 | | - | |
4200 | | - | |
4201 | | - | |
4202 | | - | |
4203 | | - | |
4204 | | - | |
4205 | | - | |
4206 | | - | |
4207 | | - | |
4208 | | - | |
4209 | | - | |
4210 | | - | |
4211 | | - | |
4212 | | - | |
4213 | | - | |
4214 | | - | |
4215 | | - | |
4216 | | - | |
4217 | | - | |
4218 | | - | |
4219 | | - | |
4220 | | - | |
4221 | | - | |
4222 | | - | |
4223 | | - | |
4224 | | - | |
4225 | | - | |
4226 | | - | |
4227 | | - | |
4228 | | - | |
4229 | | - | |
4230 | | - | |
4231 | | - | |
4232 | | - | |
4233 | | - | |
4234 | 4170 | | |
4235 | 4171 | | |
4236 | 4172 | | |
| |||
0 commit comments