|
|
|
@ -1,47 +1,58 @@ |
|
|
|
|
const options = { |
|
|
|
|
fields: { |
|
|
|
|
_id: 1, |
|
|
|
|
name: 1, |
|
|
|
|
fname: 1, |
|
|
|
|
t: 1, |
|
|
|
|
cl: 1, |
|
|
|
|
u: 1, |
|
|
|
|
// usernames: 1,
|
|
|
|
|
topic: 1, |
|
|
|
|
announcement: 1, |
|
|
|
|
muted: 1, |
|
|
|
|
_updatedAt: 1, |
|
|
|
|
archived: 1, |
|
|
|
|
jitsiTimeout: 1, |
|
|
|
|
description: 1, |
|
|
|
|
default: 1, |
|
|
|
|
customFields: 1, |
|
|
|
|
|
|
|
|
|
// @TODO create an API to register this fields based on room type
|
|
|
|
|
livechatData: 1, |
|
|
|
|
tags: 1, |
|
|
|
|
sms: 1, |
|
|
|
|
code: 1, |
|
|
|
|
open: 1, |
|
|
|
|
v: 1, |
|
|
|
|
label: 1, |
|
|
|
|
ro: 1, |
|
|
|
|
sentiment: 1 |
|
|
|
|
} |
|
|
|
|
const fields = { |
|
|
|
|
_id: 1, |
|
|
|
|
name: 1, |
|
|
|
|
fname: 1, |
|
|
|
|
t: 1, |
|
|
|
|
cl: 1, |
|
|
|
|
u: 1, |
|
|
|
|
// usernames: 1,
|
|
|
|
|
topic: 1, |
|
|
|
|
announcement: 1, |
|
|
|
|
muted: 1, |
|
|
|
|
_updatedAt: 1, |
|
|
|
|
archived: 1, |
|
|
|
|
jitsiTimeout: 1, |
|
|
|
|
description: 1, |
|
|
|
|
default: 1, |
|
|
|
|
customFields: 1, |
|
|
|
|
|
|
|
|
|
// @TODO create an API to register this fields based on room type
|
|
|
|
|
livechatData: 1, |
|
|
|
|
tags: 1, |
|
|
|
|
sms: 1, |
|
|
|
|
code: 1, |
|
|
|
|
joinCodeRequired: 1, |
|
|
|
|
open: 1, |
|
|
|
|
v: 1, |
|
|
|
|
label: 1, |
|
|
|
|
ro: 1, |
|
|
|
|
sentiment: 1 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const roomMap = (record) => { |
|
|
|
|
const roomMap = (record, fields) => { |
|
|
|
|
if (record._room) { |
|
|
|
|
return _.pick(record._room, ...Object.keys(options.fields)); |
|
|
|
|
return _.pick(record._room, ...Object.keys(fields)); |
|
|
|
|
} |
|
|
|
|
console.log('Empty Room for Subscription', record); |
|
|
|
|
return {}; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
function getFieldsForUserId(userId) { |
|
|
|
|
if (RocketChat.authz.hasPermission(userId, 'view-join-code')) { |
|
|
|
|
return { |
|
|
|
|
...fields, |
|
|
|
|
joinCode: 1 |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return fields; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Meteor.methods({ |
|
|
|
|
'rooms/get'(updatedAt) { |
|
|
|
|
let options = {fields}; |
|
|
|
|
|
|
|
|
|
if (!Meteor.userId()) { |
|
|
|
|
if (RocketChat.settings.get('Accounts_AllowAnonymousRead') === true) { |
|
|
|
|
return RocketChat.models.Rooms.findByDefaultAndTypes(true, ['c'], options).fetch(); |
|
|
|
@ -51,6 +62,10 @@ Meteor.methods({ |
|
|
|
|
|
|
|
|
|
this.unblock(); |
|
|
|
|
|
|
|
|
|
options = { |
|
|
|
|
fields: getFieldsForUserId(this.userId) |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
if (updatedAt instanceof Date) { |
|
|
|
|
return { |
|
|
|
|
update: RocketChat.models.Rooms.findBySubscriptionUserIdUpdatedAfter(Meteor.userId(), updatedAt, options).fetch(), |
|
|
|
@ -84,14 +99,14 @@ Meteor.methods({ |
|
|
|
|
throw new Meteor.Error('error-no-permission', 'No permission', { method: 'getRoomByTypeAndName' }); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return roomMap({_room: room}); |
|
|
|
|
return roomMap({_room: room}, getFieldsForUserId(this.userId)); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
RocketChat.models.Rooms.cache.on('sync', (type, room/*, diff*/) => { |
|
|
|
|
const records = RocketChat.models.Subscriptions.findByRoomId(room._id).fetch(); |
|
|
|
|
for (const record of records) { |
|
|
|
|
RocketChat.Notifications.notifyUserInThisInstance(record.u._id, 'rooms-changed', type, roomMap({_room: room})); |
|
|
|
|
RocketChat.Notifications.notifyUserInThisInstance(record.u._id, 'rooms-changed', type, roomMap({_room: room}, getFieldsForUserId(record.u._id))); |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -99,7 +114,7 @@ RocketChat.models.Subscriptions.on('changed', (type, subscription/*, diff*/) => |
|
|
|
|
if (type === 'inserted' || type === 'removed') { |
|
|
|
|
const room = RocketChat.models.Rooms.findOneById(subscription.rid); |
|
|
|
|
if (room) { |
|
|
|
|
RocketChat.Notifications.notifyUserInThisInstance(subscription.u._id, 'rooms-changed', type, roomMap({_room: room})); |
|
|
|
|
RocketChat.Notifications.notifyUserInThisInstance(subscription.u._id, 'rooms-changed', type, roomMap({_room: room}, getFieldsForUserId(subscription.u._id))); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}); |
|
|
|
|