diff --git a/packages/rocketchat-api/server/v1/channels.js b/packages/rocketchat-api/server/v1/channels.js index 087e0792de9c..c37bd89ca2a5 100644 --- a/packages/rocketchat-api/server/v1/channels.js +++ b/packages/rocketchat-api/server/v1/channels.js @@ -404,8 +404,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, { diff --git a/packages/rocketchat-api/server/v1/groups.js b/packages/rocketchat-api/server/v1/groups.js index ccc7790978c5..6e12f4b4d225 100644 --- a/packages/rocketchat-api/server/v1/groups.js +++ b/packages/rocketchat-api/server/v1/groups.js @@ -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, { @@ -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, { diff --git a/packages/rocketchat-api/server/v1/im.js b/packages/rocketchat-api/server/v1/im.js index f5bff08b80c4..4a554f6f585a 100644 --- a/packages/rocketchat-api/server/v1/im.js +++ b/packages/rocketchat-api/server/v1/im.js @@ -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, { diff --git a/packages/rocketchat-lib/server/functions/saveCustomFieldsWithoutValidation.js b/packages/rocketchat-lib/server/functions/saveCustomFieldsWithoutValidation.js index d0f6ec896d1d..4b76441089d1 100644 --- a/packages/rocketchat-lib/server/functions/saveCustomFieldsWithoutValidation.js +++ b/packages/rocketchat-lib/server/functions/saveCustomFieldsWithoutValidation.js @@ -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; diff --git a/packages/rocketchat-lib/server/models/Subscriptions.js b/packages/rocketchat-lib/server/models/Subscriptions.js index 4c59e26add7f..3f4840267ec3 100644 --- a/packages/rocketchat-lib/server/models/Subscriptions.js +++ b/packages/rocketchat-lib/server/models/Subscriptions.js @@ -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 = { @@ -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, diff --git a/server/methods/createDirectMessage.js b/server/methods/createDirectMessage.js index 1dd43f293b02..95b8d634c965 100644 --- a/server/methods/createDirectMessage.js +++ b/server/methods/createDirectMessage.js @@ -68,6 +68,7 @@ Meteor.methods({ unread: 0, userMentions: 0, groupMentions: 0, + customFields: me.customFields, u: { _id: me._id, username: me.username @@ -96,6 +97,7 @@ Meteor.methods({ unread: 0, userMentions: 0, groupMentions: 0, + customFields: to.customFields, u: { _id: to._id, username: to.username