timeline: auto-add yourself to your home timeline
This is the most intuitive, and damus iOS does the same thing. You have to follow yourself, sorry. Otherwise you won't see your posts when you post which is confusing. Fixes: https://github.com/damus-io/notedeck/issues/509
This commit is contained in:
@@ -141,6 +141,11 @@ fn try_process_event(
|
||||
app_ctx.note_cache,
|
||||
timeline,
|
||||
&app_ctx.accounts.mutefun(),
|
||||
app_ctx
|
||||
.accounts
|
||||
.get_selected_account()
|
||||
.as_ref()
|
||||
.map(|sa| &sa.pubkey),
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
@@ -25,6 +25,13 @@ impl PubkeySource {
|
||||
PubkeySource::DeckAuthor => deck_author,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_pubkey_bytes<'a>(&'a self, deck_author: &'a [u8; 32]) -> &'a [u8; 32] {
|
||||
match self {
|
||||
PubkeySource::Explicit(pk) => pk.bytes(),
|
||||
PubkeySource::DeckAuthor => deck_author,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ListKind {
|
||||
@@ -177,7 +184,7 @@ impl TimelineKind {
|
||||
));
|
||||
}
|
||||
|
||||
match Timeline::contact_list(&results[0].note, pk_src.clone()) {
|
||||
match Timeline::contact_list(&results[0].note, pk_src.clone(), default_user) {
|
||||
Err(Error::App(notedeck::Error::Filter(FilterError::EmptyContactList))) => {
|
||||
Some(Timeline::new(
|
||||
TimelineKind::contact_list(pk_src),
|
||||
|
||||
@@ -15,7 +15,7 @@ use std::fmt;
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
|
||||
use egui_virtual_list::VirtualList;
|
||||
use enostr::{Relay, RelayPool};
|
||||
use enostr::{Pubkey, Relay, RelayPool};
|
||||
use nostrdb::{Filter, Ndb, Note, Subscription, Transaction};
|
||||
use std::cell::RefCell;
|
||||
use std::hash::Hash;
|
||||
@@ -187,8 +187,13 @@ pub struct Timeline {
|
||||
|
||||
impl Timeline {
|
||||
/// Create a timeline from a contact list
|
||||
pub fn contact_list(contact_list: &Note, pk_src: PubkeySource) -> Result<Self> {
|
||||
let filter = filter::filter_from_tags(contact_list)?.into_follow_filter();
|
||||
pub fn contact_list(
|
||||
contact_list: &Note,
|
||||
pk_src: PubkeySource,
|
||||
deck_author: Option<&[u8; 32]>,
|
||||
) -> Result<Self> {
|
||||
let our_pubkey = deck_author.map(|da| pk_src.to_pubkey_bytes(da));
|
||||
let filter = filter::filter_from_tags(contact_list, our_pubkey)?.into_follow_filter();
|
||||
|
||||
Ok(Timeline::new(
|
||||
TimelineKind::contact_list(pk_src),
|
||||
@@ -388,6 +393,7 @@ pub fn merge_sorted_vecs<T: Ord + Copy>(vec1: &[T], vec2: &[T]) -> (Vec<T>, Merg
|
||||
///
|
||||
/// We do this by maintaining this sub_id in the filter state, even when
|
||||
/// in the ready state. See: [`FilterReady`]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn setup_new_timeline(
|
||||
timeline: &mut Timeline,
|
||||
ndb: &Ndb,
|
||||
@@ -396,9 +402,10 @@ pub fn setup_new_timeline(
|
||||
note_cache: &mut NoteCache,
|
||||
since_optimize: bool,
|
||||
is_muted: &MuteFun,
|
||||
our_pk: Option<&Pubkey>,
|
||||
) {
|
||||
// if we're ready, setup local subs
|
||||
if is_timeline_ready(ndb, pool, note_cache, timeline, is_muted) {
|
||||
if is_timeline_ready(ndb, pool, note_cache, timeline, is_muted, our_pk) {
|
||||
if let Err(err) = setup_timeline_nostrdb_sub(ndb, note_cache, timeline, is_muted) {
|
||||
error!("setup_new_timeline: {err}");
|
||||
}
|
||||
@@ -627,6 +634,7 @@ pub fn is_timeline_ready(
|
||||
note_cache: &mut NoteCache,
|
||||
timeline: &mut Timeline,
|
||||
is_muted: &MuteFun,
|
||||
our_pk: Option<&Pubkey>,
|
||||
) -> bool {
|
||||
// TODO: we should debounce the filter states a bit to make sure we have
|
||||
// seen all of the different contact lists from each relay
|
||||
@@ -658,7 +666,12 @@ pub fn is_timeline_ready(
|
||||
let filter = {
|
||||
let txn = Transaction::new(ndb).expect("txn");
|
||||
let note = ndb.get_note_by_key(&txn, note_key).expect("note");
|
||||
filter::filter_from_tags(¬e).map(|f| f.into_follow_filter())
|
||||
let add_pk = timeline
|
||||
.kind
|
||||
.pubkey_source()
|
||||
.as_ref()
|
||||
.and_then(|pk_src| our_pk.map(|pk| pk_src.to_pubkey_bytes(pk)));
|
||||
filter::filter_from_tags(¬e, add_pk).map(|f| f.into_follow_filter())
|
||||
};
|
||||
|
||||
// TODO: into_follow_filter is hardcoded to contact lists, let's generalize
|
||||
|
||||
@@ -504,6 +504,10 @@ pub fn render_add_column_routes(
|
||||
ctx.note_cache,
|
||||
app.since_optimize,
|
||||
&ctx.accounts.mutefun(),
|
||||
ctx.accounts
|
||||
.get_selected_account()
|
||||
.as_ref()
|
||||
.map(|sa| &sa.pubkey),
|
||||
);
|
||||
app.columns_mut(ctx.accounts)
|
||||
.add_timeline_to_column(col, timeline);
|
||||
|
||||
Reference in New Issue
Block a user