mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-19 09:34:19 +01:00
make selected accounts non optional
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -195,9 +195,7 @@ impl Accounts {
|
|||||||
update(cur_account);
|
update(cur_account);
|
||||||
}
|
}
|
||||||
|
|
||||||
let Some(cur_acc) = self.get_selected_account() else {
|
let cur_acc = self.get_selected_account();
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
|
||||||
let Some(key_store) = &self.key_store else {
|
let Some(key_store) = &self.key_store else {
|
||||||
return false;
|
return false;
|
||||||
@@ -221,31 +219,30 @@ impl Accounts {
|
|||||||
|
|
||||||
pub fn selected_or_first_nsec(&self) -> Option<FilledKeypair<'_>> {
|
pub fn selected_or_first_nsec(&self) -> Option<FilledKeypair<'_>> {
|
||||||
self.get_selected_account()
|
self.get_selected_account()
|
||||||
.and_then(|kp| kp.key.to_full())
|
.key
|
||||||
|
.to_full()
|
||||||
.or_else(|| self.accounts.iter().find_map(|a| a.key.to_full()))
|
.or_else(|| self.accounts.iter().find_map(|a| a.key.to_full()))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the selected account's pubkey as bytes. Common operation so
|
/// Get the selected account's pubkey as bytes. Common operation so
|
||||||
/// we make it a helper here.
|
/// we make it a helper here.
|
||||||
pub fn selected_account_pubkey_bytes(&self) -> Option<&[u8; 32]> {
|
pub fn selected_account_pubkey_bytes(&self) -> &[u8; 32] {
|
||||||
self.get_selected_account().map(|kp| kp.key.pubkey.bytes())
|
self.get_selected_account().key.pubkey.bytes()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected_account_pubkey(&self) -> Option<&Pubkey> {
|
pub fn selected_account_pubkey(&self) -> &Pubkey {
|
||||||
self.get_selected_account().map(|acc| &acc.key.pubkey)
|
&self.get_selected_account().key.pubkey
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_selected_account(&self) -> Option<&UserAccount> {
|
pub fn get_selected_account(&self) -> &UserAccount {
|
||||||
self.currently_selected_account
|
self.currently_selected_account
|
||||||
.map(|i| self.get_account(i))?
|
.and_then(|i| self.get_account(i))
|
||||||
|
// NOTE: yeah, this is incorrect but we just need to seperate out the changes in smaller commits
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn selected_account_has_wallet(&self) -> bool {
|
pub fn selected_account_has_wallet(&self) -> bool {
|
||||||
if let Some(acc) = self.get_selected_account() {
|
self.get_selected_account().wallet.is_some()
|
||||||
return acc.wallet.is_some();
|
|
||||||
}
|
|
||||||
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_selected_account_mut(&mut self) -> Option<&mut UserAccount> {
|
pub fn get_selected_account_mut(&mut self) -> Option<&mut UserAccount> {
|
||||||
@@ -265,7 +262,7 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_selected_account_data(&mut self) -> Option<&mut AccountData> {
|
pub fn get_selected_account_data(&mut self) -> Option<&mut AccountData> {
|
||||||
let account_pubkey = *self.selected_account_pubkey_bytes()?;
|
let account_pubkey = *self.selected_account_pubkey_bytes();
|
||||||
self.account_data.get_mut(&account_pubkey)
|
self.account_data.get_mut(&account_pubkey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,11 +81,7 @@ fn process_new_zap_event(
|
|||||||
txn: &Transaction,
|
txn: &Transaction,
|
||||||
sender_relays: Vec<String>,
|
sender_relays: Vec<String>,
|
||||||
) -> NextState {
|
) -> NextState {
|
||||||
let Some(full_kp) = accounts
|
let Some(full_kp) = accounts.get_selected_account().key.to_full() else {
|
||||||
.get_selected_account()
|
|
||||||
.or_else(|| accounts.find_account(zap_ctx.key.sender.bytes()))
|
|
||||||
.and_then(|u| u.key.to_full())
|
|
||||||
else {
|
|
||||||
return NextState::Event(EventResponse {
|
return NextState::Event(EventResponse {
|
||||||
id: zap_ctx.id,
|
id: zap_ctx.id,
|
||||||
event: Err(ZappingError::InvalidAccount),
|
event: Err(ZappingError::InvalidAccount),
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ use crate::app::NotedeckApp;
|
|||||||
use egui::{vec2, Button, Label, Layout, Rect, RichText, ThemePreference, Widget};
|
use egui::{vec2, Button, Label, Layout, Rect, RichText, ThemePreference, Widget};
|
||||||
use egui_extras::{Size, StripBuilder};
|
use egui_extras::{Size, StripBuilder};
|
||||||
use nostrdb::{ProfileRecord, Transaction};
|
use nostrdb::{ProfileRecord, Transaction};
|
||||||
use notedeck::{
|
use notedeck::{App, AppAction, AppContext, NotedeckTextStyle, UserAccount, WalletType};
|
||||||
profile::get_profile_url, App, AppAction, AppContext, NotedeckTextStyle, UserAccount,
|
|
||||||
WalletType,
|
|
||||||
};
|
|
||||||
use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus};
|
use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus};
|
||||||
|
|
||||||
use notedeck_dave::{Dave, DaveAvatar};
|
use notedeck_dave::{Dave, DaveAvatar};
|
||||||
@@ -95,27 +92,23 @@ impl ChromePanelAction {
|
|||||||
ToolbarAction::Dave => chrome.switch_to_dave(),
|
ToolbarAction::Dave => chrome.switch_to_dave(),
|
||||||
|
|
||||||
ToolbarAction::Home => {
|
ToolbarAction::Home => {
|
||||||
if let Some(pubkey) = ctx
|
Self::columns_switch(
|
||||||
.accounts
|
ctx,
|
||||||
.get_selected_account()
|
chrome,
|
||||||
.map(|acc| acc.key.pubkey)
|
&TimelineKind::List(ListKind::Contact(
|
||||||
{
|
ctx.accounts.get_selected_account().key.pubkey,
|
||||||
Self::columns_switch(
|
)),
|
||||||
ctx,
|
);
|
||||||
chrome,
|
|
||||||
&TimelineKind::List(ListKind::Contact(pubkey)),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolbarAction::Notifications => {
|
ToolbarAction::Notifications => {
|
||||||
if let Some(pubkey) = ctx
|
Self::columns_switch(
|
||||||
.accounts
|
ctx,
|
||||||
.get_selected_account()
|
chrome,
|
||||||
.map(|acc| acc.key.pubkey)
|
&TimelineKind::Notifications(
|
||||||
{
|
ctx.accounts.get_selected_account().key.pubkey,
|
||||||
Self::columns_switch(ctx, chrome, &TimelineKind::Notifications(pubkey));
|
),
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -559,16 +552,12 @@ pub fn get_profile_url_owned(profile: Option<ProfileRecord<'_>>) -> &str {
|
|||||||
pub fn get_account_url<'a>(
|
pub fn get_account_url<'a>(
|
||||||
txn: &'a nostrdb::Transaction,
|
txn: &'a nostrdb::Transaction,
|
||||||
ndb: &nostrdb::Ndb,
|
ndb: &nostrdb::Ndb,
|
||||||
account: Option<&UserAccount>,
|
account: &UserAccount,
|
||||||
) -> &'a str {
|
) -> &'a str {
|
||||||
if let Some(selected_account) = account {
|
if let Ok(profile) = ndb.get_profile_by_pubkey(txn, account.key.pubkey.bytes()) {
|
||||||
if let Ok(profile) = ndb.get_profile_by_pubkey(txn, selected_account.key.pubkey.bytes()) {
|
get_profile_url_owned(Some(profile))
|
||||||
get_profile_url_owned(Some(profile))
|
|
||||||
} else {
|
|
||||||
get_profile_url_owned(None)
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
get_profile_url(None)
|
get_profile_url_owned(None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -386,7 +386,7 @@ impl Damus {
|
|||||||
// arg parsing
|
// arg parsing
|
||||||
|
|
||||||
let (parsed_args, unrecognized_args) =
|
let (parsed_args, unrecognized_args) =
|
||||||
ColumnsArgs::parse(args, ctx.accounts.selected_account_pubkey());
|
ColumnsArgs::parse(args, Some(ctx.accounts.selected_account_pubkey()));
|
||||||
|
|
||||||
let account = ctx.accounts.selected_account_pubkey_bytes();
|
let account = ctx.accounts.selected_account_pubkey_bytes();
|
||||||
|
|
||||||
@@ -747,9 +747,7 @@ pub fn get_active_columns<'a>(accounts: &Accounts, decks_cache: &'a DecksCache)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_decks<'a>(accounts: &Accounts, decks_cache: &'a DecksCache) -> &'a Decks {
|
pub fn get_decks<'a>(accounts: &Accounts, decks_cache: &'a DecksCache) -> &'a Decks {
|
||||||
let key = accounts
|
let key = accounts.selected_account_pubkey();
|
||||||
.selected_account_pubkey()
|
|
||||||
.unwrap_or_else(|| decks_cache.get_fallback_pubkey());
|
|
||||||
decks_cache.decks(key)
|
decks_cache.decks(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -763,10 +761,7 @@ pub fn get_active_columns_mut<'a>(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_decks_mut<'a>(accounts: &Accounts, decks_cache: &'a mut DecksCache) -> &'a mut Decks {
|
pub fn get_decks_mut<'a>(accounts: &Accounts, decks_cache: &'a mut DecksCache) -> &'a mut Decks {
|
||||||
match accounts.selected_account_pubkey() {
|
decks_cache.decks_mut(accounts.selected_account_pubkey())
|
||||||
Some(acc) => decks_cache.decks_mut(acc),
|
|
||||||
None => decks_cache.fallback_mut(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_demo(
|
pub fn set_demo(
|
||||||
@@ -782,7 +777,7 @@ pub fn set_demo(
|
|||||||
accounts.select_account(accounts.num_accounts() - 1);
|
accounts.select_account(accounts.num_accounts() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn columns_to_decks_cache(cols: Columns, key: Option<&[u8; 32]>) -> DecksCache {
|
fn columns_to_decks_cache(cols: Columns, key: &[u8; 32]) -> DecksCache {
|
||||||
let mut account_to_decks: HashMap<Pubkey, Decks> = Default::default();
|
let mut account_to_decks: HashMap<Pubkey, Decks> = Default::default();
|
||||||
let decks = Decks::new(crate::decks::Deck::new_with_columns(
|
let decks = Decks::new(crate::decks::Deck::new_with_columns(
|
||||||
crate::decks::Deck::default().icon,
|
crate::decks::Deck::default().icon,
|
||||||
@@ -790,11 +785,7 @@ fn columns_to_decks_cache(cols: Columns, key: Option<&[u8; 32]>) -> DecksCache {
|
|||||||
cols,
|
cols,
|
||||||
));
|
));
|
||||||
|
|
||||||
let account = if let Some(key) = key {
|
let account = Pubkey::new(*key);
|
||||||
Pubkey::new(*key)
|
|
||||||
} else {
|
|
||||||
FALLBACK_PUBKEY()
|
|
||||||
};
|
|
||||||
account_to_decks.insert(account, decks);
|
account_to_decks.insert(account, decks);
|
||||||
DecksCache::new(account_to_decks)
|
DecksCache::new(account_to_decks)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ impl DecksCache {
|
|||||||
|
|
||||||
/// Gets the active columns
|
/// Gets the active columns
|
||||||
pub fn active_columns_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Columns> {
|
pub fn active_columns_mut(&mut self, accounts: ¬edeck::Accounts) -> Option<&mut Columns> {
|
||||||
let account = accounts.get_selected_account()?;
|
let account = accounts.get_selected_account();
|
||||||
|
|
||||||
self.decks_mut(&account.key.pubkey)
|
self.decks_mut(&account.key.pubkey)
|
||||||
.active_deck_mut()
|
.active_deck_mut()
|
||||||
|
|||||||
@@ -544,7 +544,7 @@ fn render_nav_body(
|
|||||||
response.action.map(Into::into)
|
response.action.map(Into::into)
|
||||||
}
|
}
|
||||||
Route::ComposeNote => {
|
Route::ComposeNote => {
|
||||||
let kp = ctx.accounts.get_selected_account()?.key.to_full()?;
|
let kp = ctx.accounts.get_selected_account().key.to_full()?;
|
||||||
let draft = app.drafts.compose_mut();
|
let draft = app.drafts.compose_mut();
|
||||||
|
|
||||||
let txn = Transaction::new(ctx.ndb).expect("txn");
|
let txn = Transaction::new(ctx.ndb).expect("txn");
|
||||||
@@ -594,7 +594,7 @@ fn render_nav_body(
|
|||||||
app.note_options,
|
app.note_options,
|
||||||
search_buffer,
|
search_buffer,
|
||||||
&mut note_context,
|
&mut note_context,
|
||||||
&ctx.accounts.get_selected_account().map(|a| (&a.key).into()),
|
&(&ctx.accounts.get_selected_account().key).into(),
|
||||||
&mut app.jobs,
|
&mut app.jobs,
|
||||||
)
|
)
|
||||||
.show(ui, ctx.clipboard)
|
.show(ui, ctx.clipboard)
|
||||||
@@ -605,19 +605,18 @@ fn render_nav_body(
|
|||||||
let new_deck_state = app.view_state.id_to_deck_state.entry(id).or_default();
|
let new_deck_state = app.view_state.id_to_deck_state.entry(id).or_default();
|
||||||
let mut resp = None;
|
let mut resp = None;
|
||||||
if let Some(config_resp) = ConfigureDeckView::new(new_deck_state).ui(ui) {
|
if let Some(config_resp) = ConfigureDeckView::new(new_deck_state).ui(ui) {
|
||||||
if let Some(cur_acc) = ctx.accounts.selected_account_pubkey() {
|
let cur_acc = ctx.accounts.selected_account_pubkey();
|
||||||
app.decks_cache
|
app.decks_cache
|
||||||
.add_deck(*cur_acc, Deck::new(config_resp.icon, config_resp.name));
|
.add_deck(*cur_acc, Deck::new(config_resp.icon, config_resp.name));
|
||||||
|
|
||||||
// set new deck as active
|
// set new deck as active
|
||||||
let cur_index = get_decks_mut(ctx.accounts, &mut app.decks_cache)
|
let cur_index = get_decks_mut(ctx.accounts, &mut app.decks_cache)
|
||||||
.decks()
|
.decks()
|
||||||
.len()
|
.len()
|
||||||
- 1;
|
- 1;
|
||||||
resp = Some(RenderNavAction::SwitchingAction(SwitchingAction::Decks(
|
resp = Some(RenderNavAction::SwitchingAction(SwitchingAction::Decks(
|
||||||
DecksAction::Switch(cur_index),
|
DecksAction::Switch(cur_index),
|
||||||
)));
|
)));
|
||||||
}
|
|
||||||
|
|
||||||
new_deck_state.clear();
|
new_deck_state.clear();
|
||||||
get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
|
get_active_columns_mut(ctx.accounts, &mut app.decks_cache)
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub fn render_timeline_route(
|
|||||||
&accounts.mutefun(),
|
&accounts.mutefun(),
|
||||||
note_context,
|
note_context,
|
||||||
note_options,
|
note_options,
|
||||||
&accounts.get_selected_account().map(|a| (&a.key).into()),
|
&(&accounts.get_selected_account().key).into(),
|
||||||
jobs,
|
jobs,
|
||||||
)
|
)
|
||||||
.ui(ui);
|
.ui(ui);
|
||||||
@@ -64,7 +64,7 @@ pub fn render_timeline_route(
|
|||||||
&accounts.mutefun(),
|
&accounts.mutefun(),
|
||||||
note_context,
|
note_context,
|
||||||
note_options,
|
note_options,
|
||||||
&accounts.get_selected_account().map(|a| (&a.key).into()),
|
&(&accounts.get_selected_account().key).into(),
|
||||||
jobs,
|
jobs,
|
||||||
)
|
)
|
||||||
.ui(ui);
|
.ui(ui);
|
||||||
@@ -96,7 +96,7 @@ pub fn render_thread_route(
|
|||||||
note_options,
|
note_options,
|
||||||
&accounts.mutefun(),
|
&accounts.mutefun(),
|
||||||
note_context,
|
note_context,
|
||||||
&accounts.get_selected_account().map(|a| (&a.key).into()),
|
&(&accounts.get_selected_account().key).into(),
|
||||||
jobs,
|
jobs,
|
||||||
)
|
)
|
||||||
.id_source(col)
|
.id_source(col)
|
||||||
|
|||||||
@@ -165,7 +165,7 @@ pub struct AddColumnView<'a> {
|
|||||||
key_state_map: &'a mut HashMap<Id, AcquireKeyState>,
|
key_state_map: &'a mut HashMap<Id, AcquireKeyState>,
|
||||||
ndb: &'a Ndb,
|
ndb: &'a Ndb,
|
||||||
img_cache: &'a mut Images,
|
img_cache: &'a mut Images,
|
||||||
cur_account: Option<&'a UserAccount>,
|
cur_account: &'a UserAccount,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AddColumnView<'a> {
|
impl<'a> AddColumnView<'a> {
|
||||||
@@ -173,7 +173,7 @@ impl<'a> AddColumnView<'a> {
|
|||||||
key_state_map: &'a mut HashMap<Id, AcquireKeyState>,
|
key_state_map: &'a mut HashMap<Id, AcquireKeyState>,
|
||||||
ndb: &'a Ndb,
|
ndb: &'a Ndb,
|
||||||
img_cache: &'a mut Images,
|
img_cache: &'a mut Images,
|
||||||
cur_account: Option<&'a UserAccount>,
|
cur_account: &'a UserAccount,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
key_state_map,
|
key_state_map,
|
||||||
@@ -188,7 +188,7 @@ impl<'a> AddColumnView<'a> {
|
|||||||
for column_option_data in self.get_base_options() {
|
for column_option_data in self.get_base_options() {
|
||||||
let option = column_option_data.option.clone();
|
let option = column_option_data.option.clone();
|
||||||
if self.column_option_ui(ui, column_option_data).clicked() {
|
if self.column_option_ui(ui, column_option_data).clicked() {
|
||||||
selected_option = self.cur_account.map(|acct| option.take_as_response(acct))
|
selected_option = Some(option.take_as_response(self.cur_account));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.add(Separator::default().spacing(0.0));
|
ui.add(Separator::default().spacing(0.0));
|
||||||
@@ -202,7 +202,7 @@ impl<'a> AddColumnView<'a> {
|
|||||||
for column_option_data in self.get_notifications_options() {
|
for column_option_data in self.get_notifications_options() {
|
||||||
let option = column_option_data.option.clone();
|
let option = column_option_data.option.clone();
|
||||||
if self.column_option_ui(ui, column_option_data).clicked() {
|
if self.column_option_ui(ui, column_option_data).clicked() {
|
||||||
selected_option = self.cur_account.map(|acct| option.take_as_response(acct));
|
selected_option = Some(option.take_as_response(self.cur_account));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.add(Separator::default().spacing(0.0));
|
ui.add(Separator::default().spacing(0.0));
|
||||||
@@ -233,11 +233,9 @@ impl<'a> AddColumnView<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let option = algo_option.option.clone();
|
let option = algo_option.option.clone();
|
||||||
if self.column_option_ui(ui, algo_option).clicked() {
|
self.column_option_ui(ui, algo_option)
|
||||||
self.cur_account.map(|acct| option.take_as_response(acct))
|
.clicked()
|
||||||
} else {
|
.then(|| option.take_as_response(self.cur_account))
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn algo_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> {
|
fn algo_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> {
|
||||||
@@ -249,11 +247,9 @@ impl<'a> AddColumnView<'a> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let option = algo_option.option.clone();
|
let option = algo_option.option.clone();
|
||||||
if self.column_option_ui(ui, algo_option).clicked() {
|
self.column_option_ui(ui, algo_option)
|
||||||
self.cur_account.map(|acct| option.take_as_response(acct))
|
.clicked()
|
||||||
} else {
|
.then(|| option.take_as_response(self.cur_account))
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn individual_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> {
|
fn individual_ui(&mut self, ui: &mut Ui) -> Option<AddColumnResponse> {
|
||||||
@@ -261,7 +257,7 @@ impl<'a> AddColumnView<'a> {
|
|||||||
for column_option_data in self.get_individual_options() {
|
for column_option_data in self.get_individual_options() {
|
||||||
let option = column_option_data.option.clone();
|
let option = column_option_data.option.clone();
|
||||||
if self.column_option_ui(ui, column_option_data).clicked() {
|
if self.column_option_ui(ui, column_option_data).clicked() {
|
||||||
selected_option = self.cur_account.map(|acct| option.take_as_response(acct));
|
selected_option = Some(option.take_as_response(self.cur_account));
|
||||||
}
|
}
|
||||||
|
|
||||||
ui.add(Separator::default().spacing(0.0));
|
ui.add(Separator::default().spacing(0.0));
|
||||||
@@ -327,12 +323,9 @@ impl<'a> AddColumnView<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ui.add(add_column_button()).clicked() {
|
ui.add(add_column_button())
|
||||||
self.cur_account
|
.clicked()
|
||||||
.map(|acc| to_option(keypair.pubkey).take_as_response(acc))
|
.then(|| to_option(keypair.pubkey).take_as_response(self.cur_account))
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -453,20 +446,18 @@ impl<'a> AddColumnView<'a> {
|
|||||||
option: AddColumnOption::Universe,
|
option: AddColumnOption::Universe,
|
||||||
});
|
});
|
||||||
|
|
||||||
if let Some(acc) = self.cur_account {
|
let source = if self.cur_account.key.secret_key.is_some() {
|
||||||
let source = if acc.key.secret_key.is_some() {
|
PubkeySource::DeckAuthor
|
||||||
PubkeySource::DeckAuthor
|
} else {
|
||||||
} else {
|
PubkeySource::Explicit(self.cur_account.key.pubkey)
|
||||||
PubkeySource::Explicit(acc.key.pubkey)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
vec.push(ColumnOptionData {
|
vec.push(ColumnOptionData {
|
||||||
title: "Contacts",
|
title: "Contacts",
|
||||||
description: "See notes from your contacts",
|
description: "See notes from your contacts",
|
||||||
icon: app_images::home_image(),
|
icon: app_images::home_image(),
|
||||||
option: AddColumnOption::Contacts(source),
|
option: AddColumnOption::Contacts(source),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
vec.push(ColumnOptionData {
|
vec.push(ColumnOptionData {
|
||||||
title: "Notifications",
|
title: "Notifications",
|
||||||
description: "Stay up to date with notifications and mentions",
|
description: "Stay up to date with notifications and mentions",
|
||||||
@@ -498,20 +489,18 @@ impl<'a> AddColumnView<'a> {
|
|||||||
fn get_notifications_options(&self) -> Vec<ColumnOptionData> {
|
fn get_notifications_options(&self) -> Vec<ColumnOptionData> {
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
|
|
||||||
if let Some(acc) = self.cur_account {
|
let source = if self.cur_account.key.secret_key.is_some() {
|
||||||
let source = if acc.key.secret_key.is_some() {
|
PubkeySource::DeckAuthor
|
||||||
PubkeySource::DeckAuthor
|
} else {
|
||||||
} else {
|
PubkeySource::Explicit(self.cur_account.key.pubkey)
|
||||||
PubkeySource::Explicit(acc.key.pubkey)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
vec.push(ColumnOptionData {
|
vec.push(ColumnOptionData {
|
||||||
title: "Your Notifications",
|
title: "Your Notifications",
|
||||||
description: "Stay up to date with your notifications and mentions",
|
description: "Stay up to date with your notifications and mentions",
|
||||||
icon: app_images::notifications_image(),
|
icon: app_images::notifications_image(),
|
||||||
option: AddColumnOption::Notification(source),
|
option: AddColumnOption::Notification(source),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
vec.push(ColumnOptionData {
|
vec.push(ColumnOptionData {
|
||||||
title: "Someone else's Notifications",
|
title: "Someone else's Notifications",
|
||||||
@@ -526,20 +515,18 @@ impl<'a> AddColumnView<'a> {
|
|||||||
fn get_individual_options(&self) -> Vec<ColumnOptionData> {
|
fn get_individual_options(&self) -> Vec<ColumnOptionData> {
|
||||||
let mut vec = Vec::new();
|
let mut vec = Vec::new();
|
||||||
|
|
||||||
if let Some(acc) = self.cur_account {
|
let source = if self.cur_account.key.secret_key.is_some() {
|
||||||
let source = if acc.key.secret_key.is_some() {
|
PubkeySource::DeckAuthor
|
||||||
PubkeySource::DeckAuthor
|
} else {
|
||||||
} else {
|
PubkeySource::Explicit(self.cur_account.key.pubkey)
|
||||||
PubkeySource::Explicit(acc.key.pubkey)
|
};
|
||||||
};
|
|
||||||
|
|
||||||
vec.push(ColumnOptionData {
|
vec.push(ColumnOptionData {
|
||||||
title: "Your Notes",
|
title: "Your Notes",
|
||||||
description: "Keep track of your notes & replies",
|
description: "Keep track of your notes & replies",
|
||||||
icon: app_images::profile_image(),
|
icon: app_images::profile_image(),
|
||||||
option: AddColumnOption::Individual(source),
|
option: AddColumnOption::Individual(source),
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
vec.push(ColumnOptionData {
|
vec.push(ColumnOptionData {
|
||||||
title: "Someone else's Notes",
|
title: "Someone else's Notes",
|
||||||
@@ -605,13 +592,8 @@ pub fn render_add_column_routes(
|
|||||||
AddColumnRoute::Base => add_column_view.ui(ui),
|
AddColumnRoute::Base => add_column_view.ui(ui),
|
||||||
AddColumnRoute::Algo(r) => match r {
|
AddColumnRoute::Algo(r) => match r {
|
||||||
AddAlgoRoute::Base => add_column_view.algo_ui(ui),
|
AddAlgoRoute::Base => add_column_view.algo_ui(ui),
|
||||||
AddAlgoRoute::LastPerPubkey => {
|
AddAlgoRoute::LastPerPubkey => add_column_view
|
||||||
if let Some(deck_author) = ctx.accounts.get_selected_account() {
|
.algo_last_per_pk_ui(ui, ctx.accounts.get_selected_account().key.pubkey),
|
||||||
add_column_view.algo_last_per_pk_ui(ui, deck_author.key.pubkey)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
AddColumnRoute::UndecidedNotification => add_column_view.notifications_ui(ui),
|
AddColumnRoute::UndecidedNotification => add_column_view.notifications_ui(ui),
|
||||||
AddColumnRoute::ExternalNotification => add_column_view.external_notification_ui(ui),
|
AddColumnRoute::ExternalNotification => add_column_view.external_notification_ui(ui),
|
||||||
|
|||||||
@@ -115,10 +115,7 @@ impl<'a, 'd> ProfileView<'a, 'd> {
|
|||||||
&txn,
|
&txn,
|
||||||
self.is_muted,
|
self.is_muted,
|
||||||
self.note_context,
|
self.note_context,
|
||||||
&self
|
&(&self.accounts.get_selected_account().key).into(),
|
||||||
.accounts
|
|
||||||
.get_selected_account()
|
|
||||||
.map(|a| (&a.key).into()),
|
|
||||||
self.jobs,
|
self.jobs,
|
||||||
)
|
)
|
||||||
.show(ui)
|
.show(ui)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ pub struct SearchView<'a, 'd> {
|
|||||||
txn: &'a Transaction,
|
txn: &'a Transaction,
|
||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ impl<'a, 'd> SearchView<'a, 'd> {
|
|||||||
note_options: NoteOptions,
|
note_options: NoteOptions,
|
||||||
query: &'a mut SearchQueryState,
|
query: &'a mut SearchQueryState,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub static SIDE_PANEL_WIDTH: f32 = 68.0;
|
|||||||
static ICON_WIDTH: f32 = 40.0;
|
static ICON_WIDTH: f32 = 40.0;
|
||||||
|
|
||||||
pub struct DesktopSidePanel<'a> {
|
pub struct DesktopSidePanel<'a> {
|
||||||
selected_account: Option<&'a UserAccount>,
|
selected_account: &'a UserAccount,
|
||||||
decks_cache: &'a DecksCache,
|
decks_cache: &'a DecksCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ impl SidePanelResponse {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> DesktopSidePanel<'a> {
|
impl<'a> DesktopSidePanel<'a> {
|
||||||
pub fn new(selected_account: Option<&'a UserAccount>, decks_cache: &'a DecksCache) -> Self {
|
pub fn new(selected_account: &'a UserAccount, decks_cache: &'a DecksCache) -> Self {
|
||||||
Self {
|
Self {
|
||||||
selected_account,
|
selected_account,
|
||||||
decks_cache,
|
decks_cache,
|
||||||
@@ -92,9 +92,7 @@ impl<'a> DesktopSidePanel<'a> {
|
|||||||
// ui.add_space(24.0);
|
// ui.add_space(24.0);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
let is_interactive = self
|
let is_interactive = self.selected_account.key.secret_key.is_some();
|
||||||
.selected_account
|
|
||||||
.is_some_and(|s| s.key.secret_key.is_some());
|
|
||||||
let compose_resp = ui.add(crate::ui::post::compose_note_button(
|
let compose_resp = ui.add(crate::ui::post::compose_note_button(
|
||||||
is_interactive,
|
is_interactive,
|
||||||
dark_mode,
|
dark_mode,
|
||||||
@@ -388,14 +386,10 @@ fn add_deck_button() -> impl Widget {
|
|||||||
fn show_decks<'a>(
|
fn show_decks<'a>(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
decks_cache: &'a DecksCache,
|
decks_cache: &'a DecksCache,
|
||||||
selected_account: Option<&'a UserAccount>,
|
selected_account: &'a UserAccount,
|
||||||
) -> InnerResponse<Option<usize>> {
|
) -> InnerResponse<Option<usize>> {
|
||||||
let show_decks_id = ui.id().with("show-decks");
|
let show_decks_id = ui.id().with("show-decks");
|
||||||
let account_id = if let Some(acc) = selected_account {
|
let account_id = selected_account.key.pubkey;
|
||||||
acc.key.pubkey
|
|
||||||
} else {
|
|
||||||
*decks_cache.get_fallback_pubkey()
|
|
||||||
};
|
|
||||||
let (cur_decks, account_id) = (
|
let (cur_decks, account_id) = (
|
||||||
decks_cache.decks(&account_id),
|
decks_cache.decks(&account_id),
|
||||||
show_decks_id.with(account_id),
|
show_decks_id.with(account_id),
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ pub struct ThreadView<'a, 'd> {
|
|||||||
id_source: egui::Id,
|
id_source: egui::Id,
|
||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,7 +30,7 @@ impl<'a, 'd> ThreadView<'a, 'd> {
|
|||||||
note_options: NoteOptions,
|
note_options: NoteOptions,
|
||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let id_source = egui::Id::new("threadscroll_threadview");
|
let id_source = egui::Id::new("threadscroll_threadview");
|
||||||
@@ -135,10 +135,9 @@ impl<'a, 'd> ThreadView<'a, 'd> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let zapping_acc = self
|
let zapping_acc = self
|
||||||
.cur_acc
|
.note_context
|
||||||
.as_ref()
|
.current_account_has_wallet
|
||||||
.filter(|_| self.note_context.current_account_has_wallet)
|
.then_some(self.cur_acc);
|
||||||
.or(self.cur_acc.as_ref());
|
|
||||||
|
|
||||||
show_notes(
|
show_notes(
|
||||||
ui,
|
ui,
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ pub struct TimelineView<'a, 'd> {
|
|||||||
reverse: bool,
|
reverse: bool,
|
||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ impl<'a, 'd> TimelineView<'a, 'd> {
|
|||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
note_options: NoteOptions,
|
note_options: NoteOptions,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let reverse = false;
|
let reverse = false;
|
||||||
@@ -78,7 +78,7 @@ fn timeline_ui(
|
|||||||
note_options: NoteOptions,
|
note_options: NoteOptions,
|
||||||
is_muted: &MuteFun,
|
is_muted: &MuteFun,
|
||||||
note_context: &mut NoteContext,
|
note_context: &mut NoteContext,
|
||||||
cur_acc: &Option<KeypairUnowned>,
|
cur_acc: &KeypairUnowned,
|
||||||
jobs: &mut JobsCache,
|
jobs: &mut JobsCache,
|
||||||
) -> Option<NoteAction> {
|
) -> Option<NoteAction> {
|
||||||
//padding(4.0, ui, |ui| ui.heading("Notifications"));
|
//padding(4.0, ui, |ui| ui.heading("Notifications"));
|
||||||
@@ -337,7 +337,7 @@ pub struct TimelineTabView<'a, 'd> {
|
|||||||
txn: &'a Transaction,
|
txn: &'a Transaction,
|
||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
|
|||||||
txn: &'a Transaction,
|
txn: &'a Transaction,
|
||||||
is_muted: &'a MuteFun,
|
is_muted: &'a MuteFun,
|
||||||
note_context: &'a mut NoteContext<'d>,
|
note_context: &'a mut NoteContext<'d>,
|
||||||
cur_acc: &'a Option<KeypairUnowned<'a>>,
|
cur_acc: &'a KeypairUnowned<'a>,
|
||||||
jobs: &'a mut JobsCache,
|
jobs: &'a mut JobsCache,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
@@ -407,11 +407,11 @@ impl<'a, 'd> TimelineTabView<'a, 'd> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if !muted {
|
if !muted {
|
||||||
let zapping_acc = self
|
let zapping_acc = if self.note_context.current_account_has_wallet {
|
||||||
.cur_acc
|
Some(self.cur_acc)
|
||||||
.as_ref()
|
} else {
|
||||||
.filter(|_| self.note_context.current_account_has_wallet)
|
None
|
||||||
.or(self.cur_acc.as_ref());
|
};
|
||||||
|
|
||||||
notedeck_ui::padding(8.0, ui, |ui| {
|
notedeck_ui::padding(8.0, ui, |ui| {
|
||||||
let resp = NoteView::new(
|
let resp = NoteView::new(
|
||||||
|
|||||||
@@ -92,13 +92,11 @@ impl WalletAction {
|
|||||||
global_wallet.ui_state.for_local_only = true;
|
global_wallet.ui_state.for_local_only = true;
|
||||||
}
|
}
|
||||||
WalletAction::Delete => {
|
WalletAction::Delete => {
|
||||||
if let Some(acc) = accounts.get_selected_account() {
|
if accounts.get_selected_account().wallet.is_some() {
|
||||||
if acc.wallet.is_some() {
|
accounts.update_current_account(|acc| {
|
||||||
accounts.update_current_account(|acc| {
|
acc.wallet = None;
|
||||||
acc.wallet = None;
|
});
|
||||||
});
|
return None;
|
||||||
return None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
global_wallet.wallet = None;
|
global_wallet.wallet = None;
|
||||||
|
|||||||
@@ -209,11 +209,7 @@ You are an AI agent for the nostr protocol called Dave, created by Damus. nostr
|
|||||||
};
|
};
|
||||||
tracing::debug!("sending messages, latest: {:?}", messages.last().unwrap());
|
tracing::debug!("sending messages, latest: {:?}", messages.last().unwrap());
|
||||||
|
|
||||||
let user_id = app_ctx
|
let user_id = calculate_user_id(app_ctx.accounts.get_selected_account().keypair());
|
||||||
.accounts
|
|
||||||
.get_selected_account()
|
|
||||||
.map(|sa| calculate_user_id(sa.keypair()))
|
|
||||||
.unwrap_or_else(|| "unknown_user".to_string());
|
|
||||||
|
|
||||||
let ctx = ctx.clone();
|
let ctx = ctx.clone();
|
||||||
let client = self.client.clone();
|
let client = self.client.clone();
|
||||||
|
|||||||
@@ -497,7 +497,9 @@ fn pfp_button<'me, 'a>(
|
|||||||
ndb: &Ndb,
|
ndb: &Ndb,
|
||||||
) -> ProfilePic<'me, 'a> {
|
) -> ProfilePic<'me, 'a> {
|
||||||
let account = accounts.get_selected_account();
|
let account = accounts.get_selected_account();
|
||||||
let profile = account.and_then(|a| ndb.get_profile_by_pubkey(txn, a.key.pubkey.bytes()).ok());
|
let profile = ndb
|
||||||
|
.get_profile_by_pubkey(txn, account.key.pubkey.bytes())
|
||||||
|
.ok();
|
||||||
|
|
||||||
ProfilePic::from_profile_or_default(img_cache, profile.as_ref())
|
ProfilePic::from_profile_or_default(img_cache, profile.as_ref())
|
||||||
.size(24.0)
|
.size(24.0)
|
||||||
|
|||||||
Reference in New Issue
Block a user