Skip to content

Commit

Permalink
nostr: don't set root tags when the root is null
Browse files Browse the repository at this point in the history
Closes #655

Signed-off-by: Yuki Kishimoto <[email protected]>
  • Loading branch information
yukibtc committed Dec 6, 2024
1 parent b4afe7d commit a90dbd4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
38 changes: 6 additions & 32 deletions crates/nostr/src/event/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,6 @@ impl EventBuilder {

/// Comment
///
/// If no `root` is passed, the `comment_to` will be used for root `e` tag.
///
/// <https://github.com/nostr-protocol/nips/blob/master/22.md>
pub fn comment<S>(
content: S,
Expand All @@ -486,8 +484,12 @@ impl EventBuilder {
where
S: Into<String>,
{
// The added tags will be at least 4
let mut tags: Vec<Tag> = 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<Tag> = Vec::with_capacity(3);

// Add `A`, `E` and `K` tag of **root** event
if let Some(root) = root {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a90dbd4

Please sign in to comment.