diff --git a/lib/api/route/messages.dart b/lib/api/route/messages.dart index 5226444b06..27a12c3ae0 100644 --- a/lib/api/route/messages.dart +++ b/lib/api/route/messages.dart @@ -177,6 +177,7 @@ Future 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', { @@ -191,8 +192,9 @@ Future sendMessage( throw Exception('impossible destination') // TODO(dart-3) show this statically ), 'content': RawParameter(content), - if (queueId != null) 'queue_id': queueId, - if (localId != null) 'local_id': localId, + 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, }); } diff --git a/lib/model/store.dart b/lib/model/store.dart index ea4833ab62..39a9320552 100644 --- a/lib/model/store.dart +++ b/lib/model/store.dart @@ -380,7 +380,11 @@ class PerAccountStore extends ChangeNotifier with StreamStore { Future sendMessage({required MessageDestination destination, required String content}) { // 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: true, + ); } static List _sortCustomProfileFields(List initialCustomProfileFields) { diff --git a/test/api/route/messages_test.dart b/test/api/route/messages_test.dart index 9e3975ca42..221b53ba37 100644 --- a/test/api/route/messages_test.dart +++ b/test/api/route/messages_test.dart @@ -300,11 +300,15 @@ void main() { FakeApiConnection connection, { required MessageDestination destination, required String content, + String? queueId, + String? localId, + bool? readBySender, required Map expectedBodyFields, }) async { connection.prepare(json: SendMessageResult(id: 42).toJson()); final result = await sendMessage(connection, - destination: destination, content: content); + destination: destination, content: content, + queueId: queueId, localId: localId, readBySender: readBySender); check(result).id.equals(42); check(connection.lastRequest).isA() ..method.equals('POST') @@ -312,6 +316,25 @@ void main() { ..bodyFields.deepEquals(expectedBodyFields); } + test('smoke', () { + return FakeApiConnection.with_((connection) async { + await checkSendMessage(connection, + 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', + }); + }); + }); + test('to stream', () { return FakeApiConnection.with_((connection) async { await checkSendMessage(connection, diff --git a/test/model/store_test.dart b/test/model/store_test.dart index a13bdc9b2b..07ce1beedf 100644 --- a/test/model/store_test.dart +++ b/test/model/store_test.dart @@ -4,6 +4,7 @@ import 'package:checks/checks.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart' as http; import 'package:test/scaffolding.dart'; +import 'package:zulip/api/route/messages.dart'; import 'package:zulip/model/store.dart'; import 'package:zulip/notifications.dart'; @@ -108,6 +109,28 @@ void main() { check(completers(1)).length.equals(1); }); + group('PerAccountStore.sendMessage', () { + test('smoke', () async { + final store = eg.store(); + final connection = store.connection as FakeApiConnection; + final stream = eg.stream(); + connection.prepare(json: SendMessageResult(id: 12345).toJson()); + await store.sendMessage( + destination: StreamDestination(stream.streamId, 'world'), + content: 'hello'); + check(connection.lastRequest).isA() + ..method.equals('POST') + ..url.path.equals('/api/v1/messages') + ..bodyFields.deepEquals({ + 'type': 'stream', + 'to': stream.streamId.toString(), + 'topic': 'world', + 'content': 'hello', + 'read_by_sender': 'true', + }); + }); + }); + group('UpdateMachine.registerNotificationToken', () { late UpdateMachine updateMachine; late FakeApiConnection connection;