Skip to content

Commit 28d93bd

Browse files
committed
inbox: Show at-mention marker on streams
The `hasMention` flag was added to the abstract `_HeaderItem` class so `_AllDmsHeaderItem` is affected by this change. It will be hard-coded as False for DMs for now.
1 parent 2c182c9 commit 28d93bd

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/widgets/inbox.dart

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,12 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
134134
for (final MapEntry(key: streamId, value: topics) in sortedUnreadStreams) {
135135
final topicItems = <(String, int, bool, int)>[];
136136
int countInStream = 0;
137+
bool streamHasMention = false;
137138
for (final MapEntry(key: topic, value: messageIds) in topics.entries) {
138139
if (!store.isTopicVisible(streamId, topic)) continue;
139140
final countInTopic = messageIds.length;
140141
final hasMention = messageIds.any((messageId) => unreadsModel!.mentions.contains(messageId));
142+
if (hasMention) streamHasMention = true;
141143
topicItems.add((topic, countInTopic, hasMention, messageIds.last));
142144
countInStream += countInTopic;
143145
}
@@ -149,7 +151,7 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
149151
final (_, _, _, bLastUnreadId) = b;
150152
return bLastUnreadId.compareTo(aLastUnreadId);
151153
});
152-
sections.add(_StreamSectionData(streamId, countInStream, topicItems));
154+
sections.add(_StreamSectionData(streamId, countInStream, streamHasMention, topicItems));
153155
}
154156

155157
return Scaffold(
@@ -190,20 +192,23 @@ class _AllDmsSectionData extends _InboxSectionData {
190192
class _StreamSectionData extends _InboxSectionData {
191193
final int streamId;
192194
final int count;
195+
final bool hasMention;
193196
final List<(String, int, bool, int)> items;
194197

195-
const _StreamSectionData(this.streamId, this.count, this.items);
198+
const _StreamSectionData(this.streamId, this.count, this.hasMention, this.items);
196199
}
197200

198201
abstract class _HeaderItem extends StatelessWidget {
199202
final bool collapsed;
200203
final _InboxPageState pageState;
201204
final int count;
205+
final bool hasMention;
202206

203207
const _HeaderItem({
204208
required this.collapsed,
205209
required this.pageState,
206210
required this.count,
211+
required this.hasMention,
207212
});
208213

209214
String get title;
@@ -247,7 +252,7 @@ abstract class _HeaderItem extends StatelessWidget {
247252
overflow: TextOverflow.ellipsis,
248253
title))),
249254
const SizedBox(width: 12),
250-
// TODO(#384) for streams, show @-mention indicator when it applies
255+
if (hasMention) const _AtMentionMarker(),
251256
Padding(padding: const EdgeInsetsDirectional.only(end: 16),
252257
child: UnreadCountBadge(backgroundColor: unreadCountBadgeBackgroundColor, bold: true,
253258
count: count)),
@@ -260,6 +265,7 @@ class _AllDmsHeaderItem extends _HeaderItem {
260265
required super.collapsed,
261266
required super.pageState,
262267
required super.count,
268+
required super.hasMention,
263269
});
264270

265271
@override get title => 'Direct messages'; // TODO(i18n)
@@ -290,6 +296,7 @@ class _AllDmsSection extends StatelessWidget {
290296
Widget build(BuildContext context) {
291297
final header = _AllDmsHeaderItem(
292298
count: data.count,
299+
hasMention: false,
293300
collapsed: collapsed,
294301
pageState: pageState,
295302
);
@@ -369,6 +376,7 @@ class _StreamHeaderItem extends _HeaderItem {
369376
required super.collapsed,
370377
required super.pageState,
371378
required super.count,
379+
required super.hasMention,
372380
});
373381

374382
@override get title => subscription.name;
@@ -407,6 +415,7 @@ class _StreamSection extends StatelessWidget {
407415
final header = _StreamHeaderItem(
408416
subscription: subscription,
409417
count: data.count,
418+
hasMention: data.hasMention,
410419
collapsed: collapsed,
411420
pageState: pageState,
412421
);

test/widgets/inbox_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ void main() {
203203
unreadMessages: [eg.streamMessage(stream: stream, topic: topic,
204204
flags: [MessageFlag.mentioned])]);
205205

206+
check(hasAtSign(tester, findStreamHeaderRow(tester, stream.streamId)))
207+
.isTrue();
206208
check(hasAtSign(tester, findRowByLabel(tester, topic))).isTrue();
207209
});
208210

@@ -213,6 +215,8 @@ void main() {
213215
unreadMessages: [eg.streamMessage(stream: stream, topic: topic,
214216
flags: [])]);
215217

218+
check(hasAtSign(tester, findStreamHeaderRow(tester, stream.streamId)))
219+
.isFalse();
216220
check(hasAtSign(tester, findRowByLabel(tester, topic))).isFalse();
217221
});
218222
});

0 commit comments

Comments
 (0)