Skip to content

Commit 5e12050

Browse files
gnpricechrisbobbe
authored andcommitted
message [nfc]: Pull out orig/new values from move as local variables
This lets the Dart compiler see that these are definitely constant through the function (which it can't assume when they're getters on an object). That in turn lets it narrow the types based on our null checks, so that we can leave out `!` operators later. That's small now, but will be more useful as we add more logic to this function -- if we had to scatter `!` all around that logic, we'd have to wonder whether some of them were unjustified assumptions and might throw at runtime. Also rename one local to "newStreamId", matching the property it mirrors. We'll rename both the variable and the property together, as part of a sweep coming up soon (#631).
1 parent 3409127 commit 5e12050

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

lib/model/message.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,16 @@ class MessageStoreImpl with MessageStore {
148148
// The interaction between the fields of these events are a bit tricky.
149149
// For reference, see: https://zulip.com/api/get-events#update_message
150150

151-
if (event.origTopic == null) {
151+
final origStreamId = event.origStreamId;
152+
final newStreamId = event.newStreamId; // null if topic-only move
153+
final origTopic = event.origTopic;
154+
final newTopic = event.newTopic;
155+
156+
if (origTopic == null) {
152157
// There was no move.
153158
assert(() {
154-
if (event.newStreamId != null && event.origStreamId != null
155-
&& event.newStreamId != event.origStreamId) {
159+
if (newStreamId != null && origStreamId != null
160+
&& newStreamId != origStreamId) {
156161
// This should be impossible; `orig_subject` (aka origTopic) is
157162
// documented to be present when either the stream or topic changed.
158163
debugLog('Malformed UpdateMessageEvent: stream move but no origTopic'); // TODO(log)
@@ -162,22 +167,19 @@ class MessageStoreImpl with MessageStore {
162167
return;
163168
}
164169

165-
if (event.newTopic == null) {
170+
if (newTopic == null) {
166171
// The `subject` field (aka newTopic) is documented to be present on moves.
167172
assert(debugLog('Malformed UpdateMessageEvent: move but no newTopic')); // TODO(log)
168173
return;
169174
}
170-
if (event.origStreamId == null) {
175+
if (origStreamId == null) {
171176
// The `stream_id` field (aka origStreamId) is documented to be present on moves.
172177
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
173178
return;
174179
}
175180

176-
final newTopic = event.newTopic!;
177-
final newChannelId = event.newStreamId; // null if topic-only move
178-
179-
if (newChannelId == null
180-
&& MessageEditState.topicMoveWasResolveOrUnresolve(event.origTopic!, newTopic)) {
181+
if (newStreamId == null
182+
&& MessageEditState.topicMoveWasResolveOrUnresolve(origTopic, newTopic)) {
181183
// The topic was only resolved/unresolved.
182184
// No change to the messages' editState.
183185
return;

0 commit comments

Comments
 (0)