cinnyapp / cinny

Yet another matrix client
https://cinny.in
GNU Affero General Public License v3.0
1.9k stars 244 forks source link

Notifications not sent on edge case #1892

Open TrojanerHD opened 1 month ago

TrojanerHD commented 1 month ago

Describe the bug

Upon someone sending a message and you opening the room, then unfocusing / changing the room again and someone sending a message with the same amount of highlights in the same room directly afterward, no notification about the message is shown

Reproduction

You need two accounts (A1, A2)

  1. Open Cinny with A1 while not in the test room
  2. Send a message with A2 into the test room (you should get a notification in Cinny)
  3. Open the room with A1
  4. Close the room again (e.g. click on Home)
  5. Send another message with A2 into the test room
  6. A1 gets no notification in Cinny

Expected behavior

A1 should get a notification

Platform and versions

1. OS: Arch Linux
2. Browser: LibreWolf
3. Cinny version: https://github.com/cinnyapp/cinny/commit/5058136737e177a5cabecc8b53b489eaabc23429 (dev branch at time of writing)
4. Matrix homeserver: A1: matrix.org, A2: trojaner.dev

Additional context

A friend noticed he didn't get notifications consistently so I dug into the code and found a problem in this snippet: https://github.com/cinnyapp/cinny/blob/e68c56b334107862ab2eec5635c11c40c050f00b/src/app/pages/client/ClientNonUIFeatures.tsx#L201-L211

Assume, you get a notification with unreadInfo = { total: 1, room_id: <test room id>, highlight: 0 }. unreadCacheRef is set to that info directly afterward. So far, so good.

You then read the message and another message is sent into the room. Now, an unreadInfo with the same parameters is retrieved, thus the check below is true (as now the cachedUnreadInfo is set to unreadCacheRef, i.e., the previous unreadInfo). So the function returns instead of sending a notification. I could reproduce this exact problem by building from source and setting a debugger in LibreWolf which would, in fact, exit this function exactly there.