diff --git a/bigbluebutton-html5/imports/ui/components/user-list/service.js b/bigbluebutton-html5/imports/ui/components/user-list/service.js index 189a52085f1c1f95e4f7d3da935fad72cedb893d..e3b0e38a39dc04739809cdb782718b19356dfe4e 100755 --- a/bigbluebutton-html5/imports/ui/components/user-list/service.js +++ b/bigbluebutton-html5/imports/ui/components/user-list/service.js @@ -159,6 +159,15 @@ const sortChatsByIcon = (a, b) => { return 0; }; +const sortByRecentActivity = (a, b) => { + const _a = a.lastActivity; + const _b = b.lastActivity; + if (a.userId === 'public') return -1; + if (!_b || _a > _b) return -1; + if (!_a || _a < _b) return 1; + return 0; +}; + const isPublicChat = chat => ( chat.userId === 'public' ); @@ -170,7 +179,7 @@ const sortChats = (a, b) => { sort = sortChatsByName(a, b); } - return sort; + return sort = sortByRecentActivity(a, b); }; const userFindSorting = { @@ -223,8 +232,15 @@ const getActiveChats = (chatID) => { let activeChats = GroupChatMsg .find(filter) - .fetch() - .map(mapActiveChats); + .fetch(); + + const idsWithTimeStamp = {}; + + activeChats.map((chat) => { + idsWithTimeStamp[`${chat.sender}`] = chat.timestamp; + }); + + activeChats = activeChats.map(mapActiveChats); if (chatID) { activeChats.push(chatID); @@ -239,6 +255,7 @@ const getActiveChats = (chatID) => { activeChat.unreadCounter = UnreadMessages.count(op.userId); activeChat.name = op.name; activeChat.isModerator = op.role === ROLE_MODERATOR; + activeChat.lastActivity = idsWithTimeStamp[`${op.userId}`]; return activeChat; });