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

Generic reactions improvements #150

Merged
merged 9 commits into from
May 6, 2020

Conversation

leobragaz
Copy link
Contributor

@leobragaz leobragaz commented May 5, 2020

Description

This PR fixes the problems discussed in issues #144 #145 #147.
Closes #144.
Closes #145.
Closes #147.

Checklist

  • Targeted PR against correct branch.
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Wrote unit tests.
  • Wrote integration tests (simulation & CLI).
  • Updated the documentation.
  • Added an entry to the CHANGELOG.md file.
  • Re-reviewed Files changed in the Github PR explorer.

@leobragaz leobragaz added kind/enhancement Enhance an already existing feature; no "New feature" to add x/posts Post module Status:R4R labels May 5, 2020
@leobragaz leobragaz added this to the v0.5.0 milestone May 5, 2020
@leobragaz leobragaz self-assigned this May 5, 2020
Copy link
Contributor Author

@leobragaz leobragaz left a comment

Choose a reason for hiding this comment

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

re-reviewed

@leobragaz leobragaz requested a review from RiccardoM May 5, 2020 15:48
@codecov
Copy link

codecov bot commented May 5, 2020

Codecov Report

Merging #150 into master will decrease coverage by 0.03%.
The diff coverage is 87.80%.

@@            Coverage Diff             @@
##           master     #150      +/-   ##
==========================================
- Coverage   82.64%   82.61%   -0.04%     
==========================================
  Files          56       56              
  Lines        2374     2398      +24     
==========================================
+ Hits         1962     1981      +19     
- Misses        355      357       +2     
- Partials       57       60       +3     

@RiccardoM RiccardoM removed this from the v0.5.0 milestone May 6, 2020
…generic-reactions-improvements

� Conflicts:
�	CHANGELOG.md
…generic-reactions-improvements

� Conflicts:
�	x/posts/internal/types/msgs/msg_reactions.go
�	x/posts/internal/types/msgs/msgs_post_reactions.go
�	x/posts/internal/types/msgs/msgs_post_reactions_test.go
Comment on lines 152 to 169
if emojiReact, err := emoji.LookupEmoji(parsedReaction); err == nil {
reactionShortcode = emojiReact.Shortcodes[0]
reactionValue = emojiReact.Value
} else { //if not, check if the shortcode is related to any emoji
emo, err := emoji.LookupEmojiByCode(parsedReaction)
if err != nil { // if no emoji is related to it, check if the shortcode has been registered before
regReaction, exist := keeper.GetRegisteredReaction(ctx, parsedReaction, post.Subspace)
if !exist { // if it has not been registered yet, no one can use it to react to the post
return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest,
fmt.Sprintf("reaction with short code %s isn't registered yet and can't be used to react to the post with ID %s and subspace %s, please register it before use",
parsedReaction, post.PostID, post.Subspace))
}
reactionValue = regReaction.Value
reactionShortcode = regReaction.ShortCode
} else {
reactionValue = emo.Value
reactionShortcode = emo.Shortcodes[0]
}
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 not a big fan of this piece of code's structure. I think it can be improve by doing something like

if emojiReact, err := emoji.LookupEmoji(parsedReaction); err == nil {
  // The reaction was an emoji Unicode character
} else if emojiReact, err := emoji.LookupEmojiByCode(parsedReaction); err == nil {
  // The reaction was an emoji shotcode
} else {
  // The reaction was a shortcode that should be registered
}

I think it would be more easy to read. Also, since this entire piece of code is used as well inside the handleMsgRemovePostReaction, I would avoid duplicating it. To do this, we should move it into an external function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah I was not so conviced as well but I couldn’t think a better way to do that in that moment so I was hoping for some advice from you!

…vements' into leonardo/generic-reactions-improvements

# Conflicts:
#	x/posts/internal/types/msgs/msgs_post_reactions.go
@leobragaz leobragaz requested a review from RiccardoM May 6, 2020 09:58
Copy link
Contributor

@RiccardoM RiccardoM left a comment

Choose a reason for hiding this comment

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

LGTM

@RiccardoM RiccardoM merged commit ab850d6 into master May 6, 2020
@RiccardoM RiccardoM added this to the v0.5.0 milestone May 6, 2020
@RiccardoM RiccardoM deleted the leonardo/generic-reactions-improvements branch May 6, 2020 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Enhance an already existing feature; no "New feature" to add x/posts Post module
Projects
None yet
2 participants