From 03437885efb2f552fb89e3c5433262f044d55229 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 18 Feb 2019 17:41:21 +0100 Subject: [PATCH 1/3] Read receipts : fix issues with receipts not being sent --- .../session/room/read/SetReadMarkersTask.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt index f127966d3d..ba14d83c0e 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/internal/session/room/read/SetReadMarkersTask.kt @@ -56,8 +56,8 @@ internal class DefaultSetReadMarkersTask(private val roomAPI: RoomAPI, markers[READ_MARKER] = params.fullyReadEventId } if (params.readReceiptEventId != null - && MatrixPatterns.isEventId(params.readReceiptEventId) - && !isEventRead(params.roomId, params.readReceiptEventId)) { + && MatrixPatterns.isEventId(params.readReceiptEventId) + && !isEventRead(params.roomId, params.readReceiptEventId)) { updateNotificationCountIfNecessary(params.roomId, params.readReceiptEventId) markers[READ_RECEIPT] = params.readReceiptEventId @@ -73,10 +73,10 @@ internal class DefaultSetReadMarkersTask(private val roomAPI: RoomAPI, private fun updateNotificationCountIfNecessary(roomId: String, eventId: String) { monarchy.tryTransactionAsync { realm -> - val isLatestReceived = EventEntity.latestEvent(realm, eventId)?.eventId == eventId + val isLatestReceived = EventEntity.latestEvent(realm, roomId)?.eventId == eventId if (isLatestReceived) { val roomSummary = RoomSummaryEntity.where(realm, roomId).findFirst() - ?: return@tryTransactionAsync + ?: return@tryTransactionAsync roomSummary.notificationCount = 0 roomSummary.highlightCount = 0 } @@ -87,11 +87,11 @@ internal class DefaultSetReadMarkersTask(private val roomAPI: RoomAPI, var isEventRead = false monarchy.doWithRealm { val readReceipt = ReadReceiptEntity.where(it, roomId, credentials.userId).findFirst() - ?: return@doWithRealm + ?: return@doWithRealm val liveChunk = ChunkEntity.findLastLiveChunkFromRoom(it, roomId) - ?: return@doWithRealm + ?: return@doWithRealm val readReceiptIndex = liveChunk.events.find(readReceipt.eventId)?.displayIndex - ?: -1 + ?: Int.MAX_VALUE val eventToCheckIndex = liveChunk.events.find(eventId)?.displayIndex ?: -1 isEventRead = eventToCheckIndex >= readReceiptIndex } From c42294a21eed05c9de1f6606cd331e2d979a7c53 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 18 Feb 2019 17:41:35 +0100 Subject: [PATCH 2/3] Handle room v3 event id format --- .../java/im/vector/matrix/android/api/MatrixPatterns.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt index 57edfc7ccf..922cd320f9 100644 --- a/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt +++ b/matrix-sdk-android/src/main/java/im/vector/matrix/android/api/MatrixPatterns.kt @@ -44,6 +44,10 @@ object MatrixPatterns { private val MATRIX_EVENT_IDENTIFIER_REGEX = "\\$[A-Z0-9]+$DOMAIN_REGEX" val PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER = Pattern.compile(MATRIX_EVENT_IDENTIFIER_REGEX, Pattern.CASE_INSENSITIVE) + // regex pattern to find message ids in a string. + private val MATRIX_EVENT_IDENTIFIER_V3_REGEX = "\\$[A-Z0-9/+]+" + val PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V3 = Pattern.compile(MATRIX_EVENT_IDENTIFIER_V3_REGEX, Pattern.CASE_INSENSITIVE) + // regex pattern to find group ids in a string. private val MATRIX_GROUP_IDENTIFIER_REGEX = "\\+[A-Z0-9=_\\-./]+$DOMAIN_REGEX" val PATTERN_CONTAIN_MATRIX_GROUP_IDENTIFIER = Pattern.compile(MATRIX_GROUP_IDENTIFIER_REGEX, Pattern.CASE_INSENSITIVE) @@ -116,7 +120,7 @@ object MatrixPatterns { * @return true if the string is a valid event id. */ fun isEventId(str: String?): Boolean { - return str != null && PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER.matcher(str).matches() + return str != null && (PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER.matcher(str).matches() || PATTERN_CONTAIN_MATRIX_EVENT_IDENTIFIER_V3.matcher(str).matches()) } /** From a12a9da627065a1467fe9296f62c35fdf6b24c81 Mon Sep 17 00:00:00 2001 From: ganfra Date: Mon, 18 Feb 2019 17:42:03 +0100 Subject: [PATCH 3/3] Update Realm --- matrix-sdk-android/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index 47e0f16041..612f0f7bfb 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -10,7 +10,7 @@ buildscript { jcenter() } dependencies { - classpath "io.realm:realm-gradle-plugin:5.8.0" + classpath "io.realm:realm-gradle-plugin:5.9.0" } }