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

@@ -7,8 +7,7 @@ use crate::{
};
use notedeck::{
filter, CachedNote, FilterError, FilterState, FilterStates, MuteFun, NoteCache, NoteRef,
UnknownIds,
filter, CachedNote, FilterError, FilterState, FilterStates, NoteCache, NoteRef, UnknownIds,
};
use std::fmt;
@@ -287,7 +286,6 @@ impl Timeline {
txn: &Transaction,
unknown_ids: &mut UnknownIds,
note_cache: &mut NoteCache,
is_muted: &MuteFun,
) -> Result<()> {
let timeline = timelines
.get_mut(timeline_idx)
@@ -312,9 +310,6 @@ impl Timeline {
error!("hit race condition in poll_notes_into_view: https://github.com/damus-io/nostrdb/issues/35 note {:?} was not added to timeline", key);
continue;
};
if is_muted(&note) {
continue;
}
UnknownIds::update_from_note(txn, ndb, unknown_ids, note_cache, &note);
@@ -412,12 +407,11 @@ pub fn setup_new_timeline(
pool: &mut RelayPool,
note_cache: &mut NoteCache,
since_optimize: bool,
is_muted: &MuteFun,
our_pk: Option<&Pubkey>,
) {
// if we're ready, setup local subs
if is_timeline_ready(ndb, pool, note_cache, timeline, is_muted, our_pk) {
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline, is_muted) {
if is_timeline_ready(ndb, pool, note_cache, timeline, our_pk) {
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline) {
error!("setup_new_timeline: {err}");
}
}
@@ -547,7 +541,6 @@ fn setup_initial_timeline(
timeline: &mut Timeline,
note_cache: &mut NoteCache,
filters: &[Filter],
is_muted: &MuteFun,
) -> Result<()> {
timeline.subscription = Some(ndb.subscribe(filters)?);
let txn = Transaction::new(ndb)?;
@@ -562,7 +555,7 @@ fn setup_initial_timeline(
.map(NoteRef::from_query_result)
.collect();
copy_notes_into_timeline(timeline, &txn, ndb, note_cache, notes, is_muted);
copy_notes_into_timeline(timeline, &txn, ndb, note_cache, notes);
Ok(())
}
@@ -573,7 +566,6 @@ pub fn copy_notes_into_timeline(
ndb: &Ndb,
note_cache: &mut NoteCache,
notes: Vec<NoteRef>,
is_muted: &MuteFun,
) {
let filters = {
let views = &timeline.views;
@@ -585,9 +577,6 @@ pub fn copy_notes_into_timeline(
for note_ref in notes {
for (view, filter) in filters.iter().enumerate() {
if let Ok(note) = ndb.get_note_by_key(txn, note_ref.key) {
if is_muted(&note) {
continue;
}
if filter(
note_cache.cached_note_or_insert_mut(note_ref.key, &note),
&note,
@@ -603,12 +592,11 @@ pub fn setup_initial_nostrdb_subs(
ndb: &Ndb,
note_cache: &mut NoteCache,
decks_cache: &mut DecksCache,
is_muted: &MuteFun,
) -> Result<()> {
for decks in decks_cache.get_all_decks_mut() {
for deck in decks.decks_mut() {
for timeline in deck.columns_mut().timelines_mut() {
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline, is_muted) {
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline) {
error!("setup_initial_nostrdb_subs: {err}");
}
}
@@ -622,7 +610,6 @@ fn setup_timeline_nostrdb_sub(
ndb: &Ndb,
note_cache: &mut NoteCache,
timeline: &mut Timeline,
is_muted: &MuteFun,
) -> Result<()> {
let filter_state = timeline
.filter
@@ -630,7 +617,7 @@ fn setup_timeline_nostrdb_sub(
.ok_or(Error::App(notedeck::Error::empty_contact_list()))?
.to_owned();
setup_initial_timeline(ndb, timeline, note_cache, &filter_state, is_muted)?;
setup_initial_timeline(ndb, timeline, note_cache, &filter_state)?;
Ok(())
}
@@ -644,7 +631,6 @@ pub fn is_timeline_ready(
pool: &mut RelayPool,
note_cache: &mut NoteCache,
timeline: &mut Timeline,
is_muted: &MuteFun,
our_pk: Option<&Pubkey>,
) -> bool {
// TODO: we should debounce the filter states a bit to make sure we have
@@ -705,8 +691,7 @@ pub fn is_timeline_ready(
// we just switched to the ready state, we should send initial
// queries and setup the local subscription
info!("Found contact list! Setting up local and remote contact list query");
setup_initial_timeline(ndb, timeline, note_cache, &filter, is_muted)
.expect("setup init");
setup_initial_timeline(ndb, timeline, note_cache, &filter).expect("setup init");
timeline
.filter
.set_relay_state(relay_id, FilterState::ready(filter.clone()));