forked from alemi/upub
fix(web): updated apb usage
This commit is contained in:
parent
40e01fe83b
commit
1dac83f52c
5 changed files with 17 additions and 17 deletions
|
@ -24,7 +24,7 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
|
||||||
<ActorStrip object=actor />
|
<ActorStrip object=actor />
|
||||||
</span>
|
</span>
|
||||||
<span style="float:right">
|
<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} >
|
<a class="upub-title clean" title={object_id} href={href} >
|
||||||
{kind.as_ref().to_string()}
|
{kind.as_ref().to_string()}
|
||||||
</a>
|
</a>
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub fn Attachment(
|
||||||
//
|
//
|
||||||
// those who correctly send Image type objects without a media type get shown as links here, this
|
// 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
|
// 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();
|
kind = "image".to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,7 +132,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
|
||||||
Some(view! { <div class="pb-1"></div> })
|
Some(view! { <div class="pb-1"></div> })
|
||||||
};
|
};
|
||||||
let post_inner = view! {
|
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>
|
<p inner_html={content}></p>
|
||||||
{attachments_padding}
|
{attachments_padding}
|
||||||
{attachments}
|
{attachments}
|
||||||
|
@ -140,11 +140,11 @@ pub fn Object(object: crate::Object) -> impl IntoView {
|
||||||
};
|
};
|
||||||
let post = match object.object_type() {
|
let post = match object.object_type() {
|
||||||
// mastodon, pleroma, misskey
|
// mastodon, pleroma, misskey
|
||||||
Some(apb::ObjectType::Note) => view! {
|
Ok(apb::ObjectType::Note) => view! {
|
||||||
<blockquote class="tl">{post_inner}</blockquote>
|
<blockquote class="tl">{post_inner}</blockquote>
|
||||||
}.into_view(),
|
}.into_view(),
|
||||||
// lemmy with Page, peertube with Video
|
// 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">
|
<div class="border ml-1 mr-1 mt-1">
|
||||||
<b>{object.name().unwrap_or_default().to_string()}</b>
|
<b>{object.name().unwrap_or_default().to_string()}</b>
|
||||||
<hr />
|
<hr />
|
||||||
|
@ -155,7 +155,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
|
||||||
</div>
|
</div>
|
||||||
}.into_view(),
|
}.into_view(),
|
||||||
// wordpress, ... ?
|
// wordpress, ... ?
|
||||||
Some(apb::ObjectType::Article) => view! {
|
Ok(apb::ObjectType::Article) => view! {
|
||||||
<div>
|
<div>
|
||||||
<h3>{object.name().unwrap_or_default().to_string()}</h3>
|
<h3>{object.name().unwrap_or_default().to_string()}</h3>
|
||||||
<hr />
|
<hr />
|
||||||
|
@ -163,12 +163,12 @@ pub fn Object(object: crate::Object) -> impl IntoView {
|
||||||
</div>
|
</div>
|
||||||
}.into_view(),
|
}.into_view(),
|
||||||
// everything else
|
// everything else
|
||||||
Some(t) => view! {
|
Ok(t) => view! {
|
||||||
<h3>{t.as_ref().to_string()}</h3>
|
<h3>{t.as_ref().to_string()}</h3>
|
||||||
{post_inner}
|
{post_inner}
|
||||||
}.into_view(),
|
}.into_view(),
|
||||||
// object without type?
|
// object without type?
|
||||||
None => view! { <code>missing object type</code> }.into_view(),
|
Err(_) => view! { <code>missing object type</code> }.into_view(),
|
||||||
};
|
};
|
||||||
view! {
|
view! {
|
||||||
<table class="align w-100 ml-s mr-s">
|
<table class="align w-100 ml-s mr-s">
|
||||||
|
@ -180,7 +180,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
|
||||||
})}
|
})}
|
||||||
<PrivacyMarker addressed=addressed />
|
<PrivacyMarker addressed=addressed />
|
||||||
<a class="clean hover ml-s" href={Uri::web(U::Object, object.id().unwrap_or_default())}>
|
<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>
|
</a>
|
||||||
<sup><small><a class="clean ml-s" href={external_url} target="_blank">"↗"</a></small></sup>
|
<sup><small><a class="clean ml-s" href={external_url} target="_blank">"↗"</a></small></sup>
|
||||||
</td>
|
</td>
|
||||||
|
@ -253,7 +253,7 @@ pub fn LikeButton(
|
||||||
if let Some(cached) = CACHE.get(&target) {
|
if let Some(cached) = CACHE.get(&target) {
|
||||||
let mut new = (*cached).clone().set_liked_by_me(Some(true));
|
let mut new = (*cached).clone().set_liked_by_me(Some(true));
|
||||||
if let Some(likes) = new.likes().get() {
|
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))));
|
new = new.set_likes(apb::Node::object(likes.clone().set_total_items(Some(count + 1))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ impl ReplyControls {
|
||||||
pub fn reply(&self, oid: &str) {
|
pub fn reply(&self, oid: &str) {
|
||||||
if let Some(obj) = CACHE.get(oid) {
|
if let Some(obj) = CACHE.get(oid) {
|
||||||
self.context.set(obj.context().id());
|
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(r) = reply.reply_to.get() {
|
||||||
if let Some(au) = post_author(&r) {
|
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());
|
to_vec.push(uid.to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,13 +85,13 @@ pub fn TimelineRepliesRecursive(tl: Timeline, root: String) -> impl IntoView {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|x| CACHE.get(&x))
|
.filter_map(|x| CACHE.get(&x))
|
||||||
.filter(|x| match x.object_type() {
|
.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(oid) = x.object().id() else { return false; };
|
||||||
let Some(object) = CACHE.get(&oid) else { return false; };
|
let Some(object) = CACHE.get(&oid) else { return false; };
|
||||||
let Some(reply) = object.in_reply_to().id() else { return false; };
|
let Some(reply) = object.in_reply_to().id() else { return false; };
|
||||||
reply == root
|
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),
|
_ => x.in_reply_to().id().map(|r| r == root).unwrap_or(false),
|
||||||
})
|
})
|
||||||
.collect::<Vec<crate::Object>>();
|
.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() {
|
if let Some(attributed_to) = object.attributed_to().id() {
|
||||||
actors_seen.insert(attributed_to);
|
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()));
|
CACHE.put(object_uri.to_string(), Arc::new(object.clone()));
|
||||||
} else {
|
} else {
|
||||||
tracing::warn!("embedded object without id: {object:?}");
|
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
|
// save activity, removing embedded object
|
||||||
let object_id = activity.object().id();
|
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());
|
out.push(activity_id.to_string());
|
||||||
CACHE.put(
|
CACHE.put(
|
||||||
activity_id.to_string(),
|
activity_id.to_string(),
|
||||||
|
|
|
@ -82,7 +82,7 @@ pub fn UserPage(tl: Timeline) -> impl IntoView {
|
||||||
let actor_type_tag = if actor_type == apb::ActorType::Person { None } else {
|
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> } )
|
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 following = object.following_count().unwrap_or(0);
|
||||||
let followers = object.followers_count().unwrap_or(0);
|
let followers = object.followers_count().unwrap_or(0);
|
||||||
let statuses = object.statuses_count().unwrap_or(0);
|
let statuses = object.statuses_count().unwrap_or(0);
|
||||||
|
|
Loading…
Reference in a new issue