From af768be6096987811f083e5ce4fca058edfe7e9b Mon Sep 17 00:00:00 2001 From: benthecarman Date: Mon, 13 May 2024 13:09:48 -0500 Subject: [PATCH] Match NWC events by p tag instead event pk --- mutiny-core/src/nostr/mod.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/mutiny-core/src/nostr/mod.rs b/mutiny-core/src/nostr/mod.rs index 5e5c7b06d..b9748d11d 100644 --- a/mutiny-core/src/nostr/mod.rs +++ b/mutiny-core/src/nostr/mod.rs @@ -1547,9 +1547,25 @@ impl NostrManager { ) -> anyhow::Result> { 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())?;