Skip to content

Bi-directional reactions to messages#5448

Merged
engelgabriel merged 2 commits intoRocketChat:developfrom
kable-wilmoth:ReactToMsgs
Jan 9, 2017
Merged

Bi-directional reactions to messages#5448
engelgabriel merged 2 commits intoRocketChat:developfrom
kable-wilmoth:ReactToMsgs

Conversation

@kable-wilmoth
Copy link
Copy Markdown

@RocketChat/core

Added the ability to react to slack and rocket messages. Doesn't quite work all the way because Slack sees the reactions as coming from the 'bot'. I am working w/ the Slack team to figure out some work arounds based on some alternative bot authentication mechanisms.

  • AddReact
    • slack message in slack: OK
    • rocket message in rocket: BOT in slack
    • slack message in rocket: BOT in slack
    • rocket message in slack: OK
  • RemoveReact
    • slack message, reacted in slack, removed in slack: OK
    • slack message, reacted in slack, removed in rocket: Removed in Rocket, BOT still in Slack
    • rocket message, reacted in rocket, removed in rocket: OK
    • rocket message, reacted in rocket, removed in slack: OK


return @findOne query

findOneBySlackTs: (slackTs) ->
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Needed the ability to look up a slack message w/ just the timestamp because the react message coming from slack didn't include the bot ID

Meteor.methods({
setReaction(reaction, messageId) {
if (!Meteor.userId()) {
setReaction(reaction, messageId, user) {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It was previously assumed that a reaction was coming from the current user. This is true most of the time, but in my case when Slack sends a reaction, I needed to call this method on behalf of the user. So added a user parameter, but if not present, it behaves as before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please revert this change and instead run this method as the user who is doing the reacting like such:

Meteor.runAsUser(user._id, () => {
	Meteor.call('setReaction', reaction, messageId);
});

Otherwise this is a breaking change for all of the clients out there who call this method as the user and don't pass in the user object.

Copy link
Copy Markdown
Author

@kable-wilmoth kable-wilmoth Jan 6, 2017

Choose a reason for hiding this comment

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

Will do.
Can you help me understand why it would have been a breaking change. I am new to JavaScript but I understood parameters to be optional. I had done some testing calling this method w/ out the user parameter and then the user was just resolved inside the method as previously coded. Is the potential breakage more to do w/ Meteor and the Rocket framework <meteor.call()>?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks!

@@ -41,8 +44,10 @@ Meteor.methods({
if (_.isEmpty(message.reactions)) {
delete message.reactions;
RocketChat.models.Messages.unsetReactions(messageId);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Added two new callbacks: setReaction and unsetReaction

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add the callbacks to run on the client side as well? This way people can take advantage of it for statistics, such as Piwiki or future Google Analytics

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Haven't done any client side changes to Rocket yet, but will look into this.

Meteor.methods({
setReaction(reaction, messageId) {
if (!Meteor.userId()) {
setReaction(reaction, messageId, user) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please revert this change and instead run this method as the user who is doing the reacting like such:

Meteor.runAsUser(user._id, () => {
	Meteor.call('setReaction', reaction, messageId);
});

Otherwise this is a breaking change for all of the clients out there who call this method as the user and don't pass in the user object.

@@ -41,8 +44,10 @@ Meteor.methods({
if (_.isEmpty(message.reactions)) {
delete message.reactions;
RocketChat.models.Messages.unsetReactions(messageId);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can you add the callbacks to run on the client side as well? This way people can take advantage of it for statistics, such as Piwiki or future Google Analytics

Responded to pull request comments
* Instead of passing in the user object, just used Meteor.runAs()
* Added callback events to the client side
@kable-wilmoth
Copy link
Copy Markdown
Author

@graywolf336 I have submitted the requested fixes. Not sure how to trigger the next 'steps' in the pull request process. Maybe this comment is it.
Thanks.
-kable

Copy link
Copy Markdown
Contributor

@graywolf336 graywolf336 left a comment

Choose a reason for hiding this comment

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

Thanks for making those changes, looks good to me.

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.

3 participants