Skip to content

Commit 4392beb

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. Co-authored-by: Zixuan James Li <[email protected]>
1 parent 95fbd04 commit 4392beb

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

lib/model/message.dart

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,43 +173,34 @@ 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-
}());
190183
return;
191184
}
192185

193-
if (origStreamId == null) {
186+
if (origStreamId == null || newStreamId == null) {
194187
// The `stream_id` field (aka origStreamId) is documented to be present on moves.
188+
// newStreamId should not be null either because it falls back to origStreamId.
195189
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
196190
return;
197191
}
192+
if (origTopic == null || newTopic == null) {
193+
// The `orig_subject` field (aka origTopic) is documented to be present on moves.
194+
// newTopic should not be null either because it falls back to origTopic.
195+
assert(debugLog('Malformed UpdateMessageEvent: move but no origTopic')); // TODO(log)
196+
return;
197+
}
198198
if (propagateMode == null) {
199199
// The `propagate_mode` field (aka propagateMode) is documented to be present on moves.
200200
assert(debugLog('Malformed UpdateMessageEvent: move but no propagateMode')); // TODO(log)
201201
return;
202202
}
203203

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-
213204
final wasResolveOrUnresolve = newStreamId == origStreamId
214205
&& MessageEditState.topicMoveWasResolveOrUnresolve(origTopic, newTopic);
215206

0 commit comments

Comments
 (0)