Skip to content

Commit a850103

Browse files
committed
msglist [nfc]: s/composeBox{Controller,State}/ in MessageListPageState
Soon we'll want a method for starting a message-edit session, and it'll make sense to put it on ComposeBoxState rather than ComposeBoxController; one reason is that it'll need UI code to show an error dialog. With this change, the ComposeBoxState -- and so that new method -- will be accessible in the message-list widget code, where we open the message action sheet from.
1 parent b7c3eed commit a850103

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

lib/widgets/action_sheet.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ void showMessageActionSheet({required BuildContext context, required Message mes
562562
// So we rely on the fact that isComposeBoxOffered for any given message list
563563
// will be constant through the page's life.
564564
final messageListPage = MessageListPage.ancestorOf(pageContext);
565-
final isComposeBoxOffered = messageListPage.composeBoxController != null;
565+
final isComposeBoxOffered = messageListPage.composeBoxState != null;
566566

567567
final isMessageRead = message.flags.contains(MessageFlag.read);
568568
final markAsUnreadSupported = store.zulipFeatureLevel >= 155; // TODO(server-6)
@@ -827,7 +827,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
827827
final zulipLocalizations = ZulipLocalizations.of(pageContext);
828828
final message = this.message;
829829

830-
var composeBoxController = findMessageListPage().composeBoxController;
830+
var composeBoxController = findMessageListPage().composeBoxState?.controller;
831831
// The compose box doesn't null out its controller; it's either always null
832832
// (e.g. in Combined Feed) or always non-null; it can't have been nulled out
833833
// after the action sheet opened.
@@ -857,7 +857,7 @@ class QuoteAndReplyButton extends MessageActionSheetMenuItemButton {
857857

858858
if (!pageContext.mounted) return;
859859

860-
composeBoxController = findMessageListPage().composeBoxController;
860+
composeBoxController = findMessageListPage().composeBoxState?.controller;
861861
// The compose box doesn't null out its controller; it's either always null
862862
// (e.g. in Combined Feed) or always non-null; it can't have been nulled out
863863
// during the raw-content request.

lib/widgets/message_list.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ abstract class MessageListPageState {
149149
/// The narrow for this page's message list.
150150
Narrow get narrow;
151151

152-
/// The controller for this [MessageListPage]'s compose box,
152+
/// The [ComposeBoxState] for this [MessageListPage]'s compose box,
153153
/// if this [MessageListPage] offers a compose box and it has mounted,
154154
/// else null.
155-
ComposeBoxController? get composeBoxController;
155+
ComposeBoxState? get composeBoxState;
156156

157157
/// The active [MessageListView].
158158
///
@@ -192,7 +192,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
192192
late Narrow narrow;
193193

194194
@override
195-
ComposeBoxController? get composeBoxController => _composeBoxKey.currentState?.controller;
195+
ComposeBoxState? get composeBoxState => _composeBoxKey.currentState;
196196
final GlobalKey<ComposeBoxState> _composeBoxKey = GlobalKey();
197197

198198
@override

test/widgets/message_list_test.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,20 @@ void main() {
136136
check(state.narrow).equals(ChannelNarrow(stream.streamId));
137137
});
138138

139-
testWidgets('composeBoxController finds compose box', (tester) async {
139+
testWidgets('composeBoxState finds compose box', (tester) async {
140140
final stream = eg.stream();
141141
await setupMessageListPage(tester, narrow: ChannelNarrow(stream.streamId),
142142
streams: [stream],
143143
messages: [eg.streamMessage(stream: stream, content: "<p>a message</p>")]);
144144
final state = MessageListPage.ancestorOf(tester.element(find.text("a message")));
145-
check(state.composeBoxController).isNotNull();
145+
check(state.composeBoxState).isNotNull();
146146
});
147147

148-
testWidgets('composeBoxController null when no compose box', (tester) async {
148+
testWidgets('composeBoxState null when no compose box', (tester) async {
149149
await setupMessageListPage(tester, narrow: const CombinedFeedNarrow(),
150150
messages: [eg.streamMessage(content: "<p>a message</p>")]);
151151
final state = MessageListPage.ancestorOf(tester.element(find.text("a message")));
152-
check(state.composeBoxController).isNull();
152+
check(state.composeBoxState).isNull();
153153
});
154154

155155
testWidgets('dispose MessageListView when event queue expired', (tester) async {
@@ -256,7 +256,7 @@ void main() {
256256
// Verify this message list lacks a compose box.
257257
// (The original bug wouldn't reproduce with a compose box present.)
258258
final state = MessageListPage.ancestorOf(tester.element(find.text("verb\natim")));
259-
check(state.composeBoxController).isNull();
259+
check(state.composeBoxState).isNull();
260260

261261
final element = tester.element(find.byType(CodeBlock));
262262
final padding = MediaQuery.of(element).padding;

0 commit comments

Comments
 (0)