From 2d4e5ca4a6874d8af3598ef2841bee96e95b9ded Mon Sep 17 00:00:00 2001 From: Subham Sahoo <43502196+subham103@users.noreply.github.com> Date: Thu, 26 Mar 2020 09:48:46 +0530 Subject: [PATCH] [NEW] Sort channel directory listing by latest message (#16604) Co-authored-by: Diego Sampaio --- app/ui/client/views/app/directory.html | 4 ++-- server/methods/browseChannels.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/ui/client/views/app/directory.html b/app/ui/client/views/app/directory.html index f2990d38bf8..a9c729f6b15 100644 --- a/app/ui/client/views/app/directory.html +++ b/app/ui/client/views/app/directory.html @@ -45,8 +45,8 @@
{{_ "Users"}} {{> icon icon=(sortIcon 'usersCount')}}
{{#if showLastMessage}} - -
{{_ "Last_Message"}}
+ +
{{_ "Last_Message"}} {{> icon icon=(sortIcon 'lastMessage')}}
{{/if}} diff --git a/server/methods/browseChannels.js b/server/methods/browseChannels.js index 0bb2e41362d..a0b61baad54 100644 --- a/server/methods/browseChannels.js +++ b/server/methods/browseChannels.js @@ -15,6 +15,10 @@ const sortChannels = function(field, direction) { return { ts: direction === 'asc' ? 1 : -1, }; + case 'lastMessage': + return { + 'lastMessage.ts': direction === 'asc' ? 1 : -1, + }; default: return { [field]: direction === 'asc' ? 1 : -1, @@ -51,7 +55,7 @@ Meteor.methods({ return; } - if (!['name', 'createdAt', 'usersCount', ...type === 'channels' ? ['usernames'] : [], ...type === 'users' ? ['username', 'email'] : []].includes(sortBy)) { + if (!['name', 'createdAt', 'usersCount', ...type === 'channels' ? ['usernames', 'lastMessage'] : [], ...type === 'users' ? ['username', 'email'] : []].includes(sortBy)) { return; }