Skip to content

Commit

Permalink
api: Add read_by_sender flag to sendMessage
Browse files Browse the repository at this point in the history
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: zulip#440
  • Loading branch information
sirpengi committed Dec 19, 2023
1 parent 0775369 commit 34454f0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/api/route/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ Future<SendMessageResult> 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'),
Expand All @@ -193,6 +194,7 @@ Future<SendMessageResult> sendMessage(
'content': RawParameter(content),
if (queueId != null) 'queue_id': queueId,
if (localId != null) 'local_id': localId,
if (supportsReadBySender) 'read_by_sender': 'true',
});
}

Expand Down
14 changes: 14 additions & 0 deletions test/api/route/messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit 34454f0

Please sign in to comment.