Skip to content

Commit c6dbb0e

Browse files
fernandolguevarajb55
authored andcommitted
fix(content): handle case where notes are not loaded
1 parent 48f17f9 commit c6dbb0e

File tree

9 files changed

+24
-23
lines changed

9 files changed

+24
-23
lines changed

crates/notedeck/src/note/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ pub use action::{MediaAction, NoteAction, ZapAction, ZapTargetAmount};
55
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
66

77
use crate::JobPool;
8+
use crate::UnknownIds;
89
use crate::{notecache::NoteCache, zaps::Zaps, Images};
910
use enostr::{NoteId, RelayPool};
1011
use nostrdb::{Ndb, Note, NoteKey, QueryResult, Transaction};
@@ -21,6 +22,7 @@ pub struct NoteContext<'d> {
2122
pub zaps: &'d mut Zaps,
2223
pub pool: &'d mut RelayPool,
2324
pub job_pool: &'d mut JobPool,
25+
pub unknown_ids: &'d mut UnknownIds,
2426
pub current_account_has_wallet: bool,
2527
}
2628

crates/notedeck/src/unknowns.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,11 @@ impl UnknownIds {
201201
return;
202202
}
203203

204-
self.ids.entry(UnknownId::Pubkey(*pubkey)).or_default();
204+
let unknown_id = UnknownId::Pubkey(*pubkey);
205+
if self.ids.contains_key(&unknown_id) {
206+
return;
207+
}
208+
self.ids.entry(unknown_id).or_default();
205209
self.mark_updated();
206210
}
207211

@@ -211,9 +215,11 @@ impl UnknownIds {
211215
return;
212216
}
213217

214-
self.ids
215-
.entry(UnknownId::Id(NoteId::new(*note_id)))
216-
.or_default();
218+
let unknown_id = UnknownId::Id(NoteId::new(*note_id));
219+
if self.ids.contains_key(&unknown_id) {
220+
return;
221+
}
222+
self.ids.entry(unknown_id).or_default();
217223
self.mark_updated();
218224
}
219225
}

