1
0
Fork 0
forked from alemi/upub

fix(web): prefetch users when as object, fix links

This commit is contained in:
əlemi 2024-05-02 02:07:54 +02:00
parent 4f477fd072
commit b6cac77bf2
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 12 additions and 2 deletions

View file

@ -10,6 +10,11 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
let actor_id = activity.actor().id().unwrap_or_default(); let actor_id = activity.actor().id().unwrap_or_default();
let actor = CACHE.get_or(&actor_id, serde_json::Value::String(actor_id.clone()).into()); let actor = CACHE.get_or(&actor_id, serde_json::Value::String(actor_id.clone()).into());
let kind = activity.activity_type().unwrap_or(apb::ActivityType::Activity); let kind = activity.activity_type().unwrap_or(apb::ActivityType::Activity);
let href = match kind {
apb::ActivityType::Follow => Uri::web(FetchKind::User, &object_id),
// TODO for update check what's being updated
_ => Uri::web(FetchKind::Object, &object_id),
};
view! { view! {
<div> <div>
<span class="ml-1-r"> <span class="ml-1-r">
@ -17,7 +22,7 @@ pub fn ActivityLine(activity: crate::Object) -> impl IntoView {
</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().map(|x| x.to_rfc2822())} >
<a class="upub-title clean" title={object_id.clone()} href={Uri::web(FetchKind::Object, &object_id)} > <a class="upub-title clean" title={object_id} href={href} >
{kind.as_ref().to_string()} {kind.as_ref().to_string()}
</a> </a>
<PrivacyMarker addressed=activity.addressed() /> <PrivacyMarker addressed=activity.addressed() />

View file

@ -210,6 +210,7 @@ async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth) -> V
let mut out = Vec::new(); let mut out = Vec::new();
for activity in activities { for activity in activities {
let activity_type = activity.activity_type().unwrap_or(apb::ActivityType::Activity);
// save embedded object if present // save embedded object if present
if let Some(object) = activity.object().get() { if let Some(object) = activity.object().get() {
// also fetch actor attributed to // also fetch actor attributed to
@ -224,8 +225,12 @@ async fn process_activities(activities: Vec<serde_json::Value>, auth: Auth) -> V
} else { // try fetching it } else { // try fetching it
if let Some(object_id) = activity.object().id() { if let Some(object_id) = activity.object().id() {
if !gonna_fetch.contains(&object_id) { if !gonna_fetch.contains(&object_id) {
let fetch_kind = match activity_type {
apb::ActivityType::Follow => FetchKind::User,
_ => FetchKind::Object,
};
gonna_fetch.insert(object_id.clone()); gonna_fetch.insert(object_id.clone());
sub_tasks.push(Box::pin(fetch_and_update_with_user(FetchKind::Object, object_id, auth))); sub_tasks.push(Box::pin(fetch_and_update_with_user(fetch_kind, object_id, auth)));
} }
} }
} }