From ee5aa3246964d869fa7003eb43cb2341d7b115cd Mon Sep 17 00:00:00 2001 From: kernelkind Date: Tue, 8 Oct 2024 19:10:04 -0400 Subject: [PATCH] fix deck author bug & rename titles Signed-off-by: kernelkind --- src/timeline/kind.rs | 15 +++++++-------- src/timeline/mod.rs | 4 +--- src/ui/add_column.rs | 26 ++++++++++++++++++-------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/timeline/kind.rs b/src/timeline/kind.rs index e39afa1..c48a927 100644 --- a/src/timeline/kind.rs +++ b/src/timeline/kind.rs @@ -137,7 +137,7 @@ impl TimelineKind { )); } - match Timeline::contact_list(&results[0].note) { + match Timeline::contact_list(&results[0].note, pk_src.clone()) { Err(Error::Filter(FilterError::EmptyContactList)) => Some(Timeline::new( TimelineKind::contact_list(pk_src), FilterState::needs_remote(vec![contact_filter]), @@ -156,22 +156,21 @@ impl TimelineKind { match self { TimelineKind::List(list_kind) => match list_kind { ListKind::Contact(pubkey_source) => match pubkey_source { - PubkeySource::Explicit(pubkey) => format!( - "{}'s Home Timeline", - get_profile_displayname_string(ndb, pubkey) - ), - PubkeySource::DeckAuthor => "Your Home Timeline".to_owned(), + PubkeySource::Explicit(pubkey) => { + format!("{}'s Contacts", get_profile_displayname_string(ndb, pubkey)) + } + PubkeySource::DeckAuthor => "Contacts".to_owned(), }, }, TimelineKind::Notifications(pubkey_source) => match pubkey_source { - PubkeySource::DeckAuthor => "Your Notifications".to_owned(), + PubkeySource::DeckAuthor => "Notifications".to_owned(), PubkeySource::Explicit(pk) => format!( "{}'s Notifications", get_profile_displayname_string(ndb, pk) ), }, TimelineKind::Profile(pubkey_source) => match pubkey_source { - PubkeySource::DeckAuthor => "Your Profile".to_owned(), + PubkeySource::DeckAuthor => "Profile".to_owned(), PubkeySource::Explicit(pk) => { format!("{}'s Profile", get_profile_displayname_string(ndb, pk)) } diff --git a/src/timeline/mod.rs b/src/timeline/mod.rs index e271fee..7259337 100644 --- a/src/timeline/mod.rs +++ b/src/timeline/mod.rs @@ -8,7 +8,6 @@ use std::fmt; use std::sync::atomic::{AtomicU32, Ordering}; use egui_virtual_list::VirtualList; -use enostr::Pubkey; use nostrdb::{Ndb, Note, Subscription, Transaction}; use std::cell::RefCell; use std::hash::Hash; @@ -180,9 +179,8 @@ pub struct Timeline { impl Timeline { /// Create a timeline from a contact list - pub fn contact_list(contact_list: &Note) -> Result { + pub fn contact_list(contact_list: &Note, pk_src: PubkeySource) -> Result { let filter = filter::filter_from_tags(contact_list)?.into_follow_filter(); - let pk_src = PubkeySource::Explicit(Pubkey::new(*contact_list.pubkey())); Ok(Timeline::new( TimelineKind::contact_list(pk_src), diff --git a/src/ui/add_column.rs b/src/ui/add_column.rs index c75e3c4..298addc 100644 --- a/src/ui/add_column.rs +++ b/src/ui/add_column.rs @@ -14,7 +14,7 @@ pub enum AddColumnResponse { Timeline(Timeline), } -#[derive(Clone)] +#[derive(Clone, Debug)] enum AddColumnOption { Universe, Notification(PubkeySource), @@ -22,17 +22,23 @@ enum AddColumnOption { } impl AddColumnOption { - pub fn take_as_response(self, ndb: &Ndb) -> Option { + pub fn take_as_response( + self, + ndb: &Ndb, + cur_account: Option<&UserAccount>, + ) -> Option { match self { AddColumnOption::Universe => TimelineKind::Universe .into_timeline(ndb, None) .map(AddColumnResponse::Timeline), AddColumnOption::Notification(pubkey) => TimelineKind::Notifications(pubkey) - .into_timeline(ndb, None) - .map(AddColumnResponse::Timeline), - AddColumnOption::Home(pubkey) => TimelineKind::contact_list(pubkey) - .into_timeline(ndb, None) + .into_timeline(ndb, cur_account.map(|a| a.pubkey.bytes())) .map(AddColumnResponse::Timeline), + AddColumnOption::Home(pubkey) => { + let tlk = TimelineKind::contact_list(pubkey); + tlk.into_timeline(ndb, cur_account.map(|a| a.pubkey.bytes())) + .map(AddColumnResponse::Timeline) + } } } } @@ -52,7 +58,7 @@ impl<'a> AddColumnView<'a> { for column_option_data in self.get_column_options() { let option = column_option_data.option.clone(); if self.column_option_ui(ui, column_option_data).clicked() { - selected_option = option.take_as_response(self.ndb); + selected_option = option.take_as_response(self.ndb, self.cur_account); } ui.add(Separator::default().spacing(0.0)); @@ -172,7 +178,11 @@ impl<'a> AddColumnView<'a> { }); if let Some(acc) = self.cur_account { - let source = PubkeySource::Explicit(acc.pubkey); + let source = if acc.secret_key.is_some() { + PubkeySource::DeckAuthor + } else { + PubkeySource::Explicit(acc.pubkey) + }; vec.push(ColumnOptionData { title: "Home timeline",