From 6545e1ddee7d8a67bc7dabd4525939ce0f4dcad8 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 18 Nov 2024 17:28:55 -0800 Subject: [PATCH] thread: ensure thread unknowns are handled --- src/nav.rs | 1 + src/notes_holder.rs | 1 + src/timeline/route.rs | 17 +++++++++++++---- src/ui/thread.rs | 13 ++++++++++--- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/nav.rs b/src/nav.rs index ce71903..0421d92 100644 --- a/src/nav.rs +++ b/src/nav.rs @@ -75,6 +75,7 @@ pub fn render_nav(col: usize, app: &mut Damus, ui: &mut egui::Ui) -> Option, ) -> Self; + #[must_use = "process_action must be handled in the Ok(action) case"] fn poll_notes_into_view( &mut self, txn: &Transaction, diff --git a/src/timeline/route.rs b/src/timeline/route.rs index 1769f87..a922af6 100644 --- a/src/timeline/route.rs +++ b/src/timeline/route.rs @@ -16,6 +16,7 @@ use crate::{ }, profile::ProfileView, }, + unknowns::UnknownIds, }; use enostr::{NoteId, Pubkey, RelayPool}; @@ -47,6 +48,7 @@ pub fn render_timeline_route( pool: &mut RelayPool, drafts: &mut Drafts, img_cache: &mut ImageCache, + unknown_ids: &mut UnknownIds, note_cache: &mut NoteCache, threads: &mut NotesHolderStorage, accounts: &mut AccountManager, @@ -93,10 +95,17 @@ pub fn render_timeline_route( } TimelineRoute::Thread(id) => { - let timeline_response = - ui::ThreadView::new(threads, ndb, note_cache, img_cache, id.bytes(), textmode) - .id_source(egui::Id::new(("threadscroll", col))) - .ui(ui); + let timeline_response = ui::ThreadView::new( + threads, + ndb, + note_cache, + unknown_ids, + img_cache, + id.bytes(), + textmode, + ) + .id_source(egui::Id::new(("threadscroll", col))) + .ui(ui); if let Some(bar_action) = timeline_response.bar_action { let txn = Transaction::new(ndb).expect("txn"); let mut cur_column = columns.columns_mut(); diff --git a/src/ui/thread.rs b/src/ui/thread.rs index 689dd55..e43a2a5 100644 --- a/src/ui/thread.rs +++ b/src/ui/thread.rs @@ -5,6 +5,7 @@ use crate::{ notes_holder::{NotesHolder, NotesHolderStorage}, thread::Thread, ui::note::NoteOptions, + unknowns::UnknownIds, }; use nostrdb::{Ndb, NoteKey, Transaction}; use tracing::error; @@ -15,6 +16,7 @@ pub struct ThreadView<'a> { threads: &'a mut NotesHolderStorage, ndb: &'a Ndb, note_cache: &'a mut NoteCache, + unknown_ids: &'a mut UnknownIds, img_cache: &'a mut ImageCache, selected_note_id: &'a [u8; 32], textmode: bool, @@ -27,6 +29,7 @@ impl<'a> ThreadView<'a> { threads: &'a mut NotesHolderStorage, ndb: &'a Ndb, note_cache: &'a mut NoteCache, + unknown_ids: &'a mut UnknownIds, img_cache: &'a mut ImageCache, selected_note_id: &'a [u8; 32], textmode: bool, @@ -36,6 +39,7 @@ impl<'a> ThreadView<'a> { threads, ndb, note_cache, + unknown_ids, img_cache, selected_note_id, textmode, @@ -99,9 +103,12 @@ impl<'a> ThreadView<'a> { // TODO(jb55): skip poll if ThreadResult is fresh? // poll for new notes and insert them into our existing notes - if let Err(e) = thread.poll_notes_into_view(&txn, self.ndb) { - error!("Thread::poll_notes_into_view: {e}"); - } + match thread.poll_notes_into_view(&txn, self.ndb) { + Ok(action) => { + action.process_action(&txn, self.ndb, self.unknown_ids, self.note_cache) + } + Err(err) => error!("{err}"), + }; // This is threadview. We are not the universe view... let is_universe = false;