Merge pull request #3124 from vector-im/feature/bma/fix_readMarker

Fix mandatory parameter in API (#3065)
This commit is contained in:
Benoit Marty 2021-04-07 10:47:17 +02:00 committed by GitHub
commit f7f7994685
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 3 deletions

View file

@ -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 🗣:
-

View file

@ -153,6 +153,14 @@ internal interface RoomAPI {
suspend fun sendReadMarker(@Path("roomId") roomId: String,
@Body markers: Map<String, String>)
/**
* 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

View file

@ -62,7 +62,7 @@ internal class DefaultSetReadMarkersTask @Inject constructor(
) : SetReadMarkersTask {
override suspend fun execute(params: SetReadMarkersTask.Params) {
val markers = HashMap<String, String>()
val markers = mutableMapOf<String, String>()
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<String, String>, shouldUpdateRoomSummary: Boolean) {
private suspend fun updateDatabase(roomId: String, markers: Map<String, String>, shouldUpdateRoomSummary: Boolean) {
monarchy.awaitTransaction { realm ->
val readMarkerId = markers[READ_MARKER]
val readReceiptId = markers[READ_RECEIPT]