From 2a04d1266ec679067437d43ad1e6c7bc9cfc82ea 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 | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/api/route/messages.dart b/lib/api/route/messages.dart index 5226444b06f..53b34f33b74 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..2f93d74b4d4 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: { @@ -333,6 +347,7 @@ void main() { 'type': 'direct', 'to': jsonEncode(userIds), 'content': content, + 'read_by_sender': 'true', }); }); });