Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

home: Sort leading emoji first in channel names #1234

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/widgets/subscription_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,35 @@ class _SubscriptionListPageBodyState extends State<SubscriptionListPageBody> wit
list.sort((a, b) {
if (a.isMuted && !b.isMuted) return 1;
if (!a.isMuted && b.isMuted) return -1;

final isEmojiA = _startsWithEmoji(a.name);
final isEmojiB = _startsWithEmoji(b.name);
if (isEmojiA != isEmojiB) {
return isEmojiA ? -1 : 1;
}

// TODO(i18n): add locale-aware sorting
return a.name.toLowerCase().compareTo(b.name.toLowerCase());
});
}

bool _startsWithEmoji(String name) {
final firstChar = name.characters.first;
final int firstCharCode = firstChar.runes.first;

return (firstCharCode >= 0x1F600 && firstCharCode <= 0x1F64F) || // Emoticons
(firstCharCode >= 0x1F300 && firstCharCode <= 0x1F5FF) || // Misc Symbols and Pictographs
(firstCharCode >= 0x1F680 && firstCharCode <= 0x1F6FF) || // Transport and Map
(firstCharCode >= 0x1F700 && firstCharCode <= 0x1F77F) || // Alchemical Symbols
(firstCharCode >= 0x2600 && firstCharCode <= 0x26FF) || // Misc Symbols
(firstCharCode >= 0x2700 && firstCharCode <= 0x27BF) || // Dingbats
(firstCharCode >= 0xFE00 && firstCharCode <= 0xFE0F) || // Variation Selectors
(firstCharCode >= 0x1F900 && firstCharCode <= 0x1F9FF) || // Supplemental Symbols and Pictographs
(firstCharCode >= 0x1FA70 && firstCharCode <= 0x1FAFF) || // Symbols and Pictographs Extended-A
(firstCharCode >= 0x1F1E6 && firstCharCode <= 0x1F1FF) || // Flags
(firstCharCode >= 0x1F000 && firstCharCode <= 0x1FFFF); // Supplementary Multilingual Plane
}

@override
Widget build(BuildContext context) {
// Design referenced from:
Expand Down
26 changes: 26 additions & 0 deletions test/widgets/subscription_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,32 @@ void main() {
]);
check(listedStreamIds(tester)).deepEquals([2, 1, 3, 4, 6, 5]);
});

testWidgets('channels with emoji in name are listed above non-emoji names', (tester) async {
await setupStreamListPage(tester, subscriptions: [
eg.subscription(eg.stream(streamId: 1, name: '😊 Happy Stream')),
eg.subscription(eg.stream(streamId: 2, name: 'Alpha Stream')),
eg.subscription(eg.stream(streamId: 3, name: '🚀 Rocket Stream')),
eg.subscription(eg.stream(streamId: 4, name: 'Beta Stream')),
]);

check(listedStreamIds(tester)).deepEquals([1, 3, 2, 4]);
});

testWidgets('channels with emoji in name, pinned, unpinned, muted, and unmuted are sorted correctly', (tester) async {
await setupStreamListPage(tester, subscriptions: [
eg.subscription(eg.stream(streamId: 1, name: '😊 Happy Stream'), pinToTop: true, isMuted: false),
eg.subscription(eg.stream(streamId: 2, name: '🚀 Rocket Stream'), pinToTop: true, isMuted: true),
eg.subscription(eg.stream(streamId: 3, name: 'Alpha Stream'), pinToTop: true, isMuted: false),
eg.subscription(eg.stream(streamId: 4, name: 'Beta Stream'), pinToTop: true, isMuted: true),
eg.subscription(eg.stream(streamId: 5, name: '🌟 Star Stream'), pinToTop: false, isMuted: false),
eg.subscription(eg.stream(streamId: 6, name: '🔥 Fire Stream'), pinToTop: false, isMuted: true),
eg.subscription(eg.stream(streamId: 7, name: 'Gamma Stream'), pinToTop: false, isMuted: false),
eg.subscription(eg.stream(streamId: 8, name: 'Delta Stream'), pinToTop: false, isMuted: true),
]);

check(listedStreamIds(tester)).deepEquals([1,3,2,4,5,7,6,8]);
});
});

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