diff --git a/web/src/components/object.rs b/web/src/components/object.rs index efe4503..1b8cf87 100644 --- a/web/src/components/object.rs +++ b/web/src/components/object.rs @@ -1,7 +1,9 @@ +use std::sync::Arc; + use leptos::*; use crate::{prelude::*, URL_SENSITIVE}; -use apb::{target::Addressed, ActivityMut, Base, Collection, Object, ObjectMut}; +use apb::{target::Addressed, ActivityMut, Base, Collection, CollectionMut, Object, ObjectMut}; #[component] pub fn Attachment( @@ -95,11 +97,33 @@ pub fn Object(object: crate::Object) -> impl IntoView { let likes = object.likes().get() .map_or(0, |x| x.total_items().unwrap_or(0)); let already_liked = object.liked_by_me().unwrap_or(false); + let attachments_padding = if object.attachment().is_empty() { None } else { Some(view! {
}) }; + let post_inner = view! { + +

+ {attachments_padding} + {attachments} +
+ }; + let post = match object.object_type() { + Some(apb::ObjectType::Document(apb::DocumentType::Page)) => view! { + {post_inner}
+ }.into_view(), // lemmy + Some(apb::ObjectType::Document(apb::DocumentType::Video)) => post_inner.into_view(), // peertube? + Some(apb::ObjectType::Note) => view! { +
{post_inner}
+ }.into_view(), + Some(t) => view! { +

{t.as_ref().to_string()}

+ {post_inner} + }.into_view(), + None => view! { missing object type }.into_view(), + }; view! { @@ -116,13 +140,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
-
- -

- {attachments_padding} - {attachments} -
-
+ {post}
@@ -179,11 +197,21 @@ pub fn LikeButton( .set_object(apb::Node::link(target.clone())) .set_to(to) .set_cc(cc); + let target = target.clone(); spawn_local(async move { match Http::post(&auth.outbox(), &payload, auth).await { Ok(()) => { set_clicked.set(false); set_count.set(count.get() + 1); + if let Some(cached) = CACHE.get(&target) { + let mut new = (*cached).clone().set_liked_by_me(Some(true)); + if let Some(likes) = new.likes().get() { + if let Some(count) = likes.total_items() { + new = new.set_likes(apb::Node::object(likes.clone().set_total_items(Some(count + 1)))); + } + } + CACHE.put(target, Arc::new(new)); + } }, Err(e) => tracing::error!("failed sending like: {e}"), }