Skip to content

Commit cff4ca0

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 7a9d6eb commit cff4ca0

12 files changed

+886
-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
@@ -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,
@@ -736,6 +737,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
736737
@override
737738
Map<int, Message> get messages => _messages.messages;
738739
@override
740+
Map<int, OutboxMessage> get outboxMessages => _messages.outboxMessages;
741+
@override
739742
void registerMessageList(MessageListView view) =>
740743
_messages.registerMessageList(view);
741744
@override
@@ -747,6 +750,9 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
747750
return _messages.sendMessage(destination: destination, content: content);
748751
}
749752
@override
753+
OutboxMessage takeOutboxMessage(int localMessageId) =>
754+
_messages.takeOutboxMessage(localMessageId);
755+
@override
750756
void reconcileMessages(List<Message> messages) {
751757
_messages.reconcileMessages(messages);
752758
// 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
@@ -673,8 +673,8 @@ UserTopicEvent userTopicEvent(
673673
);
674674
}
675675

676-
MessageEvent messageEvent(Message message) =>
677-
MessageEvent(id: 0, message: message, localMessageId: null);
676+
MessageEvent messageEvent(Message message, {int? localMessageId}) =>
677+
MessageEvent(id: 0, message: message, localMessageId: localMessageId?.toString());
678678

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