From e3cd91610524ab49e4592f66f70110156979c182 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 6 Apr 2021 16:25:16 +0200 Subject: [PATCH] Fix mandatory parameter in API (#3065) --- CHANGES.md | 1 + .../android/sdk/internal/session/room/RoomAPI.kt | 8 ++++++++ .../session/room/read/SetReadMarkersTask.kt | 13 ++++++++++--- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index f9b05a32a7..a6f4c7e287 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -22,6 +22,7 @@ Bugfix 🐛: - Handle encrypted reactions (#2509) - Disable URL preview for some domains (#2995) - Fix avatar rendering for DMs, after initial sync (#2693) + - Fix mandatory parameter in API (#3065) Translations 🗣: - diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt index ad699af6f4..6fee630510 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/RoomAPI.kt @@ -153,6 +153,14 @@ internal interface RoomAPI { suspend fun sendReadMarker(@Path("roomId") roomId: String, @Body markers: Map) + /** + * Send receipt to a room + */ + @POST(NetworkConstants.URI_API_PREFIX_PATH_R0 + "rooms/{roomId}/receipt/{receiptType}/{eventId}") + suspend fun sendReceipt(@Path("roomId") roomId: String, + @Path("receiptType") receiptType: String, + @Path("eventId") eventId: String) + /** * Invite a user to the given room. * Ref: https://matrix.org/docs/spec/client_server/r0.4.0.html#post-matrix-client-r0-rooms-roomid-invite diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt index 35dc6a4f0c..e4147d55b8 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/room/read/SetReadMarkersTask.kt @@ -62,7 +62,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor( ) : SetReadMarkersTask { override suspend fun execute(params: SetReadMarkersTask.Params) { - val markers = HashMap() + val markers = mutableMapOf() Timber.v("Execute set read marker with params: $params") val latestSyncedEventId = latestSyncedEventId(params.roomId) val fullyReadEventId = if (params.forceReadMarker) { @@ -100,7 +100,14 @@ internal class DefaultSetReadMarkersTask @Inject constructor( globalErrorReceiver, canRetry = true ) { - roomAPI.sendReadMarker(params.roomId, markers) + if (markers[READ_MARKER] == null) { + if (readReceiptEventId != null) { + roomAPI.sendReceipt(params.roomId, READ_RECEIPT, readReceiptEventId) + } + } else { + // "m.fully_read" value is mandatory to make this call + roomAPI.sendReadMarker(params.roomId, markers) + } } } } @@ -110,7 +117,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor( TimelineEventEntity.latestEvent(realm, roomId = roomId, includesSending = false)?.eventId } - private suspend fun updateDatabase(roomId: String, markers: HashMap, shouldUpdateRoomSummary: Boolean) { + private suspend fun updateDatabase(roomId: String, markers: Map, shouldUpdateRoomSummary: Boolean) { monarchy.awaitTransaction { realm -> val readMarkerId = markers[READ_MARKER] val readReceiptId = markers[READ_RECEIPT]