Skip to content

Commit

Permalink
Merge pull request #9487 from jgtoriginal/chat.reactAPIendPoint
Browse files Browse the repository at this point in the history
[FIX] Chat Message Reactions REST API End Point
  • Loading branch information
rodrigok authored Feb 15, 2018
2 parents 6a292a7 + 6a45ef8 commit b63eae7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/rocketchat-api/server/v1/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));

return RocketChat.API.v1.success();
}
});
15 changes: 15 additions & 0 deletions tests/end-to-end/api/05-chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,19 @@ describe('[Chat]', function() {
})
.end(done);
});

it('/chat.react', (done) => {
request.post(api('chat.react'))
.set(credentials)
.send({
emoji: 'smile',
messageId: message._id
})
.expect('Content-Type', 'application/json')
.expect(200)
.expect((res) => {
expect(res.body).to.have.property('success', true);
})
.end(done);
});
});

0 comments on commit b63eae7

Please sign in to comment.