refactor: nevernest get_display_name

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin
2025-04-17 08:36:22 -07:00
parent 8472a9b643
commit 81ef677bf2

View File

@@ -41,10 +41,17 @@ fn is_empty(s: &str) -> bool {
} }
pub fn get_display_name<'a>(record: Option<&ProfileRecord<'a>>) -> NostrName<'a> { pub fn get_display_name<'a>(record: Option<&ProfileRecord<'a>>) -> NostrName<'a> {
if let Some(record) = record { let Some(record) = record else {
if let Some(profile) = record.record().profile() { return NostrName::unknown();
};
let Some(profile) = record.record().profile() else {
return NostrName::unknown();
};
let display_name = profile.display_name().filter(|n| !is_empty(n)); let display_name = profile.display_name().filter(|n| !is_empty(n));
let username = profile.name().filter(|n| !is_empty(n)); let username = profile.name().filter(|n| !is_empty(n));
let nip05 = if let Some(raw_nip05) = profile.nip05() { let nip05 = if let Some(raw_nip05) = profile.nip05() {
if let Some(at_pos) = raw_nip05.find('@') { if let Some(at_pos) = raw_nip05.find('@') {
if raw_nip05.starts_with('_') { if raw_nip05.starts_with('_') {
@@ -64,12 +71,6 @@ pub fn get_display_name<'a>(record: Option<&ProfileRecord<'a>>) -> NostrName<'a>
display_name, display_name,
nip05, nip05,
} }
} else {
NostrName::unknown()
}
} else {
NostrName::unknown()
}
} }
pub struct SaveProfileChanges { pub struct SaveProfileChanges {