Merge unknown profile improvements by kernel #955

kernelkind (1):
      allow body on unknown profile
This commit is contained in:
William Casarin
2025-07-14 14:07:17 -07:00
3 changed files with 28 additions and 29 deletions

View File

@@ -77,14 +77,14 @@ impl<'a, 'd> ProfileView<'a, 'd> {
let output = scroll_area.show(ui, |ui| { let output = scroll_area.show(ui, |ui| {
let mut action = None; let mut action = None;
let txn = Transaction::new(self.note_context.ndb).expect("txn"); let txn = Transaction::new(self.note_context.ndb).expect("txn");
if let Ok(profile) = self let profile = self
.note_context .note_context
.ndb .ndb
.get_profile_by_pubkey(&txn, self.pubkey.bytes()) .get_profile_by_pubkey(&txn, self.pubkey.bytes())
{ .ok();
if let Some(profile_view_action) = self.profile_body(ui, profile) {
action = Some(profile_view_action); if let Some(profile_view_action) = self.profile_body(ui, profile.as_ref()) {
} action = Some(profile_view_action);
} }
let profile_timeline = self let profile_timeline = self
.timeline_cache .timeline_cache
@@ -137,13 +137,15 @@ impl<'a, 'd> ProfileView<'a, 'd> {
fn profile_body( fn profile_body(
&mut self, &mut self,
ui: &mut egui::Ui, ui: &mut egui::Ui,
profile: ProfileRecord<'_>, profile: Option<&ProfileRecord<'_>>,
) -> Option<ProfileViewAction> { ) -> Option<ProfileViewAction> {
let mut action = None; let mut action = None;
ui.vertical(|ui| { ui.vertical(|ui| {
banner( banner(
ui, ui,
profile.record().profile().and_then(|p| p.banner()), profile
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.banner())),
120.0, 120.0,
); );
@@ -158,12 +160,9 @@ impl<'a, 'd> ProfileView<'a, 'd> {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.put( ui.put(
pfp_rect, pfp_rect,
&mut ProfilePic::new( &mut ProfilePic::new(self.note_context.img_cache, get_profile_url(profile))
self.note_context.img_cache, .size(size)
get_profile_url(Some(&profile)), .border(ProfilePic::border_stroke(ui)),
)
.size(size)
.border(ProfilePic::border_stroke(ui)),
); );
if ui.add(copy_key_widget(&pfp_rect)).clicked() { if ui.add(copy_key_widget(&pfp_rect)).clicked() {
@@ -223,30 +222,25 @@ impl<'a, 'd> ProfileView<'a, 'd> {
ui.add_space(18.0); ui.add_space(18.0);
ui.add(display_name_widget( ui.add(display_name_widget(&get_display_name(profile), false));
&get_display_name(Some(&profile)),
false,
));
ui.add_space(8.0); ui.add_space(8.0);
ui.add(about_section_widget(&profile)); ui.add(about_section_widget(profile));
ui.horizontal_wrapped(|ui| { ui.horizontal_wrapped(|ui| {
if let Some(website_url) = profile if let Some(website_url) = profile
.record() .as_ref()
.profile() .map(|p| p.record().profile())
.and_then(|p| p.website()) .and_then(|p| p.and_then(|p| p.website()).filter(|s| !s.is_empty()))
.filter(|s| !s.is_empty())
{ {
handle_link(ui, website_url); handle_link(ui, website_url);
} }
if let Some(lud16) = profile if let Some(lud16) = profile
.record() .as_ref()
.profile() .map(|p| p.record().profile())
.and_then(|p| p.lud16()) .and_then(|p| p.and_then(|p| p.lud16()).filter(|s| !s.is_empty()))
.filter(|s| !s.is_empty())
{ {
handle_lud16(ui, lud16); handle_lud16(ui, lud16);
} }

View File

@@ -68,12 +68,17 @@ pub fn display_name_widget<'a>(
} }
} }
pub fn about_section_widget<'a, 'b>(profile: &'b ProfileRecord<'a>) -> impl egui::Widget + 'b pub fn about_section_widget<'a, 'b>(
profile: Option<&'b ProfileRecord<'a>>,
) -> impl egui::Widget + 'b
where where
'b: 'a, 'b: 'a,
{ {
move |ui: &mut egui::Ui| { move |ui: &mut egui::Ui| {
if let Some(about) = profile.record().profile().and_then(|p| p.about()) { if let Some(about) = profile
.map(|p| p.record().profile())
.and_then(|p| p.and_then(|p| p.about()))
{
let resp = ui.label(about); let resp = ui.label(about);
ui.add_space(8.0); ui.add_space(8.0);
resp resp

View File

@@ -46,7 +46,7 @@ impl<'a, 'cache> ProfilePreview<'a, 'cache> {
&get_display_name(Some(self.profile)), &get_display_name(Some(self.profile)),
false, false,
)); ));
ui.add(about_section_widget(self.profile)); ui.add(about_section_widget(Some(self.profile)));
}); });
} }
} }