Skip to content

Commit d97b0bc

Browse files
committed
msglist [nfc]: Make narrow mutable for _MessageListPageState.
This allows us to switch narrow when a move happens. Signed-off-by: Zixuan James Li <[email protected]>
1 parent a0219c2 commit d97b0bc

File tree

11 files changed

+25
-19
lines changed

11 files changed

+25
-19
lines changed

integration_test/unreadmarker_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void main() {
4040
child: PerAccountStoreWidget(
4141
accountId: eg.selfAccount.id,
4242
placeholder: const LoadingPlaceholderPage(),
43-
child: const MessageListPage(narrow: CombinedFeedNarrow())))));
43+
child: const MessageListPage(initNarrow: CombinedFeedNarrow())))));
4444
await tester.pumpAndSettle();
4545
return messages;
4646
}

lib/notifications/display.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ class NotificationDisplayManager {
273273
// TODO(nav): Better interact with existing nav stack on notif open
274274
navigator.push(MaterialAccountWidgetRoute<void>(accountId: account.id,
275275
// TODO(#82): Open at specific message, not just conversation
276-
page: MessageListPage(narrow: narrow)));
276+
page: MessageListPage(initNarrow: narrow)));
277277
return;
278278
}
279279

lib/widgets/message_list.dart

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ abstract class MessageListPageState {
3737
}
3838

3939
class MessageListPage extends StatefulWidget {
40-
const MessageListPage({super.key, required this.narrow});
40+
const MessageListPage({super.key, required this.initNarrow});
4141

4242
static Route<void> buildRoute({int? accountId, BuildContext? context,
4343
required Narrow narrow}) {
4444
return MaterialAccountWidgetRoute(accountId: accountId, context: context,
45-
page: MessageListPage(narrow: narrow));
45+
page: MessageListPage(initNarrow: narrow));
4646
}
4747

4848
/// The [MessageListPageState] above this context in the tree.
@@ -57,7 +57,7 @@ class MessageListPage extends StatefulWidget {
5757
return state!;
5858
}
5959

60-
final Narrow narrow;
60+
final Narrow initNarrow;
6161

6262
@override
6363
State<MessageListPage> createState() => _MessageListPageState();
@@ -68,20 +68,26 @@ const _kUnsubscribedStreamRecipientHeaderColor = Color(0xfff5f5f5);
6868

6969
class _MessageListPageState extends State<MessageListPage> implements MessageListPageState {
7070
@override
71-
Narrow get narrow => widget.narrow;
71+
late Narrow narrow;
7272

7373
@override
7474
ComposeBoxController? get composeBoxController => _composeBoxKey.currentState;
7575

7676
final GlobalKey<ComposeBoxController> _composeBoxKey = GlobalKey();
7777

78+
@override
79+
void initState() {
80+
narrow = widget.initNarrow;
81+
super.initState();
82+
}
83+
7884
@override
7985
Widget build(BuildContext context) {
8086
final store = PerAccountStoreWidget.of(context);
8187

8288
final Color? appBarBackgroundColor;
8389
bool removeAppBarBottomBorder = false;
84-
switch(widget.narrow) {
90+
switch(narrow) {
8591
case CombinedFeedNarrow():
8692
appBarBackgroundColor = null; // i.e., inherit
8793

@@ -103,7 +109,7 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
103109
}
104110

105111
return Scaffold(
106-
appBar: AppBar(title: MessageListAppBarTitle(narrow: widget.narrow),
112+
appBar: AppBar(title: MessageListAppBarTitle(narrow: narrow),
107113
backgroundColor: appBarBackgroundColor,
108114
shape: removeAppBarBottomBorder
109115
? const Border()
@@ -129,11 +135,11 @@ class _MessageListPageState extends State<MessageListPage> implements MessageLis
129135
// if those details get complicated, refactor to avoid copying.
130136
// TODO(#311) If we have a bottom nav, it will pad the bottom
131137
// inset, and this should always be true.
132-
removeBottom: widget.narrow is! CombinedFeedNarrow,
138+
removeBottom: narrow is! CombinedFeedNarrow,
133139

134140
child: Expanded(
135-
child: MessageList(narrow: widget.narrow))),
136-
ComposeBox(controllerKey: _composeBoxKey, narrow: widget.narrow),
141+
child: MessageList(narrow: narrow))),
142+
ComposeBox(controllerKey: _composeBoxKey, narrow: narrow),
137143
]))));
138144
}
139145
}

