Skip to content

Commit 7d6ee98

Browse files
committed
WIP: integrate subman into Notedeck and AppContext
1 parent 026a3af commit 7d6ee98

File tree

7 files changed

+44
-37
lines changed

7 files changed

+44
-37
lines changed

crates/notedeck/src/app.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::persist::{AppSizeHandler, ZoomHandler};
22
use crate::{
33
Accounts, AppContext, Args, DataPath, DataPathType, Directory, FileKeyStorage, ImageCache,
4-
KeyStorageType, NoteCache, RelayDebugView, ThemeHandler, UnknownIds,
4+
KeyStorageType, NoteCache, RelayDebugView, SubMan, ThemeHandler, UnknownIds,
55
};
66
use egui::ThemePreference;
77
use enostr::RelayPool;
@@ -21,7 +21,6 @@ pub struct Notedeck {
2121
ndb: Ndb,
2222
img_cache: ImageCache,
2323
unknown_ids: UnknownIds,
24-
pool: RelayPool,
2524
note_cache: NoteCache,
2625
accounts: Accounts,
2726
path: DataPath,
@@ -31,6 +30,7 @@ pub struct Notedeck {
3130
zoom: ZoomHandler,
3231
app_size: AppSizeHandler,
3332
unrecognized_args: BTreeSet<String>,
33+
subman: SubMan,
3434
}
3535

3636
fn margin_top(narrow: bool) -> f32 {
@@ -71,7 +71,7 @@ impl eframe::App for Notedeck {
7171
puffin::GlobalProfiler::lock().new_frame();
7272

7373
// handle account updates
74-
self.accounts.update(&mut self.ndb, &mut self.pool, ctx);
74+
self.accounts.update(&mut self.ndb, self.subman.pool(), ctx);
7575

7676
main_panel(&ctx.style(), crate::ui::is_narrow(ctx)).show(ctx, |ui| {
7777
// render app
@@ -85,11 +85,11 @@ impl eframe::App for Notedeck {
8585
self.app_size.try_save_app_size(ctx);
8686

8787
if self.args.relay_debug {
88-
if self.pool.debug.is_none() {
89-
self.pool.use_debug();
88+
if self.subman.pool().debug.is_none() {
89+
self.subman.pool().use_debug();
9090
}
9191

92-
if let Some(debug) = &mut self.pool.debug {
92+
if let Some(debug) = &mut self.subman.pool().debug {
9393
RelayDebugView::window(ctx, debug);
9494
}
9595
}
@@ -199,11 +199,12 @@ impl Notedeck {
199199
error!("error migrating image cache: {e}");
200200
}
201201

202+
let subman = SubMan::new(ndb.clone(), pool);
203+
202204
Self {
203205
ndb,
204206
img_cache,
205207
unknown_ids,
206-
pool,
207208
note_cache,
208209
accounts,
209210
path: path.clone(),
@@ -213,6 +214,7 @@ impl Notedeck {
213214
zoom,
214215
app_size,
215216
unrecognized_args,
217+
subman,
216218
}
217219
}
218220

@@ -226,12 +228,12 @@ impl Notedeck {
226228
ndb: &mut self.ndb,
227229
img_cache: &mut self.img_cache,
228230
unknown_ids: &mut self.unknown_ids,
229-
pool: &mut self.pool,
230231
note_cache: &mut self.note_cache,
231232
accounts: &mut self.accounts,
232233
path: &self.path,
233234
args: &self.args,
234235
theme: &mut self.theme,
236+
subman: &mut self.subman,
235237
}
236238
}
237239

crates/notedeck/src/context.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use crate::{Accounts, Args, DataPath, ImageCache, NoteCache, ThemeHandler, UnknownIds};
1+
use crate::{Accounts, Args, DataPath, ImageCache, NoteCache, SubMan, ThemeHandler, UnknownIds};
22

3-
use enostr::RelayPool;
43
use nostrdb::Ndb;
54

65
// TODO: make this interface more sandboxed
@@ -9,10 +8,10 @@ pub struct AppContext<'a> {
98
pub ndb: &'a mut Ndb,
109
pub img_cache: &'a mut ImageCache,
1110
pub unknown_ids: &'a mut UnknownIds,
12-
pub pool: &'a mut RelayPool,
1311
pub note_cache: &'a mut NoteCache,
1412
pub accounts: &'a mut Accounts,
1513
pub path: &'a DataPath,
1614
pub args: &'a Args,
1715
pub theme: &'a mut ThemeHandler,
16+
pub subman: &'a mut SubMan,
1817
}

crates/notedeck/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub use storage::{
4747
DataPath, DataPathType, Directory, FileKeyStorage, KeyStorageResponse, KeyStorageType,
4848
};
4949
pub use style::NotedeckTextStyle;
50+
pub use subman::SubMan;
5051
pub use theme::ColorTheme;
5152
pub use time::time_ago_since;
5253
pub use timecache::TimeCached;

crates/notedeck_columns/src/app.rs

+21-16
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ fn try_process_event(
9393
ctx2.request_repaint();
9494
};
9595

96-
app_ctx.pool.keepalive_ping(wakeup);
96+
app_ctx.subman.pool().keepalive_ping(wakeup);
9797

9898
// NOTE: we don't use the while let loop due to borrow issues
9999
#[allow(clippy::while_let_loop)]
100100
loop {
101-
let ev = if let Some(ev) = app_ctx.pool.try_recv() {
101+
let ev = if let Some(ev) = app_ctx.subman.pool().try_recv() {
102102
ev.into_owned()
103103
} else {
104104
break;
@@ -108,14 +108,14 @@ fn try_process_event(
108108
RelayEvent::Opened => {
109109
app_ctx
110110
.accounts
111-
.send_initial_filters(app_ctx.pool, &ev.relay);
111+
.send_initial_filters(app_ctx.subman.pool(), &ev.relay);
112112

113113
timeline::send_initial_timeline_filters(
114114
app_ctx.ndb,
115115
damus.since_optimize,
116116
&mut damus.timeline_cache,
117117
&mut damus.subscriptions,
118-
app_ctx.pool,
118+
app_ctx.subman.pool(),
119119
&ev.relay,
120120
);
121121
}
@@ -130,8 +130,12 @@ fn try_process_event(
130130
}
131131

132132
for (_kind, timeline) in damus.timeline_cache.timelines.iter_mut() {
133-
let is_ready =
134-
timeline::is_timeline_ready(app_ctx.ndb, app_ctx.pool, app_ctx.note_cache, timeline);
133+
let is_ready = timeline::is_timeline_ready(
134+
app_ctx.ndb,
135+
app_ctx.subman.pool(),
136+
app_ctx.note_cache,
137+
timeline,
138+
);
135139

136140
if is_ready {
137141
let txn = Transaction::new(app_ctx.ndb).expect("txn");
@@ -153,7 +157,7 @@ fn try_process_event(
153157
}
154158

155159
if app_ctx.unknown_ids.ready_to_send() {
156-
unknown_id_send(app_ctx.unknown_ids, app_ctx.pool);
160+
unknown_id_send(app_ctx.unknown_ids, app_ctx.subman.pool());
157161
}
158162

159163
Ok(())
@@ -229,14 +233,14 @@ fn handle_eose(
229233
);
230234
// this is possible if this is the first time
231235
if ctx.unknown_ids.ready_to_send() {
232-
unknown_id_send(ctx.unknown_ids, ctx.pool);
236+
unknown_id_send(ctx.unknown_ids, ctx.subman.pool());
233237
}
234238
}
235239

236240
// oneshot subs just close when they're done
237241
SubKind::OneShot => {
238242
let msg = ClientMessage::close(subid.to_string());
239-
ctx.pool.send_to(&msg, relay_url);
243+
ctx.subman.pool().send_to(&msg, relay_url);
240244
}
241245

242246
SubKind::FetchingContactList(timeline_uid) => {
@@ -287,12 +291,13 @@ fn handle_eose(
287291
fn process_message(damus: &mut Damus, ctx: &mut AppContext<'_>, relay: &str, msg: &RelayMessage) {
288292
match msg {
289293
RelayMessage::Event(_subid, ev) => {
290-
let relay = if let Some(relay) = ctx.pool.relays.iter().find(|r| r.url() == relay) {
291-
relay
292-
} else {
293-
error!("couldn't find relay {} for note processing!?", relay);
294-
return;
295-
};
294+
let relay =
295+
if let Some(relay) = ctx.subman.pool().relays.iter().find(|r| r.url() == relay) {
296+
relay
297+
} else {
298+
error!("couldn't find relay {} for note processing!?", relay);
299+
return;
300+
};
296301

297302
match relay {
298303
PoolRelay::Websocket(_) => {
@@ -387,7 +392,7 @@ impl Damus {
387392
&txn,
388393
ctx.ndb,
389394
ctx.note_cache,
390-
ctx.pool,
395+
ctx.subman.pool(),
391396
&timeline_kind,
392397
) {
393398
add_result.process(

crates/notedeck_columns/src/decks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ pub fn demo_decks(
323323
&txn,
324324
ctx.ndb,
325325
ctx.note_cache,
326-
ctx.pool,
326+
ctx.subman.pool(),
327327
&kind,
328328
) {
329329
results.process(

crates/notedeck_columns/src/nav.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl SwitchingAction {
7272
let kinds_to_pop =
7373
get_active_columns_mut(ctx.accounts, decks_cache).delete_column(index);
7474
for kind in &kinds_to_pop {
75-
if let Err(err) = timeline_cache.pop(kind, ctx.ndb, ctx.pool) {
75+
if let Err(err) = timeline_cache.pop(kind, ctx.ndb, ctx.subman.pool()) {
7676
error!("error popping timeline: {err}");
7777
}
7878
}
@@ -144,7 +144,7 @@ impl RenderNavResponse {
144144
let kinds_to_pop = app.columns_mut(ctx.accounts).delete_column(col);
145145

146146
for kind in &kinds_to_pop {
147-
if let Err(err) = app.timeline_cache.pop(kind, ctx.ndb, ctx.pool) {
147+
if let Err(err) = app.timeline_cache.pop(kind, ctx.ndb, ctx.subman.pool()) {
148148
error!("error popping timeline: {err}");
149149
}
150150
}
@@ -154,7 +154,7 @@ impl RenderNavResponse {
154154

155155
RenderNavAction::PostAction(post_action) => {
156156
let txn = Transaction::new(ctx.ndb).expect("txn");
157-
let _ = post_action.execute(ctx.ndb, &txn, ctx.pool, &mut app.drafts);
157+
let _ = post_action.execute(ctx.ndb, &txn, ctx.subman.pool(), &mut app.drafts);
158158
get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
159159
.column_mut(col)
160160
.router_mut()
@@ -170,7 +170,7 @@ impl RenderNavResponse {
170170
col,
171171
&mut app.timeline_cache,
172172
ctx.note_cache,
173-
ctx.pool,
173+
ctx.subman.pool(),
174174
&txn,
175175
ctx.unknown_ids,
176176
);
@@ -187,7 +187,7 @@ impl RenderNavResponse {
187187
profile_action.process(
188188
&mut app.view_state.pubkey_to_profile_state,
189189
ctx.ndb,
190-
ctx.pool,
190+
ctx.subman.pool(),
191191
get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
192192
.column_mut(col)
193193
.router_mut(),
@@ -206,7 +206,7 @@ impl RenderNavResponse {
206206
.pop();
207207

208208
if let Some(Route::Timeline(kind)) = &r {
209-
if let Err(err) = app.timeline_cache.pop(kind, ctx.ndb, ctx.pool) {
209+
if let Err(err) = app.timeline_cache.pop(kind, ctx.ndb, ctx.subman.pool()) {
210210
error!("popping timeline had an error: {err} for {:?}", kind);
211211
}
212212
};
@@ -275,7 +275,7 @@ fn render_nav_body(
275275
.map(|f| RenderNavAction::SwitchingAction(SwitchingAction::Accounts(f)))
276276
}
277277
Route::Relays => {
278-
let manager = RelayPoolManager::new(ctx.pool);
278+
let manager = RelayPoolManager::new(ctx.subman.pool());
279279
RelayView::new(ctx.accounts, manager, &mut app.view_state.id_string_map).ui(ui);
280280
None
281281
}

crates/notedeck_columns/src/ui/add_column.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ pub fn render_add_column_routes(
634634
&mut timeline,
635635
ctx.ndb,
636636
&mut app.subscriptions,
637-
ctx.pool,
637+
ctx.subman.pool(),
638638
ctx.note_cache,
639639
app.since_optimize,
640640
);
@@ -675,7 +675,7 @@ pub fn render_add_column_routes(
675675
&mut timeline,
676676
ctx.ndb,
677677
&mut app.subscriptions,
678-
ctx.pool,
678+
ctx.subman.pool(),
679679
ctx.note_cache,
680680
app.since_optimize,
681681
);

0 commit comments

Comments
 (0)