Skip to content

Commit 99d2413

Browse files
committed
subscription_list: Show @-mention indicator when it applies
Fixes: #747
1 parent 7b6d47e commit 99d2413

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
@@ -184,16 +184,19 @@ class _SubscriptionList extends StatelessWidget {
184184

185185
@override
186186
Widget build(BuildContext context) {
187+
final channelsWithMentions = unreadsModel!.channelsWithUnreadMentions;
187188
return SliverList.builder(
188189
itemCount: subscriptions.length,
189190
itemBuilder: (BuildContext context, int index) {
190191
final subscription = subscriptions[index];
191192
final unreadCount = unreadsModel!.countInChannel(subscription.streamId);
192193
final showMutedUnreadBadge = unreadCount == 0
193194
&& unreadsModel!.countInChannelNarrow(subscription.streamId) > 0;
195+
final hasMentions = channelsWithMentions.contains(subscription.streamId);
194196
return SubscriptionItem(subscription: subscription,
195197
unreadCount: unreadCount,
196-
showMutedUnreadBadge: showMutedUnreadBadge);
198+
showMutedUnreadBadge: showMutedUnreadBadge,
199+
hasMentions: hasMentions);
197200
});
198201
}
199202
}
@@ -205,11 +208,13 @@ class SubscriptionItem extends StatelessWidget {
205208
required this.subscription,
206209
required this.unreadCount,
207210
required this.showMutedUnreadBadge,
211+
required this.hasMentions,
208212
});
209213

210214
final Subscription subscription;
211215
final int unreadCount;
212216
final bool showMutedUnreadBadge;
217+
final bool hasMentions;
213218

214219
@override
215220
Widget build(BuildContext context) {
@@ -257,7 +262,7 @@ class SubscriptionItem extends StatelessWidget {
257262
subscription.name)))),
258263
if (hasUnreads) ...[
259264
const SizedBox(width: 12),
260-
// TODO(#747) show @-mention indicator when it applies
265+
if (hasMentions) const AtMentionMarker(),
261266
Opacity(
262267
opacity: opacity,
263268
child: UnreadCountBadge(
@@ -266,7 +271,7 @@ class SubscriptionItem extends StatelessWidget {
266271
bold: true)),
267272
] else if (showMutedUnreadBadge) ...[
268273
const SizedBox(width: 12),
269-
// TODO(#747) show @-mention indicator when it applies
274+
if (hasMentions) const AtMentionMarker(),
270275
const MutedUnreadBadge(),
271276
],
272277
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.text('@').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)