Skip to content

Commit 0012481

Browse files
committed
message: Create an outbox message on send; manage its states
While we do create outbox messages, there are in no way user-visible changes since the outbox messages don't end up in message list views. We create skeletons for helpers needed from message list view, but don't implement them yet, to make the diff smaller. For testing, similar to TypingNotifier.debugEnable, we add MessageStoreImpl.debugOutboxEnable for tests that do not intend to cover outbox messages. Some of the delays to fake responses added in tests are not necessary because the future of sendMessage is not completed immediately, but we still add them to keep the tests realistic.
1 parent 0c03009 commit 0012481

12 files changed

+816
-60
lines changed

lib/model/message.dart

Lines changed: 336 additions & 9 deletions
Large diffs are not rendered by default.

lib/model/message_list.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import '../api/route/messages.dart';
1010
import 'algorithms.dart';
1111
import 'channel.dart';
1212
import 'content.dart';
13+
import 'message.dart';
1314
import 'narrow.dart';
1415
import 'store.dart';
1516

@@ -613,6 +614,18 @@ class MessageListView with ChangeNotifier, _MessageSequence {
613614
}
614615
}
615616

617+
/// Add [outboxMessage] if it belongs to the view.
618+
void addOutboxMessage(OutboxMessage outboxMessage) {
619+
// TODO(#1441) implement this
620+
}
621+
622+
/// Remove the [outboxMessage] from the view.
623+
///
624+
/// This is a no-op if the message is not found.
625+
void removeOutboxMessage(OutboxMessage outboxMessage) {
626+
// TODO(#1441) implement this
627+
}
628+
616629
void handleUserTopicEvent(UserTopicEvent event) {
617630
switch (_canAffectVisibility(event)) {
618631
case VisibilityEffect.none:
@@ -774,6 +787,11 @@ class MessageListView with ChangeNotifier, _MessageSequence {
774787
}
775788
}
776789

790+
/// Notify listeners if the given outbox message is present in this view.
791+
void notifyListenersIfOutboxMessagePresent(int localMessageId) {
792+
// TODO(#1441) implement this
793+
}
794+
777795
/// Called when the app is reassembled during debugging, e.g. for hot reload.
778796
///
779797
/// This will redo from scratch any computations we can, such as parsing

lib/model/store.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
498498
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
499499
),
500500
channels: channels,
501-
messages: MessageStoreImpl(core: core),
501+
messages: MessageStoreImpl(core: core,
502+
realmEmptyTopicDisplayName: initialSnapshot.realmEmptyTopicDisplayName),
502503
unreads: Unreads(
503504
initial: initialSnapshot.unreadMsgs,
504505
core: core,
@@ -733,6 +734,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
733734
@override
734735
Map<int, Message> get messages => _messages.messages;
735736
@override
737+
Map<int, OutboxMessage> get outboxMessages => _messages.outboxMessages;
738+
@override
736739
void registerMessageList(MessageListView view) =>
737740
_messages.registerMessageList(view);
738741
@override
@@ -744,6 +747,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
744747
return _messages.sendMessage(destination: destination, content: content);
745748
}
746749
@override
750+
void removeOutboxMessage(int localMessageId) => _messages.removeOutboxMessage(localMessageId);
751+
@override
747752
void reconcileMessages(List<Message> messages) {
748753
_messages.reconcileMessages(messages);
749754
// TODO(#649) notify [unreads] of the just-fetched messages

test/api/model/model_checks.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extension TopicNameChecks on Subject<TopicName> {
3030
}
3131

3232
extension StreamConversationChecks on Subject<StreamConversation> {
33+
Subject<TopicName> get topic => has((x) => x.topic, 'topic');
3334
Subject<String?> get displayRecipient => has((x) => x.displayRecipient, 'displayRecipient');
3435
}
3536

test/example_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ UserTopicEvent userTopicEvent(
637637
);
638638
}
639639

640-
MessageEvent messageEvent(Message message) =>
641-
MessageEvent(id: 0, message: message, localMessageId: null);
640+
MessageEvent messageEvent(Message message, {int? localMessageId}) =>
641+
MessageEvent(id: 0, message: message, localMessageId: localMessageId?.toString());
642642

643643
DeleteMessageEvent deleteMessageEvent(List<StreamMessage> messages) {
644644
assert(messages.isNotEmpty);

test/fake_async_checks.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import 'package:checks/checks.dart';
2+
import 'package:fake_async/fake_async.dart';
3+
4+
extension FakeTimerChecks on Subject<FakeTimer> {
5+
Subject<Duration> get duration => has((t) => t.duration, 'duration');
6+
}

test/model/message_checks.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import 'package:checks/checks.dart';
2+
import 'package:zulip/api/model/model.dart';
3+
import 'package:zulip/model/message.dart';
4+
5+
extension OutboxMessageChecks<T extends Conversation> on Subject<OutboxMessage<T>> {
6+
Subject<int> get localMessageId => has((x) => x.localMessageId, 'localMessageId');
7+
Subject<OutboxMessageState> get state => has((x) => x.state, 'state');
8+
Subject<bool> get hidden => has((x) => x.hidden, 'hidden');
9+
}

0 commit comments

Comments
 (0)