diff --git a/packages/rocketchat-lib/server/functions/updateMessage.js b/packages/rocketchat-lib/server/functions/updateMessage.js index f32439858388..4d5c8e583b37 100644 --- a/packages/rocketchat-lib/server/functions/updateMessage.js +++ b/packages/rocketchat-lib/server/functions/updateMessage.js @@ -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); } } diff --git a/packages/rocketchat-lib/server/methods/updateMessage.js b/packages/rocketchat-lib/server/methods/updateMessage.js index db81b8f8d594..c0e389f0c6af 100644 --- a/packages/rocketchat-lib/server/methods/updateMessage.js +++ b/packages/rocketchat-lib/server/methods/updateMessage.js @@ -48,6 +48,6 @@ Meteor.methods({ message.u = originalMessage.u; - return RocketChat.updateMessage(message, Meteor.user()); + return RocketChat.updateMessage(message, Meteor.user(), originalMessage); }, });