Skip to content

Commit f0b3596

Browse files
Khader-1gnprice
authored andcommitted
subscription_list: Show a dot for unreads if channel is muted
Fixes: #712
1 parent 5d80ad5 commit f0b3596

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

lib/widgets/subscription_list.dart

+12-3
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ class _SubscriptionList extends StatelessWidget {
189189
itemBuilder: (BuildContext context, int index) {
190190
final subscription = subscriptions[index];
191191
final unreadCount = unreadsModel!.countInChannel(subscription.streamId);
192-
// TODO(#712): if stream muted, show a dot for unreads
193-
return SubscriptionItem(subscription: subscription, unreadCount: unreadCount);
192+
final showMutedUnreadBadge = unreadCount == 0
193+
&& unreadsModel!.countInChannelNarrow(subscription.streamId) > 0;
194+
return SubscriptionItem(subscription: subscription,
195+
unreadCount: unreadCount,
196+
showMutedUnreadBadge: showMutedUnreadBadge);
194197
});
195198
}
196199
}
@@ -201,10 +204,12 @@ class SubscriptionItem extends StatelessWidget {
201204
super.key,
202205
required this.subscription,
203206
required this.unreadCount,
207+
required this.showMutedUnreadBadge,
204208
});
205209

206210
final Subscription subscription;
207211
final int unreadCount;
212+
final bool showMutedUnreadBadge;
208213

209214
@override
210215
Widget build(BuildContext context) {
@@ -250,7 +255,7 @@ class SubscriptionItem extends StatelessWidget {
250255
maxLines: 1,
251256
overflow: TextOverflow.ellipsis,
252257
subscription.name)))),
253-
if (unreadCount > 0) ...[
258+
if (hasUnreads) ...[
254259
const SizedBox(width: 12),
255260
// TODO(#747) show @-mention indicator when it applies
256261
Opacity(
@@ -259,6 +264,10 @@ class SubscriptionItem extends StatelessWidget {
259264
count: unreadCount,
260265
backgroundColor: swatch,
261266
bold: true)),
267+
] else if (showMutedUnreadBadge) ...[
268+
const SizedBox(width: 12),
269+
// TODO(#747) show @-mention indicator when it applies
270+
const MutedUnreadBadge(),
262271
],
263272
const SizedBox(width: 16),
264273
])));

lib/widgets/unread_count_badge.dart

+15
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,18 @@ class UnreadCountBadge extends StatelessWidget {
5757
count.toString())));
5858
}
5959
}
60+
61+
class MutedUnreadBadge extends StatelessWidget {
62+
const MutedUnreadBadge({super.key});
63+
64+
@override
65+
Widget build(BuildContext context) {
66+
return Container(
67+
width: 8,
68+
height: 8,
69+
margin: const EdgeInsetsDirectional.only(end: 3),
70+
decoration: BoxDecoration(
71+
color: const HSLColor.fromAHSL(0.5, 0, 0, 0.8).toColor(),
72+
shape: BoxShape.circle));
73+
}
74+
}

test/widgets/subscription_list_test.dart

+42
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ void main() {
154154
eg.subscription(stream),
155155
], unreadMsgs: unreadMsgs);
156156
check(find.byType(UnreadCountBadge).evaluate()).length.equals(1);
157+
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
157158
});
158159

159160
testWidgets('unread badge counts unmuted only', (tester) async {
@@ -174,6 +175,7 @@ void main() {
174175
check(tester.widget<Text>(find.descendant(
175176
of: find.byType(UnreadCountBadge), matching: find.byType(Text))))
176177
.data.equals('1');
178+
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
177179
});
178180

179181
testWidgets('unread badge does not show with no unreads', (tester) async {
@@ -183,6 +185,46 @@ void main() {
183185
eg.subscription(stream),
184186
], unreadMsgs: unreadMsgs);
185187
check(find.byType(UnreadCountBadge).evaluate()).length.equals(0);
188+
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
189+
});
190+
191+
testWidgets('muted unread badge shows when unreads are visible in channel but not inbox', (tester) async {
192+
final stream = eg.stream();
193+
final unreadMsgs = eg.unreadMsgs(channels: [
194+
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
195+
]);
196+
await setupStreamListPage(tester,
197+
subscriptions: [eg.subscription(stream, isMuted: true)],
198+
userTopics: [eg.userTopicItem(stream, 'b', UserTopicVisibilityPolicy.none)],
199+
unreadMsgs: unreadMsgs);
200+
201+
check(find.byType(MutedUnreadBadge).evaluate().length).equals(1);
202+
});
203+
204+
testWidgets('muted unread badge does not show when unreads are visible in both channel & inbox', (tester) async {
205+
final stream = eg.stream();
206+
final unreadMsgs = eg.unreadMsgs(channels: [
207+
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
208+
]);
209+
await setupStreamListPage(tester,
210+
subscriptions: [eg.subscription(stream, isMuted: false)],
211+
userTopics: [eg.userTopicItem(stream, 'b', UserTopicVisibilityPolicy.none)],
212+
unreadMsgs: unreadMsgs);
213+
214+
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
215+
});
216+
217+
testWidgets('muted unread badge does not show when unreads are not visible in channel nor inbox', (tester) async {
218+
final stream = eg.stream();
219+
final unreadMsgs = eg.unreadMsgs(channels: [
220+
UnreadChannelSnapshot(streamId: stream.streamId, topic: 'b', unreadMessageIds: [3]),
221+
]);
222+
await setupStreamListPage(tester,
223+
subscriptions: [eg.subscription(stream, isMuted: true)],
224+
userTopics: [eg.userTopicItem(stream, 'b', UserTopicVisibilityPolicy.muted)],
225+
unreadMsgs: unreadMsgs);
226+
227+
check(find.byType(MutedUnreadBadge).evaluate().length).equals(0);
186228
});
187229

188230
testWidgets('color propagates to icon and badge', (tester) async {

0 commit comments

Comments
 (0)