mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 09:34:19 +01:00
remove unnecessary FilterState::NeedsRemote filter
all NeedsRemote states are contact lists currently, which is managed by `Accounts` Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -92,7 +92,7 @@ impl FilterStates {
|
|||||||
/// [`FilterState`] tracks this.
|
/// [`FilterState`] tracks this.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum FilterState {
|
pub enum FilterState {
|
||||||
NeedsRemote(Vec<Filter>),
|
NeedsRemote,
|
||||||
FetchingRemote(FetchingRemoteType),
|
FetchingRemote(FetchingRemoteType),
|
||||||
GotRemote(GotRemoteType),
|
GotRemote(GotRemoteType),
|
||||||
Ready(Vec<Filter>),
|
Ready(Vec<Filter>),
|
||||||
@@ -139,8 +139,8 @@ impl FilterState {
|
|||||||
/// for home timelines where we don't have a contact list yet. We
|
/// for home timelines where we don't have a contact list yet. We
|
||||||
/// need to fetch the contact list before we have the right timeline
|
/// need to fetch the contact list before we have the right timeline
|
||||||
/// filter.
|
/// filter.
|
||||||
pub fn needs_remote(filter: Vec<Filter>) -> Self {
|
pub fn needs_remote() -> Self {
|
||||||
Self::NeedsRemote(filter)
|
Self::NeedsRemote
|
||||||
}
|
}
|
||||||
|
|
||||||
/// We got the remote data. Local data should be available to build
|
/// We got the remote data. Local data should be available to build
|
||||||
|
|||||||
@@ -500,11 +500,7 @@ impl TimelineKind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TimelineKind::Algo(AlgoTimeline::LastPerPubkey(ListKind::Contact(pk))) => {
|
TimelineKind::Algo(AlgoTimeline::LastPerPubkey(ListKind::Contact(pk))) => {
|
||||||
let contact_filter = Filter::new()
|
let contact_filter = contacts_filter(pk.bytes());
|
||||||
.authors([pk.bytes()])
|
|
||||||
.kinds([3])
|
|
||||||
.limit(1)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let results = ndb
|
let results = ndb
|
||||||
.query(txn, &[contact_filter.clone()], 1)
|
.query(txn, &[contact_filter.clone()], 1)
|
||||||
@@ -516,7 +512,7 @@ impl TimelineKind {
|
|||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
return Some(Timeline::new(
|
return Some(Timeline::new(
|
||||||
kind_fn(ListKind::contact_list(pk)),
|
kind_fn(ListKind::contact_list(pk)),
|
||||||
FilterState::needs_remote(vec![contact_filter.clone()]),
|
FilterState::needs_remote(),
|
||||||
tabs,
|
tabs,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -527,7 +523,7 @@ impl TimelineKind {
|
|||||||
Err(Error::App(notedeck::Error::Filter(FilterError::EmptyContactList))) => {
|
Err(Error::App(notedeck::Error::Filter(FilterError::EmptyContactList))) => {
|
||||||
Some(Timeline::new(
|
Some(Timeline::new(
|
||||||
kind_fn(list_kind),
|
kind_fn(list_kind),
|
||||||
FilterState::needs_remote(vec![contact_filter]),
|
FilterState::needs_remote(),
|
||||||
tabs,
|
tabs,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
@@ -652,12 +648,12 @@ fn contact_filter_state(txn: &Transaction, ndb: &Ndb, pk: &Pubkey) -> FilterStat
|
|||||||
.expect("contact query failed?");
|
.expect("contact query failed?");
|
||||||
|
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
FilterState::needs_remote(vec![contact_filter.clone()])
|
FilterState::needs_remote()
|
||||||
} else {
|
} else {
|
||||||
let with_hashtags = false;
|
let with_hashtags = false;
|
||||||
match filter::filter_from_tags(&results[0].note, Some(pk.bytes()), with_hashtags) {
|
match filter::filter_from_tags(&results[0].note, Some(pk.bytes()), with_hashtags) {
|
||||||
Err(notedeck::Error::Filter(FilterError::EmptyContactList)) => {
|
Err(notedeck::Error::Filter(FilterError::EmptyContactList)) => {
|
||||||
FilterState::needs_remote(vec![contact_filter])
|
FilterState::needs_remote()
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Error getting contact filter state: {err}");
|
error!("Error getting contact filter state: {err}");
|
||||||
@@ -669,11 +665,7 @@ fn contact_filter_state(txn: &Transaction, ndb: &Ndb, pk: &Pubkey) -> FilterStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn last_per_pubkey_filter_state(ndb: &Ndb, pk: &Pubkey) -> FilterState {
|
fn last_per_pubkey_filter_state(ndb: &Ndb, pk: &Pubkey) -> FilterState {
|
||||||
let contact_filter = Filter::new()
|
let contact_filter = contacts_filter(pk.bytes());
|
||||||
.authors([pk.bytes()])
|
|
||||||
.kinds([3])
|
|
||||||
.limit(1)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
let txn = Transaction::new(ndb).expect("txn");
|
let txn = Transaction::new(ndb).expect("txn");
|
||||||
let results = ndb
|
let results = ndb
|
||||||
@@ -681,13 +673,13 @@ fn last_per_pubkey_filter_state(ndb: &Ndb, pk: &Pubkey) -> FilterState {
|
|||||||
.expect("contact query failed?");
|
.expect("contact query failed?");
|
||||||
|
|
||||||
if results.is_empty() {
|
if results.is_empty() {
|
||||||
FilterState::needs_remote(vec![contact_filter])
|
FilterState::needs_remote()
|
||||||
} else {
|
} else {
|
||||||
let kind = 1;
|
let kind = 1;
|
||||||
let notes_per_pk = 1;
|
let notes_per_pk = 1;
|
||||||
match filter::last_n_per_pubkey_from_tags(&results[0].note, kind, notes_per_pk) {
|
match filter::last_n_per_pubkey_from_tags(&results[0].note, kind, notes_per_pk) {
|
||||||
Err(notedeck::Error::Filter(FilterError::EmptyContactList)) => {
|
Err(notedeck::Error::Filter(FilterError::EmptyContactList)) => {
|
||||||
FilterState::needs_remote(vec![contact_filter])
|
FilterState::needs_remote()
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
error!("Error getting contact filter state: {err}");
|
error!("Error getting contact filter state: {err}");
|
||||||
|
|||||||
@@ -574,7 +574,7 @@ pub fn send_initial_timeline_filter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// we need some data first
|
// we need some data first
|
||||||
FilterState::NeedsRemote(_) => fetch_contact_list(subs, relay, timeline, accounts),
|
FilterState::NeedsRemote => fetch_contact_list(subs, relay, timeline, accounts),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user