test/notifications/display_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ void main() {
362362
route.isA<MaterialAccountWidgetRoute>()
363363
..accountId.equals(account.id)
364364
..page.isA<MessageListPage>()
365-
.narrow.equals(SendableNarrow.ofMessage(message,
365+
.initNarrow.equals(SendableNarrow.ofMessage(message,
366366
selfUserId: account.userId));
367367
}
368368

test/widgets/action_sheet_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Future<void> setupToMessageActionSheet(WidgetTester tester, {
6868
home: GlobalStoreWidget(
6969
child: PerAccountStoreWidget(
7070
accountId: eg.selfAccount.id,
71-
child: MessageListPage(narrow: narrow))))));
71+
child: MessageListPage(initNarrow: narrow))))));
7272

7373
// global store, per-account store, and message list get loaded
7474
await tester.pumpAndSettle();

test/widgets/autocomplete_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Future<Finder> setupToComposeInput(WidgetTester tester, {
5858
child: PerAccountStoreWidget(
5959
accountId: eg.selfAccount.id,
6060
child: MessageListPage(
61-
narrow: DmNarrow(
61+
initNarrow: DmNarrow(
6262
allRecipientIds: [eg.selfUser.userId, eg.otherUser.userId],
6363
selfUserId: eg.selfUser.userId,
6464
)))))));

test/widgets/content_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ void main() {
820820
await tapText(tester, find.text('stream'));
821821
check(testBinding.takeLaunchUrlCalls()).isEmpty();
822822
check(pushedRoutes).single.isA<WidgetRoute>()
823-
.page.isA<MessageListPage>().narrow.equals(const StreamNarrow(1));
823+
.page.isA<MessageListPage>().initNarrow.equals(const StreamNarrow(1));
824824
});
825825

826826
testWidgets('invalid internal links are opened in browser', (tester) async {

test/widgets/message_list_checks.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import 'package:zulip/model/narrow.dart';
33
import 'package:zulip/widgets/message_list.dart';
44

55
extension MessageListPageChecks on Subject<MessageListPage> {
6-
Subject<Narrow> get narrow => has((x) => x.narrow, 'narrow');
6+
Subject<Narrow> get initNarrow => has((x) => x.initNarrow, 'initNarrow');
77
}

test/widgets/message_list_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ void main() {
7676
home: GlobalStoreWidget(
7777
child: PerAccountStoreWidget(
7878
accountId: eg.selfAccount.id,
79-
child: MessageListPage(narrow: narrow))))));
79+
child: MessageListPage(initNarrow: narrow))))));
8080

8181
// global store, per-account store, and message list get loaded
8282
await tester.pumpAndSettle();

test/widgets/profile_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ void main() {
259259
await tester.tap(targetWidget);
260260
check(pushedRoutes).last.isA<WidgetRoute>().page
261261
.isA<MessageListPage>()
262-
.narrow.equals(DmNarrow.withUser(1, selfUserId: eg.selfUser.userId));
262+
.initNarrow.equals(DmNarrow.withUser(1, selfUserId: eg.selfUser.userId));
263263
});
264264

265265
testWidgets('page builds; user links render multiple avatars', (WidgetTester tester) async {

test/widgets/recent_dm_conversations_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ void main() {
328328

329329
check(pushedRoutes).last.isA<WidgetRoute>().page
330330
.isA<MessageListPage>()
331-
.narrow.equals(expectedNarrow);
331+
.initNarrow.equals(expectedNarrow);
332332
}
333333

334334
testWidgets('1:1', (WidgetTester tester) async {

0 commit comments

Comments
 (0)