-
Notifications
You must be signed in to change notification settings - Fork 46
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re-reviewed
Codecov Report
@@ 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 |
…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
x/posts/internal/keeper/handler.go
Outdated
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] | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
This PR fixes the problems discussed in issues #144 #145 #147.
Closes #144.
Closes #145.
Closes #147.
Checklist
CHANGELOG.md
file.Files changed
in the Github PR explorer.