Skip to content

Commit

Permalink
subscription_list: Show @-mention indicator when it applies
Browse files Browse the repository at this point in the history
Fixes: zulip#747
  • Loading branch information
Khader-1 committed Aug 9, 2024
1 parent 32e37ca commit 2656d84
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/model/unreads.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,17 @@ class Unreads extends ChangeNotifier {
}
}

Set<int> get channelsWithUnreadMentions {
final channels = <int>{};
for (var messageId in mentions) {
final streamId = _reverseStreamsLookup[messageId]?.streamId;
if (streamId != null) {
channels.add(streamId);
}
}
return channels;
}

void handleMessageEvent(MessageEvent event) {
final message = event.message;
if (message.flags.contains(MessageFlag.read)) {
Expand Down
17 changes: 14 additions & 3 deletions lib/widgets/subscription_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,19 @@ class _SubscriptionList extends StatelessWidget {

@override
Widget build(BuildContext context) {
final channelsWithMentions = unreadsModel!.channelsWithUnreadMentions;
return SliverList.builder(
itemCount: subscriptions.length,
itemBuilder: (BuildContext context, int index) {
final subscription = subscriptions[index];
final unreadCount = unreadsModel!.countInChannel(subscription.streamId);
final showMutedUnreadBadge = unreadCount == 0
&& unreadsModel!.countInChannelNarrow(subscription.streamId) > 0;
final hasMentions = channelsWithMentions.contains(subscription.streamId);
return SubscriptionItem(subscription: subscription,
unreadCount: unreadCount,
showMutedUnreadBadge: showMutedUnreadBadge);
showMutedUnreadBadge: showMutedUnreadBadge,
hasMentions: hasMentions);
});
}
}
Expand All @@ -205,11 +208,13 @@ class SubscriptionItem extends StatelessWidget {
required this.subscription,
required this.unreadCount,
required this.showMutedUnreadBadge,
required this.hasMentions,
});

final Subscription subscription;
final int unreadCount;
final bool showMutedUnreadBadge;
final bool hasMentions;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -257,7 +262,10 @@ class SubscriptionItem extends StatelessWidget {
subscription.name)))),
if (hasUnreads) ...[
const SizedBox(width: 12),
// TODO(#747) show @-mention indicator when it applies
if (hasMentions) ...[
const Text('@'),
const SizedBox(width: 8),
],
Opacity(
opacity: opacity,
child: UnreadCountBadge(
Expand All @@ -266,7 +274,10 @@ class SubscriptionItem extends StatelessWidget {
bold: true)),
] else if (showMutedUnreadBadge) ...[
const SizedBox(width: 12),
// TODO(#747) show @-mention indicator when it applies
if (hasMentions) ...[
const Text('@'),
const SizedBox(width: 8),
],
const MutedUnreadBadge(),
],
const SizedBox(width: 16),
Expand Down
14 changes: 14 additions & 0 deletions test/model/unreads_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,20 @@ void main() {
});
}
});

test('channelsWithUnreadMentions', () {
final stream1 = eg.stream();
final stream2 = eg.stream();

prepare();
fillWithMessages([
eg.streamMessage(stream: stream1, flags: [MessageFlag.mentioned]),
eg.streamMessage(stream: stream1, flags: []),
eg.streamMessage(stream: stream2, flags: []),
]);

check(model.channelsWithUnreadMentions.single).equals(stream1.streamId);
});
});

group('DM messages', () {
Expand Down
28 changes: 28 additions & 0 deletions test/widgets/subscription_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -315,4 +315,32 @@ void main() {
checkStreamNameWght(mutedStreamWithUnmutedUnreads.name, 400);
checkStreamNameWght(mutedStreamWithNoUnmutedUnreads.name, 400);
});

testWidgets('@-mention indicator is shown when subscription has unread mentions', (tester) async {
void checkMentionIndicatorsCount(int expectedCount) {
check(find.text('@').evaluate().length).equals(expectedCount);
}

final streamWithMentions = eg.stream();
final streamWithNoMentions = eg.stream();

await setupStreamListPage(tester,
subscriptions: [
eg.subscription(streamWithMentions),
eg.subscription(streamWithNoMentions),
],
userTopics: [
eg.userTopicItem(streamWithMentions, 'a', UserTopicVisibilityPolicy.unmuted),
eg.userTopicItem(streamWithNoMentions, 'b', UserTopicVisibilityPolicy.muted),
],
unreadMsgs: eg.unreadMsgs(
mentions: [1],
channels: [
UnreadChannelSnapshot(streamId: streamWithMentions.streamId, topic: 'a', unreadMessageIds: [1]),
UnreadChannelSnapshot(streamId: streamWithNoMentions.streamId, topic: 'b', unreadMessageIds: [2]),
]),
);

checkMentionIndicatorsCount(1);
});
}

0 comments on commit 2656d84

Please sign in to comment.