From 34454f06bb655e6dcf19062d73cbb8925c0f9ebd Mon Sep 17 00:00:00 2001 From: Shu Chen Date: Tue, 19 Dec 2023 15:08:35 +0000 Subject: [PATCH] api: Add read_by_sender flag to sendMessage This flag allows the client to communicate to the server that the new message should be initially marked as read for its sender. Added in FL 236 in https://github.com/zulip/zulip/pull/28204 . Fixes: #440 --- lib/api/route/messages.dart | 2 ++ test/api/route/messages_test.dart | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/lib/api/route/messages.dart b/lib/api/route/messages.dart index 5226444b06f..b38b211c4ac 100644 --- a/lib/api/route/messages.dart +++ b/lib/api/route/messages.dart @@ -179,6 +179,7 @@ Future sendMessage( String? localId, }) { final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7) + final supportsReadBySender = connection.zulipFeatureLevel! >= 236; // TODO(server-8) return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', { if (destination is StreamDestination) ...{ 'type': RawParameter('stream'), @@ -193,6 +194,7 @@ Future sendMessage( 'content': RawParameter(content), if (queueId != null) 'queue_id': queueId, if (localId != null) 'local_id': localId, + if (supportsReadBySender) 'read_by_sender': 'true', }); } diff --git a/test/api/route/messages_test.dart b/test/api/route/messages_test.dart index 9e3975ca42c..284c21fd44f 100644 --- a/test/api/route/messages_test.dart +++ b/test/api/route/messages_test.dart @@ -314,6 +314,20 @@ void main() { test('to stream', () { return FakeApiConnection.with_((connection) async { + await checkSendMessage(connection, + destination: StreamDestination(streamId, topic), content: content, + expectedBodyFields: { + 'type': 'stream', + 'to': streamId.toString(), + 'topic': topic, + 'content': content, + 'read_by_sender': 'true', + }); + }); + }); + + test('to server without read_by_sender support', () { + return FakeApiConnection.with_(zulipFeatureLevel: 235, (connection) async { await checkSendMessage(connection, destination: StreamDestination(streamId, topic), content: content, expectedBodyFields: {