From a2f78d01bd4d105da374c46bd40c2a585bddd536 Mon Sep 17 00:00:00 2001 From: Joram Wilander Date: Fri, 24 Mar 2017 16:41:45 -0400 Subject: [PATCH] Fix LHS group message sorting (#5812) --- webapp/utils/channel_utils.jsx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/webapp/utils/channel_utils.jsx b/webapp/utils/channel_utils.jsx index 2bb30af5c7..d916ca2545 100644 --- a/webapp/utils/channel_utils.jsx +++ b/webapp/utils/channel_utils.jsx @@ -102,13 +102,30 @@ export function sortChannelsByDisplayName(a, b) { 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}); + const aDisplayName = getChannelDisplayName(a); + const bDisplayName = getChannelDisplayName(b); + + if (aDisplayName !== bDisplayName) { + return aDisplayName.localeCompare(bDisplayName, locale, {numeric: true}); } return a.name.localeCompare(b.name, locale, {numeric: true}); } +function getChannelDisplayName(channel) { + if (channel.type !== Constants.GM_CHANNEL) { + return channel.display_name; + } + + const currentUser = UserStore.getCurrentUser(); + + if (currentUser) { + return channel.display_name.replace(currentUser.username + ', ', ''); + } + + return channel.display_name; +} + export function showCreateOption(channelType, isAdmin, isSystemAdmin) { if (global.window.mm_license.IsLicensed !== 'true') { return true;