From a90dbd46b80c65984b1be935793dbcfbfe81372a Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Fri, 6 Dec 2024 11:10:44 +0100 Subject: [PATCH] nostr: don't set root tags when the root is null Closes https://github.com/rust-nostr/nostr/issues/655 Signed-off-by: Yuki Kishimoto --- CHANGELOG.md | 1 + crates/nostr/src/event/builder.rs | 38 +++++-------------------------- 2 files changed, 7 insertions(+), 32 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8d5e5b10..6b1ff8d9b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ * Bump `async-utility` to 0.3, `async-wsocket` to 0.11 and `atomic-destructor` to 0.3 ([Yuki Kishimoto]) * nostr: remove self-tagging when building events ([Yuki Kishimoto]) +* nostr: don't set root tags when the root is null ([Yuki Kishimoto]) * database: add manual trait implementations for `BTreeCappedSet` ([Yuki Kishimoto]) * lmdb: use `async-utility` to spawn blocking tasks ([Yuki Kishimoto]) * ndb: bump `nostr-ndb` to 0.4 ([Yuki Kishimoto]) diff --git a/crates/nostr/src/event/builder.rs b/crates/nostr/src/event/builder.rs index c2cdddb5e..5f1586fdf 100644 --- a/crates/nostr/src/event/builder.rs +++ b/crates/nostr/src/event/builder.rs @@ -474,8 +474,6 @@ impl EventBuilder { /// Comment /// - /// If no `root` is passed, the `comment_to` will be used for root `e` tag. - /// /// pub fn comment( content: S, @@ -486,8 +484,12 @@ impl EventBuilder { where S: Into, { - // The added tags will be at least 4 - let mut tags: Vec = Vec::with_capacity(4); + // Not use `comment_to` as root if no root is set. + // It's better to have no tags than wrong tags. + // Issue: https://github.com/rust-nostr/nostr/issues/655 + + // The added tags will be at least 3 + let mut tags: Vec = Vec::with_capacity(3); // Add `A`, `E` and `K` tag of **root** event if let Some(root) = root { @@ -533,34 +535,6 @@ impl EventBuilder { }) .cloned(), ); - } else { - match comment_to.coordinate() { - Some(coordinate) => { - tags.push(Tag::from_standardized_without_cell( - TagStandard::Coordinate { - coordinate, - relay_url: relay_url.clone(), - uppercase: true, - }, - )); - } - None => { - // ID and author - tags.push(Tag::from_standardized_without_cell(TagStandard::Event { - event_id: comment_to.id, - relay_url: relay_url.clone(), - marker: None, - public_key: Some(comment_to.pubkey), - uppercase: true, - })); - } - } - - // Kind - tags.push(Tag::from_standardized_without_cell(TagStandard::Kind { - kind: comment_to.kind, - uppercase: true, - })); } // Add `a` tag (if event has it)