diff options
author | George Goldberg <george@gberg.me> | 2017-01-06 14:03:11 +0000 |
---|---|---|
committer | Harrison Healey <harrisonmhealey@gmail.com> | 2017-01-06 09:03:11 -0500 |
commit | 0c0635d766f61eb25db52e4e11706932185e416d (patch) | |
tree | ed034dce1487969b57d3a8efd70bc4f340ad5bf6 /webapp/utils/channel_utils.jsx | |
parent | 3076a5c4bde25bb49c4114cb5dcef68cbad3a32c (diff) | |
download | chat-0c0635d766f61eb25db52e4e11706932185e416d.tar.gz chat-0c0635d766f61eb25db52e4e11706932185e416d.tar.bz2 chat-0c0635d766f61eb25db52e4e11706932185e416d.zip |
PLT-4614 Fix ordering of channels. (#4980)
Diffstat (limited to 'webapp/utils/channel_utils.jsx')
-rw-r--r-- | webapp/utils/channel_utils.jsx | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx index 50573e077..ffc69d7b4 100644 --- a/webapp/utils/channel_utils.jsx +++ b/webapp/utils/channel_utils.jsx @@ -76,10 +76,21 @@ export function completeDirectChannelInfo(channel) { }); } +const defaultPrefix = 'D'; // fallback for future types +const typeToPrefixMap = {[Constants.OPEN_CHANNEL]: 'A', [Constants.PRIVATE_CHANNEL]: 'B', [Constants.DM_CHANNEL]: 'C'}; + export function sortChannelsByDisplayName(a, b) { const locale = LocalizationStore.getLocale(); - return buildDisplayNameAndTypeComparable(a).localeCompare(buildDisplayNameAndTypeComparable(b), locale, {numeric: true}); + if (a.type !== b.type) { + return (typeToPrefixMap[a.type] || defaultPrefix).localeCompare((typeToPrefixMap[b.type] || defaultPrefix), locale); + } + + if (a.display_name !== b.display_name) { + return a.display_name.localeCompare(b.display_name, locale, {numeric: true}); + } + + return a.name.localeCompare(b.name, locale, {numeric: true}); } export function showCreateOption(channelType, isAdmin, isSystemAdmin) { @@ -200,10 +211,3 @@ function not(f) { function andX(...fns) { return (...args) => fns.every((f) => f(...args)); } - -const defaultPrefix = 'D'; // fallback for future types -const typeToPrefixMap = {[Constants.OPEN_CHANNEL]: 'A', [Constants.PRIVATE_CHANNEL]: 'B', [Constants.DM_CHANNEL]: 'C'}; - -function buildDisplayNameAndTypeComparable(channel) { - return (typeToPrefixMap[channel.type] || defaultPrefix) + channel.display_name + channel.name; -} |