Skip to content

Commit

Permalink
[FIX] Changing Room name updates the webhook (#13672)
Browse files Browse the repository at this point in the history
* Fixes #8477

* Rebased branch

* CI fix
  • Loading branch information
knrt10 authored and sampaiodiego committed Mar 14, 2019
1 parent 98c5d22 commit d33d3cd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/channel-settings/server/functions/saveRoomName.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Meteor } from 'meteor/meteor';
import { Rooms, Messages, Subscriptions } from '/app/models';
import { Rooms, Messages, Subscriptions, Integrations } from '/app/models';
import { roomTypes, getValidRoomName } from '/app/utils';

export const saveRoomName = function(rid, displayName, user, sendMessage = true) {
Expand All @@ -17,7 +17,13 @@ export const saveRoomName = function(rid, displayName, user, sendMessage = true)

const update = Rooms.setNameById(rid, slugifiedRoomName, displayName) && Subscriptions.updateNameAndAlertByRoomId(rid, slugifiedRoomName, displayName);

if (update && sendMessage) {
if (!update) {
return;
}

Integrations.updateRoomName(room.name, displayName);

if (sendMessage) {
Messages.createRoomRenamedWithRoomIdRoomNameAndUser(rid, displayName, user);
}
return displayName;
Expand Down
6 changes: 6 additions & 0 deletions app/models/server/models/Integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ export class Integrations extends Base {
disableByUserId(userId) {
return this.update({ userId }, { $set: { enabled: false } }, { multi: true });
}

updateRoomName(oldRoomName, newRoomName) {
const hashedOldRoomName = `#${ oldRoomName }`;
const hashedNewRoomName = `#${ newRoomName }`;
return this.update({ channel: hashedOldRoomName }, { $set: { 'channel.$': hashedNewRoomName } }, { multi: true });
}
}

export default new Integrations();

0 comments on commit d33d3cd

Please sign in to comment.