fix(content): handle case where notes are not loaded

This commit is contained in:
Fernando López Guevara
2025-06-09 10:51:17 -03:00
committed by William Casarin
parent 48f17f91b8
commit c6dbb0e856
9 changed files with 24 additions and 23 deletions

View File

@@ -5,6 +5,7 @@ pub use action::{MediaAction, NoteAction, ZapAction, ZapTargetAmount};
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection}; pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
use crate::JobPool; use crate::JobPool;
use crate::UnknownIds;
use crate::{notecache::NoteCache, zaps::Zaps, Images}; use crate::{notecache::NoteCache, zaps::Zaps, Images};
use enostr::{NoteId, RelayPool}; use enostr::{NoteId, RelayPool};
use nostrdb::{Ndb, Note, NoteKey, QueryResult, Transaction}; use nostrdb::{Ndb, Note, NoteKey, QueryResult, Transaction};
@@ -21,6 +22,7 @@ pub struct NoteContext<'d> {
pub zaps: &'d mut Zaps, pub zaps: &'d mut Zaps,
pub pool: &'d mut RelayPool, pub pool: &'d mut RelayPool,
pub job_pool: &'d mut JobPool, pub job_pool: &'d mut JobPool,
pub unknown_ids: &'d mut UnknownIds,
pub current_account_has_wallet: bool, pub current_account_has_wallet: bool,
} }

View File

@@ -201,7 +201,11 @@ impl UnknownIds {
return; return;
} }
self.ids.entry(UnknownId::Pubkey(*pubkey)).or_default(); let unknown_id = UnknownId::Pubkey(*pubkey);
if self.ids.contains_key(&unknown_id) {
return;
}
self.ids.entry(unknown_id).or_default();
self.mark_updated(); self.mark_updated();
} }
@@ -211,9 +215,11 @@ impl UnknownIds {
return; return;
} }
self.ids let unknown_id = UnknownId::Id(NoteId::new(*note_id));
.entry(UnknownId::Id(NoteId::new(*note_id))) if self.ids.contains_key(&unknown_id) {
.or_default(); return;
}
self.ids.entry(unknown_id).or_default();
self.mark_updated(); self.mark_updated();
} }
} }

View File

