Skip to content

Commit c7ae486

Browse files
committed
home: Show unread count on Channels button in main menu
Add a counter badge showing the number of unread channel messages on the Channels button in the main menu. The count is computed as countInCombinedFeedNarrow() - countInDms(), matching the web app. Also add an explicit test confirming that _CombinedFeedButton does not show a counter badge, documenting the intentional absence. Fixes-partly: zulip#1088
1 parent c82aae7 commit c7ae486

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

lib/widgets/home.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,21 @@ class _ChannelsButton extends _NavigationBarMenuButton {
755755
return zulipLocalizations.channelsPageTitle;
756756
}
757757

758+
@override
759+
Widget? buildTrailing(BuildContext context) {
760+
final store = PerAccountStoreWidget.of(context);
761+
final unreads = store.unreads;
762+
final unreadCount =
763+
unreads.countInCombinedFeedNarrow() - unreads.countInDms();
764+
if (unreadCount == 0) return null;
765+
return CounterBadge(
766+
kind: CounterBadgeKind.unread,
767+
style: CounterBadgeStyle.mainMenu,
768+
count: unreadCount,
769+
channelIdForBackground: null,
770+
);
771+
}
772+
758773
@override
759774
_HomePageTab get navigationTarget => _HomePageTab.channels;
760775
}

test/widgets/home_test.dart

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,52 @@ void main () {
495495
});
496496
});
497497

498+
group('_ChannelsButton counter', () {
499+
final findButton = find.byWidgetPredicate((widget) =>
500+
widget is MenuButton && widget.icon == ZulipIcons.hash_italic);
501+
502+
testWidgets('no badge when no unread channel messages', (tester) async {
503+
await prepare(tester);
504+
await tapOpenMenuAndAwait(tester);
505+
check(find.descendant(
506+
of: findButton, matching: find.byType(CounterBadge))).findsNothing();
507+
debugNetworkImageHttpClientProvider = null;
508+
});
509+
510+
testWidgets('shows unread channel message count', (tester) async {
511+
await prepare(tester);
512+
await addUnreadStreamMessage();
513+
await tapOpenMenuAndAwait(tester);
514+
check(find.descendant(
515+
of: findButton, matching: find.text('1'))).findsOne();
516+
debugNetworkImageHttpClientProvider = null;
517+
});
518+
519+
testWidgets('does not count DM unreads', (tester) async {
520+
await prepare(tester);
521+
final dmMessage = eg.dmMessage(from: eg.otherUser, to: [eg.selfUser]);
522+
await store.addMessage(dmMessage);
523+
await tapOpenMenuAndAwait(tester);
524+
check(find.descendant(
525+
of: findButton, matching: find.byType(CounterBadge))).findsNothing();
526+
debugNetworkImageHttpClientProvider = null;
527+
});
528+
});
529+
530+
group('_CombinedFeedButton', () {
531+
final findButton = find.byWidgetPredicate((widget) =>
532+
widget is MenuButton && widget.icon == ZulipIcons.message_feed);
533+
534+
testWidgets('no counter badge', (tester) async {
535+
await prepare(tester);
536+
await addUnreadStreamMessage();
537+
await tapOpenMenuAndAwait(tester);
538+
check(find.descendant(
539+
of: findButton, matching: find.byType(CounterBadge))).findsNothing();
540+
debugNetworkImageHttpClientProvider = null;
541+
});
542+
});
543+
498544
group('_DirectMessagesButton counter', () {
499545
final findButton = find.byWidgetPredicate((widget) =>
500546
widget is MenuButton && widget.icon == ZulipIcons.two_person);

0 commit comments

Comments
 (0)