Skip to content

Commit 62038de

Browse files
committed
api: Simplify move data parsing
This drops the separate if-statements in favor of null-checks and tries to rely on the natural semantics of the API. See Greg's comment on this: zulip#1311 (comment) Signed-off-by: Zixuan James Li <[email protected]>
1 parent f242b02 commit 62038de

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

lib/api/model/events.dart

+4-23
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ class UpdateMessageMoveData {
718718
required this.propagateMode,
719719
required this.origTopic,
720720
required this.newTopic,
721-
});
721+
}) : assert(origStreamId != newStreamId || origTopic != newTopic);
722722

723723
/// Try to extract [UpdateMessageMoveData] from the JSON object for an
724724
/// [UpdateMessageEvent].
@@ -741,17 +741,8 @@ class UpdateMessageMoveData {
741741
final newTopic = json['subject'] == null ? null
742742
: TopicName.fromJson(json['subject'] as String);
743743

744-
if (origTopic == null) {
744+
if (propagateMode == null) {
745745
// There was no move.
746-
assert(() {
747-
if (newStreamId != null && origStreamId != null
748-
&& newStreamId != origStreamId) {
749-
// This should be impossible; `orig_subject` (aka origTopic) is
750-
// documented to be present when either the stream or topic changed.
751-
debugLog('Malformed UpdateMessageEvent: stream move but no origTopic'); // TODO(log)
752-
}
753-
return true;
754-
}());
755746
return null;
756747
}
757748

@@ -761,22 +752,12 @@ class UpdateMessageMoveData {
761752
assert(debugLog('Malformed UpdateMessageEvent: move but no newStreamId or newTopic')); // TODO(log)
762753
throw FormatException();
763754
}
764-
if (origStreamId == null) {
765-
// The `stream_id` field (aka origStreamId) is documented to be present on moves.
766-
assert(debugLog('Malformed UpdateMessageEvent: move but no origStreamId')); // TODO(log)
767-
throw FormatException();
768-
}
769-
if (propagateMode == null) {
770-
// The `propagate_mode` field (aka propagateMode) is documented to be present on moves.
771-
assert(debugLog('Malformed UpdateMessageEvent: move but no propagateMode')); // TODO(log)
772-
throw FormatException();
773-
}
774755

775756
return UpdateMessageMoveData(
776-
origStreamId: origStreamId,
757+
origStreamId: origStreamId!,
777758
newStreamId: newStreamId ?? origStreamId,
778759
propagateMode: propagateMode,
779-
origTopic: origTopic,
760+
origTopic: origTopic!,
780761
newTopic: newTopic ?? origTopic,
781762
);
782763
}

0 commit comments

Comments
 (0)