Skip to content

Commit

Permalink
compose [nfc]: Simplify choose-body logic by switching on controller
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbobbe committed Nov 27, 2024
1 parent bac2ce9 commit 84c812e
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions lib/widgets/compose_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1356,24 +1356,17 @@ class _ComposeBoxState extends State<ComposeBox> implements ComposeBoxState {
// ZulipLocalizations.of(context).errorSendMessageTimeout);
// }
final narrow = widget.narrow;
switch (narrow) {
case ChannelNarrow():
assert(_controller is StreamComposeBoxController);
body = _StreamComposeBoxBody(controller: (_controller as StreamComposeBoxController),
narrow: narrow);
case TopicNarrow():
assert(_controller is FixedDestinationComposeBoxController);
body = _FixedDestinationComposeBoxBody(controller: (_controller as FixedDestinationComposeBoxController),
narrow: narrow);
case DmNarrow():
assert(_controller is FixedDestinationComposeBoxController);
body = _FixedDestinationComposeBoxBody(controller: (_controller as FixedDestinationComposeBoxController),
narrow: narrow);
case CombinedFeedNarrow():
case MentionsNarrow():
case StarredMessagesNarrow():
assert(false);
body = null;
switch (_controller) {
case StreamComposeBoxController(): {
assert(narrow is ChannelNarrow);
body = _StreamComposeBoxBody(controller: _controller,
narrow: (narrow as ChannelNarrow));
}
case FixedDestinationComposeBoxController(): {
assert(narrow is SendableNarrow);
body = _FixedDestinationComposeBoxBody(controller: _controller,
narrow: (narrow as SendableNarrow));
}
}
}

Expand Down

0 comments on commit 84c812e

Please sign in to comment.