Skip to content

Commit 17a1a4c

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.
1 parent b806f9d commit 17a1a4c

12 files changed

+887
-63
lines changed

lib/model/message.dart

Lines changed: 448 additions & 12 deletions
Large diffs are not rendered by default.

lib/model/message_list.dart

Lines changed: 20 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

@@ -616,6 +617,20 @@ class MessageListView with ChangeNotifier, _MessageSequence {
616617
}
617618
}
618619

620+
/// Add [outboxMessage] if it belongs to the view.
621+
void addOutboxMessage(OutboxMessage outboxMessage) {
622+
// TODO(#1441) implement this
623+
}
624+
625+
/// Remove the [outboxMessage] from the view.
626+
///
627+
/// This is a no-op if the message is not found.
628+
///
629+
/// This should only be called from [MessageStore.takeOutboxMessage].
630+
void removeOutboxMessage(OutboxMessage outboxMessage) {
631+
// TODO(#1441) implement this
632+
}
633+
619634
void handleUserTopicEvent(UserTopicEvent event) {
620635
switch (_canAffectVisibility(event)) {
621636
case VisibilityEffect.none:
@@ -777,6 +792,11 @@ class MessageListView with ChangeNotifier, _MessageSequence {
777792
}
778793
}
779794

795+
/// Notify listeners if the given outbox message is present in this view.
796+
void notifyListenersIfOutboxMessagePresent(int localMessageId) {
797+
// TODO(#1441) implement this
798+
}
799+
780800
/// Called when the app is reassembled during debugging, e.g. for hot reload.
781801
///
782802
/// This will redo from scratch any computations we can, such as parsing

lib/model/store.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
501501
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
502502
),
503503
channels: channels,
504-
messages: MessageStoreImpl(core: core),
504+
messages: MessageStoreImpl(core: core,
505+
realmEmptyTopicDisplayName: initialSnapshot.realmEmptyTopicDisplayName),
505506
unreads: Unreads(
506507
initial: initialSnapshot.unreadMsgs,
507508
core: core,
@@ -745,6 +746,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
745746
@override
746747
Map<int, Message> get messages => _messages.messages;
747748
@override
749+
Map<int, OutboxMessage> get outboxMessages => _messages.outboxMessages;
750+
@override
748751
void registerMessageList(MessageListView view) =>
749752
_messages.registerMessageList(view);
750753
@override
@@ -756,6 +759,9 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
756759
return _messages.sendMessage(destination: destination, content: content);
757760
}
758761
@override
762+
OutboxMessage takeOutboxMessage(int localMessageId) =>
763+
_messages.takeOutboxMessage(localMessageId);
764+
@override
759765
void reconcileMessages(List<Message> messages) {
760766
_messages.reconcileMessages(messages);
761767
// 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
@@ -37,6 +37,7 @@ extension TopicNameChecks on Subject<TopicName> {
3737
}
3838

3939
extension StreamConversationChecks on Subject<StreamConversation> {
40+
Subject<TopicName> get topic => has((x) => x.topic, 'topic');
4041
Subject<String?> get displayRecipient => has((x) => x.displayRecipient, 'displayRecipient');
4142
}
4243

test/example_data.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,8 +695,8 @@ UserTopicEvent userTopicEvent(
695695
);
696696
}
697697

698-
MessageEvent messageEvent(Message message) =>
699-
MessageEvent(id: 0, message: message, localMessageId: null);
698+
MessageEvent messageEvent(Message message, {int? localMessageId}) =>
699+
MessageEvent(id: 0, message: message, localMessageId: localMessageId?.toString());
700700

701701
DeleteMessageEvent deleteMessageEvent(List<StreamMessage> messages) {
702702
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)