Skip to content

Commit 0c567a3

Browse files
committed
home: Sort leading emoji first in channel names
Update the channel sorting logic to match the channels order of web by putting emoji-prefixed channels first. Fixes: zulip#1202
1 parent 5e8d0a8 commit 0c567a3

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/widgets/subscription_list.dart

+12
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,22 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
4141
});
4242
}
4343

44+
final _startsWithEmojiRegex = RegExp(r'^\p{Emoji}', unicode: true);
45+
4446
void _sortSubs(List<Subscription> list) {
4547
list.sort((a, b) {
4648
if (a.isMuted && !b.isMuted) return 1;
4749
if (!a.isMuted && b.isMuted) return -1;
50+
51+
// A user gave feedback wanting zulip-flutter to match web in putting
52+
// emoji-prefixed channels first; see #1202.
53+
// For matching web's ordering completely, see:
54+
// https://github.com/zulip/zulip-flutter/issues/1165
55+
final aStartsWithEmoji = _startsWithEmojiRegex.hasMatch(a.name);
56+
final bStartsWithEmoji = _startsWithEmojiRegex.hasMatch(b.name);
57+
if (aStartsWithEmoji && !bStartsWithEmoji) return -1;
58+
if (!aStartsWithEmoji && bStartsWithEmoji) return 1;
59+
4860
// TODO(i18n): add locale-aware sorting
4961
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
5062
});

test/widgets/subscription_list_test.dart

+26
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,32 @@ void main() {
150150
]);
151151
check(listedStreamIds(tester)).deepEquals([2, 1, 3, 4, 6, 5]);
152152
});
153+
154+
testWidgets('channels with emoji in name are listed above non-emoji names', (tester) async {
155+
await setupStreamListPage(tester, subscriptions: [
156+
eg.subscription(eg.stream(streamId: 1, name: 'Happy 😊 Stream')),
157+
eg.subscription(eg.stream(streamId: 2, name: 'Alpha Stream')),
158+
eg.subscription(eg.stream(streamId: 3, name: '🚀 Rocket Stream')),
159+
eg.subscription(eg.stream(streamId: 4, name: 'Beta Stream')),
160+
]);
161+
162+
check(listedStreamIds(tester)).deepEquals([3, 2, 4, 1]);
163+
});
164+
165+
testWidgets('channels with emoji in name, pinned, unpinned, muted, and unmuted are sorted correctly', (tester) async {
166+
await setupStreamListPage(tester, subscriptions: [
167+
eg.subscription(eg.stream(streamId: 1, name: '😊 Happy Stream'), pinToTop: true, isMuted: false),
168+
eg.subscription(eg.stream(streamId: 2, name: '🚀 Rocket Stream'), pinToTop: true, isMuted: true),
169+
eg.subscription(eg.stream(streamId: 3, name: 'Alpha Stream'), pinToTop: true, isMuted: false),
170+
eg.subscription(eg.stream(streamId: 4, name: 'Beta Stream'), pinToTop: true, isMuted: true),
171+
eg.subscription(eg.stream(streamId: 5, name: '🌟 Star Stream'), pinToTop: false, isMuted: false),
172+
eg.subscription(eg.stream(streamId: 6, name: '🔥 Fire Stream'), pinToTop: false, isMuted: true),
173+
eg.subscription(eg.stream(streamId: 7, name: 'Gamma Stream'), pinToTop: false, isMuted: false),
174+
eg.subscription(eg.stream(streamId: 8, name: 'Delta Stream'), pinToTop: false, isMuted: true),
175+
]);
176+
177+
check(listedStreamIds(tester)).deepEquals([1, 3, 2, 4, 5, 7, 6, 8]);
178+
});
153179
});
154180

155181
testWidgets('unread badge shows with unreads', (tester) async {

0 commit comments

Comments
 (0)