Skip to content

Fixing notifications not being dismissed when read from other devices #4129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 1, 2021

Conversation

ouchadam
Copy link
Contributor

@ouchadam ouchadam commented Sep 30, 2021

Fixes #3347 and #523

Our notification dismissing works by matching the currently held notification events to the latest timeline chunk for the room, this presents a problem when the next chunk is created which doesn't reference those original notification events, which then presents itself as notifications not being dismissed when read from other sessions.

The fix is to check the existence of missing events against the entire chunk history if there's also a read receipt event in the latest chunk.

  • I was able to to reproduce the issue by spamming messages to force the timeline to create a new chunk

Here's the worlds least exciting gif... notice the element icon in the top

after-new-chunk

…aining the event is no longer the latest

- use explict returns constants to attempt to add more documentation
- queries for the existence of the event in all of the chunk history and if a read receipt exists in the latest chunk (which it should if a user has just read on another client) which allows us to mark old notifications events as read
@github-actions
Copy link

github-actions bot commented Sep 30, 2021

Unit Test Results

  42 files  ±0    42 suites  ±0   45s ⏱️ ±0s
  83 tests ±0    83 ✔️ ±0  0 💤 ±0  0 ±0 
220 runs  ±0  220 ✔️ ±0  0 💤 ±0  0 ±0 

Results for commit 2366227. ± Comparison against base commit 2366227.

♻️ This comment has been updated with latest results.

@bmarty bmarty requested a review from BillCarsonFr October 1, 2021 08:56
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That a really good catch, thanks!
I have not tested it, but I understand the idea.
See my 2 small remarks.

@@ -23,6 +23,9 @@ import org.matrix.android.sdk.internal.database.model.TimelineEventEntity
import io.realm.Realm
import io.realm.RealmConfiguration

private const val MARK_OLD_EVENT_AS_READ = true
private const val MARK_UNREAD_DUE_TO_FASTLANE = false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure declaring const for boolean returned value increases the readability of the code. Maybe a good comment is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I think this is a sign that the handleMissingEvent is the wrong name, renaming to hasReadMissingEvent allows us to infer the return result is has read or has not read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, roomId: String, userId: String) : Boolean {
return ReadReceiptEntity.where(this, roomId, userId).findFirst()?.let {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: The code is OK, but maybe use named arguments for roomId and userId to avoid confusion, since the types are the same (String)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯 will do

@ouchadam ouchadam force-pushed the feature/adm/sync-read-notifications branch from 4a51583 to c72f668 Compare October 1, 2021 15:22
Copy link
Member

@bmarty bmarty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update! It's more readable to me now!

@bmarty bmarty enabled auto-merge October 1, 2021 15:26
@bmarty bmarty merged commit 2366227 into develop Oct 1, 2021
@bmarty bmarty deleted the feature/adm/sync-read-notifications branch October 1, 2021 16:11
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.

Notification does not vanish if the message is read on another session
2 participants