Skip to content

Commit 058b711

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 f113594 commit 058b711

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.
@@ -95,8 +96,7 @@ class MessageStoreImpl with MessageStore {
9596
void handleUpdateMessageEvent(UpdateMessageEvent event) {
9697
_handleUpdateMessageEventTimestamp(event);
9798
_handleUpdateMessageEventContent(event);
98-
// TODO(#150): Handle message moves. The views' recipient headers
99-
// may need updating, and consequently showSender too.
99+
_handleUpdateMessageEventMove(event);
100100
for (final view in _messageListViews) {
101101
view.notifyListenersIfAnyMessagePresent(event.messageIds);
102102
}
@@ -138,6 +138,41 @@ class MessageStoreImpl with MessageStore {
138138
}
139139
}
140140

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

0 commit comments

Comments
 (0)