From 5c8fba220c79f26a5a633eaf7d3f8700992362e4 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 22 Apr 2025 10:48:48 -0700 Subject: [PATCH] ui: add ProfilePic::from_profile_or_default This is yet another helper, I really need to clean this ui widget up in terms of its possible constructors... --- crates/notedeck_ui/src/profile/picture.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/crates/notedeck_ui/src/profile/picture.rs b/crates/notedeck_ui/src/profile/picture.rs index e2e10405..a5b9fa41 100644 --- a/crates/notedeck_ui/src/profile/picture.rs +++ b/crates/notedeck_ui/src/profile/picture.rs @@ -43,6 +43,19 @@ impl<'cache, 'url> ProfilePic<'cache, 'url> { .map(|url| ProfilePic::new(cache, url)) } + pub fn from_profile_or_default( + cache: &'cache mut Images, + profile: Option<&nostrdb::ProfileRecord<'url>>, + ) -> Self { + let url = profile + .map(|p| p.record()) + .and_then(|p| p.profile()) + .and_then(|p| p.picture()) + .unwrap_or(notedeck::profile::no_pfp_url()); + + ProfilePic::new(cache, url) + } + #[inline] pub fn default_size() -> i8 { 38