-
Notifications
You must be signed in to change notification settings - Fork 906
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
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7105a20
fixes notifications not being marked as read when the last chunk cont…
ouchadam 49e332c
formatting
ouchadam a3c4f56
adding changelog entry
ouchadam f9d2f23
using named parameters when the same types are used in close proximity
ouchadam c72f668
replacing boolean constants with an improved function name + doc arou…
ouchadam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Fixes notifications not dismissing when reading messages on other devices |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| internal fun isEventRead(realmConfiguration: RealmConfiguration, | ||
| userId: String?, | ||
| roomId: String?, | ||
|
|
@@ -39,10 +42,7 @@ internal fun isEventRead(realmConfiguration: RealmConfiguration, | |
| val liveChunk = ChunkEntity.findLastForwardChunkOfRoom(realm, roomId) ?: return@use | ||
| val eventToCheck = liveChunk.timelineEvents.find(eventId) | ||
| isEventRead = when { | ||
| eventToCheck == null -> { | ||
| // This can happen in case of fast lane Event | ||
| false | ||
| } | ||
| eventToCheck == null -> handleMissingEvent(realm, liveChunk, roomId, userId, eventId) | ||
| eventToCheck.root?.sender == userId -> true | ||
| else -> { | ||
| val readReceipt = ReadReceiptEntity.where(realm, roomId, userId).findFirst() | ||
|
|
@@ -59,6 +59,25 @@ internal fun isEventRead(realmConfiguration: RealmConfiguration, | |
| return isEventRead | ||
| } | ||
|
|
||
| private fun handleMissingEvent(realm: Realm, latestChunkEntity: ChunkEntity, roomId: String, userId: String, eventId: String): Boolean { | ||
| return if (realm.doesEventExistInChunkHistory(eventId) && realm.hasReadReceiptInLatestChunk(latestChunkEntity, roomId, userId)) { | ||
| MARK_OLD_EVENT_AS_READ | ||
| } else { | ||
| // This can happen when fast lane events are displayed before the database finishes updating | ||
| MARK_UNREAD_DUE_TO_FASTLANE | ||
| } | ||
| } | ||
|
|
||
| private fun Realm.doesEventExistInChunkHistory(eventId: String): Boolean { | ||
| return ChunkEntity.findIncludingEvent(this, eventId) != null | ||
| } | ||
|
|
||
| private fun Realm.hasReadReceiptInLatestChunk(latestChunkEntity: ChunkEntity, roomId: String, userId: String) : Boolean { | ||
| return ReadReceiptEntity.where(this, roomId, userId).findFirst()?.let { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 will do |
||
| latestChunkEntity.timelineEvents.find(it.eventId) | ||
| } != null | ||
| } | ||
|
|
||
| internal fun isReadMarkerMoreRecent(realmConfiguration: RealmConfiguration, | ||
| roomId: String?, | ||
| eventId: String?): Boolean { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
handleMissingEventis the wrong name, renaming tohasReadMissingEventallows us to infer the return result ishas readorhas not readThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4a51583