Remove RocketChat.cache.Rooms

pull/4511/head
Rodrigo Nascimento 9 years ago
parent fd294053c1
commit 39db03c646
No known key found for this signature in database
GPG Key ID: 2C85B3AFE75D23F9
  1. 2
      packages/rocketchat-action-links/server/actionLinkHandler.js
  2. 8
      packages/rocketchat-api/server/routes.coffee
  3. 4
      packages/rocketchat-channel-settings/server/functions/saveRoomName.coffee
  4. 2
      packages/rocketchat-channel-settings/server/methods/saveRoomSettings.coffee
  5. 2
      packages/rocketchat-error-handler/server/lib/RocketChat.ErrorHandler.js
  6. 4
      packages/rocketchat-importer-hipchat/server.coffee
  7. 4
      packages/rocketchat-importer-slack/server.coffee
  8. 2
      packages/rocketchat-integrations/server/methods/incoming/addIncomingIntegration.coffee
  9. 2
      packages/rocketchat-integrations/server/methods/incoming/updateIncomingIntegration.coffee
  10. 2
      packages/rocketchat-integrations/server/methods/outgoing/addOutgoingIntegration.coffee
  11. 2
      packages/rocketchat-integrations/server/methods/outgoing/updateOutgoingIntegration.coffee
  12. 6
      packages/rocketchat-integrations/server/processWebhookMessage.js
  13. 2
      packages/rocketchat-internal-hubot/hubot.coffee
  14. 8
      packages/rocketchat-irc/irc.server.coffee
  15. 2
      packages/rocketchat-lib/server/functions/Notifications.coffee
  16. 2
      packages/rocketchat-lib/server/functions/addUserToDefaultChannels.js
  17. 2
      packages/rocketchat-lib/server/functions/addUserToRoom.js
  18. 2
      packages/rocketchat-lib/server/functions/createRoom.js
  19. 2
      packages/rocketchat-lib/server/functions/deleteUser.js
  20. 2
      packages/rocketchat-lib/server/functions/removeUserFromRoom.js
  21. 2
      packages/rocketchat-lib/server/functions/sendMessage.coffee
  22. 2
      packages/rocketchat-lib/server/functions/updateMessage.js
  23. 2
      packages/rocketchat-lib/server/methods/addUserToRoom.coffee
  24. 2
      packages/rocketchat-lib/server/methods/archiveRoom.coffee
  25. 2
      packages/rocketchat-lib/server/methods/joinRoom.coffee
  26. 2
      packages/rocketchat-lib/server/methods/leaveRoom.coffee
  27. 2
      packages/rocketchat-lib/server/methods/unarchiveRoom.coffee
  28. 2
      packages/rocketchat-lib/server/models/Messages.coffee
  29. 2
      packages/rocketchat-lib/server/models/Rooms.coffee
  30. 2
      packages/rocketchat-livechat/server/api.js
  31. 4
      packages/rocketchat-livechat/server/lib/Livechat.js
  32. 2
      packages/rocketchat-livechat/server/methods/closeRoom.js
  33. 2
      packages/rocketchat-livechat/server/methods/getInitialData.js
  34. 2
      packages/rocketchat-livechat/server/methods/saveInfo.js
  35. 2
      packages/rocketchat-livechat/server/methods/saveSurveyFeedback.js
  36. 2
      packages/rocketchat-livechat/server/methods/takeInquiry.js
  37. 2
      packages/rocketchat-livechat/server/methods/transfer.js
  38. 6
      packages/rocketchat-livechat/server/models/Rooms.js
  39. 2
      packages/rocketchat-livechat/server/publications/visitorHistory.js
  40. 2
      packages/rocketchat-livechat/server/publications/visitorInfo.js
  41. 2
      packages/rocketchat-livechat/server/publications/visitorPageVisited.js
  42. 2
      packages/rocketchat-livechat/server/startup.js
  43. 4
      packages/rocketchat-mentions/server.coffee
  44. 4
      packages/rocketchat-message-pin/server/pinMessage.coffee
  45. 2
      packages/rocketchat-message-star/server/starMessage.coffee
  46. 8
      packages/rocketchat-slackbridge/slackbridge.js
  47. 2
      packages/rocketchat-slackbridge/slashcommand/slackbridge_import.server.js
  48. 4
      packages/rocketchat-slashcommands-archiveroom/server.js
  49. 2
      packages/rocketchat-slashcommands-create/server.js
  50. 2
      packages/rocketchat-slashcommands-invite/server.coffee
  51. 2
      packages/rocketchat-slashcommands-join/server.coffee
  52. 2
      packages/rocketchat-slashcommands-kick/server.coffee
  53. 2
      packages/rocketchat-slashcommands-mute/server/mute.coffee
  54. 2
      packages/rocketchat-slashcommands-mute/server/unmute.coffee
  55. 4
      packages/rocketchat-slashcommands-unarchiveroom/server.js
  56. 8
      packages/rocketchat-statistics/server/functions/get.coffee
  57. 2
      packages/rocketchat-videobridge/server/methods/jitsiSetTimeout.js
  58. 2
      server/methods/addAllUserToRoom.js
  59. 2
      server/methods/canAccessRoom.coffee
  60. 4
      server/methods/channelsList.coffee
  61. 2
      server/methods/eraseRoom.coffee
  62. 2
      server/methods/getRoomIdByNameOrId.coffee
  63. 2
      server/methods/getTotalChannels.coffee
  64. 4
      server/methods/groupsList.js
  65. 2
      server/methods/muteUserInRoom.coffee
  66. 2
      server/methods/removeUserFromRoom.coffee
  67. 2
      server/methods/unmuteUserInRoom.coffee
  68. 2
      server/publications/privateHistory.coffee
  69. 6
      server/publications/room.js
  70. 2
      server/publications/spotlight.coffee
  71. 6
      server/restapi/restapi.coffee
  72. 2
      server/startup/initialData.coffee

