mirror of
https://github.com/mikedilger/gossip.git
synced 2024-09-29 16:31:18 +00:00
Merge pull request #255 from ok300/ok300-reaction-icon
Reactions: Show filled icon if user already reacted
This commit is contained in:
commit
608203be18
@ -171,14 +171,22 @@ impl Globals {
|
||||
|
||||
// FIXME - this allows people to react many times to the same event, and
|
||||
// it counts them all!
|
||||
pub fn get_reactions_sync(id: Id) -> Vec<(char, usize)> {
|
||||
/// Returns the list of reactions and whether or not this account has already reacted to this event
|
||||
pub fn get_reactions_sync(id: Id) -> (Vec<(char, usize)>, bool) {
|
||||
let mut output: HashMap<char, HashSet<PublicKeyHex>> = HashMap::new();
|
||||
|
||||
// Whether or not the Gossip user already reacted to this event
|
||||
let mut self_already_reacted = false;
|
||||
|
||||
if let Some(relationships) = GLOBALS.relationships.blocking_read().get(&id) {
|
||||
for (other_id, relationship) in relationships.iter() {
|
||||
// get the reacting event to make sure publickeys are unique
|
||||
if let Some(e) = GLOBALS.events.get(other_id) {
|
||||
if let Relationship::Reaction(reaction) = relationship {
|
||||
if Some(e.pubkey) == GLOBALS.signer.public_key() {
|
||||
self_already_reacted = true;
|
||||
}
|
||||
|
||||
let symbol: char = if let Some(ch) = reaction.chars().next() {
|
||||
ch
|
||||
} else {
|
||||
@ -202,7 +210,7 @@ impl Globals {
|
||||
|
||||
let mut v: Vec<(char, usize)> = output.iter().map(|(c, u)| (*c, u.len())).collect();
|
||||
v.sort();
|
||||
v
|
||||
(v, self_already_reacted)
|
||||
}
|
||||
|
||||
pub fn get_deletion_sync(id: Id) -> Option<String> {
|
||||
|
@ -365,7 +365,7 @@ fn render_post_inner(
|
||||
) {
|
||||
let deletion = Globals::get_deletion_sync(event.id);
|
||||
|
||||
let reactions = Globals::get_reactions_sync(event.id);
|
||||
let (reactions, self_already_reacted) = Globals::get_reactions_sync(event.id);
|
||||
|
||||
let tag_re = app.tag_re.clone();
|
||||
|
||||
@ -635,8 +635,12 @@ fn render_post_inner(
|
||||
|
||||
// Buttons to react and reaction counts
|
||||
if app.settings.reactions {
|
||||
let default_reaction_icon = match self_already_reacted {
|
||||
true => "♥",
|
||||
false => "♡"
|
||||
};
|
||||
if ui
|
||||
.add(Label::new(RichText::new("♡").size(20.0)).sense(Sense::click()))
|
||||
.add(Label::new(RichText::new(default_reaction_icon).size(20.0)).sense(Sense::click()))
|
||||
.clicked()
|
||||
{
|
||||
let _ = GLOBALS
|
||||
|
Loading…
Reference in New Issue
Block a user