Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] Chat Message Reactions REST API End Point #9487

Merged
merged 4 commits into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move this verification to see if have or not message to the setReactions method, cuz already has one call to db for retrieve message, and you can save a call.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to have to disagree with this. That is outside of the scope of this pull request. If we change how the setReaction works then we are going to have to change how the other places which calls that method handles the result. The setReaction method doesn't return errors when the message doesn't exist and it only returns false so I think we should keep this error here for other developer's sake.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok @graywolf336, I had not througt about it. You're right.

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);
});
});