Compare commits

..

No commits in common. "677cab1871af07dc3c33fde51f338edfd593d6cb" and "a6015a32ede4b0ebbee1c39792e43c0a193f1b80" have entirely different histories.

3 changed files with 10 additions and 50 deletions

View file

@ -113,7 +113,7 @@ impl<T : super::Base> Node<T> {
Node::Empty => vec![],
Node::Link(uri) => vec![uri.href().to_string()],
Node::Object(x) => x.id().map_or(vec![], |x| vec![x.to_string()]),
Node::Array(x) => x.iter().filter_map(|x| Some(x.id().ok()?.to_string())).collect()
Node::Array(x) => x.iter().filter_map(|x| x.id().ok()).map(|x| x.to_string()).collect()
}
}

View file

@ -43,34 +43,3 @@ impl<T: Object> Addressed for T {
// to
// }
}
#[cfg(test)]
mod test {
use super::Addressed;
#[test]
#[cfg(feature = "unstructured")]
fn addressed_trait_finds_all_targets_on_json_objects() {
let obj = serde_json::json!({
"id": "http://localhost:8080/obj/1",
"type": "Note",
"content": "hello world!",
"published": "2024-06-04T17:09:20+00:00",
"to": ["http://localhost:8080/usr/root/followers"],
"bto": ["https://localhost:8080/usr/secret"],
"cc": [crate::target::PUBLIC],
"bcc": [],
});
let addressed = obj.addressed();
assert_eq!(
addressed,
vec![
"http://localhost:8080/usr/root/followers".to_string(),
"https://localhost:8080/usr/secret".to_string(),
crate::target::PUBLIC.to_string(),
]
);
}
}

View file

@ -15,16 +15,15 @@ pub fn ObjectPage(tl: Timeline) -> impl IntoView {
let object = create_local_resource(
move || params.get().get("id").cloned().unwrap_or_default(),
move |oid| async move {
let obj = match CACHE.get(&Uri::full(U::Object, &oid)) {
Some(x) => x.clone(),
let tl_url = format!("{}/page", Uri::api(U::Context, &oid, false));
if !tl.next.get().starts_with(&tl_url) {
tl.reset(tl_url);
}
match CACHE.get(&Uri::full(U::Object, &oid)) {
Some(x) => Some(x.clone()),
None => {
let obj = match Http::fetch::<serde_json::Value>(&Uri::api(U::Object, &oid, true), auth).await {
Ok(obj) => Arc::new(obj),
Err(e) => {
tracing::error!("failed loading object from backend: {e}");
return None;
},
};
let obj = Http::fetch::<serde_json::Value>(&Uri::api(U::Object, &oid, true), auth).await.ok()?;
let obj = Arc::new(obj);
if let Ok(author) = obj.attributed_to().id() {
if let Ok(user) = Http::fetch::<serde_json::Value>(
&Uri::api(U::Actor, author, true), auth
@ -33,17 +32,9 @@ pub fn ObjectPage(tl: Timeline) -> impl IntoView {
}
}
CACHE.put(Uri::full(U::Object, &oid), obj.clone());
obj
}
};
if let Ok(ctx) = obj.context().id() {
let tl_url = format!("{}/page", ctx);
if !tl.next.get().starts_with(&tl_url) {
tl.reset(tl_url);
Some(obj)
}
}
Some(obj)
}
);
view! {