* chore: refactor account registry * wip: nip4e * chore: rename account to device * feat: nip44 encryption with master signer * update * refactor * feat: unwrap with device keys * chore: improve handler * chore: fix rustls * chore: refactor onboarding * chore: fix compose * chore: fix send message * chore: fix forgot to request device * fix send message * chore: fix deadlock * chore: small fixes * chore: improve * fix * refactor * refactor * refactor * fix * add fetch request * save keys * fix * update * update * update
66 lines
1.8 KiB
Rust
66 lines
1.8 KiB
Rust
use global::constants::IMAGE_SERVICE;
|
|
use gpui::SharedString;
|
|
use nostr_sdk::prelude::*;
|
|
use smallvec::SmallVec;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
pub struct NostrProfile {
|
|
pub public_key: PublicKey,
|
|
pub avatar: SharedString,
|
|
pub name: SharedString,
|
|
pub messaging_relays: Option<SmallVec<[RelayUrl; 3]>>,
|
|
}
|
|
|
|
impl NostrProfile {
|
|
pub fn new(public_key: PublicKey, metadata: Metadata) -> Self {
|
|
let name = Self::extract_name(&public_key, &metadata);
|
|
let avatar = Self::extract_avatar(&metadata);
|
|
|
|
Self {
|
|
public_key,
|
|
name,
|
|
avatar,
|
|
messaging_relays: None,
|
|
}
|
|
}
|
|
|
|
/// Set contact's relays
|
|
pub fn relays(mut self, relays: Option<SmallVec<[RelayUrl; 3]>>) -> Self {
|
|
self.messaging_relays = relays;
|
|
self
|
|
}
|
|
|
|
fn extract_avatar(metadata: &Metadata) -> SharedString {
|
|
metadata
|
|
.picture
|
|
.as_ref()
|
|
.filter(|picture| !picture.is_empty())
|
|
.map(|picture| {
|
|
format!(
|
|
"{}/?url={}&w=100&h=100&fit=cover&mask=circle&n=-1",
|
|
IMAGE_SERVICE, picture
|
|
)
|
|
.into()
|
|
})
|
|
.unwrap_or_else(|| "brand/avatar.jpg".into())
|
|
}
|
|
|
|
fn extract_name(public_key: &PublicKey, metadata: &Metadata) -> SharedString {
|
|
if let Some(display_name) = metadata.display_name.as_ref() {
|
|
if !display_name.is_empty() {
|
|
return display_name.into();
|
|
}
|
|
}
|
|
|
|
if let Some(name) = metadata.name.as_ref() {
|
|
if !name.is_empty() {
|
|
return name.into();
|
|
}
|
|
}
|
|
|
|
let pubkey = public_key.to_hex();
|
|
|
|
format!("{}:{}", &pubkey[0..4], &pubkey[pubkey.len() - 4..]).into()
|
|
}
|
|
}
|