commit a4c6cfd445511c747433914ad6df034cfbea94fd
parent 5c9237e0708c9154a7e854cf41deccf6bb73deb6
Author: William Casarin <jb55@jb55.com>
Date: Fri, 14 Nov 2025 17:46:26 -0800
refactor: move hashtag counting out of mutes
we want to use this in custom queries, so let's extract it
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
2 files changed, 22 insertions(+), 30 deletions(-)
diff --git a/crates/notedeck/src/muted.rs b/crates/notedeck/src/muted.rs
@@ -70,7 +70,7 @@ impl Muted {
// Filter notes with too many hashtags (early return on limit exceeded)
if self.max_hashtags_per_note > 0 {
- let hashtag_count = self.count_hashtags(note);
+ let hashtag_count = crate::note::count_hashtags(note);
if hashtag_count > self.max_hashtags_per_note {
return true;
}
@@ -104,35 +104,6 @@ impl Muted {
false
}
- /// Count the number of hashtags in a note by examining its tags
- fn count_hashtags(&self, note: &Note) -> usize {
- let mut count = 0;
-
- for tag in note.tags() {
- // Early continue if not enough elements
- if tag.count() < 2 {
- continue;
- }
-
- // Check if this is a hashtag tag (type "t")
- let tag_type = match tag.get_unchecked(0).variant().str() {
- Some(t) => t,
- None => continue,
- };
-
- if tag_type != "t" {
- continue;
- }
-
- // Verify the hashtag value exists
- if tag.get_unchecked(1).variant().str().is_some() {
- count += 1;
- }
- }
-
- count
- }
-
pub fn is_pk_muted(&self, pk: &[u8; 32]) -> bool {
self.pubkeys.contains(pk)
}
diff --git a/crates/notedeck/src/note/mod.rs b/crates/notedeck/src/note/mod.rs
@@ -218,3 +218,24 @@ pub fn event_tag<'a>(ev: &nostrdb::Note<'a>, name: &str) -> Option<&'a str> {
pub fn reaction_sent_id(sender_pk: &enostr::Pubkey, note_reacted_to: &[u8; 32]) -> egui::Id {
egui::Id::new(("sent-reaction-id", note_reacted_to, sender_pk))
}
+
+/// Count the number of hashtags in a note by examining its tags
+pub fn count_hashtags(note: &Note) -> usize {
+ let mut count = 0;
+
+ for tag in note.tags() {
+ // Early continue if not enough elements
+ if tag.count() < 2 {
+ continue;
+ }
+
+ // Check if this is a hashtag tag (type "t")
+ let Some("t") = tag.get_unchecked(0).variant().str() else {
+ continue;
+ };
+
+ count += 1;
+ }
+
+ count
+}