Skip to content

Commit

Permalink
inbox: Show at-mention markers on DMs
Browse files Browse the repository at this point in the history
Fixes: zulip#384
  • Loading branch information
sirpengi authored and gnprice committed Feb 12, 2024
1 parent 97e87c0 commit ee99129
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
23 changes: 16 additions & 7 deletions lib/widgets/inbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,22 @@ class _InboxPageState extends State<InboxPage> with PerAccountStoreAwareStateMix
// TODO efficiently include DM conversations that aren't recent enough
// to appear in recentDmConversationsView, but still have unreads in
// unreadsModel.
final dmItems = <(DmNarrow, int)>[];
final dmItems = <(DmNarrow, int, bool)>[];
int allDmsCount = 0;
bool allDmsHasMention = false;
for (final dmNarrow in recentDmConversationsModel!.sorted) {
final countInNarrow = unreadsModel!.countInDmNarrow(dmNarrow);
if (countInNarrow == 0) {
continue;
}
dmItems.add((dmNarrow, countInNarrow));
final hasMention = unreadsModel!.dms[dmNarrow]!.any(
(messageId) => unreadsModel!.mentions.contains(messageId));
if (hasMention) allDmsHasMention = true;
dmItems.add((dmNarrow, countInNarrow, hasMention));
allDmsCount += countInNarrow;
}
if (allDmsCount > 0) {
sections.add(_AllDmsSectionData(allDmsCount, dmItems));
sections.add(_AllDmsSectionData(allDmsCount, allDmsHasMention, dmItems));
}

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

class _AllDmsSectionData extends _InboxSectionData {
final int count;
final List<(DmNarrow, int)> items;
final bool hasMention;
final List<(DmNarrow, int, bool)> items;

const _AllDmsSectionData(this.count, this.items);
const _AllDmsSectionData(this.count, this.hasMention, this.items);
}

class _StreamSectionData extends _InboxSectionData {
Expand Down Expand Up @@ -296,7 +301,7 @@ class _AllDmsSection extends StatelessWidget {
Widget build(BuildContext context) {
final header = _AllDmsHeaderItem(
count: data.count,
hasMention: false,
hasMention: data.hasMention,
collapsed: collapsed,
pageState: pageState,
);
Expand All @@ -305,10 +310,11 @@ class _AllDmsSection extends StatelessWidget {
child: Column(children: [
header,
if (!collapsed) ...data.items.map((item) {
final (narrow, count) = item;
final (narrow, count, hasMention) = item;
return _DmItem(
narrow: narrow,
count: count,
hasMention: hasMention,
);
}),
]));
Expand All @@ -319,10 +325,12 @@ class _DmItem extends StatelessWidget {
const _DmItem({
required this.narrow,
required this.count,
required this.hasMention,
});

final DmNarrow narrow;
final int count;
final bool hasMention;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -361,6 +369,7 @@ class _DmItem extends StatelessWidget {
overflow: TextOverflow.ellipsis,
title))),
const SizedBox(width: 12),
if (hasMention) const _AtMentionMarker(),
Padding(padding: const EdgeInsetsDirectional.only(end: 16),
child: UnreadCountBadge(backgroundColor: null,
count: count)),
Expand Down
20 changes: 20 additions & 0 deletions test/widgets/inbox_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,26 @@ void main() {
.isFalse();
check(hasAtSign(tester, findRowByLabel(tester, topic))).isFalse();
});

testWidgets('dm with a mention', (tester) async {
await setupPage(tester,
users: [eg.selfUser, eg.otherUser],
unreadMessages: [eg.dmMessage(from: eg.otherUser, to: [eg.selfUser],
flags: [MessageFlag.mentioned])]);

check(hasAtSign(tester, findAllDmsHeaderRow(tester))).isTrue();
check(hasAtSign(tester, findRowByLabel(tester, eg.otherUser.fullName))).isTrue();
});

testWidgets('dm without mention', (tester) async {
await setupPage(tester,
users: [eg.selfUser, eg.otherUser],
unreadMessages: [eg.dmMessage(from: eg.otherUser, to: [eg.selfUser],
flags: [])]);

check(hasAtSign(tester, findAllDmsHeaderRow(tester))).isFalse();
check(hasAtSign(tester, findRowByLabel(tester, eg.otherUser.fullName))).isFalse();
});
});

group('collapsing', () {
Expand Down

0 comments on commit ee99129

Please sign in to comment.