Skip to content

Commit 6b005df

Browse files
committed
inbox [nfc]: Factor out a data class so things are clearly labeled
1 parent cac0171 commit 6b005df

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

lib/widgets/inbox.dart

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,28 @@ class _InboxPageState extends State<InboxPageBody> with PerAccountStoreAwareStat
132132
});
133133

134134
for (final MapEntry(key: streamId, value: topics) in sortedUnreadStreams) {
135-
final topicItems = <(TopicName, int, bool, int)>[];
135+
final topicItems = <_StreamSectionTopicData>[];
136136
int countInStream = 0;
137137
bool streamHasMention = false;
138138
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
139139
if (!store.isTopicVisible(streamId, topic)) continue;
140140
final countInTopic = messageIds.length;
141141
final hasMention = messageIds.any((messageId) => unreadsModel!.mentions.contains(messageId));
142142
if (hasMention) streamHasMention = true;
143-
topicItems.add((topic, countInTopic, hasMention, messageIds.last));
143+
topicItems.add(_StreamSectionTopicData(
144+
topic: topic,
145+
count: countInTopic,
146+
hasMention: hasMention,
147+
lastUnreadId: messageIds.last,
148+
));
144149
countInStream += countInTopic;
145150
}
146151
if (countInStream == 0) {
147152
continue;
148153
}
149154
topicItems.sort((a, b) {
150-
final (_, _, _, aLastUnreadId) = a;
151-
final (_, _, _, bLastUnreadId) = b;
155+
final aLastUnreadId = a.lastUnreadId;
156+
final bLastUnreadId = b.lastUnreadId;
152157
return bLastUnreadId.compareTo(aLastUnreadId);
153158
});
154159
sections.add(_StreamSectionData(streamId, countInStream, streamHasMention, topicItems));
@@ -192,11 +197,25 @@ class _StreamSectionData extends _InboxSectionData {
192197
final int streamId;
193198
final int count;
194199
final bool hasMention;
195-
final List<(TopicName, int, bool, int)> items;
200+
final List<_StreamSectionTopicData> items;
196201

197202
const _StreamSectionData(this.streamId, this.count, this.hasMention, this.items);
198203
}
199204

205+
class _StreamSectionTopicData {
206+
final TopicName topic;
207+
final int count;
208+
final bool hasMention;
209+
final int lastUnreadId;
210+
211+
const _StreamSectionTopicData({
212+
required this.topic,
213+
required this.count,
214+
required this.hasMention,
215+
required this.lastUnreadId,
216+
});
217+
}
218+
200219
abstract class _HeaderItem extends StatelessWidget {
201220
final bool collapsed;
202221
final _InboxPageState pageState;
@@ -466,7 +485,7 @@ class _StreamSection extends StatelessWidget {
466485
child: Column(children: [
467486
header,
468487
if (!collapsed) ...data.items.map((item) {
469-
final (topic, count, hasMention, _) = item;
488+
final _StreamSectionTopicData(:topic, :count, :hasMention) = item;
470489
return _TopicItem(
471490
streamId: data.streamId,
472491
topic: topic,

0 commit comments

Comments
 (0)