Process and show reactions

This commit is contained in:
Mike Dilger 2022-12-22 06:26:58 +13:00
parent bd592aacc7
commit ec07c2272e
2 changed files with 51 additions and 2 deletions

View File

@ -97,8 +97,11 @@ fn sort_feed(mut feed: Vec<FeedEvent>) -> Vec<Id> {
// Linear sort neweset first:
feed.sort_unstable_by(|a, b| {
if a.event.is_some() && b.event.is_some() {
b.event.as_ref().unwrap().created_at.cmp(
&a.event.as_ref().unwrap().created_at)
b.event
.as_ref()
.unwrap()
.created_at
.cmp(&a.event.as_ref().unwrap().created_at)
} else if a.event.is_some() {
std::cmp::Ordering::Greater
} else if b.event.is_some() {
@ -230,6 +233,45 @@ pub async fn add_event(event: &Event) -> Result<(), Error> {
}
}
if event.kind == EventKind::Reaction {
for tag in event.tags.iter() {
if let Tag::Event {
id,
recommended_relay_url: _,
marker: _,
} = tag
{
// last 'e' is the id reacted to
if event.content.starts_with('+') {
update_feed_event(id.to_owned(), |er| {
er.reactions.upvotes += 1;
})
.await;
} else if event.content.starts_with('-') {
update_feed_event(id.to_owned(), |er| {
er.reactions.downvotes += 1;
})
.await;
} else if event.content.is_empty() {
// consider it an upvote
update_feed_event(id.to_owned(), |er| {
er.reactions.upvotes += 1;
})
.await;
} else {
// consider it an emoji
update_feed_event(id.to_owned(), |er| {
// FIXME: If it exists, increment it
er.reactions
.emojis
.push((event.content.chars().next().unwrap(), 1))
})
.await;
}
}
}
}
Ok(())
}

View File

@ -19,6 +19,13 @@ pub(super) fn update(_app: &mut GossipUi, ctx: &Context, _frame: &mut eframe::Fr
if let Some(event) = &fevent.event {
ui.label(crate::date_ago::date_ago(event.created_at));
if fevent.reactions.upvotes > 0 {
ui.label(&format!("Upvotes={}", fevent.reactions.upvotes));
}
if fevent.reactions.downvotes > 0 {
ui.label(&format!("Downvotes={}", fevent.reactions.downvotes));
}
if let Some(person) = crate::globals::GLOBALS
.people
.blocking_lock()