From 29e9901583021c6297d7bb96732a37f573fa8159 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 5 Jul 2024 17:17:26 +0200 Subject: [PATCH] feat(web): pre-populate webfinger cache when i put an actor in cache, put its pretty url in webfinger cache too --- web/src/actors/header.rs | 6 +++++- web/src/timeline/mod.rs | 13 ++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/web/src/actors/header.rs b/web/src/actors/header.rs index 05842c2..442eba8 100644 --- a/web/src/actors/header.rs +++ b/web/src/actors/header.rs @@ -19,7 +19,11 @@ pub fn ActorHeader() -> impl IntoView { .await .map_err(|e| e.to_string())?; let user = std::sync::Arc::new(user); - cache::OBJECTS.store(&Uri::full(U::Actor, &id), user.clone()); + let uid = Uri::full(U::Actor, &id); + cache::OBJECTS.store(&uid, user.clone()); + if let Some(url) = user.url().id().str() { + cache::WEBFINGER.store(&url, uid); + } Ok(user) }, } diff --git a/web/src/timeline/mod.rs b/web/src/timeline/mod.rs index 8581ec3..7172510 100644 --- a/web/src/timeline/mod.rs +++ b/web/src/timeline/mod.rs @@ -3,7 +3,7 @@ pub mod thread; use std::{collections::BTreeSet, pin::Pin, sync::Arc}; -use apb::{field::OptionalString, Activity, ActivityMut, Base, Object}; +use apb::{field::OptionalString, Activity, ActivityMut, Actor, Base, Object}; use leptos::*; use crate::prelude::*; @@ -169,9 +169,16 @@ async fn process_activities(activities: Vec, auth: Auth) -> V } async fn fetch_and_update(kind: U, id: String, auth: Auth) { - match Http::fetch(&Uri::api(kind, &id, false), auth).await { - Ok(data) => { cache::OBJECTS.store(&id, Arc::new(data)); }, + match Http::fetch::(&Uri::api(kind, &id, false), auth).await { Err(e) => console_warn(&format!("could not fetch '{id}': {e}")), + Ok(data) => { + if data.actor_type().is_ok() { + if let Some(url) = data.url().id().str() { + cache::WEBFINGER.store(&id, url); + } + } + cache::OBJECTS.store(&id, Arc::new(data)); + }, } }