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

Conversation

jgtoriginal
Copy link
Contributor

@jgtoriginal jgtoriginal commented Jan 24, 2018

[FIX] Chat Message Reactions REST API End Point

/api/v1/chat.react method is documented but not present on packages/rocketchat-api/server/v1/chat.js

after having a chat with @graywolf336 it seems that he implemented it at some point, but a git blame on that file shows no result, hence I just provide an implementation for it since it's very useful to have.

INSTRUCTION: Just follow the docs
@RocketChat/core

NOTE: not on the rocketchat-reactions package nor on this endpoint, is there any sort of sanitization in place, so if you send a non existing emoji it would work the same. I'm not sure how to go by that, since we could stick to the default emojis for sanitization, but I'm not sure we could do so with custom ones. But probably that would be an other task centralized on the rockatchat-reactions packages that's the one instantiated by this new API method.


const emoji = this.bodyParams.emoji;

Meteor.runAsUser(this.userId, () => Meteor.call('setReaction', emoji, msg._id, this.userId));
Copy link
Member

Choose a reason for hiding this comment

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

Why do you need to pass the this.userId if you are already executing the method using runAsUser?

Copy link
Contributor Author

@jgtoriginal jgtoriginal Jan 24, 2018

Choose a reason for hiding this comment

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

@rodrigok you are right it is not strictly necessary to do it that way.
However if you look at every single method on that file, they all do it in that very same way. So I just tried to stick to the standards and to the scope.

Copy link
Contributor

Choose a reason for hiding this comment

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

@jgtoriginal What method(s) and what files are you talking about?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@graywolf336 every API method on this file packages/rocketchat-api/server/v1/chat.js does Meteor.runAsUser. Does it make sense?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that part makes sense however the part we are talking about is the passed in this.userId to the Meteor.call('setReaction... piece of the code along with the new argument usr added to the definition of the setReaction method. These last two aren't necessary and can be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@graywolf336 got you! let me get that done. thx!

Copy link
Member

@MarcosSpessatto MarcosSpessatto left a comment

Choose a reason for hiding this comment

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

I confirm what has been said above, like @graywolf336 said you can remove the usr param, and the verification added over this param. Missing end to end tests in this endpoint.


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.

@geekgonecrazy
Copy link
Contributor

Is this one blocked on anything particular? Would be great to have this land in 0.62.0

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-9487 February 15, 2018 14:49 Inactive
@jgtoriginal
Copy link
Contributor Author

@geekgonecrazy sorry, I'm not blocked on this specific task, I just got jammed among other projects. Will get back to this today so as we can proceed. Thanks for the reminder!

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-9487 February 15, 2018 16:45 Inactive
@geekgonecrazy geekgonecrazy dismissed MarcosSpessatto’s stale review February 15, 2018 18:17

please see discussion around review. Seems not needed

@geekgonecrazy
Copy link
Contributor

@jgtoriginal no problem :) Just seems like a great endpoint to make sure lands in 0.62.0.

I believe we intend to release the candidate / feature freeze on the 20th

@engelgabriel engelgabriel temporarily deployed to rocket-chat-pr-9487 February 15, 2018 20:16 Inactive
@jgtoriginal
Copy link
Contributor Author

@MarcosSpessatto I can see that you took over on removing the unnecessary parameter mentioned by @graywolf336 further up.
are you taking over on the end to end testing you mentioned early on?
just for me to chilax and move forward on other task I got in hands. Thx!

@rodrigok rodrigok merged commit b63eae7 into RocketChat:develop Feb 15, 2018
@rodrigok rodrigok mentioned this pull request Feb 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants