Skip to content

Commit

Permalink
api: Add readBySender 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.
Flag was added in FL 236, see:
  zulip/zulip#28204

Fixes: zulip#440
  • Loading branch information
sirpengi authored and gnprice committed Dec 21, 2023
1 parent f5fc643 commit d30383c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/api/route/messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ Future<SendMessageResult> sendMessage(
required String content,
String? queueId,
String? localId,
bool? readBySender,
}) {
final supportsTypeDirect = connection.zulipFeatureLevel! >= 174; // TODO(server-7)
return connection.post('sendMessage', SendMessageResult.fromJson, 'messages', {
Expand All @@ -193,6 +194,7 @@ Future<SendMessageResult> sendMessage(
'content': RawParameter(content),
if (queueId != null) 'queue_id': queueId, // TODO should this use RawParameter?
if (localId != null) 'local_id': localId, // TODO should this use RawParameter?
if (readBySender != null) 'read_by_sender': readBySender,
});
}

Expand Down
8 changes: 6 additions & 2 deletions lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,14 @@ class PerAccountStore extends ChangeNotifier with StreamStore {
}
}

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

static List<CustomProfileField> _sortCustomProfileFields(List<CustomProfileField> initialCustomProfileFields) {
Expand Down
2 changes: 1 addition & 1 deletion lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ class _SendButtonState extends State<_SendButton> {

final store = PerAccountStoreWidget.of(context);
final content = widget.contentController.textNormalized;
store.sendMessage(destination: widget.getDestination(), content: content);
store.sendMessage(destination: widget.getDestination(), content: content, readBySender: true);

widget.contentController.clear();
}
Expand Down
5 changes: 4 additions & 1 deletion test/api/route/messages_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,13 @@ void main() {
required String content,
String? queueId,
String? localId,
bool? readBySender,
required Map<String, String> expectedBodyFields,
}) async {
connection.prepare(json: SendMessageResult(id: 42).toJson());
final result = await sendMessage(connection,
destination: destination, content: content,
queueId: queueId, localId: localId);
queueId: queueId, localId: localId, readBySender: readBySender);
check(result).id.equals(42);
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
Expand All @@ -321,13 +322,15 @@ void main() {
destination: StreamDestination(streamId, topic), content: content,
queueId: 'abc:123',
localId: '456',
readBySender: true,
expectedBodyFields: {
'type': 'stream',
'to': streamId.toString(),
'topic': topic,
'content': content,
'queue_id': '"abc:123"',
'local_id': '"456"',
'read_by_sender': 'true',
});
});
});
Expand Down

0 comments on commit d30383c

Please sign in to comment.