Skip to content

Commit 48dc619

Browse files
committed
send [nfc]: Always pass readBySender true
I think we're always going to want this parameter to be true for all the messages we send from the app. In the API bindings themselves, i.e. in lib/api/ , I generally prefer not to hard-code this sort of thing. That lets the API bindings be a faithful reflection of the Zulip Server API, with a minimum of ad-hoc specializations for the needs of our app. So that's why the `sendMessage` binding just takes the parameter from its caller. But this method PerAccountStore.sendMessage is already something specific to our app rather than an API binding; it doesn't do much now beyond wrap the API, but the reason it exists is to be the future home of our "outbox" logic. That means (a) recording the message locally so that we can display it immediately, (b) possibly retrying the send, and (c) if the send fails or times out, recording that fact so that our UI can present the user with that information and the option to retry. So that makes it a natural home for encapsulating any other logic that this app will always want when sending a message. In particular, passing this parameter.
1 parent d30383c commit 48dc619

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/model/store.dart

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

380-
Future<void> sendMessage({required MessageDestination destination, required String content, bool? readBySender}) {
380+
Future<void> sendMessage({required MessageDestination destination, required String content}) {
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
383383
return _apiSendMessage(connection,
384384
destination: destination,
385385
content: content,
386-
readBySender: readBySender,
386+
readBySender: true,
387387
);
388388
}
389389

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, readBySender: true);
736+
store.sendMessage(destination: widget.getDestination(), content: content);
737737

738738
widget.contentController.clear();
739739
}

test/model/store_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'package:checks/checks.dart';
44
import 'package:flutter/foundation.dart';
55
import 'package:http/http.dart' as http;
66
import 'package:test/scaffolding.dart';
7+
import 'package:zulip/api/route/messages.dart';
78
import 'package:zulip/model/store.dart';
89
import 'package:zulip/notifications.dart';
910

@@ -108,6 +109,28 @@ void main() {
108109
check(completers(1)).length.equals(1);
109110
});
110111

112+
group('PerAccountStore.sendMessage', () {
113+
test('smoke', () async {
114+
final store = eg.store();
115+
final connection = store.connection as FakeApiConnection;
116+
final stream = eg.stream();
117+
connection.prepare(json: SendMessageResult(id: 12345).toJson());
118+
await store.sendMessage(
119+
destination: StreamDestination(stream.streamId, 'world'),
120+
content: 'hello');
121+
check(connection.lastRequest).isA<http.Request>()
122+
..method.equals('POST')
123+
..url.path.equals('/api/v1/messages')
124+
..bodyFields.deepEquals({
125+
'type': 'stream',
126+
'to': stream.streamId.toString(),
127+
'topic': 'world',
128+
'content': 'hello',
129+
'read_by_sender': 'true',
130+
});
131+
});
132+
});
133+
111134
group('UpdateMachine.registerNotificationToken', () {
112135
late UpdateMachine updateMachine;
113136
late FakeApiConnection connection;

0 commit comments

Comments
 (0)