diff --git a/src/overlord/mod.rs b/src/overlord/mod.rs index c7fd4959..37d023ce 100644 --- a/src/overlord/mod.rs +++ b/src/overlord/mod.rs @@ -680,11 +680,43 @@ impl Overlord { } }; + // Add all the 'p' tags from the note we are replying to + for parent_p_tag in event.tags.iter() { + match parent_p_tag { + Tag::Pubkey { + pubkey: parent_p_tag_pubkey, + .. + } => { + if parent_p_tag_pubkey.0 == public_key.as_hex_string() { + // do not tag ourselves + continue; + } + + if tags + .iter() + .find(|existing_tag| { + matches!( + existing_tag, + Tag::Pubkey { pubkey: existing_pubkey, .. } if existing_pubkey.0 == parent_p_tag_pubkey.0 + ) + }) + .is_some() { + // we already have this `p` tag, do not add again + continue; + } + + // add (FIXME: include relay hint it not exists) + tags.push(parent_p_tag.to_owned()) + } + _ => {} + } + } + if let Some((root, _maybeurl)) = event.replies_to_root() { // Add an 'e' tag for the root tags.push(Tag::Event { id: root, - recommended_relay_url: DbRelay::recommended_relay_for_reply(reply_to).await?, + recommended_relay_url: DbRelay::recommended_relay_for_reply(root).await?, marker: Some("root".to_string()), }); @@ -705,30 +737,6 @@ impl Overlord { }); } - /* These are now done in the UI so the poster can refer to them - - // Add a 'p' tag for the author we are replying to - tags.push(Tag::Pubkey { - pubkey: event.pubkey, - recommended_relay_url: None, // FIXME - petname: None, - }); - - // Add all the 'p' tags from the note we are replying to - let parent_p_tags: Vec = event - .tags - .iter() - .filter(|t| match t { - Tag::Pubkey { pubkey, .. } => *pubkey != event.pubkey, - _ => false, - }) - .map(|t| t.to_owned()) - .collect(); - tags.extend(parent_p_tags); - - // FIXME deduplicate 'p' tags - */ - if GLOBALS.settings.read().await.set_client_tag { tags.push(Tag::Other { tag: "client".to_owned(), diff --git a/src/ui/feed.rs b/src/ui/feed.rs index b8608e4d..84211d4c 100644 --- a/src/ui/feed.rs +++ b/src/ui/feed.rs @@ -542,24 +542,18 @@ fn render_post_actual( if ui.add(ReplyButton {}).clicked() { app.replying_to = Some(event.id); - // Add a 'p' tag for the author we are replying to - app.draft_tags.push(Tag::Pubkey { - pubkey: event.pubkey.into(), - recommended_relay_url: None, // FIXME - petname: None, - }); - - // Add all the 'p' tags from the note we are replying to - let parent_p_tags: Vec = event - .tags - .iter() - .filter(|t| match t { - Tag::Pubkey { pubkey, .. } => *pubkey != event.pubkey.into(), - _ => false, - }) - .map(|t| t.to_owned()) - .collect(); - app.draft_tags.extend(parent_p_tags); + // Cleanup tags + app.draft_tags = vec![]; + // Add a 'p' tag for the author we are replying to (except if it is our own key) + if let Some(pubkey) = GLOBALS.signer.blocking_read().public_key() { + if pubkey != event.pubkey { + app.draft_tags.push(Tag::Pubkey { + pubkey: event.pubkey.into(), + recommended_relay_url: None, // FIXME + petname: None, + }); + } + } } ui.add_space(24.0);