Skip to content

Commit 98e3527

Browse files
committed
inbox [nfc]: Get data all from subscription object, vs. stream
Since we always have the subscription object around, we might as well use it for the stream properties too, simplifying this code a bit.
1 parent 0219c16 commit 98e3527

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

lib/widgets/inbox.dart

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
8686
@override
8787
Widget build(BuildContext context) {
8888
final store = PerAccountStoreWidget.of(context);
89-
90-
final streams = store.streams;
9189
final subscriptions = store.subscriptions;
9290

9391
// TODO(perf) make an incrementally-updated view-model for InboxPage
@@ -111,30 +109,26 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
111109
}
112110

113111
final sortedUnreadStreams = unreadsModel!.streams.entries
114-
.where((entry) =>
115-
streams.containsKey(entry.key) // TODO(log) a bug if missing in streams
116-
// Filter out any straggling unreads in unsubscribed streams.
117-
// There won't normally be any, but it happens with certain infrequent
118-
// state changes, typically for less than a few hundred milliseconds.
119-
// See [Unreads].
120-
//
121-
// Also, we want to depend on the subscription data for things like
122-
// choosing the stream icon.
123-
&& subscriptions.containsKey(entry.key))
112+
// Filter out any straggling unreads in unsubscribed streams.
113+
// There won't normally be any, but it happens with certain infrequent
114+
// state changes, typically for less than a few hundred milliseconds.
115+
// See [Unreads].
116+
//
117+
// Also, we want to depend on the subscription data for things like
118+
// choosing the stream icon.
119+
.where((entry) => subscriptions.containsKey(entry.key))
124120
.toList()
125121
..sort((a, b) {
122+
final subA = subscriptions[a.key]!;
123+
final subB = subscriptions[b.key]!;
124+
126125
// TODO "pin" icon on the stream row? dividers in the list?
127-
final aPinned = subscriptions[a.key]!.pinToTop;
128-
final bPinned = subscriptions[b.key]!.pinToTop;
129-
if (aPinned != bPinned) {
130-
return aPinned ? -1 : 1;
126+
if (subA.pinToTop != subB.pinToTop) {
127+
return subA.pinToTop ? -1 : 1;
131128
}
132129

133-
final streamA = streams[a.key]!;
134-
final streamB = streams[b.key]!;
135-
136130
// TODO(i18n) something like JS's String.prototype.localeCompare
137-
return streamA.name.toLowerCase().compareTo(streamB.name.toLowerCase());
131+
return subA.name.toLowerCase().compareTo(subB.name.toLowerCase());
138132
});
139133

140134
for (final MapEntry(key: streamId, value: topics) in sortedUnreadStreams) {

0 commit comments

Comments
 (0)