Skip to content

Commit

Permalink
Fix: Message changing order when been edited with apps enabled (#12188)
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigok authored and sampaiodiego committed Sep 28, 2018
1 parent 335d9d8 commit 2f6e58c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 10 additions & 4 deletions packages/rocketchat-lib/server/functions/updateMessage.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
RocketChat.updateMessage = function(message, user) {
RocketChat.updateMessage = function(message, user, originalMessage) {
if (!originalMessage) {
originalMessage = RocketChat.models.Messages.findOneById(message._id);
}

// For the Rocket.Chat Apps :)
if (message && Apps && Apps.isLoaded()) {
const prevent = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedPrevent', message));
const appMessage = Object.assign({}, originalMessage, message);

const prevent = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedPrevent', appMessage));
if (prevent) {
throw new Meteor.Error('error-app-prevented-updating', 'A Rocket.Chat App prevented the message updating.');
}

let result;
result = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedExtend', message));
result = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedExtend', appMessage));
result = Promise.await(Apps.getBridges().getListenerBridge().messageEvent('IPreMessageUpdatedModify', result));

if (typeof result === 'object') {
message = Object.assign(message, result);
message = Object.assign(appMessage, result);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rocketchat-lib/server/methods/updateMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ Meteor.methods({

message.u = originalMessage.u;

return RocketChat.updateMessage(message, Meteor.user());
return RocketChat.updateMessage(message, Meteor.user(), originalMessage);
},
});

0 comments on commit 2f6e58c

Please sign in to comment.