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 committed Dec 21, 2023
1 parent 01e4f14 commit 6c59f1e
Show file tree
Hide file tree
Showing 4 changed files with 9 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,
if (localId != null) 'local_id': localId,
if (readBySender != null) 'read_by_sender': readBySender,
});
}

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

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 @@ -304,7 +304,7 @@ void main() {
}) async {
connection.prepare(json: SendMessageResult(id: 42).toJson());
final result = await sendMessage(connection,
destination: destination, content: content);
destination: destination, content: content, readBySender: true);
check(result).id.equals(42);
check(connection.lastRequest).isA<http.Request>()
..method.equals('POST')
Expand All @@ -321,6 +321,7 @@ void main() {
'to': streamId.toString(),
'topic': topic,
'content': content,
'read_by_sender': 'true',
});
});
});
Expand All @@ -333,6 +334,7 @@ void main() {
'type': 'direct',
'to': jsonEncode(userIds),
'content': content,
'read_by_sender': 'true',
});
});
});
Expand All @@ -345,6 +347,7 @@ void main() {
'type': 'private',
'to': jsonEncode(userIds),
'content': content,
'read_by_sender': 'true',
});
});
});
Expand Down

0 comments on commit 6c59f1e

Please sign in to comment.