Skip to content

Commit

Permalink
Match NWC events by p tag instead event pk
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed May 13, 2024
1 parent 43599f4 commit af768be
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions mutiny-core/src/nostr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1547,9 +1547,25 @@ impl<S: MutinyStorage, P: PrimalApi, C: NostrClient> NostrManager<S, P, C> {
) -> anyhow::Result<Option<Event>> {
let nwc = {
let vec = self.nwc.read().unwrap();
vec.iter()
.find(|nwc| nwc.client_pubkey() == event.pubkey)
.cloned()
// Need to find the p tag, not the client pubkey because there can be duplicates
// of the same client pubkey but we guarantee that the P tag is unique.
let p_tag = event
.tags
.iter()
.find_map(|tag| {
if let Tag::PublicKey {
public_key,
uppercase: false,
..
} = tag
{
Some(*public_key)
} else {
None
}
})
.ok_or(anyhow::anyhow!("No P tag found"))?;
vec.iter().find(|nwc| nwc.server_pubkey() == p_tag).cloned()
};

self.storage.set_nwc_sync_time(event.created_at.as_u64())?;
Expand Down

0 comments on commit af768be

Please sign in to comment.