Skip to content

Commit 5b6c13a

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 7b7021e commit 5b6c13a

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
@@ -454,10 +454,16 @@ class MessageListView with ChangeNotifier, _MessageSequence {
454454
.._register();
455455
}
456456

457-
MessageListView._({required this.store, required this.narrow});
457+
MessageListView._({required this.store, required Narrow narrow})
458+
: _narrow = narrow;
458459

459460
final PerAccountStore store;
460-
Narrow narrow;
461+
462+
/// The narrow shown in this message list.
463+
///
464+
/// This can change over time, notably if showing a topic that gets moved.
465+
Narrow get narrow => _narrow;
466+
Narrow _narrow;
461467

462468
void _register() {
463469
store.registerMessageList(this);
@@ -601,9 +607,9 @@ class MessageListView with ChangeNotifier, _MessageSequence {
601607
// This can't be a redirect; a redirect can't produce an empty result.
602608
// (The server only redirects if the message is accessible to the user,
603609
// and if it is, it'll appear in the result, making it non-empty.)
604-
this.narrow = narrow.sansWith();
610+
_narrow = narrow.sansWith();
605611
case StreamMessage():
606-
this.narrow = TopicNarrow.ofMessage(someFetchedMessageOrNull);
612+
_narrow = TopicNarrow.ofMessage(someFetchedMessageOrNull);
607613
case DmMessage(): // TODO(log)
608614
assert(false);
609615
}
@@ -786,7 +792,7 @@ class MessageListView with ChangeNotifier, _MessageSequence {
786792
switch (propagateMode) {
787793
case PropagateMode.changeAll:
788794
case PropagateMode.changeLater:
789-
narrow = newNarrow;
795+
_narrow = newNarrow;
790796
_reset();
791797
fetchInitial();
792798
case PropagateMode.changeOne:

0 commit comments

Comments
 (0)