From 1182cb589fef0bb41fe27efbea47fd3cf7ac87f9 Mon Sep 17 00:00:00 2001 From: alemi Date: Fri, 3 May 2024 01:00:37 +0200 Subject: [PATCH] feat(web): fallback avatar url --- web/src/components/user.rs | 6 +++--- web/src/lib.rs | 1 + web/src/page.rs | 6 +++--- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/web/src/components/user.rs b/web/src/components/user.rs index 3bb36139..12a2b9ad 100644 --- a/web/src/components/user.rs +++ b/web/src/components/user.rs @@ -1,5 +1,5 @@ use leptos::*; -use crate::prelude::*; +use crate::{prelude::*, DEFAULT_AVATAR_URL}; use apb::{Activity, ActivityMut, Actor, Base, Object, ObjectMut}; @@ -8,7 +8,7 @@ pub fn ActorStrip(object: crate::Object) -> impl IntoView { let actor_id = object.id().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); let domain = object.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string(); - let avatar = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default(); + let avatar = object.icon().get().map(|x| x.url().id().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); view! { {username}@{domain} @@ -25,7 +25,7 @@ pub fn ActorBanner(object: crate::Object) -> impl IntoView { serde_json::Value::Object(_) => { let uid = object.id().unwrap_or_default().to_string(); let uri = Uri::web(FetchKind::User, &uid); - let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default(); + let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); let display_name = object.name().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); let domain = object.id().unwrap_or_default().replace("https://", "").split('/').next().unwrap_or_default().to_string(); diff --git a/web/src/lib.rs b/web/src/lib.rs index 5f196563..afca2201 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -11,6 +11,7 @@ pub mod prelude; pub const URL_BASE: &str = "https://feditest.alemi.dev"; pub const URL_PREFIX: &str = "/web"; pub const URL_SENSITIVE: &str = "https://cdn.alemi.dev/social/nsfw.png"; +pub const DEFAULT_AVATAR_URL: &str = "https://cdn.alemi.dev/social/gradient.png"; pub const NAME: &str = "μ"; use std::sync::Arc; diff --git a/web/src/page.rs b/web/src/page.rs index 477b12bc..438b8289 100644 --- a/web/src/page.rs +++ b/web/src/page.rs @@ -4,7 +4,7 @@ use apb::{ActivityMut, Actor, Base, Object, ObjectMut}; use leptos::*; use leptos_router::*; -use crate::prelude::*; +use crate::{prelude::*, DEFAULT_AVATAR_URL}; #[component] pub fn AboutPage() -> impl IntoView { @@ -86,8 +86,8 @@ pub fn UserPage(tl: Timeline) -> impl IntoView { }, Some(Some(object)) => { let uid = object.id().unwrap_or_default().to_string(); - let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default(); - let background_url = object.image().get().map(|x| x.url().id().unwrap_or_default()).unwrap_or_default(); + let avatar_url = object.icon().get().map(|x| x.url().id().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); + let background_url = object.image().get().map(|x| x.url().id().unwrap_or(DEFAULT_AVATAR_URL.into())).unwrap_or(DEFAULT_AVATAR_URL.into()); let display_name = object.name().unwrap_or_default().to_string(); let username = object.preferred_username().unwrap_or_default().to_string(); let summary = object.summary().unwrap_or_default().to_string();