Revert "Unify sub for contacts in accounts & timeline"
Since its causing contact timelines to not load
eg: ./target/release/notedeck --datapath new3 -c contacts
This reverts commit 9940537897.
This commit is contained in:
@@ -8,16 +8,14 @@ use crate::{
|
|||||||
storage,
|
storage,
|
||||||
subscriptions::{SubKind, Subscriptions},
|
subscriptions::{SubKind, Subscriptions},
|
||||||
support::Support,
|
support::Support,
|
||||||
timeline::{
|
timeline::{self, kind::ListKind, thread::Threads, TimelineCache, TimelineKind},
|
||||||
self, fetch_contact_list, kind::ListKind, thread::Threads, TimelineCache, TimelineKind,
|
|
||||||
},
|
|
||||||
ui::{self, DesktopSidePanel, SidePanelAction},
|
ui::{self, DesktopSidePanel, SidePanelAction},
|
||||||
view_state::ViewState,
|
view_state::ViewState,
|
||||||
Result,
|
Result,
|
||||||
};
|
};
|
||||||
|
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
ui::is_narrow, Accounts, AppAction, AppContext, DataPath, DataPathType, UnknownIds,
|
ui::is_narrow, Accounts, AppAction, AppContext, DataPath, DataPathType, FilterState, UnknownIds,
|
||||||
};
|
};
|
||||||
use notedeck_ui::{jobs::JobsCache, NoteOptions};
|
use notedeck_ui::{jobs::JobsCache, NoteOptions};
|
||||||
|
|
||||||
@@ -118,21 +116,13 @@ fn try_process_event(
|
|||||||
.accounts
|
.accounts
|
||||||
.send_initial_filters(app_ctx.pool, &ev.relay);
|
.send_initial_filters(app_ctx.pool, &ev.relay);
|
||||||
|
|
||||||
let data = app_ctx.accounts.get_subs();
|
|
||||||
damus.subscriptions.subs.insert(
|
|
||||||
data.contacts.remote.clone(),
|
|
||||||
SubKind::FetchingContactList(TimelineKind::List(ListKind::Contact(
|
|
||||||
*app_ctx.accounts.selected_account_pubkey(),
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
|
|
||||||
timeline::send_initial_timeline_filters(
|
timeline::send_initial_timeline_filters(
|
||||||
|
app_ctx.ndb,
|
||||||
damus.since_optimize,
|
damus.since_optimize,
|
||||||
&mut damus.timeline_cache,
|
&mut damus.timeline_cache,
|
||||||
&mut damus.subscriptions,
|
&mut damus.subscriptions,
|
||||||
app_ctx.pool,
|
app_ctx.pool,
|
||||||
&ev.relay,
|
&ev.relay,
|
||||||
app_ctx.accounts,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
// TODO: handle reconnects
|
// TODO: handle reconnects
|
||||||
@@ -258,11 +248,44 @@ fn handle_eose(
|
|||||||
}
|
}
|
||||||
|
|
||||||
SubKind::FetchingContactList(timeline_uid) => {
|
SubKind::FetchingContactList(timeline_uid) => {
|
||||||
let Some(timeline) = timeline_cache.timelines.get_mut(timeline_uid) else {
|
let timeline = if let Some(tl) = timeline_cache.timelines.get_mut(timeline_uid) {
|
||||||
|
tl
|
||||||
|
} else {
|
||||||
|
error!(
|
||||||
|
"timeline uid:{} not found for FetchingContactList",
|
||||||
|
timeline_uid
|
||||||
|
);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
fetch_contact_list(relay_url, timeline, ctx.accounts);
|
let filter_state = timeline.filter.get_mut(relay_url);
|
||||||
|
|
||||||
|
// If this request was fetching a contact list, our filter
|
||||||
|
// state should be "FetchingRemote". We look at the local
|
||||||
|
// subscription for that filter state and get the subscription id
|
||||||
|
let local_sub = if let FilterState::FetchingRemote(unisub) = filter_state {
|
||||||
|
unisub.local
|
||||||
|
} else {
|
||||||
|
// TODO: we could have multiple contact list results, we need
|
||||||
|
// to check to see if this one is newer and use that instead
|
||||||
|
warn!(
|
||||||
|
"Expected timeline to have FetchingRemote state but was {:?}",
|
||||||
|
timeline.filter
|
||||||
|
);
|
||||||
|
return Ok(());
|
||||||
|
};
|
||||||
|
|
||||||
|
info!(
|
||||||
|
"got contact list from {}, updating filter_state to got_remote",
|
||||||
|
relay_url
|
||||||
|
);
|
||||||
|
|
||||||
|
// We take the subscription id and pass it to the new state of
|
||||||
|
// "GotRemote". This will let future frames know that it can try
|
||||||
|
// to look for the contact list in nostrdb.
|
||||||
|
timeline
|
||||||
|
.filter
|
||||||
|
.set_relay_state(relay_url.to_string(), FilterState::got_remote(local_sub));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -724,13 +747,7 @@ fn timelines_view(
|
|||||||
let mut save_cols = false;
|
let mut save_cols = false;
|
||||||
if let Some(action) = side_panel_action {
|
if let Some(action) = side_panel_action {
|
||||||
save_cols = save_cols
|
save_cols = save_cols
|
||||||
|| action.process(
|
|| action.process(&mut app.timeline_cache, &mut app.decks_cache, ctx, ui.ctx());
|
||||||
&mut app.timeline_cache,
|
|
||||||
&mut app.decks_cache,
|
|
||||||
&mut app.subscriptions,
|
|
||||||
ctx,
|
|
||||||
ui.ctx(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut app_action: Option<AppAction> = None;
|
let mut app_action: Option<AppAction> = None;
|
||||||
|
|||||||
@@ -7,11 +7,9 @@ use crate::{
|
|||||||
profile::{ProfileAction, SaveProfileChanges},
|
profile::{ProfileAction, SaveProfileChanges},
|
||||||
profile_state::ProfileState,
|
profile_state::ProfileState,
|
||||||
route::{Route, Router, SingletonRouter},
|
route::{Route, Router, SingletonRouter},
|
||||||
subscriptions::{SubKind, Subscriptions},
|
|
||||||
timeline::{
|
timeline::{
|
||||||
kind::ListKind,
|
|
||||||
route::{render_thread_route, render_timeline_route},
|
route::{render_thread_route, render_timeline_route},
|
||||||
TimelineCache, TimelineKind,
|
TimelineCache,
|
||||||
},
|
},
|
||||||
ui::{
|
ui::{
|
||||||
self,
|
self,
|
||||||
@@ -74,7 +72,6 @@ impl SwitchingAction {
|
|||||||
&self,
|
&self,
|
||||||
timeline_cache: &mut TimelineCache,
|
timeline_cache: &mut TimelineCache,
|
||||||
decks_cache: &mut DecksCache,
|
decks_cache: &mut DecksCache,
|
||||||
subs: &mut Subscriptions,
|
|
||||||
ctx: &mut AppContext<'_>,
|
ctx: &mut AppContext<'_>,
|
||||||
ui_ctx: &egui::Context,
|
ui_ctx: &egui::Context,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
@@ -89,16 +86,6 @@ impl SwitchingAction {
|
|||||||
ctx.pool,
|
ctx.pool,
|
||||||
ui_ctx,
|
ui_ctx,
|
||||||
);
|
);
|
||||||
|
|
||||||
let new_subs = ctx.accounts.get_subs();
|
|
||||||
|
|
||||||
subs.subs.insert(
|
|
||||||
new_subs.contacts.remote.clone(),
|
|
||||||
SubKind::FetchingContactList(TimelineKind::List(ListKind::Contact(
|
|
||||||
*ctx.accounts.selected_account_pubkey(),
|
|
||||||
))),
|
|
||||||
);
|
|
||||||
|
|
||||||
// pop nav after switch
|
// pop nav after switch
|
||||||
get_active_columns_mut(ctx.accounts, decks_cache)
|
get_active_columns_mut(ctx.accounts, decks_cache)
|
||||||
.column_mut(switch_action.source_column)
|
.column_mut(switch_action.source_column)
|
||||||
@@ -393,7 +380,6 @@ fn process_render_nav_action(
|
|||||||
if switching_action.process(
|
if switching_action.process(
|
||||||
&mut app.timeline_cache,
|
&mut app.timeline_cache,
|
||||||
&mut app.decks_cache,
|
&mut app.decks_cache,
|
||||||
&mut app.subscriptions,
|
|
||||||
ctx,
|
ctx,
|
||||||
ui.ctx(),
|
ui.ctx(),
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
filter, Accounts, CachedNote, FilterError, FilterState, FilterStates, NoteCache, NoteRef,
|
filter, CachedNote, FilterError, FilterState, FilterStates, NoteCache, NoteRef, UnknownIds,
|
||||||
UnknownIds,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use egui_virtual_list::VirtualList;
|
use egui_virtual_list::VirtualList;
|
||||||
@@ -475,7 +474,6 @@ pub fn setup_new_timeline(
|
|||||||
pool: &mut RelayPool,
|
pool: &mut RelayPool,
|
||||||
note_cache: &mut NoteCache,
|
note_cache: &mut NoteCache,
|
||||||
since_optimize: bool,
|
since_optimize: bool,
|
||||||
accounts: &Accounts,
|
|
||||||
) {
|
) {
|
||||||
// if we're ready, setup local subs
|
// if we're ready, setup local subs
|
||||||
if is_timeline_ready(ndb, pool, note_cache, timeline) {
|
if is_timeline_ready(ndb, pool, note_cache, timeline) {
|
||||||
@@ -485,7 +483,7 @@ pub fn setup_new_timeline(
|
|||||||
}
|
}
|
||||||
|
|
||||||
for relay in &mut pool.relays {
|
for relay in &mut pool.relays {
|
||||||
send_initial_timeline_filter(since_optimize, subs, relay, timeline, accounts);
|
send_initial_timeline_filter(ndb, since_optimize, subs, relay, timeline);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -494,29 +492,29 @@ pub fn setup_new_timeline(
|
|||||||
/// situations where you are adding a new timeline, use
|
/// situations where you are adding a new timeline, use
|
||||||
/// setup_new_timeline.
|
/// setup_new_timeline.
|
||||||
pub fn send_initial_timeline_filters(
|
pub fn send_initial_timeline_filters(
|
||||||
|
ndb: &Ndb,
|
||||||
since_optimize: bool,
|
since_optimize: bool,
|
||||||
timeline_cache: &mut TimelineCache,
|
timeline_cache: &mut TimelineCache,
|
||||||
subs: &mut Subscriptions,
|
subs: &mut Subscriptions,
|
||||||
pool: &mut RelayPool,
|
pool: &mut RelayPool,
|
||||||
relay_id: &str,
|
relay_id: &str,
|
||||||
accounts: &Accounts,
|
|
||||||
) -> Option<()> {
|
) -> Option<()> {
|
||||||
info!("Sending initial filters to {}", relay_id);
|
info!("Sending initial filters to {}", relay_id);
|
||||||
let relay = &mut pool.relays.iter_mut().find(|r| r.url() == relay_id)?;
|
let relay = &mut pool.relays.iter_mut().find(|r| r.url() == relay_id)?;
|
||||||
|
|
||||||
for (_kind, timeline) in timeline_cache.timelines.iter_mut() {
|
for (_kind, timeline) in timeline_cache.timelines.iter_mut() {
|
||||||
send_initial_timeline_filter(since_optimize, subs, relay, timeline, accounts);
|
send_initial_timeline_filter(ndb, since_optimize, subs, relay, timeline);
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(())
|
Some(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_initial_timeline_filter(
|
pub fn send_initial_timeline_filter(
|
||||||
|
ndb: &Ndb,
|
||||||
can_since_optimize: bool,
|
can_since_optimize: bool,
|
||||||
subs: &mut Subscriptions,
|
subs: &mut Subscriptions,
|
||||||
relay: &mut PoolRelay,
|
relay: &mut PoolRelay,
|
||||||
timeline: &mut Timeline,
|
timeline: &mut Timeline,
|
||||||
accounts: &Accounts,
|
|
||||||
) {
|
) {
|
||||||
let filter_state = timeline.filter.get_mut(relay.url());
|
let filter_state = timeline.filter.get_mut(relay.url());
|
||||||
|
|
||||||
@@ -574,27 +572,34 @@ pub fn send_initial_timeline_filter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we need some data first
|
// we need some data first
|
||||||
FilterState::NeedsRemote(_filter) => fetch_contact_list(relay.url(), timeline, accounts),
|
FilterState::NeedsRemote(filter) => {
|
||||||
|
fetch_contact_list(filter.to_owned(), ndb, subs, relay, timeline)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fetch_contact_list(relay_url: &str, timeline: &mut Timeline, accounts: &Accounts) {
|
pub fn fetch_contact_list(
|
||||||
let account_subs = accounts.get_subs();
|
filter: Vec<Filter>,
|
||||||
let local = account_subs.contacts.local;
|
ndb: &Ndb,
|
||||||
|
subs: &mut Subscriptions,
|
||||||
|
relay: &mut PoolRelay,
|
||||||
|
timeline: &mut Timeline,
|
||||||
|
) {
|
||||||
|
let sub_kind = SubKind::FetchingContactList(timeline.kind.clone());
|
||||||
|
let sub_id = subscriptions::new_sub_id();
|
||||||
|
let local_sub = ndb.subscribe(&filter).expect("sub");
|
||||||
|
|
||||||
let filter_state = match accounts.get_selected_account().data.contacts.get_state() {
|
timeline.filter.set_relay_state(
|
||||||
notedeck::ContactState::Unreceived => {
|
relay.url().to_string(),
|
||||||
FilterState::fetching_remote(account_subs.contacts.remote.clone(), local)
|
FilterState::fetching_remote(sub_id.clone(), local_sub),
|
||||||
}
|
);
|
||||||
notedeck::ContactState::Received {
|
|
||||||
contacts: _,
|
|
||||||
note_key: _,
|
|
||||||
} => FilterState::GotRemote(local),
|
|
||||||
};
|
|
||||||
|
|
||||||
timeline
|
subs.subs.insert(sub_id.clone(), sub_kind);
|
||||||
.filter
|
|
||||||
.set_relay_state(relay_url.to_owned(), filter_state);
|
info!("fetching contact list from {}", relay.url());
|
||||||
|
if let Err(err) = relay.subscribe(sub_id, filter) {
|
||||||
|
error!("error subscribing: {err}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_initial_timeline(
|
fn setup_initial_timeline(
|
||||||
|
|||||||
@@ -623,7 +623,6 @@ pub fn render_add_column_routes(
|
|||||||
ctx.pool,
|
ctx.pool,
|
||||||
ctx.note_cache,
|
ctx.note_cache,
|
||||||
app.since_optimize,
|
app.since_optimize,
|
||||||
ctx.accounts,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
app.columns_mut(ctx.accounts)
|
app.columns_mut(ctx.accounts)
|
||||||
@@ -665,7 +664,6 @@ pub fn render_add_column_routes(
|
|||||||
ctx.pool,
|
ctx.pool,
|
||||||
ctx.note_cache,
|
ctx.note_cache,
|
||||||
app.since_optimize,
|
app.since_optimize,
|
||||||
ctx.accounts,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
app.columns_mut(ctx.accounts)
|
app.columns_mut(ctx.accounts)
|
||||||
|
|||||||
Reference in New Issue
Block a user