Skip to content

Commit e5e635e

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 6054679 commit e5e635e

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

lib/model/message.dart

+32-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,36 @@ class MessageStoreImpl with MessageStore {
138138
}
139139
}
140140

141+
void _handleUpdateMessageEventMove(UpdateMessageEvent event) {
142+
if (event.origTopic == null) {
143+
// There was no move.
144+
assert(() {
145+
if (event.newStreamId != null && event.origStreamId != null
146+
&& event.newStreamId != event.origStreamId) {
147+
// This should be impossible; `orig_subject` (aka origTopic) is
148+
// documented to be present when either the stream or topic changed.
149+
debugLog('Malformed UpdateMessageEvent: stream move but no origTopic'); // TODO(log)
150+
}
151+
return true;
152+
}());
153+
return;
154+
}
155+
156+
if (event.newTopic == null) {
157+
assert(debugLog('Malformed UpdateMessageEvent: move but no topic')); // TODO(log)
158+
return;
159+
}
160+
if (event.origStreamId == null) {
161+
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
162+
return;
163+
}
164+
165+
// final newStreamId = event.newStreamId; // null if topic-only move
166+
// final newTopic = event.newTopic!;
167+
// TODO(#150): Handle message moves. The views' recipient headers
168+
// may need updating, and consequently showSender too.
169+
}
170+
141171
void handleDeleteMessageEvent(DeleteMessageEvent event) {
142172
// TODO handle DeleteMessageEvent, particularly in MessageListView
143173
}

0 commit comments

Comments
 (0)