1
0
Fork 0
forked from alemi/upub

fix(web): updated apb usage

This commit is contained in:
əlemi 2024-06-01 01:13:49 +02:00
parent 40e01fe83b
commit 1dac83f52c
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 17 additions and 17 deletions

View file

@ -24,7 +24,7 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
<ActorStrip object=actor />
</span>
<span style="float:right">
<code class="color moreinfo" title={activity.published().map(|x| x.to_rfc2822())} >
<code class="color moreinfo" title={activity.published().ok().map(|x| x.to_rfc2822())} >
<a class="upub-title clean" title={object_id} href={href} >
{kind.as_ref().to_string()}
</a>

View file

@ -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! { <div class="pb-1"></div> })
};
let post_inner = view! {
<Summary summary=object.summary().map(|x| x.to_string()) >
<Summary summary=object.summary().ok().map(|x| x.to_string()) >
<p inner_html={content}></p>
{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! {
<blockquote class="tl">{post_inner}</blockquote>
}.into_view(),
// lemmy with Page, peertube with Video
Some(apb::ObjectType::Document(t)) => view! {
Ok(apb::ObjectType::Document(t)) => view! {
<div class="border ml-1 mr-1 mt-1">
<b>{object.name().unwrap_or_default().to_string()}</b>
<hr />
@ -155,7 +155,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
</div>
}.into_view(),
// wordpress, ... ?
Some(apb::ObjectType::Article) => view! {
Ok(apb::ObjectType::Article) => view! {
<div>
<h3>{object.name().unwrap_or_default().to_string()}</h3>
<hr />
@ -163,12 +163,12 @@ pub fn Object(object: crate::Object) -> impl IntoView {
</div>
}.into_view(),
// everything else
Some(t) => view! {
Ok(t) => view! {
<h3>{t.as_ref().to_string()}</h3>
{post_inner}
}.into_view(),
// object without type?
None => view! { <code>missing object type</code> }.into_view(),
Err(_) => view! { <code>missing object type</code> }.into_view(),
};
view! {
<table class="align w-100 ml-s mr-s">
@ -180,7 +180,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
})}
<PrivacyMarker addressed=addressed />
<a class="clean hover ml-s" href={Uri::web(U::Object, object.id().unwrap_or_default())}>
<DateTime t=object.published() />
<DateTime t=object.published().ok() />
</a>
<sup><small><a class="clean ml-s" href={external_url} target="_blank">""</a></small></sup>
</td>
@ -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))));
}
}

View file

@ -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<bool>) -> 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());
}
}

View file

@ -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::<Vec<crate::Object>>();
@ -202,7 +202,7 @@ async fn process_activities(activities: Vec<serde_json::Value>, 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<serde_json::Value>, 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(),

View file

@ -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! { <sup class="ml-s"><small>"["{actor_type.as_ref().to_lowercase()}"]"</small></sup> } )
};
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);