@@ -420,11 +420,11 @@ fn render_nav_body(
zaps: ctx.zaps, zaps: ctx.zaps,
pool: ctx.pool, pool: ctx.pool,
job_pool: ctx.job_pool, job_pool: ctx.job_pool,
unknown_ids: ctx.unknown_ids,
current_account_has_wallet: get_current_wallet(ctx.accounts, ctx.global_wallet).is_some(), current_account_has_wallet: get_current_wallet(ctx.accounts, ctx.global_wallet).is_some(),
}; };
match top { match top {
Route::Timeline(kind) => render_timeline_route( Route::Timeline(kind) => render_timeline_route(
ctx.unknown_ids,
&mut app.timeline_cache, &mut app.timeline_cache,
ctx.accounts, ctx.accounts,
kind, kind,
@@ -436,7 +436,6 @@ fn render_nav_body(
&mut app.jobs, &mut app.jobs,
), ),
Route::Thread(selection) => render_thread_route( Route::Thread(selection) => render_thread_route(
ctx.unknown_ids,
&mut app.threads, &mut app.threads,
ctx.accounts, ctx.accounts,
selection, selection,

View File

@@ -6,12 +6,11 @@ use crate::{
}; };
use enostr::Pubkey; use enostr::Pubkey;
use notedeck::{Accounts, MuteFun, NoteContext, UnknownIds}; use notedeck::{Accounts, MuteFun, NoteContext};
use notedeck_ui::{jobs::JobsCache, NoteOptions}; use notedeck_ui::{jobs::JobsCache, NoteOptions};
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn render_timeline_route( pub fn render_timeline_route(
unknown_ids: &mut UnknownIds,
timeline_cache: &mut TimelineCache, timeline_cache: &mut TimelineCache,
accounts: &mut Accounts, accounts: &mut Accounts,
kind: &TimelineKind, kind: &TimelineKind,
@@ -50,7 +49,6 @@ pub fn render_timeline_route(
pubkey, pubkey,
accounts, accounts,
timeline_cache, timeline_cache,
unknown_ids,
col, col,
ui, ui,
&accounts.mutefun(), &accounts.mutefun(),
@@ -79,7 +77,6 @@ pub fn render_timeline_route(
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn render_thread_route( pub fn render_thread_route(
unknown_ids: &mut UnknownIds,
threads: &mut Threads, threads: &mut Threads,
accounts: &mut Accounts, accounts: &mut Accounts,
selection: &ThreadSelection, selection: &ThreadSelection,
@@ -95,7 +92,6 @@ pub fn render_thread_route(
ui::ThreadView::new( ui::ThreadView::new(
threads, threads,
unknown_ids,
selection.selected_or_root(), selection.selected_or_root(),
note_options, note_options,
&accounts.mutefun(), &accounts.mutefun(),
@@ -113,7 +109,6 @@ pub fn render_profile_route(
pubkey: &Pubkey, pubkey: &Pubkey,
accounts: &Accounts, accounts: &Accounts,
timeline_cache: &mut TimelineCache, timeline_cache: &mut TimelineCache,
unknown_ids: &mut UnknownIds,
col: usize, col: usize,
ui: &mut egui::Ui, ui: &mut egui::Ui,
is_muted: &MuteFun, is_muted: &MuteFun,
@@ -127,7 +122,6 @@ pub fn render_profile_route(
col, col,
timeline_cache, timeline_cache,
note_options, note_options,
unknown_ids,
is_muted, is_muted,
note_context, note_context,
jobs, jobs,

View File

@@ -785,6 +785,7 @@ mod preview {
zaps: app.zaps, zaps: app.zaps,
pool: app.pool, pool: app.pool,
job_pool: app.job_pool, job_pool: app.job_pool,
unknown_ids: app.unknown_ids,
current_account_has_wallet: false, current_account_has_wallet: false,
}; };

View File

@@ -12,7 +12,7 @@ use crate::{
}; };
use notedeck::{ use notedeck::{
name::get_display_name, profile::get_profile_url, Accounts, MuteFun, NoteAction, NoteContext, name::get_display_name, profile::get_profile_url, Accounts, MuteFun, NoteAction, NoteContext,
NotedeckTextStyle, UnknownIds, NotedeckTextStyle,
}; };
use notedeck_ui::{ use notedeck_ui::{
jobs::JobsCache, jobs::JobsCache,
@@ -26,7 +26,6 @@ pub struct ProfileView<'a, 'd> {
col_id: usize, col_id: usize,
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
note_options: NoteOptions, note_options: NoteOptions,
unknown_ids: &'a mut UnknownIds,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
jobs: &'a mut JobsCache, jobs: &'a mut JobsCache,
@@ -45,7 +44,6 @@ impl<'a, 'd> ProfileView<'a, 'd> {
col_id: usize, col_id: usize,
timeline_cache: &'a mut TimelineCache, timeline_cache: &'a mut TimelineCache,
note_options: NoteOptions, note_options: NoteOptions,
unknown_ids: &'a mut UnknownIds,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
note_context: &'a mut NoteContext<'d>, note_context: &'a mut NoteContext<'d>,
jobs: &'a mut JobsCache, jobs: &'a mut JobsCache,
@@ -56,7 +54,6 @@ impl<'a, 'd> ProfileView<'a, 'd> {
col_id, col_id,
timeline_cache, timeline_cache,
note_options, note_options,
unknown_ids,
is_muted, is_muted,
note_context, note_context,
jobs, jobs,
@@ -103,7 +100,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
if let Err(e) = profile_timeline.poll_notes_into_view( if let Err(e) = profile_timeline.poll_notes_into_view(
self.note_context.ndb, self.note_context.ndb,
&txn, &txn,
self.unknown_ids, self.note_context.unknown_ids,
self.note_context.note_cache, self.note_context.note_cache,
reversed, reversed,
) { ) {

View File

@@ -3,7 +3,7 @@ use egui_virtual_list::VirtualList;
use enostr::KeypairUnowned; use enostr::KeypairUnowned;
use nostrdb::{Note, Transaction}; use nostrdb::{Note, Transaction};
use notedeck::note::root_note_id_from_selected_id; use notedeck::note::root_note_id_from_selected_id;
use notedeck::{MuteFun, NoteAction, NoteContext, UnknownIds}; use notedeck::{MuteFun, NoteAction, NoteContext};
use notedeck_ui::jobs::JobsCache; use notedeck_ui::jobs::JobsCache;
use notedeck_ui::note::NoteResponse; use notedeck_ui::note::NoteResponse;
use notedeck_ui::{NoteOptions, NoteView}; use notedeck_ui::{NoteOptions, NoteView};
@@ -12,7 +12,6 @@ use crate::timeline::thread::{NoteSeenFlags, ParentState, Threads};
pub struct ThreadView<'a, 'd> { pub struct ThreadView<'a, 'd> {
threads: &'a mut Threads, threads: &'a mut Threads,
unknown_ids: &'a mut UnknownIds,
selected_note_id: &'a [u8; 32], selected_note_id: &'a [u8; 32],
note_options: NoteOptions, note_options: NoteOptions,
col: usize, col: usize,
@@ -27,7 +26,6 @@ impl<'a, 'd> ThreadView<'a, 'd> {
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn new( pub fn new(
threads: &'a mut Threads, threads: &'a mut Threads,
unknown_ids: &'a mut UnknownIds,
selected_note_id: &'a [u8; 32], selected_note_id: &'a [u8; 32],
note_options: NoteOptions, note_options: NoteOptions,
is_muted: &'a MuteFun, is_muted: &'a MuteFun,
@@ -38,7 +36,6 @@ impl<'a, 'd> ThreadView<'a, 'd> {
let id_source = egui::Id::new("threadscroll_threadview"); let id_source = egui::Id::new("threadscroll_threadview");
ThreadView { ThreadView {
threads, threads,
unknown_ids,
selected_note_id, selected_note_id,
note_options, note_options,
id_source, id_source,
@@ -96,7 +93,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
self.note_context.note_cache, self.note_context.note_cache,
self.note_context.ndb, self.note_context.ndb,
txn, txn,
self.unknown_ids, self.note_context.unknown_ids,
self.col, self.col,
); );

View File

@@ -216,6 +216,7 @@ impl<'a> DaveUi<'a> {
zaps: ctx.zaps, zaps: ctx.zaps,
pool: ctx.pool, pool: ctx.pool,
job_pool: ctx.job_pool, job_pool: ctx.job_pool,
unknown_ids: ctx.unknown_ids,
current_account_has_wallet: false, current_account_has_wallet: false,
}; };

View File

@@ -89,6 +89,10 @@ pub fn render_note_preview(
)); ));
} }
} else { } else {
note_context
.unknown_ids
.add_note_id_if_missing(note_context.ndb, txn, id);
return NoteResponse::new(ui.colored_label(Color32::RED, "TODO: COULD NOT LOAD")); return NoteResponse::new(ui.colored_label(Color32::RED, "TODO: COULD NOT LOAD"));
/* /*
return ui return ui