Skip to content

Commit

Permalink
Merge pull request #9424 from xbolshe/develop
Browse files Browse the repository at this point in the history
[FIX] 'Query' support for channels.list.joined, groups.list, groups.listAll, im.list
  • Loading branch information
rodrigok authored Feb 17, 2018
2 parents ff319c8 + 0f4da73 commit 490fa2d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
9 changes: 7 additions & 2 deletions packages/rocketchat-api/server/v1/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,13 @@ RocketChat.API.v1.addRoute('channels.list', { authRequired: true }, {
RocketChat.API.v1.addRoute('channels.list.joined', { authRequired: true }, {
get() {
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
let rooms = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('c', this.userId).fetch(), '_room');
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, {
t: 'c',
'u._id': this.userId
});

let rooms = _.pluck(RocketChat.models.Subscriptions.find(ourQuery).fetch(), '_room');
const totalCount = rooms.length;

rooms = RocketChat.models.Rooms.processQueryOptionsOnResult(rooms, {
Expand Down
15 changes: 11 additions & 4 deletions packages/rocketchat-api/server/v1/groups.js
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,13 @@ RocketChat.API.v1.addRoute('groups.leave', { authRequired: true }, {
RocketChat.API.v1.addRoute('groups.list', { authRequired: true }, {
get() {
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
let rooms = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('p', this.userId).fetch(), '_room');
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, {
t: 'p',
'u._id': this.userId
});

let rooms = _.pluck(RocketChat.models.Subscriptions.find(ourQuery).fetch(), '_room');
const totalCount = rooms.length;

rooms = RocketChat.models.Rooms.processQueryOptionsOnResult(rooms, {
Expand All @@ -344,8 +349,10 @@ RocketChat.API.v1.addRoute('groups.listAll', { authRequired: true }, {
return RocketChat.API.v1.unauthorized();
}
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
let rooms = RocketChat.models.Rooms.findByType('p').fetch();
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, { t: 'p' });

let rooms = RocketChat.models.Rooms.find(ourQuery).fetch();
const totalCount = rooms.length;

rooms = RocketChat.models.Rooms.processQueryOptionsOnResult(rooms, {
Expand Down
9 changes: 7 additions & 2 deletions packages/rocketchat-api/server/v1/im.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,13 @@ RocketChat.API.v1.addRoute(['dm.messages.others', 'im.messages.others'], { authR
RocketChat.API.v1.addRoute(['dm.list', 'im.list'], { authRequired: true }, {
get() {
const { offset, count } = this.getPaginationItems();
const { sort, fields } = this.parseJsonQuery();
let rooms = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('d', this.userId).fetch(), '_room');
const { sort, fields, query } = this.parseJsonQuery();
const ourQuery = Object.assign({}, query, {
t: 'd',
'u._id': this.userId
});

let rooms = _.pluck(RocketChat.models.Subscriptions.find(ourQuery).fetch(), '_room');
const totalCount = rooms.length;

rooms = RocketChat.models.Rooms.processQueryOptionsOnResult(rooms, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ RocketChat.saveCustomFieldsWithoutValidation = function(userId, formData) {
Object.keys(customFieldsMeta).forEach(key => customFields[key] = formData[key]);
RocketChat.models.Users.setCustomFields(userId, customFields);

// Update customFields of all Direct Messages' Rooms for userId
RocketChat.models.Subscriptions.setCustomFieldsDirectMessagesByUserId(userId, customFields);

Object.keys(customFields).forEach((fieldName) => {
if (!customFieldsMeta[fieldName].modifyRecordField) {
return;
Expand Down
17 changes: 17 additions & 0 deletions packages/rocketchat-lib/server/models/Subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ class ModelSubscriptions extends RocketChat.models._Base {
return this.update(query, update);
}

setCustomFieldsDirectMessagesByUserId(userId, fields) {
const values = {};
Object.keys(fields).forEach(key => {
values[`customFields.${ key }`] = fields[key];
});

const query = {
'u._id': userId,
't': 'd'
};
const update = { $set: values };
const options = { 'multi': true };

return this.update(query, update, options);
}

setFavoriteByRoomIdAndUserId(roomId, userId, favorite) {
if (favorite == null) { favorite = true; }
const query = {
Expand Down Expand Up @@ -557,6 +573,7 @@ class ModelSubscriptions extends RocketChat.models._Base {
rid: room._id,
name: room.name,
fname: room.fname,
customFields: room.customFields,
t: room.t,
u: {
_id: user._id,
Expand Down
2 changes: 2 additions & 0 deletions server/methods/createDirectMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Meteor.methods({
unread: 0,
userMentions: 0,
groupMentions: 0,
customFields: me.customFields,
u: {
_id: me._id,
username: me.username
Expand Down Expand Up @@ -96,6 +97,7 @@ Meteor.methods({
unread: 0,
userMentions: 0,
groupMentions: 0,
customFields: to.customFields,
u: {
_id: to._id,
username: to.username
Expand Down

0 comments on commit 490fa2d

Please sign in to comment.