Skip to content
Snippets Groups Projects
Unverified Commit 300cdc34 authored by Bradley Hilton's avatar Bradley Hilton
Browse files

Fix the cache layer not respecting findById via query

parent ec0df3a9
No related branches found
No related tags found
No related merge requests found
......@@ -21,16 +21,16 @@ function retrieveDirectMessageInfo({ currentUserId, channel, findByUserIdOnly=fa
} else {
roomUser = RocketChat.models.Users.findOne({
$or: [{ _id: channel }, { username: channel }]
});
}
if (!_.isObject(roomUser)) {
throw new Meteor.Error('invalid-channel');
}) || {};
}
const rid = [currentUserId, roomUser._id].sort().join('');
let room = RocketChat.models.Rooms.findOneById({ $in: [rid, channel] });
if (!_.isObject(room)) {
throw new Meteor.Error('invalid-channel');
}
if (!room) {
Meteor.runAsUser(currentUserId, function() {
Meteor.call('createDirectMessage', roomUser.username);
......@@ -60,6 +60,7 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) {
for (channel of channels) {
channelType = channel[0];
console.log('The channelType:', channel);
channel = channel.substr(1);
......@@ -74,12 +75,14 @@ this.processWebhookMessage = function(messageObj, user, defaultValues) {
//Try to find the room by id or name if they didn't include the prefix.
room = retrieveRoomInfo({ currentUserId: user._id, channel: channelType + channel, ignoreEmpty: true });
if (room) {
channel = channelType + channel;
break;
}
//We didn't get a room, let's try finding direct messages
room = retrieveDirectMessageInfo({ currentUserId: user._id, channel: channelType + channel, findByUserIdOnly: true });
if (room) {
channel = channelType + channel;
break;
}
......
......@@ -370,6 +370,17 @@ class ModelsBaseCache extends EventEmitter {
}
_findByIndex(index, keys) {
if (keys.$in) {
for (let i = 0; i < keys.$in.length; i++) {
const result = this._findByIndex(index, keys.$in[i]);
if (result) {
return result;
}
}
return;
}
const key = [].concat(keys).join('|');
if (!this.indexes[index]) {
return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment