diff options
author | Christopher Speller <crspeller@gmail.com> | 2017-01-12 19:59:37 -0500 |
---|---|---|
committer | Christopher Speller <crspeller@gmail.com> | 2017-01-12 19:59:37 -0500 |
commit | 8fb66c2b834ee4e0669de173e5ddfebd56c34d58 (patch) | |
tree | 9e8e66772d44c4f9010a48c8e0afed70421238b1 /webapp/utils | |
parent | 4208e42ba9df02b9c4bd7081179922c21206d83d (diff) | |
parent | aafb8be87c79c60df7534b3b69f967c6301b157e (diff) | |
download | chat-8fb66c2b834ee4e0669de173e5ddfebd56c34d58.tar.gz chat-8fb66c2b834ee4e0669de173e5ddfebd56c34d58.tar.bz2 chat-8fb66c2b834ee4e0669de173e5ddfebd56c34d58.zip |
Merge branch 'release-3.6'
Diffstat (limited to 'webapp/utils')
-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; -} |