Skip to content

Commit 74a010b

Browse files
committed
subscription_list: Show unread count when hasOnlyMutedMentions
1 parent a1411cc commit 74a010b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

lib/model/unreads.dart

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,25 @@ class Unreads extends ChangeNotifier {
194194
return c;
195195
}
196196

197+
/// The "broadest" unread count for this channel,
198+
/// without doing any checking on visibility policy.
199+
///
200+
/// This includes all topics that have regardless visibility policy,
201+
/// even if the channel is muted.
202+
///
203+
/// This is needed for one specific case, which is when the channel has
204+
/// only muted unreads including a mention or more, in that case we show
205+
/// total unread count including muted unreads.
206+
int countAll(int streamId) {
207+
final topics = streams[streamId];
208+
if (topics == null) return 0;
209+
int c = 0;
210+
for (final entry in topics.entries) {
211+
c = c + entry.value.length;
212+
}
213+
return c;
214+
}
215+
197216
int countInTopicNarrow(int streamId, String topic) {
198217
final topics = streams[streamId];
199218
return topics?[topic]?.length ?? 0;

lib/widgets/subscription_list.dart

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,11 @@ class _SubscriptionList extends StatelessWidget {
198198
final hasOnlyMutedMentions = !subscription.isMuted
199199
&& channelsWithMentions.contains(subscription.streamId)
200200
&& !channelsWithUnmutedMentions.contains(subscription.streamId);
201+
final mutedUnreadCount = hasOnlyMutedMentions && unreadCount == 0 ?
202+
unreadsModel!.countAll(subscription.streamId) : 0;
201203
return SubscriptionItem(subscription: subscription,
202204
unreadCount: unreadCount,
205+
mutedUnreadCount: mutedUnreadCount,
203206
showMutedUnreadBadge: showMutedUnreadBadge,
204207
hasMentions: hasMentions,
205208
hasOnlyMutedMentions: hasOnlyMutedMentions);
@@ -213,13 +216,15 @@ class SubscriptionItem extends StatelessWidget {
213216
super.key,
214217
required this.subscription,
215218
required this.unreadCount,
219+
required this.mutedUnreadCount,
216220
required this.showMutedUnreadBadge,
217221
required this.hasMentions,
218222
required this.hasOnlyMutedMentions,
219223
});
220224

221225
final Subscription subscription;
222226
final int unreadCount;
227+
final int mutedUnreadCount;
223228
final bool showMutedUnreadBadge;
224229
final bool hasMentions;
225230
final bool hasOnlyMutedMentions;
@@ -230,7 +235,8 @@ class SubscriptionItem extends StatelessWidget {
230235

231236
final swatch = colorSwatchFor(context, subscription);
232237
final hasUnreads = (unreadCount > 0);
233-
final opacity = subscription.isMuted ? 0.55 : 1.0;
238+
const mutedOpacity = 0.55;
239+
final opacity = subscription.isMuted ? mutedOpacity : 1.0;
234240
return Material(
235241
// TODO(design) check if this is the right variable
236242
color: designVariables.background,
@@ -277,6 +283,15 @@ class SubscriptionItem extends StatelessWidget {
277283
count: unreadCount,
278284
backgroundColor: swatch,
279285
bold: true)),
286+
] else if (hasOnlyMutedMentions && !subscription.isMuted) ...[
287+
const SizedBox(width: 12),
288+
const AtMentionMarker(muted: true),
289+
Opacity(
290+
opacity: mutedOpacity,
291+
child: UnreadCountBadge(
292+
count: mutedUnreadCount,
293+
backgroundColor: swatch,
294+
bold: true)),
280295
] else if (showMutedUnreadBadge) ...[
281296
const SizedBox(width: 12),
282297
if (hasMentions) const AtMentionMarker(muted: true),

test/widgets/subscription_list_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,29 @@ void main() {
189189
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
190190
});
191191

192+
testWidgets('unread badge shows as faded when non-muted subscription has only muted mentions', (tester) async {
193+
final stream = eg.stream();
194+
195+
await setupStreamListPage(tester,
196+
subscriptions: [
197+
eg.subscription(stream),
198+
],
199+
userTopics: [
200+
eg.userTopicItem(stream, 'a', UserTopicVisibilityPolicy.muted),
201+
],
202+
unreadMsgs: eg.unreadMsgs(
203+
mentions: [1, 2],
204+
channels: [
205+
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'a', unreadMessageIds: [1, 2]),
206+
]),
207+
);
208+
209+
check(find.byType(AtMentionMarker).evaluate()).single;
210+
check(tester.widget<Text>(find.descendant(
211+
of: find.byType(UnreadCountBadge), matching: find.byType(Text))))
212+
.data.equals('2');
213+
});
214+
192215
testWidgets('muted unread badge shows when unreads are visible in channel but not inbox', (tester) async {
193216
final stream = eg.stream();
194217
final unreadMsgs = eg.unreadMsgs(channels: [

0 commit comments

Comments
 (0)