Mute rendering instead of ingress

Previous approach was to keep muted content from getting inserted.

Instead, this version alters it's display.  This makes toggling mutes
on and off externally much more stable (the display changes but we
don't have to rebuild content trees)

For now muted content is collapsed to a red "Muted" tombstone w/ a reason.
This commit is contained in:
Ken Sedgwick
2024-12-19 15:27:26 -08:00
parent 2d7de8fdc0
commit e193e00539
15 changed files with 93 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};
@@ -401,17 +401,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
}
}