Merge tombstone muted notes #606

Changelog-Changed: Tombstone muted notes
This commit is contained in:
William Casarin
2025-01-04 14:08:33 -08:00
18 changed files with 134 additions and 125 deletions

View File

@@ -1,7 +1,7 @@
use tracing::{debug, error, info};
use crate::{
KeyStorageResponse, KeyStorageType, Muted, SingleUnkIdAction, UnknownIds, UserAccount,
KeyStorageResponse, KeyStorageType, MuteFun, Muted, SingleUnkIdAction, UnknownIds, UserAccount,
};
use enostr::{ClientMessage, FilledKeypair, Keypair, RelayPool};
use nostrdb::{Filter, Ndb, Note, NoteKey, Subscription, Transaction};
@@ -409,17 +409,19 @@ impl Accounts {
self.key_store.select_key(None);
}
pub fn mutefun(&self) -> Box<dyn Fn(&Note) -> bool> {
pub fn mutefun(&self) -> Box<MuteFun> {
if let Some(index) = self.currently_selected_account {
if let Some(account) = self.accounts.get(index) {
let pubkey = account.pubkey.bytes();
if let Some(account_data) = self.account_data.get(pubkey) {
let muted = Arc::clone(&account_data.muted.muted);
return Box::new(move |note: &Note| muted.is_muted(note));
return Box::new(move |note: &Note, thread: &[u8; 32]| {
muted.is_muted(note, thread)
});
}
}
}
Box::new(|_: &Note| false)
Box::new(|_: &Note, _: &[u8; 32]| None)
}
pub fn send_initial_filters(&mut self, pool: &mut RelayPool, relay_url: &str) {

View File

@@ -1,9 +1,10 @@
use nostrdb::Note;
use std::collections::BTreeSet;
use tracing::debug;
use tracing::{debug, trace};
pub type MuteFun = dyn Fn(&Note) -> bool;
// If the note is muted return a reason string, otherwise None
pub type MuteFun = dyn Fn(&Note, &[u8; 32]) -> Option<String>;
#[derive(Default)]
pub struct Muted {
@@ -32,14 +33,21 @@ impl std::fmt::Debug for Muted {
}
impl Muted {
pub fn is_muted(&self, note: &Note) -> bool {
// If the note is muted return a reason string, otherwise None
pub fn is_muted(&self, note: &Note, thread: &[u8; 32]) -> Option<String> {
trace!(
"{}: thread: {}",
hex::encode(note.id()),
hex::encode(thread)
);
if self.pubkeys.contains(note.pubkey()) {
debug!(
"{}: MUTED pubkey: {}",
hex::encode(note.id()),
hex::encode(note.pubkey())
);
return true;
return Some(format!("pubkey {}", hex::encode(note.pubkey())));
}
// FIXME - Implement hashtag muting here
@@ -51,11 +59,20 @@ impl Muted {
// for word in &self.words {
// if content.contains(&word.to_lowercase()) {
// debug!("{}: MUTED word: {}", hex::encode(note.id()), word);
// return true;
// return Some(format!("muted word {}", word));
// }
// }
// FIXME - Implement thread muting here
false
if self.threads.contains(thread) {
debug!(
"{}: MUTED thread: {}",
hex::encode(note.id()),
hex::encode(thread)
);
return Some(format!("thread {}", hex::encode(thread)));
}
// if we get here it's not muted
None
}
}