11import 'dart:convert' ;
22
3+ import '../api/core.dart' ;
34import '../api/model/events.dart' ;
45import '../api/model/model.dart' ;
6+ import '../api/route/messages.dart' ;
57import '../log.dart' ;
68import 'message_list.dart' ;
79
10+ const _apiSendMessage = sendMessage; // Bit ugly; for alternatives, see: https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/flutter.3A.20PerAccountStore.20methods/near/1545809
11+
812/// The portion of [PerAccountStore] for messages and message lists.
913mixin MessageStore {
1014 /// All known messages, indexed by [Message.id] .
@@ -15,6 +19,11 @@ mixin MessageStore {
1519 void registerMessageList (MessageListView view);
1620 void unregisterMessageList (MessageListView view);
1721
22+ Future <void > sendMessage ({
23+ required MessageDestination destination,
24+ required String content,
25+ });
26+
1827 /// Reconcile a batch of just-fetched messages with the store,
1928 /// mutating the list.
2029 ///
@@ -29,11 +38,13 @@ mixin MessageStore {
2938}
3039
3140class MessageStoreImpl with MessageStore {
32- MessageStoreImpl ()
41+ MessageStoreImpl ({ required this .connection} )
3342 // There are no messages in InitialSnapshot, so we don't have
3443 // a use case for initializing MessageStore with nonempty [messages].
3544 : messages = {};
3645
46+ final ApiConnection connection;
47+
3748 @override
3849 final Map <int , Message > messages;
3950
@@ -77,6 +88,17 @@ class MessageStoreImpl with MessageStore {
7788 // https://chat.zulip.org/#narrow/channel/243-mobile-team/topic/MessageListView.20lifecycle/near/2086893
7889 }
7990
91+ @override
92+ Future <void > sendMessage ({required MessageDestination destination, required String content}) {
93+ // TODO implement outbox; see design at
94+ // https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/.23M3881.20Sending.20outbox.20messages.20is.20fraught.20with.20issues/near/1405739
95+ return _apiSendMessage (connection,
96+ destination: destination,
97+ content: content,
98+ readBySender: true ,
99+ );
100+ }
101+
80102 @override
81103 void reconcileMessages (List <Message > messages) {
82104 // What to do when some of the just-fetched messages are already known?
0 commit comments