Skip to content

Commit 97e1bbb

Browse files
committed
subscription_list: Show muted streams as faded in streams list
Fixes: zulip#424
1 parent 544642a commit 97e1bbb

File tree

2 files changed

+86
-22
lines changed

2 files changed

+86
-22
lines changed

lib/widgets/subscription_list.dart

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,17 @@ class _SubscriptionList extends StatelessWidget {
175175

176176
@override
177177
Widget build(BuildContext context) {
178+
final unmutedSubs = subscriptions.where((element) => !element.isMuted);
179+
final mutedSubs = subscriptions.where((element) => element.isMuted);
178180
return SliverList.builder(
179181
itemCount: subscriptions.length,
180182
itemBuilder: (BuildContext context, int index) {
181-
final subscription = subscriptions[index];
183+
Subscription? subscription;
184+
if (index < unmutedSubs.length) {
185+
subscription = unmutedSubs.elementAt(index);
186+
} else {
187+
subscription = mutedSubs.elementAt(index - unmutedSubs.length);
188+
}
182189
final unreadCount = unreadsModel!.countInStream(subscription.streamId);
183190
// TODO(#712): if stream muted, show a dot for unreads
184191
return SubscriptionItem(subscription: subscription, unreadCount: unreadCount);
@@ -212,28 +219,34 @@ class SubscriptionItem extends StatelessWidget {
212219
},
213220
child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
214221
const SizedBox(width: 16),
215-
Padding(
216-
padding: const EdgeInsets.symmetric(vertical: 11),
217-
child: Icon(size: 18, color: swatch.iconOnPlainBackground,
218-
iconDataForStream(subscription))),
219-
const SizedBox(width: 5),
220222
Expanded(
221-
child: Padding(
222-
padding: const EdgeInsets.symmetric(vertical: 10),
223-
// TODO(design): unclear whether bold text is applied to all subscriptions
224-
// or only those with unreads:
225-
// https://github.com/zulip/zulip-flutter/pull/397#pullrequestreview-1742524205
226-
child: Text(
227-
style: const TextStyle(
228-
fontSize: 18,
229-
height: (20 / 18),
230-
// TODO(#95) need dark-theme color
231-
color: Color(0xFF262626),
232-
).merge(weightVariableTextStyle(context,
233-
wght: hasUnreads ? 600 : null)),
234-
maxLines: 1,
235-
overflow: TextOverflow.ellipsis,
236-
subscription.name))),
223+
child: Opacity(
224+
opacity: subscription.isMuted ? 0.55 : 1,
225+
child: Row(
226+
children: [
227+
Padding(
228+
padding: const EdgeInsets.symmetric(vertical: 11),
229+
child: Icon(size: 18, color: swatch.iconOnPlainBackground,
230+
iconDataForStream(subscription))),
231+
const SizedBox(width: 5),
232+
Expanded(
233+
child: Padding(
234+
padding: const EdgeInsets.symmetric(vertical: 10),
235+
// TODO(design): unclear whether bold text is applied to all subscriptions
236+
// or only those with unreads:
237+
// https://github.com/zulip/zulip-flutter/pull/397#pullrequestreview-1742524205
238+
child: Text(
239+
style: const TextStyle(
240+
fontSize: 18,
241+
height: (20 / 18),
242+
// TODO(#95) need dark-theme color
243+
color: Color(0xFF262626),
244+
).merge(weightVariableTextStyle(context,
245+
wght: hasUnreads ? 600 : null)),
246+
maxLines: 1,
247+
overflow: TextOverflow.ellipsis,
248+
subscription.name)))])),
249+
),
237250
if (unreadCount > 0) ...[
238251
const SizedBox(width: 12),
239252
// TODO(#384) show @-mention indicator when it applies

test/widgets/subscription_list_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ void main() {
132132
]);
133133
check(listedStreamIds(tester)).deepEquals([1, 2, 3, 4, 5, 6]);
134134
});
135+
136+
testWidgets('muted subscriptions come at last', (tester) async {
137+
await setupStreamListPage(tester, subscriptions: [
138+
eg.subscription(eg.stream(streamId: 1, name: 'a'), isMuted: true, pinToTop: true),
139+
eg.subscription(eg.stream(streamId: 2, name: 'b'), isMuted: false, pinToTop: true),
140+
eg.subscription(eg.stream(streamId: 3, name: 'c'), isMuted: true, pinToTop: true),
141+
eg.subscription(eg.stream(streamId: 4, name: 'd'), isMuted: false, pinToTop: false),
142+
eg.subscription(eg.stream(streamId: 5, name: 'e'), isMuted: true, pinToTop: false),
143+
eg.subscription(eg.stream(streamId: 6, name: 'f'), isMuted: false, pinToTop: false),
144+
]);
145+
check(listedStreamIds(tester)).deepEquals([2, 1, 3, 4, 6, 5]);
146+
});
135147
});
136148

137149
testWidgets('unread badge shows with unreads', (tester) async {
@@ -190,4 +202,43 @@ void main() {
190202
check(tester.widget<UnreadCountBadge>(find.byType(UnreadCountBadge)).backgroundColor)
191203
.equals(swatch);
192204
});
205+
206+
testWidgets('muted streams are displayed as faded', (tester) async {
207+
final stream1 = eg.stream(name: 'Stream 1');
208+
final stream2 = eg.stream(streamId: 2, name: 'Stream 2');
209+
final unreadMsgs = eg.unreadMsgs(streams: [
210+
UnreadStreamSnapshot(streamId: stream1.streamId, topic: 'a', unreadMessageIds: [1, 2]),
211+
UnreadStreamSnapshot(streamId: stream2.streamId, topic: 'b', unreadMessageIds: [3]),
212+
]);
213+
await setupStreamListPage(tester,
214+
subscriptions: [
215+
eg.subscription(stream1, isMuted: true),
216+
eg.subscription(stream2, isMuted: false)
217+
],
218+
userTopics: [
219+
UserTopicItem(
220+
streamId: stream1.streamId,
221+
topicName: 'a',
222+
lastUpdated: 1234567890,
223+
visibilityPolicy: UserTopicVisibilityPolicy.unmuted,
224+
),
225+
UserTopicItem(
226+
streamId: stream2.streamId,
227+
topicName: 'b',
228+
lastUpdated: 1234567890,
229+
visibilityPolicy: UserTopicVisibilityPolicy.unmuted,
230+
),
231+
],
232+
unreadMsgs: unreadMsgs);
233+
234+
final stream1Finder = find.text('Stream 1');
235+
final stream1Opacity = tester.widget<Opacity>(
236+
find.ancestor(of: stream1Finder, matching: find.byType(Opacity))).opacity;
237+
check(stream1Opacity).equals(0.55);
238+
239+
final stream2Finder = find.text('Stream 2');
240+
final stream2Opacity = tester.widget<Opacity>(
241+
find.ancestor(of: stream2Finder, matching: find.byType(Opacity))).opacity;
242+
check(stream2Opacity).equals(1.0);
243+
});
193244
}

0 commit comments

Comments
 (0)