@@ -717,7 +717,7 @@ class UpdateMessageMoveData {
717
717
required this .propagateMode,
718
718
required this .origTopic,
719
719
required this .newTopic,
720
- });
720
+ }) : assert (origStreamId != newStreamId || origTopic != newTopic) ;
721
721
722
722
/// Try to extract [UpdateMessageMoveData] from the JSON object for an
723
723
/// [UpdateMessageEvent] .
@@ -730,50 +730,33 @@ class UpdateMessageMoveData {
730
730
// This may matter if we ever need 'stream_id' when no message move occurred.
731
731
static UpdateMessageMoveData ? tryParseFromJson (Object ? json) {
732
732
json as Map <String , Object ?>;
733
- final origStreamId = (json['stream_id' ] as num ? )? .toInt ();
734
- final newStreamId = (json['new_stream_id' ] as num ? )? .toInt ();
735
733
final propagateModeString = json['propagate_mode' ] as String ? ;
736
734
final propagateMode = propagateModeString == null ? null
737
735
: PropagateMode .fromRawString (propagateModeString);
738
- final origTopic = json['orig_subject' ] == null ? null
739
- : TopicName .fromJson (json['orig_subject' ] as String );
740
- final newTopic = json['subject' ] == null ? null
741
- : TopicName .fromJson (json['subject' ] as String );
742
736
743
- if (origTopic == null ) {
737
+ if (propagateMode == null ) {
744
738
// There was no move.
745
- assert (() {
746
- if (newStreamId != null && origStreamId != null
747
- && newStreamId != origStreamId) {
748
- // This should be impossible; `orig_subject` (aka origTopic) is
749
- // documented to be present when either the stream or topic changed.
750
- throw FormatException ('stream move but no origTopic' );
751
- }
752
- return true ;
753
- }());
754
739
return null ;
755
740
}
756
741
757
- if (newStreamId == null && newTopic == null ) {
742
+ final origStreamId = (json['stream_id' ] as num ).toInt ();
743
+ final newStreamId = (json['new_stream_id' ] as num ? )? .toInt () ?? origStreamId;
744
+ final origTopic = TopicName .fromJson (json['orig_subject' ] as String );
745
+ final newTopic = json['subject' ] == null ? origTopic
746
+ : TopicName .fromJson (json['subject' ] as String );
747
+
748
+ if (origStreamId == newStreamId && origTopic == newTopic) {
758
749
// If neither the channel nor topic name changed, nothing moved.
759
- // In that case `orig_subject` (aka origTopic) should have been null.
760
- throw FormatException ('move but no newStreamId or newTopic' );
761
- }
762
- if (origStreamId == null ) {
763
- // The `stream_id` field (aka origStreamId) is documented to be present on moves.
764
- throw FormatException ('move but no origStreamId' );
765
- }
766
- if (propagateMode == null ) {
767
- // The `propagate_mode` field (aka propagateMode) is documented to be present on moves.
768
- throw FormatException ('move but no propagateMode' );
750
+ // In that case `propagate_mode` (aka propagateMode) should have been null.
751
+ throw FormatException ('move but unchanged newStreamId and newTopic' );
769
752
}
770
753
771
754
return UpdateMessageMoveData (
772
755
origStreamId: origStreamId,
773
- newStreamId: newStreamId ?? origStreamId ,
756
+ newStreamId: newStreamId,
774
757
propagateMode: propagateMode,
775
758
origTopic: origTopic,
776
- newTopic: newTopic ?? origTopic ,
759
+ newTopic: newTopic,
777
760
);
778
761
}
779
762
0 commit comments