Skip to content

Commit

Permalink
nostr: add Event::hashtags method
Browse files Browse the repository at this point in the history
Ref #460 (comment)

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
  • Loading branch information
yukibtc committed Jun 7, 2024
1 parent 28c9aa3 commit 23d41e0
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
* nostr: add support to `nrelay` NIP-19 entity ([Yuki Kishimoto])
* nostr: add `Event::get_tag_content` method ([Yuki Kishimoto])
* nostr: add `Event::get_tags_content` method ([Yuki Kishimoto])
* nostr: add `Event::hashtags` method ([Yuki Kishimoto])
* pool: allow to set event limits per kind ([Yuki Kishimoto])
* pool: log warn when high latency ([Yuki Kishimoto])
* sdk: add support to automatic authentication to relays (NIP-42) ([Yuki Kishimoto])
Expand Down
7 changes: 7 additions & 0 deletions bindings/nostr-ffi/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ impl Event {
.collect()
}

/// Extract hashtags from tags (`t` tag)
///
/// **This method extract ONLY supported standard variants**
pub fn hashtags(&self) -> Vec<String> {
self.inner.hashtags().map(|t| t.to_owned()).collect()
}

#[inline]
#[uniffi::constructor]
pub fn from_json(json: &str) -> Result<Self> {
Expand Down
7 changes: 7 additions & 0 deletions bindings/nostr-js/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ impl JsEvent {
self.inner.verify().is_ok()
}

/// Extract hashtags from tags (`t` tag)
///
/// **This method extract ONLY supported standard variants**
pub fn hashtags(&self) -> Vec<String> {
self.inner.hashtags().map(|t| t.to_owned()).collect()
}

#[wasm_bindgen(js_name = fromJson)]
pub fn from_json(json: &str) -> Result<JsEvent> {
Ok(Self {
Expand Down
11 changes: 11 additions & 0 deletions crates/nostr/src/event/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,17 @@ impl Event {
})
}

/// Extract hashtags from tags (`t` tag)
///
/// **This method extract ONLY `TagStandard::Hashtag`**
#[inline]
pub fn hashtags(&self) -> impl Iterator<Item = &String> {
self.iter_tags().filter_map(|t| match t.as_standardized() {
Some(TagStandard::Hashtag(hashtag)) => Some(hashtag),
_ => None,
})
}

pub(crate) fn build_tags_indexes(&self) -> TagsIndexes {
let mut idx: TagsIndexes = TagsIndexes::new();
for (single_letter_tag, content) in self
Expand Down

0 comments on commit 23d41e0

Please sign in to comment.