Skip to content

Commit d00ea21

Browse files
committed
api: Add readBySender 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. Flag was added in FL 236, see: zulip/zulip#28204 Fixes: #440
1 parent 0775369 commit d00ea21

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

lib/api/route/messages.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ Future<SendMessageResult> sendMessage(
177177
required String content,
178178
String? queueId,
179179
String? localId,
180+
bool? readBySender,
180181
}) {
181182
final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)
182183
return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', {
@@ -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 (readBySender != null) 'read_by_sender': readBySender,
196198
});
197199
}
198200

lib/model/store.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,10 +392,10 @@ class PerAccountStore extends ChangeNotifier {
392392
}
393393
}
394394

395-
Future<void> sendMessage({required MessageDestination destination, required String content}) {
395+
Future<void> sendMessage({required MessageDestination destination, required String content, bool? readBySender}) {
396396
// TODO implement outbox; see design at
397397
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3881.20Sending.20outbox.20messages.20is.20fraught.20with.20issues/near/1405739
398-
return _apiSendMessage(connection, destination: destination, content: content);
398+
return _apiSendMessage(connection, destination: destination, content: content, readBySender: readBySender);
399399
}
400400

401401
static List<CustomProfileField> _sortCustomProfileFields(List<CustomProfileField> initialCustomProfileFields) {

lib/widgets/compose_box.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ class _SendButtonState extends State<_SendButton> {
733733

734734
final store = PerAccountStoreWidget.of(context);
735735
final content = widget.contentController.textNormalized;
736-
store.sendMessage(destination: widget.getDestination(), content: content);
736+
store.sendMessage(destination: widget.getDestination(), content: content, readBySender: true);
737737

738738
widget.contentController.clear();
739739
}

test/api/route/messages_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ void main() {
304304
}) async {
305305
connection.prepare(json: SendMessageResult(id: 42).toJson());
306306
final result = await sendMessage(connection,
307-
destination: destination, content: content);
307+
destination: destination, content: content, readBySender: true);
308308
check(result).id.equals(42);
309309
check(connection.lastRequest).isA<http.Request>()
310310
..method.equals('POST')
@@ -321,6 +321,7 @@ void main() {
321321
'to': streamId.toString(),
322322
'topic': topic,
323323
'content': content,
324+
'read_by_sender': 'true',
324325
});
325326
});
326327
});
@@ -333,6 +334,7 @@ void main() {
333334
'type': 'direct',
334335
'to': jsonEncode(userIds),
335336
'content': content,
337+
'read_by_sender': 'true',
336338
});
337339
});
338340
});
@@ -345,6 +347,7 @@ void main() {
345347
'type': 'private',
346348
'to': jsonEncode(userIds),
347349
'content': content,
350+
'read_by_sender': 'true',
348351
});
349352
});
350353
});

0 commit comments

Comments
 (0)