Skip to content

Commit aad1988

Browse files
committed
inbox: Show at-mention markers on DMs
Fixes: #384
1 parent 3ac1fe3 commit aad1988

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

lib/widgets/inbox.dart

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,22 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
9494
// TODO efficiently include DM conversations that aren't recent enough
9595
// to appear in recentDmConversationsView, but still have unreads in
9696
// unreadsModel.
97-
final dmItems = <(DmNarrow, int)>[];
97+
final dmItems = <(DmNarrow, int, bool)>[];
9898
int allDmsCount = 0;
99+
bool allDmsHasMention = false;
99100
for (final dmNarrow in recentDmConversationsModel!.sorted) {
100101
final countInNarrow = unreadsModel!.countInDmNarrow(dmNarrow);
101102
if (countInNarrow == 0) {
102103
continue;
103104
}
104-
dmItems.add((dmNarrow, countInNarrow));
105+
final hasMention = unreadsModel!.dms[dmNarrow]!.any(
106+
(messageId) => unreadsModel!.mentions.contains(messageId));
107+
if (hasMention) allDmsHasMention = true;
108+
dmItems.add((dmNarrow, countInNarrow, hasMention));
105109
allDmsCount += countInNarrow;
106110
}
107111
if (allDmsCount > 0) {
108-
sections.add(_AllDmsSectionData(allDmsCount, dmItems));
112+
sections.add(_AllDmsSectionData(allDmsCount, allDmsHasMention, dmItems));
109113
}
110114

111115
final sortedUnreadStreams = unreadsModel!.streams.entries
@@ -184,9 +188,10 @@ sealed class _InboxSectionData {
184188

185189
class _AllDmsSectionData extends _InboxSectionData {
186190
final int count;
187-
final List<(DmNarrow, int)> items;
191+
final bool hasMention;
192+
final List<(DmNarrow, int, bool)> items;
188193

189-
const _AllDmsSectionData(this.count, this.items);
194+
const _AllDmsSectionData(this.count, this.hasMention, this.items);
190195
}
191196

192197
class _StreamSectionData extends _InboxSectionData {
@@ -296,7 +301,7 @@ class _AllDmsSection extends StatelessWidget {
296301
Widget build(BuildContext context) {
297302
final header = _AllDmsHeaderItem(
298303
count: data.count,
299-
hasMention: false,
304+
hasMention: data.hasMention,
300305
collapsed: collapsed,
301306
pageState: pageState,
302307
);
@@ -305,10 +310,11 @@ class _AllDmsSection extends StatelessWidget {
305310
child: Column(children: [
306311
header,
307312
if (!collapsed) ...data.items.map((item) {
308-
final (narrow, count) = item;
313+
final (narrow, count, hasMention) = item;
309314
return _DmItem(
310315
narrow: narrow,
311316
count: count,
317+
hasMention: hasMention,
312318
);
313319
}),
314320
]));
@@ -319,10 +325,12 @@ class _DmItem extends StatelessWidget {
319325
const _DmItem({
320326
required this.narrow,
321327
required this.count,
328+
required this.hasMention,
322329
});
323330

324331
final DmNarrow narrow;
325332
final int count;
333+
final bool hasMention;
326334

327335
@override
328336
Widget build(BuildContext context) {
@@ -361,6 +369,7 @@ class _DmItem extends StatelessWidget {
361369
overflow: TextOverflow.ellipsis,
362370
title))),
363371
const SizedBox(width: 12),
372+
if (hasMention) const _AtMentionMarker(),
364373
Padding(padding: const EdgeInsetsDirectional.only(end: 16),
365374
child: UnreadCountBadge(backgroundColor: null,
366375
count: count)),

test/widgets/inbox_test.dart

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,26 @@ void main() {
219219
.isFalse();
220220
check(hasAtSign(tester, findRowByLabel(tester, topic))).isFalse();
221221
});
222+
223+
testWidgets('dm with a mention', (tester) async {
224+
await setupPage(tester,
225+
users: [eg.selfUser, eg.otherUser],
226+
unreadMessages: [eg.dmMessage(from: eg.otherUser, to: [eg.selfUser],
227+
flags: [MessageFlag.mentioned])]);
228+
229+
check(hasAtSign(tester, findAllDmsHeaderRow(tester))).isTrue();
230+
check(hasAtSign(tester, findRowByLabel(tester, eg.otherUser.fullName))).isTrue();
231+
});
232+
233+
testWidgets('dm without mention', (tester) async {
234+
await setupPage(tester,
235+
users: [eg.selfUser, eg.otherUser],
236+
unreadMessages: [eg.dmMessage(from: eg.otherUser, to: [eg.selfUser],
237+
flags: [])]);
238+
239+
check(hasAtSign(tester, findAllDmsHeaderRow(tester))).isFalse();
240+
check(hasAtSign(tester, findRowByLabel(tester, eg.otherUser.fullName))).isFalse();
241+
});
222242
});
223243

224244
group('collapsing', () {

0 commit comments

Comments
 (0)