From 1dac83f52c0be2d4b6ea8b73e8029c8dbc8ca688 Mon Sep 17 00:00:00 2001 From: alemi Date: Sat, 1 Jun 2024 01:13:49 +0200 Subject: [PATCH] fix(web): updated apb usage --- web/src/components/activity.rs | 2 +- web/src/components/object.rs | 18 +++++++++--------- web/src/components/post.rs | 4 ++-- web/src/components/timeline.rs | 8 ++++---- web/src/page/user.rs | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/web/src/components/activity.rs b/web/src/components/activity.rs index 9198a56..0fee85b 100644 --- a/web/src/components/activity.rs +++ b/web/src/components/activity.rs @@ -24,7 +24,7 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView { - + {kind.as_ref().to_string()} diff --git a/web/src/components/object.rs b/web/src/components/object.rs index e108aeb..7be75b0 100644 --- a/web/src/components/object.rs +++ b/web/src/components/object.rs @@ -29,7 +29,7 @@ pub fn Attachment( // // those who correctly send Image type objects without a media type get shown as links here, this // is a dirty fix to properly display as images - if kind == "link" && matches!(object.document_type(), Some(apb::DocumentType::Image)) { + if kind == "link" && matches!(object.document_type(), Ok(apb::DocumentType::Image)) { kind = "image".to_string(); } @@ -132,7 +132,7 @@ pub fn Object(object: crate::Object) -> impl IntoView { Some(view! {
}) }; let post_inner = view! { - +

{attachments_padding} {attachments} @@ -140,11 +140,11 @@ pub fn Object(object: crate::Object) -> impl IntoView { }; let post = match object.object_type() { // mastodon, pleroma, misskey - Some(apb::ObjectType::Note) => view! { + Ok(apb::ObjectType::Note) => view! {
{post_inner}
}.into_view(), // lemmy with Page, peertube with Video - Some(apb::ObjectType::Document(t)) => view! { + Ok(apb::ObjectType::Document(t)) => view! {
{object.name().unwrap_or_default().to_string()}
@@ -155,7 +155,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
}.into_view(), // wordpress, ... ? - Some(apb::ObjectType::Article) => view! { + Ok(apb::ObjectType::Article) => view! {

{object.name().unwrap_or_default().to_string()}


@@ -163,12 +163,12 @@ pub fn Object(object: crate::Object) -> impl IntoView {
}.into_view(), // everything else - Some(t) => view! { + Ok(t) => view! {

{t.as_ref().to_string()}

{post_inner} }.into_view(), // object without type? - None => view! { missing object type }.into_view(), + Err(_) => view! { missing object type }.into_view(), }; view! { @@ -180,7 +180,7 @@ pub fn Object(object: crate::Object) -> impl IntoView { })} - + "↗" @@ -253,7 +253,7 @@ pub fn LikeButton( 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() { + if let Ok(count) = likes.total_items() { new = new.set_likes(apb::Node::object(likes.clone().set_total_items(Some(count + 1)))); } } diff --git a/web/src/components/post.rs b/web/src/components/post.rs index 59e88c7..9470d3c 100644 --- a/web/src/components/post.rs +++ b/web/src/components/post.rs @@ -13,7 +13,7 @@ impl ReplyControls { pub fn reply(&self, oid: &str) { if let Some(obj) = CACHE.get(oid) { self.context.set(obj.context().id()); - self.reply_to.set(obj.id().map(|x| x.to_string())); + self.reply_to.set(obj.id().ok().map(|x| x.to_string())); } } @@ -123,7 +123,7 @@ pub fn PostBox(advanced: WriteSignal) -> impl IntoView { } if let Some(r) = reply.reply_to.get() { if let Some(au) = post_author(&r) { - if let Some(uid) = au.id() { + if let Ok(uid) = au.id() { to_vec.push(uid.to_string()); } } diff --git a/web/src/components/timeline.rs b/web/src/components/timeline.rs index 791558c..c760412 100644 --- a/web/src/components/timeline.rs +++ b/web/src/components/timeline.rs @@ -85,13 +85,13 @@ pub fn TimelineRepliesRecursive(tl: Timeline, root: String) -> impl IntoView { .into_iter() .filter_map(|x| CACHE.get(&x)) .filter(|x| match x.object_type() { - Some(apb::ObjectType::Activity(apb::ActivityType::Create)) => { + Ok(apb::ObjectType::Activity(apb::ActivityType::Create)) => { let Some(oid) = x.object().id() else { return false; }; let Some(object) = CACHE.get(&oid) else { return false; }; let Some(reply) = object.in_reply_to().id() else { return false; }; reply == root }, - Some(apb::ObjectType::Activity(_)) => x.object().id().map(|o| o == root).unwrap_or(false), + Ok(apb::ObjectType::Activity(_)) => x.object().id().map(|o| o == root).unwrap_or(false), _ => x.in_reply_to().id().map(|r| r == root).unwrap_or(false), }) .collect::>(); @@ -202,7 +202,7 @@ async fn process_activities(activities: Vec, auth: Auth) -> V if let Some(attributed_to) = object.attributed_to().id() { actors_seen.insert(attributed_to); } - if let Some(object_uri) = object.id() { + if let Ok(object_uri) = object.id() { CACHE.put(object_uri.to_string(), Arc::new(object.clone())); } else { tracing::warn!("embedded object without id: {object:?}"); @@ -222,7 +222,7 @@ async fn process_activities(activities: Vec, auth: Auth) -> V // save activity, removing embedded object let object_id = activity.object().id(); - if let Some(activity_id) = activity.id() { + if let Ok(activity_id) = activity.id() { out.push(activity_id.to_string()); CACHE.put( activity_id.to_string(), diff --git a/web/src/page/user.rs b/web/src/page/user.rs index 1228511..ffdce3f 100644 --- a/web/src/page/user.rs +++ b/web/src/page/user.rs @@ -82,7 +82,7 @@ pub fn UserPage(tl: Timeline) -> impl IntoView { let actor_type_tag = if actor_type == apb::ActorType::Person { None } else { Some(view! { "["{actor_type.as_ref().to_lowercase()}"]" } ) }; - let created = object.published(); + let created = object.published().ok(); let following = object.following_count().unwrap_or(0); let followers = object.followers_count().unwrap_or(0); let statuses = object.statuses_count().unwrap_or(0);