crates/notedeck_columns/src/nav.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -420,11 +420,11 @@ fn render_nav_body(
420420
zaps: ctx.zaps,
421421
pool: ctx.pool,
422422
job_pool: ctx.job_pool,
423+
unknown_ids: ctx.unknown_ids,
423424
current_account_has_wallet: get_current_wallet(ctx.accounts, ctx.global_wallet).is_some(),
424425
};
425426
match top {
426427
Route::Timeline(kind) => render_timeline_route(
427-
ctx.unknown_ids,
428428
&mut app.timeline_cache,
429429
ctx.accounts,
430430
kind,
@@ -436,7 +436,6 @@ fn render_nav_body(
436436
&mut app.jobs,
437437
),
438438
Route::Thread(selection) => render_thread_route(
439-
ctx.unknown_ids,
440439
&mut app.threads,
441440
ctx.accounts,
442441
selection,

crates/notedeck_columns/src/timeline/route.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@ use crate::{
66
};
77

88
use enostr::Pubkey;
9-
use notedeck::{Accounts, MuteFun, NoteContext, UnknownIds};
9+
use notedeck::{Accounts, MuteFun, NoteContext};
1010
use notedeck_ui::{jobs::JobsCache, NoteOptions};
1111

1212
#[allow(clippy::too_many_arguments)]
1313
pub fn render_timeline_route(
14-
unknown_ids: &mut UnknownIds,
1514
timeline_cache: &mut TimelineCache,
1615
accounts: &mut Accounts,
1716
kind: &TimelineKind,
@@ -50,7 +49,6 @@ pub fn render_timeline_route(
5049
pubkey,
5150
accounts,
5251
timeline_cache,
53-
unknown_ids,
5452
col,
5553
ui,
5654
&accounts.mutefun(),
@@ -79,7 +77,6 @@ pub fn render_timeline_route(
7977

8078
#[allow(clippy::too_many_arguments)]
8179
pub fn render_thread_route(
82-
unknown_ids: &mut UnknownIds,
8380
threads: &mut Threads,
8481
accounts: &mut Accounts,
8582
selection: &ThreadSelection,
@@ -95,7 +92,6 @@ pub fn render_thread_route(
9592

9693
ui::ThreadView::new(
9794
threads,
98-
unknown_ids,
9995
selection.selected_or_root(),
10096
note_options,
10197
&accounts.mutefun(),
@@ -113,7 +109,6 @@ pub fn render_profile_route(
113109
pubkey: &Pubkey,
114110
accounts: &Accounts,
115111
timeline_cache: &mut TimelineCache,
116-
unknown_ids: &mut UnknownIds,
117112
col: usize,
118113
ui: &mut egui::Ui,
119114
is_muted: &MuteFun,
@@ -127,7 +122,6 @@ pub fn render_profile_route(
127122
col,
128123
timeline_cache,
129124
note_options,
130-
unknown_ids,
131125
is_muted,
132126
note_context,
133127
jobs,

crates/notedeck_columns/src/ui/note/post.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -785,6 +785,7 @@ mod preview {
785785
zaps: app.zaps,
786786
pool: app.pool,
787787
job_pool: app.job_pool,
788+
unknown_ids: app.unknown_ids,
788789
current_account_has_wallet: false,
789790
};
790791

crates/notedeck_columns/src/ui/profile/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
};
1313
use notedeck::{
1414
name::get_display_name, profile::get_profile_url, Accounts, MuteFun, NoteAction, NoteContext,
15-
NotedeckTextStyle, UnknownIds,
15+
NotedeckTextStyle,
1616
};
1717
use notedeck_ui::{
1818
jobs::JobsCache,
@@ -26,7 +26,6 @@ pub struct ProfileView<'a, 'd> {
2626
col_id: usize,
2727
timeline_cache: &'a mut TimelineCache,
2828
note_options: NoteOptions,
29-
unknown_ids: &'a mut UnknownIds,
3029
is_muted: &'a MuteFun,
3130
note_context: &'a mut NoteContext<'d>,
3231
jobs: &'a mut JobsCache,
@@ -45,7 +44,6 @@ impl<'a, 'd> ProfileView<'a, 'd> {
4544
col_id: usize,
4645
timeline_cache: &'a mut TimelineCache,
4746
note_options: NoteOptions,
48-
unknown_ids: &'a mut UnknownIds,
4947
is_muted: &'a MuteFun,
5048
note_context: &'a mut NoteContext<'d>,
5149
jobs: &'a mut JobsCache,
@@ -56,7 +54,6 @@ impl<'a, 'd> ProfileView<'a, 'd> {
5654
col_id,
5755
timeline_cache,
5856
note_options,
59-
unknown_ids,
6057
is_muted,
6158
note_context,
6259
jobs,
@@ -103,7 +100,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
103100
if let Err(e) = profile_timeline.poll_notes_into_view(
104101
self.note_context.ndb,
105102
&txn,
106-
self.unknown_ids,
103+
self.note_context.unknown_ids,
107104
self.note_context.note_cache,
108105
reversed,
109106
) {

crates/notedeck_columns/src/ui/thread.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use egui_virtual_list::VirtualList;
33
use enostr::KeypairUnowned;
44
use nostrdb::{Note, Transaction};
55
use notedeck::note::root_note_id_from_selected_id;
6-
use notedeck::{MuteFun, NoteAction, NoteContext, UnknownIds};
6+
use notedeck::{MuteFun, NoteAction, NoteContext};
77
use notedeck_ui::jobs::JobsCache;
88
use notedeck_ui::note::NoteResponse;
99
use notedeck_ui::{NoteOptions, NoteView};
@@ -12,7 +12,6 @@ use crate::timeline::thread::{NoteSeenFlags, ParentState, Threads};
1212

1313
pub struct ThreadView<'a, 'd> {
1414
threads: &'a mut Threads,
15-
unknown_ids: &'a mut UnknownIds,
1615
selected_note_id: &'a [u8; 32],
1716
note_options: NoteOptions,
1817
col: usize,
@@ -27,7 +26,6 @@ impl<'a, 'd> ThreadView<'a, 'd> {
2726
#[allow(clippy::too_many_arguments)]
2827
pub fn new(
2928
threads: &'a mut Threads,
30-
unknown_ids: &'a mut UnknownIds,
3129
selected_note_id: &'a [u8; 32],
3230
note_options: NoteOptions,
3331
is_muted: &'a MuteFun,
@@ -38,7 +36,6 @@ impl<'a, 'd> ThreadView<'a, 'd> {
3836
let id_source = egui::Id::new("threadscroll_threadview");
3937
ThreadView {
4038
threads,
41-
unknown_ids,
4239
selected_note_id,
4340
note_options,
4441
id_source,
@@ -96,7 +93,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
9693
self.note_context.note_cache,
9794
self.note_context.ndb,
9895
txn,
99-
self.unknown_ids,
96+
self.note_context.unknown_ids,
10097
self.col,
10198
);
10299

crates/notedeck_dave/src/ui/dave.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl<'a> DaveUi<'a> {
216216
zaps: ctx.zaps,
217217
pool: ctx.pool,
218218
job_pool: ctx.job_pool,
219+
unknown_ids: ctx.unknown_ids,
219220
current_account_has_wallet: false,
220221
};
221222

crates/notedeck_ui/src/note/contents.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pub fn render_note_preview(
8989
));
9090
}
9191
} else {
92+
note_context
93+
.unknown_ids
94+
.add_note_id_if_missing(note_context.ndb, txn, id);
95+
9296
return NoteResponse::new(ui.colored_label(Color32::RED, "TODO: COULD NOT LOAD"));
9397
/*
9498
return ui

0 commit comments

Comments
 (0)