Skip to content

Commit a635d4f

Browse files
committed
subscription_list: Show unread count when hasOnlyMutedMentions
1 parent b1e8fb7 commit a635d4f

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-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
@@ -197,8 +197,11 @@ class _SubscriptionList extends StatelessWidget {
197197
final hasMentions = channelsWithMentions.contains(subscription.streamId);
198198
final hasOnlyMutedMentions = !subscription.isMuted && hasMentions
199199
&& !channelsWithUnmutedMentions.contains(subscription.streamId);
200+
final mutedUnreadCount = hasOnlyMutedMentions && unreadCount == 0 ?
201+
unreadsModel!.countAll(subscription.streamId) : 0;
200202
return SubscriptionItem(subscription: subscription,
201203
unreadCount: unreadCount,
204+
mutedUnreadCount: mutedUnreadCount,
202205
showMutedUnreadBadge: showMutedUnreadBadge,
203206
hasMentions: hasMentions,
204207
hasOnlyMutedMentions: hasOnlyMutedMentions);
@@ -212,13 +215,15 @@ class SubscriptionItem extends StatelessWidget {
212215
super.key,
213216
required this.subscription,
214217
required this.unreadCount,
218+
required this.mutedUnreadCount,
215219
required this.showMutedUnreadBadge,
216220
required this.hasMentions,
217221
required this.hasOnlyMutedMentions,
218222
});
219223

220224
final Subscription subscription;
221225
final int unreadCount;
226+
final int mutedUnreadCount;
222227
final bool showMutedUnreadBadge;
223228
final bool hasMentions;
224229
final bool hasOnlyMutedMentions;
@@ -229,7 +234,8 @@ class SubscriptionItem extends StatelessWidget {
229234

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

test/widgets/subscription_list_test.dart

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

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

0 commit comments

Comments
 (0)