Skip to content

Commit d30383c

Browse files
sirpengignprice
authored andcommitted
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 f5fc643 commit d30383c

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-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, // TODO should this use RawParameter?
195196
if (localId != null) 'local_id': localId, // TODO should this use RawParameter?
197+
if (readBySender != null) 'read_by_sender': readBySender,
196198
});
197199
}
198200

lib/model/store.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,14 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
377377
}
378378
}
379379

380-
Future<void> sendMessage({required MessageDestination destination, required String content}) {
380+
Future<void> sendMessage({required MessageDestination destination, required String content, bool? readBySender}) {
381381
// TODO implement outbox; see design at
382382
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3881.20Sending.20outbox.20messages.20is.20fraught.20with.20issues/near/1405739
383-
return _apiSendMessage(connection, destination: destination, content: content);
383+
return _apiSendMessage(connection,
384+
destination: destination,
385+
content: content,
386+
readBySender: readBySender,
387+
);
384388
}
385389

386390
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
@@ -302,12 +302,13 @@ void main() {
302302
required String content,
303303
String? queueId,
304304
String? localId,
305+
bool? readBySender,
305306
required Map<String, String> expectedBodyFields,
306307
}) async {
307308
connection.prepare(json: SendMessageResult(id: 42).toJson());
308309
final result = await sendMessage(connection,
309310
destination: destination, content: content,
310-
queueId: queueId, localId: localId);
311+
queueId: queueId, localId: localId, readBySender: readBySender);
311312
check(result).id.equals(42);
312313
check(connection.lastRequest).isA<http.Request>()
313314
..method.equals('POST')
@@ -321,13 +322,15 @@ void main() {
321322
destination: StreamDestination(streamId, topic), content: content,
322323
queueId: 'abc:123',
323324
localId: '456',
325+
readBySender: true,
324326
expectedBodyFields: {
325327
'type': 'stream',
326328
'to': streamId.toString(),
327329
'topic': topic,
328330
'content': content,
329331
'queue_id': '"abc:123"',
330332
'local_id': '"456"',
333+
'read_by_sender': 'true',
331334
});
332335
});
333336
});

0 commit comments

Comments
 (0)