Skip to content

Commit 39188fd

Browse files
committed
subscription_list: Show @-mention indicator when it applies
Fixes: #747
1 parent a26e05a commit 39188fd

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

lib/model/unreads.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,17 @@ class Unreads extends ChangeNotifier {
219219
}
220220
}
221221

222+
Set<int> get channelsWithUnreadMentions {
223+
final channels = <int>{};
224+
for (var messageId in mentions) {
225+
final streamId = _reverseStreamsLookup[messageId]?.streamId;
226+
if (streamId != null) {
227+
channels.add(streamId);
228+
}
229+
}
230+
return channels;
231+
}
232+
222233
void handleMessageEvent(MessageEvent event) {
223234
final message = event.message;
224235
if (message.flags.contains(MessageFlag.read)) {

lib/widgets/subscription_list.dart

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,16 +185,19 @@ class _SubscriptionList extends StatelessWidget {
185185

186186
@override
187187
Widget build(BuildContext context) {
188+
final channelsWithMentions = unreadsModel!.channelsWithUnreadMentions;
188189
return SliverList.builder(
189190
itemCount: subscriptions.length,
190191
itemBuilder: (BuildContext context, int index) {
191192
final subscription = subscriptions[index];
192193
final unreadCount = unreadsModel!.countInChannel(subscription.streamId);
193194
final showMutedUnreadBadge = unreadCount == 0
194195
&& unreadsModel!.countInChannelNarrow(subscription.streamId) > 0;
196+
final hasMentions = channelsWithMentions.contains(subscription.streamId);
195197
return SubscriptionItem(subscription: subscription,
196198
unreadCount: unreadCount,
197-
showMutedUnreadBadge: showMutedUnreadBadge);
199+
showMutedUnreadBadge: showMutedUnreadBadge,
200+
hasMentions: hasMentions);
198201
});
199202
}
200203
}
@@ -206,11 +209,13 @@ class SubscriptionItem extends StatelessWidget {
206209
required this.subscription,
207210
required this.unreadCount,
208211
required this.showMutedUnreadBadge,
212+
required this.hasMentions,
209213
});
210214

211215
final Subscription subscription;
212216
final int unreadCount;
213217
final bool showMutedUnreadBadge;
218+
final bool hasMentions;
214219

215220
@override
216221
Widget build(BuildContext context) {
@@ -258,7 +263,7 @@ class SubscriptionItem extends StatelessWidget {
258263
subscription.name)))),
259264
if (hasUnreads) ...[
260265
const SizedBox(width: 12),
261-
// TODO(#747) show @-mention indicator when it applies
266+
if (hasMentions) const AtMentionMarker(),
262267
Opacity(
263268
opacity: opacity,
264269
child: UnreadCountBadge(
@@ -267,7 +272,7 @@ class SubscriptionItem extends StatelessWidget {
267272
bold: true)),
268273
] else if (showMutedUnreadBadge) ...[
269274
const SizedBox(width: 12),
270-
// TODO(#747) show @-mention indicator when it applies
275+
if (hasMentions) const AtMentionMarker(),
271276
const MutedUnreadBadge(),
272277
],
273278
const SizedBox(width: 16),

test/model/unreads_test.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,20 @@ void main() {
298298
});
299299
}
300300
});
301+
302+
test('channelsWithUnreadMentions', () {
303+
final stream1 = eg.stream();
304+
final stream2 = eg.stream();
305+
306+
prepare();
307+
fillWithMessages([
308+
eg.streamMessage(stream: stream1, flags: [MessageFlag.mentioned]),
309+
eg.streamMessage(stream: stream1, flags: []),
310+
eg.streamMessage(stream: stream2, flags: []),
311+
]);
312+
313+
check(model.channelsWithUnreadMentions.single).equals(stream1.streamId);
314+
});
301315
});
302316

303317
group('DM messages', () {

test/widgets/subscription_list_test.dart

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,32 @@ void main() {
315315
checkStreamNameWght(mutedStreamWithUnmutedUnreads.name, 400);
316316
checkStreamNameWght(mutedStreamWithNoUnmutedUnreads.name, 400);
317317
});
318+
319+
testWidgets('@-mention indicator is shown when subscription has unread mentions', (tester) async {
320+
void checkMentionIndicatorsCount(int expectedCount) {
321+
check(find.byIcon(ZulipIcons.at_sign).evaluate().length).equals(expectedCount);
322+
}
323+
324+
final streamWithMentions = eg.stream();
325+
final streamWithNoMentions = eg.stream();
326+
327+
await setupStreamListPage(tester,
328+
subscriptions: [
329+
eg.subscription(streamWithMentions),
330+
eg.subscription(streamWithNoMentions),
331+
],
332+
userTopics: [
333+
eg.userTopicItem(streamWithMentions, 'a', UserTopicVisibilityPolicy.unmuted),
334+
eg.userTopicItem(streamWithNoMentions, 'b', UserTopicVisibilityPolicy.muted),
335+
],
336+
unreadMsgs: eg.unreadMsgs(
337+
mentions: [1],
338+
channels: [
339+
UnreadChannelSnapshot(streamId: streamWithMentions.streamId, topic: 'a', unreadMessageIds: [1]),
340+
UnreadChannelSnapshot(streamId: streamWithNoMentions.streamId, topic: 'b', unreadMessageIds: [2]),
341+
]),
342+
);
343+
344+
checkMentionIndicatorsCount(1);
345+
});
318346
}

0 commit comments

Comments
 (0)