Skip to content

Commit 00bd054

Browse files
committed
message: Add skeleton of handling a move UpdateMessageEvent
The way the Zulip server API expresses whether there was a move, and if so what kind of move, is a bit quirky. This change adds logic to interpret that information into a more canonical form. The logic here is translated from what we have in zulip-mobile: https://github.com/zulip/zulip-mobile/blob/e352f563e/src/api/misc.js#L26 This doesn't yet do anything to actually update our data structures, and it's an NFC change for release builds. The only behavior change is new asserts that fire when the event from the server is malformed.
1 parent 0755784 commit 00bd054

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

lib/model/message.dart

+37-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import '../api/model/events.dart';
22
import '../api/model/model.dart';
3+
import '../log.dart';
34
import 'message_list.dart';
45

56
/// The portion of [PerAccountStore] for messages and message lists.
@@ -96,8 +97,7 @@ class MessageStoreImpl with MessageStore {
9697
assert(event.messageIds.contains(event.messageId), "See https://github.com/zulip/zulip-flutter/pull/753#discussion_r1649463633");
9798
_handleUpdateMessageEventTimestamp(event);
9899
_handleUpdateMessageEventContent(event);
99-
// TODO(#150): Handle message moves. The views' recipient headers
100-
// may need updating, and consequently showSender too.
100+
_handleUpdateMessageEventMove(event);
101101
for (final view in _messageListViews) {
102102
view.notifyListenersIfAnyMessagePresent(event.messageIds);
103103
}
@@ -139,6 +139,41 @@ class MessageStoreImpl with MessageStore {
139139
}
140140
}
141141

142+
void _handleUpdateMessageEventMove(UpdateMessageEvent event) {
143+
// The interaction between the fields of these events are a bit tricky.
144+
// For reference, see: https://zulip.com/api/get-events#update_message
145+
146+
if (event.origTopic == null) {
147+
// There was no move.
148+
assert(() {
149+
if (event.newStreamId != null && event.origStreamId != null
150+
&& event.newStreamId != event.origStreamId) {
151+
// This should be impossible; `orig_subject` (aka origTopic) is
152+
// documented to be present when either the stream or topic changed.
153+
debugLog('Malformed UpdateMessageEvent: stream move but no origTopic'); // TODO(log)
154+
}
155+
return true;
156+
}());
157+
return;
158+
}
159+
160+
if (event.newTopic == null) {
161+
// The `subject` field (aka newTopic) is documented to be present on moves.
162+
assert(debugLog('Malformed UpdateMessageEvent: move but no newTopic')); // TODO(log)
163+
return;
164+
}
165+
if (event.origStreamId == null) {
166+
// The `stream_id` field (aka origStreamId) is documented to be present on moves.
167+
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
168+
return;
169+
}
170+
171+
// final newStreamId = event.newStreamId; // null if topic-only move
172+
// final newTopic = event.newTopic!;
173+
// TODO(#150): Handle message moves. The views' recipient headers
174+
// may need updating, and consequently showSender too.
175+
}
176+
142177
void handleDeleteMessageEvent(DeleteMessageEvent event) {
143178
// TODO handle DeleteMessageEvent, particularly in MessageListView
144179
}

0 commit comments

Comments
 (0)