Commit 86a3ccb
authored
fix: fetch room/sender avatar and display name for push notifications (#551)
### Description
When the pusher is configured with `event_id_only` format, the service
worker fetches event details itself rather than receiving them in the
push payload. Previously only the sender display name and room name were
retrieved — `room_avatar_url` was always `undefined`, so every
notification showed the default app logo regardless of whether the room
or sender had an avatar set. Display names could also be stale in the
encrypted path when the app resumed from a cold state.
**Changes in `src/sw.ts`:**
- `fetchMemberDisplayName` → `fetchMemberInfo`: the same single HTTP
request to `m.room.member` state now also extracts `avatar_url`, giving
both display name and sender avatar for free
- `fetchRoomAvatar`: new helper that fetches the `m.room.avatar` state
event URL
- `mxcToNotificationUrl`: converts `mxc://` to a legacy unauthenticated
thumbnail URL (`/_matrix/media/v3/thumbnail/…`) so the OS can load the
notification icon without an auth header
- `handleMinimalPushPayload`: room avatar is now fetched in the initial
parallel batch alongside the event and room name; icon is resolved as
room avatar → member avatar (DM fallback) → default logo;
`room_avatar_url` passed to all `handlePushNotificationPushData` call
sites
- Encrypted relay path now uses the server-fetched `senderDisplay`
(authoritative) rather than the SDK cache value from the relay, which
can be absent or stale when the app hasn't fully synced after a cold
resume
Fixes #
#### Type of change
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
### Checklist:
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
### AI disclosure:
- [ ] Partially AI assisted (clarify which code was AI assisted and
briefly explain what it does).
- [x] Fully AI generated (explain what all the generated code does in
moderate detail).
`fetchMemberInfo` extends the existing member state fetch to also return
`avatar_url`. `fetchRoomAvatar` GETs `m.room.avatar` state.
`mxcToNotificationUrl` builds a legacy `/_matrix/media/v3/thumbnail/`
URL (no auth required, OS-loadable) from an `mxc://` URI.
`handleMinimalPushPayload` adds `fetchRoomAvatar` to its parallel fetch
batch, resolves the notification icon with room > member > default
priority, and passes it through as `room_avatar_url` to every
`handlePushNotificationPushData` invocation. The encrypted relay path is
updated to prefer the server-fetched display name over the relay's
potentially-stale SDK cache value.2 files changed
Lines changed: 77 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
277 | 277 | | |
278 | 278 | | |
279 | 279 | | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
280 | 285 | | |
281 | | - | |
282 | | - | |
| 286 | + | |
| 287 | + | |
283 | 288 | | |
284 | | - | |
| 289 | + | |
285 | 290 | | |
286 | 291 | | |
287 | 292 | | |
288 | 293 | | |
289 | | - | |
| 294 | + | |
290 | 295 | | |
291 | 296 | | |
292 | 297 | | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
293 | 326 | | |
294 | 327 | | |
295 | | - | |
296 | | - | |
| 328 | + | |
| 329 | + | |
297 | 330 | | |
298 | 331 | | |
299 | 332 | | |
300 | 333 | | |
301 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
302 | 347 | | |
303 | 348 | | |
304 | 349 | | |
| |||
386 | 431 | | |
387 | 432 | | |
388 | 433 | | |
389 | | - | |
390 | | - | |
| 434 | + | |
| 435 | + | |
391 | 436 | | |
392 | 437 | | |
| 438 | + | |
393 | 439 | | |
394 | 440 | | |
395 | 441 | | |
| |||
406 | 452 | | |
407 | 453 | | |
408 | 454 | | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
414 | 461 | | |
415 | 462 | | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
416 | 469 | | |
417 | 470 | | |
418 | 471 | | |
| |||
432 | 485 | | |
433 | 486 | | |
434 | 487 | | |
| 488 | + | |
| 489 | + | |
435 | 490 | | |
436 | 491 | | |
437 | 492 | | |
438 | 493 | | |
439 | | - | |
| 494 | + | |
440 | 495 | | |
441 | 496 | | |
| 497 | + | |
442 | 498 | | |
443 | 499 | | |
444 | 500 | | |
| |||
448 | 504 | | |
449 | 505 | | |
450 | 506 | | |
| 507 | + | |
451 | 508 | | |
452 | 509 | | |
453 | 510 | | |
| |||
458 | 515 | | |
459 | 516 | | |
460 | 517 | | |
| 518 | + | |
461 | 519 | | |
462 | 520 | | |
463 | 521 | | |
| |||
0 commit comments