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

feat: Add custom reactions to ReactionKind for posts #209

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions pallets/reactions/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ benchmarks! {
let other_kind = match reaction.kind {
ReactionKind::Upvote => ReactionKind::Downvote,
ReactionKind::Downvote => ReactionKind::Upvote,
_ => ReactionKind::Upvote,
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure about this. What if this is a negative emoji? Then it cannot be considered as an upvote.

};
}: _(origin, post.id, reaction.id, other_kind)
verify {
Expand Down
4 changes: 4 additions & 0 deletions pallets/reactions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub type ReactionId = u64;
pub enum ReactionKind {
Upvote,
Downvote,
Custom(u32),
Copy link
Member

@siman siman May 31, 2023

Choose a reason for hiding this comment

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

Maybe call it Emoji?
But I am not sure, need to discuss it.

Copy link
Member

Choose a reason for hiding this comment

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

I remember one idea was to support custom reactions (not even emojis).
For example, you could use custom reactions to implement on-chain voting, and having 4 bytes can give you a lot of variations for different options in a poll.

}

impl Default for ReactionKind {
Expand Down Expand Up @@ -201,6 +202,7 @@ pub mod pallet {
)?;
post.inc_downvotes();
},
_ => {},
}

PostById::<T>::insert(post_id, post.clone());
Expand Down Expand Up @@ -256,6 +258,7 @@ pub mod pallet {
post.inc_downvotes();
post.dec_upvotes();
},
_ => {},
}

ReactionById::<T>::insert(reaction_id, reaction);
Expand Down Expand Up @@ -299,6 +302,7 @@ pub mod pallet {
match reaction.kind {
ReactionKind::Upvote => post.dec_upvotes(),
ReactionKind::Downvote => post.dec_downvotes(),
_ => {},
}

PostById::<T>::insert(post_id, post.clone());
Expand Down