Skip to content

nostr: add Filter::tag#1383

Merged
yukibtc merged 1 commit into
nostrdevkit:masterfrom
mvanhorn:feat/1359-filter-tag
Jun 28, 2026
Merged

nostr: add Filter::tag#1383
yukibtc merged 1 commit into
nostrdevkit:masterfrom
mvanhorn:feat/1359-filter-tag

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Description

Adds a Filter::tag(self, tag: Tag) -> Self convenience method (requested in #1359) so callers can add an already-constructed Tag to a Filter directly, instead of manually decomposing it into a SingleLetterTag and a value with the verbose custom_tag(tag.single_letter_tag().unwrap(), tag.content().unwrap()) dance.

The method:

  • derives the index key from tag.single_letter_tag(), since only single-letter tags can be indexed in a filter,
  • derives the value from the tag's serialized form (Tag::to_vec, the element after the tag name),
  • delegates to the existing custom_tag so generic-tag storage stays in one place,
  • and is a no-op returning self unchanged when the tag has no single-letter representation or no value.

This is additive and non-breaking.

Closes #1359

Notes to the reviewers

Following @TheAwiteb's guidance on the issue: not all tags fit in a filter, so the method handles the non-fitting case gracefully rather than unwrapping, and reads the value from the tag's serialized form rather than panicking. This gives callers (e.g. building a NIP-66 requirement filter) a clean builder method consistent with the existing event / pubkey / hashtag helpers.

Inline unit tests in crates/nostr/src/filter.rs cover the happy path (a single-letter t tag equals the matching custom_tag / hashtag call), a multi-element single-letter tag indexing the value right after the tag name, chaining .tag() twice to accumulate values, and the two no-op cases (no single-letter representation, and no value). cargo test -p nostr passes (245 + 8 tests).

Checklist

Add a Filter::tag(self, tag: Tag) convenience method that adds an
already-constructed Tag to a Filter without manually decomposing it into
a SingleLetterTag and value. Only single-letter tags can be indexed in a
filter, so the method is a no-op when the tag has no single-letter
representation or no value, deriving the value from the tag's serialized
form rather than unwrapping.

Closes nostrdevkit#1359

@TheAwiteb TheAwiteb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK

@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.64%. Comparing base (83fa932) to head (b4df19b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1383      +/-   ##
==========================================
+ Coverage   75.59%   75.64%   +0.04%     
==========================================
  Files         199      199              
  Lines       32743    32770      +27     
==========================================
+ Hits        24753    24789      +36     
+ Misses       7990     7981       -9     
Flag Coverage Δ
rust 75.64% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TheAwiteb

Copy link
Copy Markdown
Member

@mvanhorn Thank you for your contribution

@yukibtc yukibtc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b4df19b

@yukibtc yukibtc merged commit 28a2c8c into nostrdevkit:master Jun 28, 2026
46 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nostr: add Filter::tag

3 participants