@ -16,7 +16,7 @@ Meteor.methods({
throw new Meteor.Error('error-invalid-actionlink', 'Invalid action link', { method: 'actionLinkHandler' });
}
var room = RocketChat.cache.Rooms.findOneById(message.rid);
var room = RocketChat.models.Rooms.findOneById(message.rid);
if (Array.isArray(room.usernames) && room.usernames.indexOf(Meteor.user().username) === -1) {
throw new Meteor.Error('error-not-allowed', 'Not allowed', { method: 'actionLinkHandler' });
}

@ -103,13 +103,13 @@ RocketChat.API.v1.addRoute 'channels.create', authRequired: true,
return RocketChat.API.v1.failure e.name + ': ' + e.message
return RocketChat.API.v1.success
channel: RocketChat.cache.Rooms.findOneById(id.rid)
channel: RocketChat.models.Rooms.findOneById(id.rid)
# List Private Groups a user has access to
RocketChat.API.v1.addRoute 'groups.list', authRequired: true,
get: ->
roomIds = _.pluck RocketChat.models.Subscriptions.findByTypeAndUserId('p', @userId).fetch(), 'rid'
return { groups: RocketChat.cache.Rooms.findByIds(roomIds).fetch() }
return { groups: RocketChat.models.Rooms.findByIds(roomIds).fetch() }
# Add All Users to Channel
RocketChat.API.v1.addRoute 'channel.addall', authRequired: true,
@ -123,7 +123,7 @@ RocketChat.API.v1.addRoute 'channel.addall', authRequired: true,
return RocketChat.API.v1.failure e.name + ': ' + e.message
return RocketChat.API.v1.success
channel: RocketChat.cache.Rooms.findOneById(@bodyParams.roomId)
channel: RocketChat.models.Rooms.findOneById(@bodyParams.roomId)
# List all users
RocketChat.API.v1.addRoute 'users.list', authRequired: true,
@ -255,5 +255,5 @@ RocketChat.API.v1.addRoute 'groups.create', authRequired: true,
return RocketChat.API.v1.failure e.name + ': ' + e.message
return RocketChat.API.v1.success
group: RocketChat.cache.Rooms.findOneById(id.rid)
group: RocketChat.models.Rooms.findOneById(id.rid)

@ -1,5 +1,5 @@
RocketChat.saveRoomName = (rid, name) ->
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
if room.t not in ['c', 'p']
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { function: 'RocketChat.saveRoomName' }
@ -19,7 +19,7 @@ RocketChat.saveRoomName = (rid, name) ->
return
# avoid duplicate names
if RocketChat.cache.Rooms.findOneByName name
if RocketChat.models.Rooms.findOneByName name
throw new Meteor.Error 'error-duplicate-channel-name', 'A channel with name \'' + name + '\' exists', { function: 'RocketChat.saveRoomName', channel_name: name }
RocketChat.models.Rooms.setNameById rid, name

@ -15,7 +15,7 @@ Meteor.methods
if setting is 'default' and not RocketChat.authz.hasPermission(@userId, 'view-room-administration')
throw new Meteor.Error 'error-action-not-allowed', 'Viewing room administration is not allowed', { method: 'saveRoomSettings', action: 'Viewing_room_administration' }
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
if room?
switch setting
when 'roomName'

@ -38,7 +38,7 @@ class ErrorHandler {
getRoomId(roomName) {
roomName = roomName.replace('#');
let room = RocketChat.cache.Rooms.findOneByName(roomName, { fields: { _id: 1, t: 1 } });
let room = RocketChat.models.Rooms.findOneByName(roomName, { fields: { _id: 1, t: 1 } });
if (room && (room.t === 'c' || room.t === 'p')) {
return room._id;
} else {

@ -151,7 +151,7 @@ Importer.HipChat = class Importer.HipChat extends Importer.Base
do (channel) =>
Meteor.runAsUser startedByUserId, () =>
channel.name = channel.name.replace(/ /g, '')
existantRoom = RocketChat.cache.Rooms.findOneByName channel.name
existantRoom = RocketChat.models.Rooms.findOneByName channel.name
if existantRoom
channel.rocketId = existantRoom._id
else
@ -177,7 +177,7 @@ Importer.HipChat = class Importer.HipChat extends Importer.Base
Meteor.runAsUser startedByUserId, () =>
hipchatChannel = @getHipChatChannelFromName channel
if hipchatChannel?.do_import
room = RocketChat.cache.Rooms.findOneById hipchatChannel.rocketId, { fields: { usernames: 1, t: 1, name: 1 } }
room = RocketChat.models.Rooms.findOneById hipchatChannel.rocketId, { fields: { usernames: 1, t: 1, name: 1 } }
for date, msgs of messagesObj
@updateRecord { 'messagesstatus': "#{channel}/#{date}.#{msgs.messages.length}" }
for message in msgs.messages

@ -157,7 +157,7 @@ Importer.Slack = class Importer.Slack extends Importer.Base
for channel in @channels.channels when channel.do_import
do (channel) =>
Meteor.runAsUser startedByUserId, () =>
existantRoom = RocketChat.cache.Rooms.findOneByName channel.name
existantRoom = RocketChat.models.Rooms.findOneByName channel.name
if existantRoom or channel.is_general
if channel.is_general and channel.name isnt existantRoom?.name
Meteor.call 'saveRoomSettings', 'GENERAL', 'roomName', channel.name
@ -206,7 +206,7 @@ Importer.Slack = class Importer.Slack extends Importer.Base
Meteor.runAsUser startedByUserId, () =>
slackChannel = @getSlackChannelFromName channel
if slackChannel?.do_import
room = RocketChat.cache.Rooms.findOneById slackChannel.rocketId, { fields: { usernames: 1, t: 1, name: 1 } }
room = RocketChat.models.Rooms.findOneById slackChannel.rocketId, { fields: { usernames: 1, t: 1, name: 1 } }
for date, msgs of messagesObj
@updateRecord { 'messagesstatus': "#{channel}/#{date}.#{msgs.messages.length}" }
for message in msgs.messages

@ -39,7 +39,7 @@ Meteor.methods
switch channelType
when '#'
record = RocketChat.cache.Rooms.findOne
record = RocketChat.models.Rooms.findOne
$or: [
{_id: channel}
{name: channel}

@ -42,7 +42,7 @@ Meteor.methods
switch channelType
when '#'
record = RocketChat.cache.Rooms.findOne
record = RocketChat.models.Rooms.findOne
$or: [
{_id: channel}
{name: channel}

@ -57,7 +57,7 @@ Meteor.methods
switch channelType
when '#'
record = RocketChat.cache.Rooms.findOne
record = RocketChat.models.Rooms.findOne
$or: [
{_id: channel}
{name: channel}

@ -69,7 +69,7 @@ Meteor.methods
switch channelType
when '#'
record = RocketChat.cache.Rooms.findOne
record = RocketChat.models.Rooms.findOne
$or: [
{_id: channel}
{name: channel}

@ -22,7 +22,7 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) {
switch (channelType) {
case '#':
room = RocketChat.cache.Rooms.findOneByIdOrName(channel);
room = RocketChat.models.Rooms.findOneByIdOrName(channel);
if (!_.isObject(room)) {
throw new Meteor.Error('invalid-channel');
}
@ -44,14 +44,14 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) {
]
}) || {};
rid = [user._id, roomUser._id].sort().join('');
room = RocketChat.cache.Rooms.findOneById({$in: [rid, channel]});
room = RocketChat.models.Rooms.findOneById({$in: [rid, channel]});
if (!_.isObject(roomUser) && !_.isObject(room)) {
throw new Meteor.Error('invalid-channel');
}
if (!room) {
Meteor.runAsUser(user._id, function() {
Meteor.call('createDirectMessage', roomUser.username);
room = RocketChat.cache.Rooms.findOneById(rid);
room = RocketChat.models.Rooms.findOneById(rid);
});
}
break;

@ -137,7 +137,7 @@ class InternalHubotReceiver
constructor: (message) ->
console.log message if DEBUG
if message.u.username isnt InternalHubot.name
room = RocketChat.cache.Rooms.findOneById message.rid
room = RocketChat.models.Rooms.findOneById message.rid
if room.t is 'c'
InternalHubotUser = new Hubot.User(message.u.username, room: message.rid)

@ -160,7 +160,7 @@ class IrcClient
console.log '[irc] onReceiveMessage -> '.yellow, 'source:', source, 'target:', target, 'content:', content
source = @createUserWhenNotExist source
if target[0] == '#'
room = RocketChat.cache.Rooms.findOneByName target.substring(1)
room = RocketChat.models.Rooms.findOneByName target.substring(1)
else
room = @createDirectRoomWhenNotExist(source, @user)
@ -178,7 +178,7 @@ class IrcClient
onEndMemberList: (roomName) ->
newMembers = @receiveMemberListBuf[roomName]
console.log '[irc] onEndMemberList -> '.yellow, 'room:', roomName, 'members:', newMembers.join ','
room = RocketChat.cache.Rooms.findOneByNameAndType roomName, 'c'
room = RocketChat.models.Rooms.findOneByNameAndType roomName, 'c'
unless room
return
@ -224,7 +224,7 @@ class IrcClient
@sendRawMessage msg
initRoomList: ->
roomsCursor = RocketChat.cache.Rooms.findByTypeContainigUsername 'c', @user.username,
roomsCursor = RocketChat.models.Rooms.findByTypeContainigUsername 'c', @user.username,
fields:
name: 1
t: 1
@ -355,7 +355,7 @@ class IrcSender
if ircReceiveMessageCache.get cacheKey
return message
room = RocketChat.cache.Rooms.findOneById message.rid, { fields: { name: 1, usernames: 1, t: 1 } }
room = RocketChat.models.Rooms.findOneById message.rid, { fields: { name: 1, usernames: 1, t: 1 } }
ircClient = IrcClient.getByUid message.u._id
ircClient.sendMessage room, message
return message

@ -33,7 +33,7 @@ RocketChat.Notifications = new class
roomId = eventName.split('/')[0]
user = Meteor.users.findOne @userId, {fields: {username: 1}}
return RocketChat.cache.Rooms.findOneByIdContainigUsername(roomId, user.username, {fields: {_id: 1}})?
return RocketChat.models.Rooms.findOneByIdContainigUsername(roomId, user.username, {fields: {_id: 1}})?
@streamRoomUsers.allowRead('none');

@ -1,6 +1,6 @@
RocketChat.addUserToDefaultChannels = function(user, silenced) {
RocketChat.callbacks.run('beforeJoinDefaultChannels', user);
let defaultRooms = RocketChat.cache.Rooms.findByDefaultAndTypes(true, ['c', 'p'], {fields: {usernames: 0}}).fetch();
let defaultRooms = RocketChat.models.Rooms.findByDefaultAndTypes(true, ['c', 'p'], {fields: {usernames: 0}}).fetch();
defaultRooms.forEach((room) => {
// put user in default rooms

@ -1,6 +1,6 @@
RocketChat.addUserToRoom = function(rid, user, inviter, silenced) {
let now = new Date();
let room = RocketChat.cache.Rooms.findOneById(rid);
let room = RocketChat.models.Rooms.findOneById(rid);
// Check if user is already in room
let subscription = RocketChat.models.Subscriptions.findOneByRoomIdAndUserId(rid, user._id);

@ -30,7 +30,7 @@ RocketChat.createRoom = function(type, name, owner, members, readOnly) {
}
// avoid duplicate names
let room = RocketChat.cache.Rooms.findOneByName(name);
let room = RocketChat.models.Rooms.findOneByName(name);
if (room) {
if (room.archived) {
throw new Meteor.Error('error-archived-duplicate-name', 'There\'s an archived channel with name ' + name, { function: 'RocketChat.createRoom', room_name: name });

@ -4,7 +4,7 @@ RocketChat.deleteUser = function(userId) {
RocketChat.models.Messages.removeByUserId(userId); // Remove user messages
RocketChat.models.Subscriptions.findByUserId(userId).forEach((subscription) => {
let room = RocketChat.cache.Rooms.findOneById(subscription.rid);
let room = RocketChat.models.Rooms.findOneById(subscription.rid);
if (room) {
if (room.t !== 'c' && room.usernames.length === 1) {
RocketChat.models.Rooms.removeById(subscription.rid); // Remove non-channel rooms with only 1 user (the one being deleted)

@ -1,5 +1,5 @@
RocketChat.removeUserFromRoom = function(rid, user) {
let room = RocketChat.cache.Rooms.findOneById(rid);
let room = RocketChat.models.Rooms.findOneById(rid);
if (room) {
RocketChat.callbacks.run('beforeLeaveRoom', user, room);

@ -13,7 +13,7 @@ RocketChat.sendMessage = (user, message, room, upsert = false) ->
message.rid = room._id
if not room.usernames? || room.usernames.length is 0
room = RocketChat.cache.Rooms.findOne({_id: room._id})
room = RocketChat.models.Rooms.findOne({_id: room._id})
if message.parseUrls isnt false
if urls = message.msg.match /([A-Za-z]{3,9}):\/\/([-;:&=\+\$,\w]+@{1})?([-A-Za-z0-9\.]+)+:?(\d+)?((\/[-\+=!:~%\/\.@\,\w]*)?\??([-\+=&!:;%@\/\.\,\w]+)?(?:#([^\s\)]+))?)?/g

@ -22,7 +22,7 @@ RocketChat.updateMessage = function(message, user) {
RocketChat.models.Messages.update({ _id: tempid }, { $set: message });
let room = RocketChat.cache.Rooms.findOneById(message.rid);
let room = RocketChat.models.Rooms.findOneById(message.rid);
Meteor.defer(function() {
RocketChat.callbacks.run('afterSaveMessage', RocketChat.models.Messages.findOneById(tempid), room);

@ -9,7 +9,7 @@ Meteor.methods
unless Match.test data?.username, String
throw new Meteor.Error 'error-invalid-username', 'Invalid username', { method: 'addUserToRoom' }
room = RocketChat.cache.Rooms.findOneById data.rid
room = RocketChat.models.Rooms.findOneById data.rid
if room.usernames.indexOf(Meteor.user().username) is -1
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { method: 'addUserToRoom' }

@ -6,7 +6,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'archiveRoom' }
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
unless room
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'archiveRoom' }

@ -7,7 +7,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'joinRoom' }
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
if not room?
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'joinRoom' }

@ -9,7 +9,7 @@ Meteor.methods
this.unblock()
fromId = Meteor.userId()
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
user = Meteor.user()
# If user is room owner, check if there are other owners. If there isn't anyone else, warn user to set a new owner.

@ -6,7 +6,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'unarchiveRoom' }
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
unless room
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'unarchiveRoom' }

@ -262,7 +262,7 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base
# INSERT
createWithTypeRoomIdMessageAndUser: (type, roomId, message, user, extraData) ->
room = RocketChat.cache.Rooms.findOneById roomId, { fields: { sysMes: 1 }}
room = RocketChat.models.Rooms.findOneById roomId, { fields: { sysMes: 1 }}
if room?.sysMes is false
return
record =

@ -547,6 +547,4 @@ class ModelRooms extends RocketChat.models._Base
return @remove query
# TODO_CACHE: remove
RocketChat.models.Rooms = new ModelRooms('room', true)
RocketChat.cache.Rooms = RocketChat.models.Rooms

@ -25,7 +25,7 @@ Api.addRoute('sms-incoming/:service', {
};
if (visitor) {
const rooms = RocketChat.cache.Rooms.findOpenByVisitorToken(visitor.profile.token).fetch();
const rooms = RocketChat.models.Rooms.findOpenByVisitorToken(visitor.profile.token).fetch();
if (rooms && rooms.length > 0) {
sendMessage.message.rid = rooms[0]._id;

@ -32,7 +32,7 @@ RocketChat.Livechat = {
}
},
getRoom(guest, message, roomInfo) {
var room = RocketChat.cache.Rooms.findOneById(message.rid);
var room = RocketChat.models.Rooms.findOneById(message.rid);
var newRoom = false;
if (room && !room.open) {
@ -249,7 +249,7 @@ RocketChat.Livechat = {
},
forwardOpenChats(userId) {
RocketChat.cache.Rooms.findOpenByAgent(userId).forEach((room) => {
RocketChat.models.Rooms.findOpenByAgent(userId).forEach((room) => {
const guest = RocketChat.models.Users.findOneById(room.v._id);
this.transfer(room, guest, { departmentId: guest.department });
});

@ -4,7 +4,7 @@ Meteor.methods({
throw new Meteor.Error('error-not-authorized', 'Not authorized', { method: 'livechat:closeRoom' });
}
const room = RocketChat.cache.Rooms.findOneById(roomId);
const room = RocketChat.models.Rooms.findOneById(roomId);
const user = Meteor.user();

@ -17,7 +17,7 @@ Meteor.methods({
videoCall: null
};
const room = RocketChat.cache.Rooms.findOpenByVisitorToken(visitorToken, {
const room = RocketChat.models.Rooms.findOpenByVisitorToken(visitorToken, {
fields: {
name: 1,
t: 1,

@ -22,7 +22,7 @@ Meteor.methods({
const ret = RocketChat.Livechat.saveGuest(guestData) && RocketChat.Livechat.saveRoomInfo(roomData, guestData);
Meteor.defer(() => {
RocketChat.callbacks.run('livechat.saveInfo', RocketChat.cache.Rooms.findOneById(roomData._id));
RocketChat.callbacks.run('livechat.saveInfo', RocketChat.models.Rooms.findOneById(roomData._id));
});
return ret;

@ -7,7 +7,7 @@ Meteor.methods({
check(formData, [Match.ObjectIncluding({ name: String, value: String })]);
const visitor = RocketChat.models.Users.getVisitorByToken(visitorToken);
const room = RocketChat.cache.Rooms.findOneById(visitorRoom);
const room = RocketChat.models.Rooms.findOneById(visitorRoom);
if (visitor !== undefined && room !== undefined && room.v !== undefined && visitor.profile !== undefined && room.v.token === visitor.profile.token) {
const updateData = {};

@ -36,7 +36,7 @@ Meteor.methods({
};
RocketChat.models.Subscriptions.insert(subscriptionData);
const room = RocketChat.cache.Rooms.findOneById(inquiry.rid);
const room = RocketChat.models.Rooms.findOneById(inquiry.rid);
const usernames = room.usernames.concat(agent.username);
RocketChat.models.Rooms.changeAgentByRoomId(inquiry.rid, usernames, agent);

@ -11,7 +11,7 @@ Meteor.methods({
deparmentId: Match.Optional(String)
});
const room = RocketChat.cache.Rooms.findOneById(transferData.roomId);
const room = RocketChat.models.Rooms.findOneById(transferData.roomId);
const guest = RocketChat.cache.Users.findOneById(room.v._id);

@ -83,7 +83,7 @@ RocketChat.models.Rooms.getNextLivechatRoomCode = function() {
return livechatCount.value.value;
};
RocketChat.cache.Rooms.findOpenByVisitorToken = function(visitorToken, options) {
RocketChat.models.Rooms.findOpenByVisitorToken = function(visitorToken, options) {
const query = {
open: true,
'v.token': visitorToken
@ -92,7 +92,7 @@ RocketChat.cache.Rooms.findOpenByVisitorToken = function(visitorToken, options)
return this.find(query, options);
};
RocketChat.cache.Rooms.findByVisitorToken = function(visitorToken) {
RocketChat.models.Rooms.findByVisitorToken = function(visitorToken) {
const query = {
'v.token': visitorToken
};
@ -157,7 +157,7 @@ RocketChat.models.Rooms.setLabelByRoomId = function(roomId, label) {
return this.update({ _id: roomId }, { $set: { label: label } });
};
RocketChat.cache.Rooms.findOpenByAgent = function(userId) {
RocketChat.models.Rooms.findOpenByAgent = function(userId) {
const query = {
open: true,
'servedBy._id': userId

@ -7,7 +7,7 @@ Meteor.publish('livechat:visitorHistory', function({ rid: roomId }) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorHistory' }));
}
var room = RocketChat.cache.Rooms.findOneById(roomId);
var room = RocketChat.models.Rooms.findOneById(roomId);
const user = RocketChat.models.Users.findOneById(this.userId);

@ -7,7 +7,7 @@ Meteor.publish('livechat:visitorInfo', function({ rid: roomId }) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorInfo' }));
}
var room = RocketChat.cache.Rooms.findOneById(roomId);
var room = RocketChat.models.Rooms.findOneById(roomId);
if (room && room.v && room.v._id) {
return RocketChat.models.Users.findById(room.v._id);

@ -7,7 +7,7 @@ Meteor.publish('livechat:visitorPageVisited', function({ rid: roomId }) {
return this.error(new Meteor.Error('error-not-authorized', 'Not authorized', { publish: 'livechat:visitorPageVisited' }));
}
var room = RocketChat.cache.Rooms.findOneById(roomId);
var room = RocketChat.models.Rooms.findOneById(roomId);
if (room && room.v && room.v.token) {
return RocketChat.models.LivechatPageVisited.findByToken(room.v.token);

@ -1,6 +1,6 @@
Meteor.startup(() => {
RocketChat.roomTypes.setRoomFind('l', (code) => {
return RocketChat.cache.Rooms.findLivechatByCode(code).fetch();
return RocketChat.models.Rooms.findLivechatByCode(code).fetch();
});
RocketChat.authz.addRoomAccessValidator(function(room, user) {

@ -17,7 +17,7 @@ class MentionsServer
if mention is 'all'
messageMaxAll = RocketChat.settings.get('Message_MaxAll')
if messageMaxAll > 0
allChannel = RocketChat.cache.Rooms.findOneById message.rid
allChannel = RocketChat.models.Rooms.findOneById message.rid
if allChannel.usernames.length <= messageMaxAll
verifiedMention =
_id: mention
@ -42,7 +42,7 @@ class MentionsServer
channels = _.unique channels
verifiedChannels = []
channels.forEach (mention) ->
verifiedChannel = RocketChat.cache.Rooms.findOneByNameAndType(mention, 'c', { fields: {_id: 1, name: 1 } })
verifiedChannel = RocketChat.models.Rooms.findOneByNameAndType(mention, 'c', { fields: {_id: 1, name: 1 } })
verifiedChannels.push verifiedChannel if verifiedChannel?
if verifiedChannels.length isnt 0

@ -6,7 +6,7 @@ Meteor.methods
if not RocketChat.settings.get 'Message_AllowPinning'
throw new Meteor.Error 'error-action-not-allowed', 'Message pinning not allowed', { method: 'pinMessage', action: 'Message_pinning' }
room = RocketChat.cache.Rooms.findOneById(message.rid)
room = RocketChat.models.Rooms.findOneById(message.rid)
if Array.isArray(room.usernames) && room.usernames.indexOf(Meteor.user().username) is -1
return false
@ -42,7 +42,7 @@ Meteor.methods
if not RocketChat.settings.get 'Message_AllowPinning'
throw new Meteor.Error 'error-action-not-allowed', 'Message pinning not allowed', { method: 'unpinMessage', action: 'Message_pinning' }
room = RocketChat.cache.Rooms.findOneById(message.rid)
room = RocketChat.models.Rooms.findOneById(message.rid)
if Array.isArray(room.usernames) && room.usernames.indexOf(Meteor.user().username) is -1
return false

@ -6,7 +6,7 @@ Meteor.methods
if not RocketChat.settings.get 'Message_AllowStarring'
throw new Meteor.Error 'error-action-not-allowed', 'Message starring not allowed', { method: 'pinMessage', action: 'Message_starring' }
room = RocketChat.cache.Rooms.findOneById(message.rid)
room = RocketChat.models.Rooms.findOneById(message.rid)
if Array.isArray(room.usernames) && room.usernames.indexOf(Meteor.user().username) is -1
return false

@ -88,7 +88,7 @@ class SlackBridge {
findChannel(channelId) {
logger.class.debug('Searching for Rocket.Chat channel', channelId);
return RocketChat.cache.Rooms.findOneByImportId(channelId);
return RocketChat.models.Rooms.findOneByImportId(channelId);
}
addChannel(channelId, hasRetried = false) {
@ -103,7 +103,7 @@ class SlackBridge {
}
if (data && data.data && data.data.ok === true) {
let channelData = isGroup ? data.data.group : data.data.channel;
let existingRoom = RocketChat.cache.Rooms.findOneByName(channelData.name);
let existingRoom = RocketChat.models.Rooms.findOneByName(channelData.name);
// If the room exists, make sure we have its id in importIds
if (existingRoom || channelData.is_general) {
@ -154,7 +154,7 @@ class SlackBridge {
RocketChat.models.Rooms.update({ _id: channelData.rocketId }, { $set: roomUpdate, $addToSet: { importIds: channelData.id } });
this.channelMap[channelData.rocketId] = { id: channelId, family: channelId.charAt(0) === 'C' ? 'channels' : 'groups' };
}
return RocketChat.cache.Rooms.findOneById(channelData.rocketId);
return RocketChat.models.Rooms.findOneById(channelData.rocketId);
}
return;
@ -878,7 +878,7 @@ class SlackBridge {
importMessages(rid, callback) {
logger.class.info('importMessages: ', rid);
let rocketchat_room = RocketChat.cache.Rooms.findOneById(rid);
let rocketchat_room = RocketChat.models.Rooms.findOneById(rid);
if (rocketchat_room) {
if (this.channelMap[rid]) {
this.copyChannelInfo(rid, this.channelMap[rid]);

@ -4,7 +4,7 @@ function SlackBridgeImport(command, params, item) {
if (command !== 'slackbridge-import' || !Match.test(params, String)) {
return;
}
room = RocketChat.cache.Rooms.findOneById(item.rid);
room = RocketChat.models.Rooms.findOneById(item.rid);
channel = room.name;
user = Meteor.users.findOne(Meteor.userId());

@ -5,11 +5,11 @@ function Archive(command, params, item) {
}
channel = params.trim();
if (channel === '') {
room = RocketChat.cache.Rooms.findOneById(item.rid);
room = RocketChat.models.Rooms.findOneById(item.rid);
channel = room.name;
} else {
channel = channel.replace('#', '');
room = RocketChat.cache.Rooms.findOneByName(channel);
room = RocketChat.models.Rooms.findOneByName(channel);
}
user = Meteor.users.findOne(Meteor.userId());

@ -9,7 +9,7 @@ function Create(command, params, item) {
}
user = Meteor.users.findOne(Meteor.userId());
room = RocketChat.cache.Rooms.findOneByName(channel);
room = RocketChat.models.Rooms.findOneByName(channel);
if (room != null) {
RocketChat.Notifications.notifyUser(Meteor.userId(), 'message', {
_id: Random.id(),

@ -25,7 +25,7 @@ class Invite
return
usernames = usernames.filter((username) ->
if not RocketChat.cache.Rooms.findOneByIdContainigUsername(item.rid, username)?
if not RocketChat.models.Rooms.findOneByIdContainigUsername(item.rid, username)?
return true
# Cancel if user is already in this room

@ -15,7 +15,7 @@ class Join
channel = channel.replace('#', '')
user = Meteor.users.findOne Meteor.userId()
room = RocketChat.cache.Rooms.findOneByNameAndTypeNotContainigUsername(channel, 'c', user.username)
room = RocketChat.models.Rooms.findOneByNameAndTypeNotContainigUsername(channel, 'c', user.username)
if not room?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {

@ -15,7 +15,7 @@ class Kick
user = Meteor.users.findOne Meteor.userId()
kickedUser = RocketChat.models.Users.findOneByUsername username
room = RocketChat.cache.Rooms.findOneById item.rid
room = RocketChat.models.Rooms.findOneById item.rid
if not kickedUser?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {

@ -15,7 +15,7 @@ class Mute
user = Meteor.users.findOne Meteor.userId()
mutedUser = RocketChat.models.Users.findOneByUsername username
room = RocketChat.cache.Rooms.findOneById item.rid
room = RocketChat.models.Rooms.findOneById item.rid
if not mutedUser?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {

@ -15,7 +15,7 @@ class Unmute
user = Meteor.users.findOne Meteor.userId()
unmutedUser = RocketChat.models.Users.findOneByUsername username
room = RocketChat.cache.Rooms.findOneById item.rid
room = RocketChat.models.Rooms.findOneById item.rid
if not unmutedUser?
RocketChat.Notifications.notifyUser Meteor.userId(), 'message', {

@ -5,11 +5,11 @@ function Unarchive(command, params, item) {
}
channel = params.trim();
if (channel === '') {
room = RocketChat.cache.Rooms.findOneById(item.rid);
room = RocketChat.models.Rooms.findOneById(item.rid);
channel = room.name;
} else {
channel = channel.replace('#', '');
room = RocketChat.cache.Rooms.findOneByName(channel);
room = RocketChat.models.Rooms.findOneByName(channel);
}
user = Meteor.users.findOne(Meteor.userId());

@ -17,10 +17,10 @@ RocketChat.statistics.get = ->
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers
# Room statistics
statistics.totalRooms = RocketChat.cache.Rooms.find().count()
statistics.totalChannels = RocketChat.cache.Rooms.findByType('c').count()
statistics.totalPrivateGroups = RocketChat.cache.Rooms.findByType('p').count()
statistics.totalDirect = RocketChat.cache.Rooms.findByType('d').count()
statistics.totalRooms = RocketChat.models.Rooms.find().count()
statistics.totalChannels = RocketChat.models.Rooms.findByType('c').count()
statistics.totalPrivateGroups = RocketChat.models.Rooms.findByType('p').count()
statistics.totalDirect = RocketChat.models.Rooms.findByType('d').count()
# Message statistics
statistics.totalMessages = RocketChat.models.Messages.find().count()

@ -1,7 +1,7 @@
Meteor.methods({
'jitsi:updateTimeout': (rid) => {
let room = RocketChat.cache.Rooms.findOneById(rid);
let room = RocketChat.models.Rooms.findOneById(rid);
let currentTime = new Date().getTime();
let jitsiTimeout = new Date((room && room.jitsiTimeout) || currentTime).getTime();

@ -11,7 +11,7 @@ Meteor.methods({
method: 'addAllToRoom'
});
}
room = RocketChat.cache.Rooms.findOneById(rid);
room = RocketChat.models.Rooms.findOneById(rid);
if (room == null) {
throw new Meteor.Error('error-invalid-room', 'Invalid room', {
method: 'addAllToRoom'

@ -12,7 +12,7 @@ Meteor.methods
unless rid
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'canAccessRoom' }
room = RocketChat.cache.Rooms.findOneById rid
room = RocketChat.models.Rooms.findOneById rid
if room
if RocketChat.authz.canAccessRoom.call(this, room, user)

@ -37,8 +37,8 @@ Meteor.methods
if roomTypes.length
if filter
return { channels: RocketChat.cache.Rooms.findByNameContainingTypesWithUsername(filter, roomTypes, options).fetch() }
return { channels: RocketChat.models.Rooms.findByNameContainingTypesWithUsername(filter, roomTypes, options).fetch() }
else
return { channels: RocketChat.cache.Rooms.findContainingTypesWithUsername(roomTypes, options).fetch() }
return { channels: RocketChat.models.Rooms.findContainingTypesWithUsername(roomTypes, options).fetch() }
else
return { channels: [] }

@ -8,7 +8,7 @@ Meteor.methods
fromId = Meteor.userId()
roomType = RocketChat.cache.Rooms.findOneById(rid)?.t
roomType = RocketChat.models.Rooms.findOneById(rid)?.t
if RocketChat.authz.hasPermission( fromId, "delete-#{roomType}", rid )
# ChatRoom.update({ _id: rid}, {'$pull': { userWatching: Meteor.userId(), userIn: Meteor.userId() }})

@ -6,7 +6,7 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'getRoomIdByNameOrId' }
room = RocketChat.cache.Rooms.findOneById(rid) or RocketChat.cache.Rooms.findOneByName(rid)
room = RocketChat.models.Rooms.findOneById(rid) or RocketChat.models.Rooms.findOneByName(rid)
if not room?
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { method: 'getRoomIdByNameOrId' }

@ -3,4 +3,4 @@ Meteor.methods
if not Meteor.userId()
throw new Meteor.Error 'error-invalid-user', 'Invalid user', { method: 'getTotalChannels' }
return RocketChat.cache.Rooms.find({ t: 'c' }).count()
return RocketChat.models.Rooms.find({ t: 'c' }).count()

@ -33,10 +33,10 @@ Meteor.methods({
//Determine if they are searching or not, base it upon the name field
if (nameFilter) {
return { groups: RocketChat.cache.Rooms.findByTypeAndNameContainingUsername('p', new RegExp(s.trim(s.escapeRegExp(nameFilter)), 'i'), Meteor.user().username, options).fetch() };
return { groups: RocketChat.models.Rooms.findByTypeAndNameContainingUsername('p', new RegExp(s.trim(s.escapeRegExp(nameFilter)), 'i'), Meteor.user().username, options).fetch() };
} else {
let roomIds = _.pluck(RocketChat.models.Subscriptions.findByTypeAndUserId('p', Meteor.userId()).fetch(), 'rid');
return { groups: RocketChat.cache.Rooms.findByIds(roomIds, options).fetch() };
return { groups: RocketChat.models.Rooms.findByIds(roomIds, options).fetch() };
}
}
});

@ -11,7 +11,7 @@ Meteor.methods
unless RocketChat.authz.hasPermission(fromId, 'mute-user', data.rid)
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { method: 'muteUserInRoom' }
room = RocketChat.cache.Rooms.findOneById data.rid
room = RocketChat.models.Rooms.findOneById data.rid
if not room
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'muteUserInRoom' }

@ -11,7 +11,7 @@ Meteor.methods
unless RocketChat.authz.hasPermission(fromId, 'remove-user', data.rid)
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { method: 'removeUserFromRoom' }
room = RocketChat.cache.Rooms.findOneById data.rid
room = RocketChat.models.Rooms.findOneById data.rid
if data.username not in (room?.usernames or [])
throw new Meteor.Error 'error-user-not-in-room', 'User is not in this room', { method: 'removeUserFromRoom' }

@ -6,7 +6,7 @@ Meteor.methods
unless RocketChat.authz.hasPermission(fromId, 'mute-user', data.rid)
throw new Meteor.Error 'error-not-allowed', 'Not allowed', { method: 'unmuteUserInRoom' }
room = RocketChat.cache.Rooms.findOneById data.rid
room = RocketChat.models.Rooms.findOneById data.rid
if not room
throw new Meteor.Error 'error-invalid-room', 'Invalid room', { method: 'unmuteUserInRoom' }

@ -2,7 +2,7 @@ Meteor.publish 'privateHistory', ->
unless this.userId
return this.ready()
RocketChat.cache.Rooms.findByContainigUsername RocketChat.models.Users.findOneById(this.userId).username,
RocketChat.models.Rooms.findByContainigUsername RocketChat.models.Users.findOneById(this.userId).username,
fields:
t: 1
name: 1

@ -68,7 +68,7 @@ Meteor.methods({
if (roomFind) {
room = roomFind.call(this, name);
} else {
room = RocketChat.cache.Rooms.findByTypeAndName(type, name).fetch();
room = RocketChat.models.Rooms.findByTypeAndName(type, name).fetch();
}
if (!room) {
@ -83,7 +83,7 @@ Meteor.methods({
}
});
RocketChat.cache.Rooms.on('sync', (type, room/*, diff*/) => {
RocketChat.models.Rooms.cache.on('sync', (type, room/*, diff*/) => {
const records = RocketChat.cache.Subscriptions.findByRoomId(room._id).fetch();
for (const record of records) {
RocketChat.Notifications.notifyUserInThisInstance(record.u._id, 'rooms-changed', type, roomMap({_room: room}));
@ -92,7 +92,7 @@ RocketChat.cache.Rooms.on('sync', (type, room/*, diff*/) => {
RocketChat.cache.Subscriptions.on('changed', (type, subscription/*, diff*/) => {
if (type === 'inserted') {
const room = RocketChat.cache.Rooms.findOneById(subscription.rid);
const room = RocketChat.models.Rooms.findOneById(subscription.rid);
if (room) {
RocketChat.Notifications.notifyUserInThisInstance(subscription.u._id, 'rooms-changed', type, roomMap({_room: room}));
}

@ -14,7 +14,7 @@ Meteor.methods
if type.rooms is true and RocketChat.authz.hasPermission this.userId, 'view-c-room'
username = RocketChat.cache.Users.findOneById(this.userId, { username: 1 }).username
result.rooms = RocketChat.cache.Rooms.findByNameAndTypeNotContainingUsername(regex, 'c', username, { limit: 5, fields: { t: 1, name: 1 }, sort: { name: 1 } }).fetch()
result.rooms = RocketChat.models.Rooms.findByNameAndTypeNotContainingUsername(regex, 'c', username, { limit: 5, fields: { t: 1, name: 1 }, sort: { name: 1 } }).fetch()
return result

@ -15,7 +15,7 @@ Api.addRoute 'version', authRequired: false,
Api.addRoute 'publicRooms', authRequired: true,
get: ->
rooms = RocketChat.cache.Rooms.findByType('c', { sort: { msgs:-1 } }).fetch()
rooms = RocketChat.models.Rooms.findByType('c', { sort: { msgs:-1 } }).fetch()
status: 'success', rooms: rooms
###
@ -23,7 +23,7 @@ Api.addRoute 'publicRooms', authRequired: true,
###
Api.addRoute 'joinedRooms', authRequired: true,
get: ->
rooms = RocketChat.cache.Rooms.findByContainigUsername(@user.username).fetch()
rooms = RocketChat.models.Rooms.findByContainigUsername(@user.username).fetch()
status: 'success', rooms: rooms
# join a room
@ -83,7 +83,7 @@ Api.addRoute 'rooms/:id/send', authRequired: true,
# get list of online users in a room
Api.addRoute 'rooms/:id/online', authRequired: true,
get: ->
room = RocketChat.cache.Rooms.findOneById @urlParams.id
room = RocketChat.models.Rooms.findOneById @urlParams.id
online = RocketChat.models.Users.findUsersNotOffline(fields:
username: 1
status: 1).fetch()

@ -1,7 +1,7 @@
Meteor.startup ->
Meteor.defer ->
if not RocketChat.cache.Rooms.findOneById('GENERAL')?
if not RocketChat.models.Rooms.findOneById('GENERAL')?
RocketChat.models.Rooms.createWithIdTypeAndName 'GENERAL', 'c', 'general',
default: true

Loading…
Cancel
Save