feat(web): prefetch and inline quote posts

finally!!!
This commit is contained in:
əlemi 2024-12-28 19:07:48 +01:00
parent 44232ede58
commit 99abc2e71a
Signed by: alemi
GPG key ID: A4895B84D311642C
5 changed files with 36 additions and 6 deletions

2
Cargo.lock generated
View file

@ -4958,7 +4958,7 @@ dependencies = [
[[package]]
name = "upub-web"
version = "0.4.0"
version = "0.4.1"
dependencies = [
"apb",
"base64 0.22.1",

View file

@ -1,6 +1,6 @@
[package]
name = "upub-web"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
authors = [ "alemi <me@alemi.dev>" ]
description = "web frontend for upub"

View file

@ -136,6 +136,13 @@
div.sep-top {
border-top: 2px solid rgba(var(--accent-rgb), 0.45);
}
div.quote {
border: 2px dotted var(--background-dim);
margin-top: 1em;
margin-left: 1em;
margin-bottom: 1em;
padding: 1em;
}
hr.sticky {
position: sticky;
z-index: 100;

View file

@ -50,9 +50,19 @@ pub fn Object(object: crate::Object) -> impl IntoView {
}
});
let quote_badge = object.quote_url()
let quote_block = object.quote_url()
.id()
.ok()
.and_then(|x| {
Some(view! {
<div class="quote">
<Object object=crate::cache::OBJECTS.get(&x)? />
</div>
})
});
let quote_badge = object.quote_url()
.id()
.map(|x| {
let href = Uri::web(U::Object, &x);
view! {
@ -60,12 +70,13 @@ pub fn Object(object: crate::Object) -> impl IntoView {
<span class="border-button ml-s" >
<code class="color mr-s">">"</code>
<small class="mr-s">
RE
quote
</small>
</span>
</a>" "
}
});
})
.ok();
let tag_badges = object.tag()
.flat()
@ -143,7 +154,10 @@ pub fn Object(object: crate::Object) -> impl IntoView {
let post = match object.object_type() {
// mastodon, pleroma, misskey
Ok(apb::ObjectType::Note) => view! {
<article class="tl">{post_inner}</article>
<article class="tl">
{post_inner}
{quote_block}
</article>
}.into_view(),
// lemmy with Page, peertube with Video
Ok(apb::ObjectType::Document(t)) => view! {
@ -154,6 +168,7 @@ pub fn Object(object: crate::Object) -> impl IntoView {
<b>{object.name().unwrap_or_default().to_string()}</b>
</h4>
{post_inner}
{quote_block}
</div>
</article>
}.into_view(),
@ -163,12 +178,14 @@ pub fn Object(object: crate::Object) -> impl IntoView {
<h3>{object.name().unwrap_or_default().to_string()}</h3>
<hr />
{post_inner}
{quote_block}
</article>
}.into_view(),
// everything else
Ok(t) => view! {
<h3>{t.as_ref().to_string()}</h3>
{post_inner}
{quote_block}
}.into_view(),
// object without type?
Err(_) => view! { <code>missing object type</code> }.into_view(),

View file

@ -126,6 +126,12 @@ pub async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth)
if let Ok(attributed_to) = object.attributed_to().id() {
actors_seen.insert(attributed_to);
}
if let Ok(quote_id) = object.quote_url().id() {
if !gonna_fetch.contains(&quote_id) {
gonna_fetch.insert(quote_id.clone());
sub_tasks.push(Box::pin(fetch_and_update_with_user(U::Object, quote_id, auth)));
}
}
if let Ok(object_uri) = object.id() {
cache::OBJECTS.store(&object_uri, Arc::new(object.clone()));
} else {