Skip to content

local echo (5/n): Create outbox messages on send #1472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
404 changes: 392 additions & 12 deletions lib/model/message.dart

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions lib/model/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../api/route/messages.dart';
import 'algorithms.dart';
import 'channel.dart';
import 'content.dart';
import 'message.dart';
import 'narrow.dart';
import 'store.dart';

Expand Down Expand Up @@ -564,6 +565,20 @@ class MessageListView with ChangeNotifier, _MessageSequence {
}
}

/// Add [outboxMessage] if it belongs to the view.
void addOutboxMessage(OutboxMessage outboxMessage) {
// TODO(#1441) implement this
}

/// Remove the [outboxMessage] from the view.
///
/// This is a no-op if the message is not found.
///
/// This should only be called from [MessageStore.takeOutboxMessage].
void removeOutboxMessage(OutboxMessage outboxMessage) {
// TODO(#1441) implement this
}

void handleUserTopicEvent(UserTopicEvent event) {
switch (_canAffectVisibility(event)) {
case VisibilityEffect.none:
Expand Down Expand Up @@ -725,6 +740,11 @@ class MessageListView with ChangeNotifier, _MessageSequence {
}
}

/// Notify listeners if the given outbox message is present in this view.
void notifyListenersIfOutboxMessagePresent(int localMessageId) {
// TODO(#1441) implement this
}

/// Called when the app is reassembled during debugging, e.g. for hot reload.
///
/// This will redo from scratch any computations we can, such as parsing
Expand Down
8 changes: 7 additions & 1 deletion lib/model/store.dart
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
typingStartedExpiryPeriod: Duration(milliseconds: initialSnapshot.serverTypingStartedExpiryPeriodMilliseconds),
),
channels: channels,
messages: MessageStoreImpl(core: core),
messages: MessageStoreImpl(core: core,
realmEmptyTopicDisplayName: initialSnapshot.realmEmptyTopicDisplayName),
unreads: Unreads(
initial: initialSnapshot.unreadMsgs,
core: core,
Expand Down Expand Up @@ -733,6 +734,8 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
@override
Map<int, Message> get messages => _messages.messages;
@override
Map<int, OutboxMessage> get outboxMessages => _messages.outboxMessages;
@override
void registerMessageList(MessageListView view) =>
_messages.registerMessageList(view);
@override
Expand All @@ -744,6 +747,9 @@ class PerAccountStore extends PerAccountStoreBase with ChangeNotifier, EmojiStor
return _messages.sendMessage(destination: destination, content: content);
}
@override
OutboxMessage takeOutboxMessage(int localMessageId) =>
_messages.takeOutboxMessage(localMessageId);
@override
void reconcileMessages(List<Message> messages) {
_messages.reconcileMessages(messages);
// TODO(#649) notify [unreads] of the just-fetched messages
Expand Down
1 change: 1 addition & 0 deletions test/api/model/model_checks.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ extension TopicNameChecks on Subject<TopicName> {
}

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

Expand Down
4 changes: 2 additions & 2 deletions test/example_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -637,8 +637,8 @@ UserTopicEvent userTopicEvent(
);
}

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

DeleteMessageEvent deleteMessageEvent(List<StreamMessage> messages) {
assert(messages.isNotEmpty);
Expand Down
6 changes: 6 additions & 0 deletions test/fake_async_checks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:checks/checks.dart';
import 'package:fake_async/fake_async.dart';

extension FakeTimerChecks on Subject<FakeTimer> {
Subject<Duration> get duration => has((t) => t.duration, 'duration');
}
9 changes: 9 additions & 0 deletions test/model/message_checks.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import 'package:checks/checks.dart';
import 'package:zulip/api/model/model.dart';
import 'package:zulip/model/message.dart';

extension OutboxMessageChecks<T extends Conversation> on Subject<OutboxMessage<T>> {
Subject<int> get localMessageId => has((x) => x.localMessageId, 'localMessageId');
Subject<OutboxMessageState> get state => has((x) => x.state, 'state');
Subject<bool> get hidden => has((x) => x.hidden, 'hidden');
}
Loading