matrix-org / matrix-org/matrix-js-sdk

Sliding Sync RoomData overwrites notification counts

Open
#4,812 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-Notifications O-Occasional S-Minor T-Defect
Dominant language
TypeScript
Stars
2.2k
Forks
704
Avg merge
1d 20h
Merged PRs (30d)
40

Description

When using sliding sync, the notification counts will get overwritten by the RoomData handler.

https://github.com/matrix-org/matrix-js-sdk/blob/69f1bea89bf7becf45ae2fdb0a2fe60606413be2/src/sliding-sync-sdk.ts#L623-L625

This is assuming that the RoomData count is more accurate that what we have in the Room's state, but this isn't the case with encrypted rooms.
Below, the highlight counters are not being overwritten with encrypted rooms, but for some reason it isn't being done for regular notification counts.

I added some logging to the code to double check and here are the results:
```ts
if (roomData.notification_count != null) {
console.log(room.getUnreadNotificationCount(NotificationCountType.Total), roomData.notification_count);
room.setUnreadNotificationCount(NotificationCountType.Total, roomData.notification_count);
}
```
`10 0`

This lines up with what I'm seeing. On reload, the room shows 10 (I'm only getting the last 10 timeline events with Sliding Sync), and then when a new message comes in it's reset to 1

If we use the same encryption check as the highlight count, it works as expected. Is there a reason we shouldn't implement it the same way?
If not, I'm happy to open a PR with the change

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/sliding-sync-sdk.ts at lines 623-625 and compare the regular notification-count handling with the highlight-counter encryption check. Reproduce the reload and new-message sequence for an encrypted room, then verify that the existing notification count is not overwritten by a lower RoomData count.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.