Skip to content

Commit

Permalink
[NEW] Sort channel directory listing by latest message (#16604)
Browse files Browse the repository at this point in the history
Co-authored-by: Diego Sampaio <chinello@gmail.com>
  • Loading branch information
subham103 and sampaiodiego authored Mar 26, 2020
1 parent 5355b82 commit 2d4e5ca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/ui/client/views/app/directory.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
<div class="table-fake-th"><span>{{_ "Users"}}</span> {{> icon icon=(sortIcon 'usersCount')}}</div>
</th>
{{#if showLastMessage}}
<th class="table-column-date">
<div class="table-fake-th">{{_ "Last_Message"}}</div>
<th class="table-column-date js-sort {{#if searchSortBy 'lastMessage'}}is-sorting{{/if}}" data-sort="lastMessage">
<div class="table-fake-th"><span>{{_ "Last_Message"}}</span> {{> icon icon=(sortIcon 'lastMessage')}}</div>
</th>
{{/if}}
<th class="js-sort table-column-date {{#if searchSortBy 'createdAt'}}is-sorting{{/if}}" data-sort="createdAt">
Expand Down
6 changes: 5 additions & 1 deletion server/methods/browseChannels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 2d4e5ca

Please sign in to comment.