Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Fix bug when user try recreate channel or group with same name and remove room from cache when user leaves room #12341

Merged
merged 8 commits into from
Jan 29, 2019
3 changes: 2 additions & 1 deletion packages/rocketchat-lib/client/lib/cachedCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,9 @@ class CachedCollection {
this.log('record received', t, record);
RocketChat.callbacks.run(`cachedCollection-received-${ this.name }`, record, t);
if (t === 'removed') {
const type = FlowRouter.current().route.name === 'channel' ? 'c' : 'p';
rodrigok marked this conversation as resolved.
Show resolved Hide resolved
this.collection.remove(record._id);
RoomManager.close(record.t + record.name);
RoomManager.close(type + FlowRouter.getParam('name'));
} else {
this.collection.upsert({ _id: record._id }, _.omit(record, '_id'));
}
Expand Down
9 changes: 8 additions & 1 deletion server/publications/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ Meteor.methods({
},
});

const getSubscriptions = (clientAction, id) => {
const fields = { 'u._id': 1 };
return clientAction === 'removed'
? RocketChat.models.Subscriptions.trashFind({ rid: id }, { fields })
: RocketChat.models.Subscriptions.findByRoomId(id, { fields });
rodrigok marked this conversation as resolved.
Show resolved Hide resolved
};

RocketChat.models.Rooms.on('change', ({ clientAction, id, data }) => {
switch (clientAction) {
case 'updated':
Expand All @@ -125,7 +132,7 @@ RocketChat.models.Rooms.on('change', ({ clientAction, id, data }) => {
}

if (data) {
RocketChat.models.Subscriptions.findByRoomId(id, { fields: { 'u._id': 1 } }).forEach(({ u }) => {
getSubscriptions(clientAction, id).forEach(({ u }) => {
RocketChat.Notifications.notifyUserInThisInstance(u._id, 'rooms-changed', clientAction, data);
});
}
Expand Down