Skip to content

Commit 64ac89e

Browse files
committed
subscription_list: Show unread count when hasOnlyMutedMentions
1 parent 0c52009 commit 64ac89e

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
@@ -193,6 +193,25 @@ class Unreads extends ChangeNotifier {
193193
return c;
194194
}
195195

196+
/// The "broadest" unread count for this channel,
197+
/// without doing any checking on visibility policy.
198+
///
199+
/// This includes all topics that have regardless visibility policy,
200+
/// even if the channel is muted.
201+
///
202+
/// This is needed for one specific case, which is when the channel has
203+
/// only muted unreads including a mention or more, in that case we show
204+
/// total unread count including muted unreads.
205+
int countAll(int streamId) {
206+
final topics = streams[streamId];
207+
if (topics == null) return 0;
208+
int c = 0;
209+
for (final entry in topics.entries) {
210+
c = c + entry.value.length;
211+
}
212+
return c;
213+
}
214+
196215
int countInTopicNarrow(int streamId, String topic) {
197216
final topics = streams[streamId];
198217
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
@@ -188,6 +188,29 @@ void main() {
188188
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
189189
});
190190

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

0 commit comments

Comments
 (0)