Skip to content

Commit 2a04d12

Browse files
committed
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 zulip/zulip#28204 . Fixes: #440
1 parent 0775369 commit 2a04d12

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

lib/api/route/messages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ Future<SendMessageResult> sendMessage(
179179
String? localId,
180180
}) {
181181
final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)
182+
final supportsReadBySender = connection.zulipFeatureLevel! >= 236; // TODO(server-8)
182183
return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', {
183184
if (destination is StreamDestination) ...{
184185
'type': RawParameter('stream'),
@@ -193,6 +194,7 @@ Future<SendMessageResult> sendMessage(
193194
'content': RawParameter(content),
194195
if (queueId != null) 'queue_id': queueId,
195196
if (localId != null) 'local_id': localId,
197+
if (supportsReadBySender) 'read_by_sender': true,
196198
});
197199
}
198200

test/api/route/messages_test.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,20 @@ void main() {
314314

315315
test('to stream', () {
316316
return FakeApiConnection.with_((connection) async {
317+
await checkSendMessage(connection,
318+
destination: StreamDestination(streamId, topic), content: content,
319+
expectedBodyFields: {
320+
'type': 'stream',
321+
'to': streamId.toString(),
322+
'topic': topic,
323+
'content': content,
324+
'read_by_sender': 'true',
325+
});
326+
});
327+
});
328+
329+
test('to server without read_by_sender support', () {
330+
return FakeApiConnection.with_(zulipFeatureLevel: 235, (connection) async {
317331
await checkSendMessage(connection,
318332
destination: StreamDestination(streamId, topic), content: content,
319333
expectedBodyFields: {
@@ -333,6 +347,7 @@ void main() {
333347
'type': 'direct',
334348
'to': jsonEncode(userIds),
335349
'content': content,
350+
'read_by_sender': 'true',
336351
});
337352
});
338353
});

0 commit comments

Comments
 (0)