summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--webapp/utils/channel_utils.jsx20
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;
-}