1
1
import 'dart:convert' ;
2
2
3
+ import '../api/core.dart' ;
3
4
import '../api/model/events.dart' ;
4
5
import '../api/model/model.dart' ;
6
+ import '../api/route/messages.dart' ;
5
7
import '../log.dart' ;
6
8
import 'message_list.dart' ;
7
9
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
+
8
12
/// The portion of [PerAccountStore] for messages and message lists.
9
13
mixin MessageStore {
10
14
/// All known messages, indexed by [Message.id] .
@@ -15,6 +19,11 @@ mixin MessageStore {
15
19
void registerMessageList (MessageListView view);
16
20
void unregisterMessageList (MessageListView view);
17
21
22
+ Future <void > sendMessage ({
23
+ required MessageDestination destination,
24
+ required String content,
25
+ });
26
+
18
27
/// Reconcile a batch of just-fetched messages with the store,
19
28
/// mutating the list.
20
29
///
@@ -29,11 +38,13 @@ mixin MessageStore {
29
38
}
30
39
31
40
class MessageStoreImpl with MessageStore {
32
- MessageStoreImpl ()
41
+ MessageStoreImpl ({ required this .connection} )
33
42
// There are no messages in InitialSnapshot, so we don't have
34
43
// a use case for initializing MessageStore with nonempty [messages].
35
44
: messages = {};
36
45
46
+ final ApiConnection connection;
47
+
37
48
@override
38
49
final Map <int , Message > messages;
39
50
@@ -77,6 +88,17 @@ class MessageStoreImpl with MessageStore {
77
88
// https://chat.zulip.org/#narrow/channel/243-mobile-team/topic/MessageListView.20lifecycle/near/2086893
78
89
}
79
90
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
+
80
102
@override
81
103
void reconcileMessages (List <Message > messages) {
82
104
// What to do when some of the just-fetched messages are already known?
0 commit comments