From 5167e92913784937fb7ec5bd4f64072c50924e19 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Fri, 4 Dec 2020 12:17:00 +0100 Subject: [PATCH] feat: Update room api --- lib/src/room.dart | 32 +++++++++++++++++++++++++++++++- test/room_test.dart | 4 ++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/src/room.dart b/lib/src/room.dart index 4130d442..2ff25352 100644 --- a/lib/src/room.dart +++ b/lib/src/room.dart @@ -445,7 +445,8 @@ class Room { MarkedUnread(unread).toJson(), ); if (unread == false) { - await sendReadReceipt(lastEvent.eventId); + await sendReadMarker(lastEvent.eventId, + readReceiptLocationEventId: lastEvent.eventId); } } @@ -980,7 +981,36 @@ class Room { return; } + /// Sets the position of the read marker for a given room, and optionally the + /// read receipt's location. + Future sendReadMarker(String eventId, + {String readReceiptLocationEventId}) async { + if (readReceiptLocationEventId != null) { + notificationCount = 0; + await client.database?.resetNotificationCount(client.id, id); + } + await client.sendReadMarker( + id, + eventId, + readReceiptLocationEventId: readReceiptLocationEventId, + ); + return; + } + + /// This API updates the marker for the given receipt type to the event ID + /// specified. + Future sendReceiptMarker(String eventId) async { + notificationCount = 0; + await client.database?.resetNotificationCount(client.id, id); + await client.sendReceiptMarker( + id, + eventId, + ); + return; + } + /// Sends *m.fully_read* and *m.read* for the given event ID. + @Deprecated('Use sendReadMarker instead') Future sendReadReceipt(String eventID) async { notificationCount = 0; await client.database?.resetNotificationCount(client.id, id); diff --git a/test/room_test.dart b/test/room_test.dart index 499cf239..e17a3145 100644 --- a/test/room_test.dart +++ b/test/room_test.dart @@ -204,8 +204,8 @@ void main() { expect(room.lastEvent.type, 'm.room.encrypted'); }); - test('sendReadReceipt', () async { - await room.sendReadReceipt('§1234:fakeServer.notExisting'); + test('sendReadMarker', () async { + await room.sendReadMarker('§1234:fakeServer.notExisting'); }); test('requestParticipants', () async {