diff --git a/packages/rocketchat-api/server/v1/chat.js b/packages/rocketchat-api/server/v1/chat.js index 15f1500d0b2..bb3aeb50c09 100644 --- a/packages/rocketchat-api/server/v1/chat.js +++ b/packages/rocketchat-api/server/v1/chat.js @@ -255,3 +255,23 @@ RocketChat.API.v1.addRoute('chat.update', { authRequired: true }, { }); } }); + +RocketChat.API.v1.addRoute('chat.react', { authRequired: true }, { + post() { + if (!this.bodyParams.messageId || !this.bodyParams.messageId.trim()) { + throw new Meteor.Error('error-messageid-param-not-provided', 'The required "messageId" param is missing.'); + } + + const msg = RocketChat.models.Messages.findOneById(this.bodyParams.messageId); + + if (!msg) { + throw new Meteor.Error('error-message-not-found', 'The provided "messageId" does not match any existing message.'); + } + + const emoji = this.bodyParams.emoji; + + Meteor.runAsUser(this.userId, () => Meteor.call('setReaction', emoji, msg._id, this.userId)); + + return RocketChat.API.v1.success(); + } +}); diff --git a/packages/rocketchat-reactions/client/methods/setReaction.js b/packages/rocketchat-reactions/client/methods/setReaction.js index 59d05ae71dc..75caf00e7f9 100644 --- a/packages/rocketchat-reactions/client/methods/setReaction.js +++ b/packages/rocketchat-reactions/client/methods/setReaction.js @@ -1,12 +1,12 @@ import _ from 'underscore'; Meteor.methods({ - setReaction(reaction, messageId) { + setReaction(reaction, messageId, usr) { if (!Meteor.userId()) { throw new Meteor.Error(203, 'User_logged_out'); } - const user = Meteor.user(); + const user = usr ? usr : Meteor.user(); const message = RocketChat.models.Messages.findOne({ _id: messageId }); const room = RocketChat.models.Rooms.findOne({ _id: message.rid });