notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

muted.rs (1799B)


      1 use nostrdb::Note;
      2 use std::collections::BTreeSet;
      3 
      4 use tracing::debug;
      5 
      6 pub type MuteFun = dyn Fn(&Note) -> bool;
      7 
      8 #[derive(Default)]
      9 pub struct Muted {
     10     // TODO - implement private mutes
     11     pub pubkeys: BTreeSet<[u8; 32]>,
     12     pub hashtags: BTreeSet<String>,
     13     pub words: BTreeSet<String>,
     14     pub threads: BTreeSet<[u8; 32]>,
     15 }
     16 
     17 impl std::fmt::Debug for Muted {
     18     fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
     19         f.debug_struct("Muted")
     20             .field(
     21                 "pubkeys",
     22                 &self.pubkeys.iter().map(hex::encode).collect::<Vec<_>>(),
     23             )
     24             .field("hashtags", &self.hashtags)
     25             .field("words", &self.words)
     26             .field(
     27                 "threads",
     28                 &self.threads.iter().map(hex::encode).collect::<Vec<_>>(),
     29             )
     30             .finish()
     31     }
     32 }
     33 
     34 impl Muted {
     35     pub fn is_muted(&self, note: &Note) -> bool {
     36         if self.pubkeys.contains(note.pubkey()) {
     37             debug!(
     38                 "{}: MUTED pubkey: {}",
     39                 hex::encode(note.id()),
     40                 hex::encode(note.pubkey())
     41             );
     42             return true;
     43         }
     44         // FIXME - Implement hashtag muting here
     45 
     46         // TODO - let's not add this for now, we will likely need to
     47         // have an optimized data structure in nostrdb to properly
     48         // mute words. this mutes substrings which is not ideal.
     49         //
     50         // let content = note.content().to_lowercase();
     51         // for word in &self.words {
     52         //     if content.contains(&word.to_lowercase()) {
     53         //         debug!("{}: MUTED word: {}", hex::encode(note.id()), word);
     54         //         return true;
     55         //     }
     56         // }
     57 
     58         // FIXME - Implement thread muting here
     59         false
     60     }
     61 }