[FIX] Results pagination on /directory REST endpoint (#11551)

pull/10269/head^2
Marcos Spessatto Defendi 8 years ago committed by Diego Sampaio
parent 3366c3569a
commit ab21be6bfc
  1. 4
      packages/rocketchat-api/server/v1/misc.js
  2. 9
      server/methods/browseChannels.js

@ -156,8 +156,8 @@ RocketChat.API.v1.addRoute('directory', { authRequired: true }, {
type,
sortBy,
sortDirection,
page: offset,
limit: count,
offset: Math.max(0, offset),
limit: Math.max(0, count),
}));
if (!result) {

@ -23,7 +23,7 @@ const sortUsers = function(field, direction) {
};
Meteor.methods({
browseChannels({ text = '', type = 'channels', sortBy = 'name', sortDirection = 'asc', page = 0, limit = 10 }) {
browseChannels({ text = '', type = 'channels', sortBy = 'name', sortDirection = 'asc', page, offset, limit = 10 }) {
const regex = new RegExp(s.trim(s.escapeRegExp(text)), 'i');
if (!['channels', 'users'].includes(type)) {
@ -34,17 +34,20 @@ Meteor.methods({
return;
}
if ((!page && page !== 0) && (!offset && offset !== 0)) {
return;
}
if (!['name', 'createdAt', 'usersCount', ...type === 'channels' ? ['usernames'] : [], ...type === 'users' ? ['username'] : []].includes(sortBy)) {
return;
}
page = page > -1 ? page : 0;
const skip = Math.max(0, offset || (page > -1 ? limit * page : 0));
limit = limit > 0 ? limit : 10;
const options = {
skip: limit * page,
skip,
limit,
};

Loading…
Cancel
Save