Skip to content

Commit 5149268

Browse files
gnpricePIG208
andcommitted
message [nfc]: In moves, give newStreamId/newTopic their fallback values sooner
To see that this is NFC, first observe that the only possible behavior change this could cause is to change some event from being ignored (hitting a `return` in this section of code) to being processed by the code below, or vice versa. (It might also change what particular message gets printed to the debug log; but that doesn't count as a behavior change.) Then both before and after this change, the events that this overall set of conditions accepts are those that (a) have all of origTopic, origStreamId, and propagateMode non-null, and (b) have at least one of newTopic or newStreamId with a non-null value different from origTopic or origStreamId respectively. This change is useful because it brings this logic closer to how it will look when we move it into the API parsing code. While here, we add a debug log message on unexpected propagateMode, to further bring this closer to how it will look in the API parsing code. Co-authored-by: Zixuan James Li <[email protected]>
1 parent d396e28 commit 5149268

File tree

1 file changed

+16
-20
lines changed

1 file changed

+16
-20
lines changed

lib/model/message.dart

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,43 +173,39 @@ class MessageStoreImpl with MessageStore {
173173
// For reference, see: https://zulip.com/api/get-events#update_message
174174

175175
final origStreamId = event.origStreamId;
176+
final newStreamId = event.newStreamId ?? origStreamId;
176177
final origTopic = event.origTopic;
178+
final newTopic = event.newTopic ?? origTopic;
177179
final propagateMode = event.propagateMode;
178180

179-
if (origTopic == null) {
181+
if (newStreamId == origStreamId && newTopic == origTopic) {
180182
// There was no move.
181-
assert(() {
182-
if (event.newStreamId != null && origStreamId != null
183-
&& event.newStreamId != origStreamId) {
184-
// This should be impossible; `orig_subject` (aka origTopic) is
185-
// documented to be present when either the stream or topic changed.
186-
debugLog('Malformed UpdateMessageEvent: stream move but no origTopic'); // TODO(log)
187-
}
188-
return true;
189-
}());
183+
if (propagateMode != null) {
184+
assert(debugLog(
185+
'Malformed UpdateMessageEvent: incoherent message-move fields; '
186+
'propagate_mode present but no new channel or topic')); // TODO(log)
187+
}
190188
return;
191189
}
192190

193-
if (origStreamId == null) {
191+
if (origStreamId == null || newStreamId == null) {
194192
// The `stream_id` field (aka origStreamId) is documented to be present on moves.
193+
// newStreamId should not be null either because it falls back to origStreamId.
195194
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
196195
return;
197196
}
197+
if (origTopic == null || newTopic == null) {
198+
// The `orig_subject` field (aka origTopic) is documented to be present on moves.
199+
// newTopic should not be null either because it falls back to origTopic.
200+
assert(debugLog('Malformed UpdateMessageEvent: move but no origTopic')); // TODO(log)
201+
return;
202+
}
198203
if (propagateMode == null) {
199204
// The `propagate_mode` field (aka propagateMode) is documented to be present on moves.
200205
assert(debugLog('Malformed UpdateMessageEvent: move but no propagateMode')); // TODO(log)
201206
return;
202207
}
203208

204-
final newStreamId = event.newStreamId ?? origStreamId;
205-
final newTopic = event.newTopic ?? origTopic;
206-
if (newStreamId == origStreamId && newTopic == origTopic) {
207-
// If neither the channel nor topic name changed, nothing moved.
208-
// In that case `orig_subject` (aka origTopic) should have been null.
209-
assert(debugLog('Malformed UpdateMessageEvent: move but no newStreamId or newTopic')); // TODO(log)
210-
return;
211-
}
212-
213209
final wasResolveOrUnresolve = newStreamId == origStreamId
214210
&& MessageEditState.topicMoveWasResolveOrUnresolve(origTopic, newTopic);
215211

0 commit comments

Comments
 (0)