Skip to content

Small NFC tweaks to message-move-related code #786

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

Merged
merged 2 commits into from
Jul 3, 2024
Merged
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
22 changes: 12 additions & 10 deletions lib/model/message.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,16 @@ class MessageStoreImpl with MessageStore {
// The interaction between the fields of these events are a bit tricky.
// For reference, see: https://zulip.com/api/get-events#update_message

if (event.origTopic == null) {
final origStreamId = event.origStreamId;
final newStreamId = event.newStreamId; // null if topic-only move
final origTopic = event.origTopic;
final newTopic = event.newTopic;

if (origTopic == null) {
// There was no move.
assert(() {
if (event.newStreamId != null && event.origStreamId != null
&& event.newStreamId != event.origStreamId) {
if (newStreamId != null && origStreamId != null
&& newStreamId != origStreamId) {
// This should be impossible; `orig_subject` (aka origTopic) is
// documented to be present when either the stream or topic changed.
debugLog('Malformed UpdateMessageEvent: stream move but no origTopic'); // TODO(log)
Expand All @@ -162,22 +167,19 @@ class MessageStoreImpl with MessageStore {
return;
}

if (event.newTopic == null) {
if (newTopic == null) {
// The `subject` field (aka newTopic) is documented to be present on moves.
assert(debugLog('Malformed UpdateMessageEvent: move but no newTopic')); // TODO(log)
return;
}
if (event.origStreamId == null) {
if (origStreamId == null) {
// The `stream_id` field (aka origStreamId) is documented to be present on moves.
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
return;
}

final newTopic = event.newTopic!;
final newChannelId = event.newStreamId; // null if topic-only move

if (newChannelId == null
&& MessageEditState.topicMoveWasResolveOrUnresolve(event.origTopic!, newTopic)) {
if (newStreamId == null
&& MessageEditState.topicMoveWasResolveOrUnresolve(origTopic, newTopic)) {
// The topic was only resolved/unresolved.
// No change to the messages' editState.
return;
Expand Down
22 changes: 11 additions & 11 deletions lib/model/message_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,17 @@ class MessageListView with ChangeNotifier, _MessageSequence {
notifyListeners();
}

/// Update data derived from the content of the given message.
///
/// This does not notify listeners.
/// The caller should ensure that happens later.
void messageContentChanged(int messageId) {
final index = _findMessageWithId(messageId);
if (index != -1) {
_reparseContent(index);
}
}

// Repeal the `@protected` annotation that applies on the base implementation,
// so we can call this method from [MessageStoreImpl].
@override
Expand All @@ -497,17 +508,6 @@ class MessageListView with ChangeNotifier, _MessageSequence {
}
}

/// Update data derived from the content of the given message.
///
/// This does not notify listeners.
/// The caller should ensure that happens later.
void messageContentChanged(int messageId) {
final index = _findMessageWithId(messageId);
if (index != -1) {
_reparseContent(index);
}
}

/// 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
Loading