Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.

Commit

Permalink
Get contact for npub
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Feb 6, 2024
1 parent 25bd173 commit d01bd30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions mutiny-core/src/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,20 @@ pub trait LabelStorage {
}
Ok(None)
}
/// Finds a contact that has the given npub
fn get_contact_for_npub(
&self,
npub: XOnlyPublicKey,
) -> Result<Option<(String, Contact)>, MutinyError> {
// todo this is not efficient, we should have a map of npub to contact
let contacts = self.get_contacts()?;
for (id, contact) in contacts {
if contact.npub == Some(npub) {
return Ok(Some((id, contact)));
}
}
Ok(None)
}
}

impl<S: MutinyStorage> LabelStorage for S {
Expand Down
13 changes: 13 additions & 0 deletions mutiny-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1312,6 +1312,19 @@ impl MutinyWallet {
Ok(self.inner.node_manager.edit_contact(id, contact)?)
}

pub async fn get_contact_for_npub(
&self,
npub: String,
) -> Result<Option<TagItem>, MutinyJsError> {
let npub = parse_npub(&npub)?;
let contact = self.inner.node_manager.get_contact_for_npub(npub)?;

match contact {
Some((id, c)) => Ok(Some((id, c).into())),
None => Ok(None),
}
}

pub fn get_tag_items(&self) -> Result<Vec<TagItem>, MutinyJsError> {
let mut tags: Vec<TagItem> = self
.inner
Expand Down

0 comments on commit d01bd30

Please sign in to comment.