Skip to content

Commit f9efd71

Browse files
committed
msglist [nfc]: Document narrow field; make setter private
Even if the reader is already sure that the field doesn't get mutated from outside this file, giving it a different name from the getter is useful for seeing exactly where it does get mutated: now one can look at the references to `_narrow`, and see the mutation sites without having them intermingled with all the sites that just read it.
1 parent aff0ae5 commit f9efd71

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

lib/model/message_list.dart

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,16 @@ class MessageListView with ChangeNotifier, _MessageSequence {
424424
.._register();
425425
}
426426

427-
MessageListView._({required this.store, required this.narrow});
427+
MessageListView._({required this.store, required Narrow narrow})
428+
: _narrow = narrow;
428429

429430
final PerAccountStore store;
430-
Narrow narrow;
431+
432+
/// The narrow shown in this message list.
433+
///
434+
/// This can change over time, notably if showing a topic that gets moved.
435+
Narrow get narrow => _narrow;
436+
Narrow _narrow;
431437

432438
void _register() {
433439
store.registerMessageList(this);
@@ -571,9 +577,9 @@ class MessageListView with ChangeNotifier, _MessageSequence {
571577
// This can't be a redirect; a redirect can't produce an empty result.
572578
// (The server only redirects if the message is accessible to the user,
573579
// and if it is, it'll appear in the result, making it non-empty.)
574-
this.narrow = narrow.sansWith();
580+
_narrow = narrow.sansWith();
575581
case StreamMessage():
576-
this.narrow = TopicNarrow.ofMessage(someFetchedMessageOrNull);
582+
_narrow = TopicNarrow.ofMessage(someFetchedMessageOrNull);
577583
case DmMessage(): // TODO(log)
578584
assert(false);
579585
}
@@ -734,7 +740,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
734740
switch (propagateMode) {
735741
case PropagateMode.changeAll:
736742
case PropagateMode.changeLater:
737-
narrow = newNarrow;
743+
_narrow = newNarrow;
738744
_reset();
739745
fetchInitial();
740746
case PropagateMode.changeOne:

0 commit comments

Comments
 (0)