mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 17:14:21 +01:00
Merge remote-tracking branch 'github/pr/1023'
This commit is contained in:
@@ -207,6 +207,10 @@ impl Accounts {
|
|||||||
self.cache.selected_mut()
|
self.cache.selected_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_selected_wallet(&self) -> Option<&ZapWallet> {
|
||||||
|
self.cache.selected().wallet.as_ref()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn get_selected_wallet_mut(&mut self) -> Option<&mut ZapWallet> {
|
pub fn get_selected_wallet_mut(&mut self) -> Option<&mut ZapWallet> {
|
||||||
self.cache.selected_mut().wallet.as_mut()
|
self.cache.selected_mut().wallet.as_mut()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,8 +72,8 @@ pub use unknowns::{get_unknown_note_ids, NoteRefsUnkIdAction, SingleUnkIdAction,
|
|||||||
pub use urls::{supported_mime_hosted_at_url, SupportedMimeType, UrlMimes};
|
pub use urls::{supported_mime_hosted_at_url, SupportedMimeType, UrlMimes};
|
||||||
pub use user_account::UserAccount;
|
pub use user_account::UserAccount;
|
||||||
pub use wallet::{
|
pub use wallet::{
|
||||||
get_current_wallet, get_wallet_for, GlobalWallet, Wallet, WalletError, WalletType,
|
get_current_wallet, get_current_wallet_mut, get_wallet_for, GlobalWallet, Wallet, WalletError,
|
||||||
WalletUIState, ZapWallet,
|
WalletType, WalletUIState, ZapWallet,
|
||||||
};
|
};
|
||||||
pub use zaps::{
|
pub use zaps::{
|
||||||
get_current_default_msats, AnyZapState, DefaultZapError, DefaultZapMsats, NoteZapTarget,
|
get_current_default_msats, AnyZapState, DefaultZapError, DefaultZapMsats, NoteZapTarget,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ pub use action::{MediaAction, NoteAction, ScrollInfo, ZapAction, ZapTargetAmount
|
|||||||
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
|
pub use context::{BroadcastContext, ContextSelection, NoteContextSelection};
|
||||||
|
|
||||||
use crate::Accounts;
|
use crate::Accounts;
|
||||||
|
use crate::GlobalWallet;
|
||||||
use crate::JobPool;
|
use crate::JobPool;
|
||||||
use crate::Localization;
|
use crate::Localization;
|
||||||
use crate::UnknownIds;
|
use crate::UnknownIds;
|
||||||
@@ -20,6 +21,7 @@ use std::fmt;
|
|||||||
pub struct NoteContext<'d> {
|
pub struct NoteContext<'d> {
|
||||||
pub ndb: &'d Ndb,
|
pub ndb: &'d Ndb,
|
||||||
pub accounts: &'d Accounts,
|
pub accounts: &'d Accounts,
|
||||||
|
pub global_wallet: &'d GlobalWallet,
|
||||||
pub i18n: &'d mut Localization,
|
pub i18n: &'d mut Localization,
|
||||||
pub img_cache: &'d mut Images,
|
pub img_cache: &'d mut Images,
|
||||||
pub note_cache: &'d mut NoteCache,
|
pub note_cache: &'d mut NoteCache,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub fn get_wallet_for<'a>(
|
|||||||
global_wallet.wallet.as_ref()
|
global_wallet.wallet.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_current_wallet<'a>(
|
pub fn get_current_wallet_mut<'a>(
|
||||||
accounts: &'a mut Accounts,
|
accounts: &'a mut Accounts,
|
||||||
global_wallet: &'a mut GlobalWallet,
|
global_wallet: &'a mut GlobalWallet,
|
||||||
) -> Option<&'a mut ZapWallet> {
|
) -> Option<&'a mut ZapWallet> {
|
||||||
@@ -35,6 +35,17 @@ pub fn get_current_wallet<'a>(
|
|||||||
Some(wallet)
|
Some(wallet)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_current_wallet<'a>(
|
||||||
|
accounts: &'a Accounts,
|
||||||
|
global_wallet: &'a GlobalWallet,
|
||||||
|
) -> Option<&'a ZapWallet> {
|
||||||
|
let Some(wallet) = accounts.get_selected_wallet() else {
|
||||||
|
return global_wallet.wallet.as_ref();
|
||||||
|
};
|
||||||
|
|
||||||
|
Some(wallet)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Eq, PartialEq, Debug)]
|
#[derive(Clone, Eq, PartialEq, Debug)]
|
||||||
pub enum WalletType {
|
pub enum WalletType {
|
||||||
Auto,
|
Auto,
|
||||||
|
|||||||
@@ -520,6 +520,7 @@ fn render_nav_body(
|
|||||||
unknown_ids: ctx.unknown_ids,
|
unknown_ids: ctx.unknown_ids,
|
||||||
clipboard: ctx.clipboard,
|
clipboard: ctx.clipboard,
|
||||||
i18n: ctx.i18n,
|
i18n: ctx.i18n,
|
||||||
|
global_wallet: ctx.global_wallet,
|
||||||
};
|
};
|
||||||
match top {
|
match top {
|
||||||
Route::Timeline(kind) => {
|
Route::Timeline(kind) => {
|
||||||
|
|||||||
@@ -802,6 +802,7 @@ mod preview {
|
|||||||
let mut note_context = NoteContext {
|
let mut note_context = NoteContext {
|
||||||
ndb: app.ndb,
|
ndb: app.ndb,
|
||||||
accounts: app.accounts,
|
accounts: app.accounts,
|
||||||
|
global_wallet: app.global_wallet,
|
||||||
img_cache: app.img_cache,
|
img_cache: app.img_cache,
|
||||||
note_cache: app.note_cache,
|
note_cache: app.note_cache,
|
||||||
zaps: app.zaps,
|
zaps: app.zaps,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
use egui::{vec2, CornerRadius, Layout};
|
use egui::{vec2, CornerRadius, Layout};
|
||||||
use notedeck::{
|
use notedeck::{
|
||||||
get_current_wallet, tr, Accounts, DefaultZapMsats, GlobalWallet, Localization,
|
get_current_wallet_mut, tr, Accounts, DefaultZapMsats, GlobalWallet, Localization,
|
||||||
NotedeckTextStyle, PendingDefaultZapState, Wallet, WalletError, WalletUIState, ZapWallet,
|
NotedeckTextStyle, PendingDefaultZapState, Wallet, WalletError, WalletUIState, ZapWallet,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ impl WalletAction {
|
|||||||
}
|
}
|
||||||
WalletAction::SetDefaultZapSats(new_default) => 's: {
|
WalletAction::SetDefaultZapSats(new_default) => 's: {
|
||||||
let sats = {
|
let sats = {
|
||||||
let Some(wallet) = get_current_wallet(accounts, global_wallet) else {
|
let Some(wallet) = get_current_wallet_mut(accounts, global_wallet) else {
|
||||||
break 's;
|
break 's;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ impl WalletAction {
|
|||||||
global_wallet.save_wallet();
|
global_wallet.save_wallet();
|
||||||
}
|
}
|
||||||
WalletAction::EditDefaultZaps => 's: {
|
WalletAction::EditDefaultZaps => 's: {
|
||||||
let Some(wallet) = get_current_wallet(accounts, global_wallet) else {
|
let Some(wallet) = get_current_wallet_mut(accounts, global_wallet) else {
|
||||||
break 's;
|
break 's;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -220,6 +220,7 @@ impl<'a> DaveUi<'a> {
|
|||||||
unknown_ids: ctx.unknown_ids,
|
unknown_ids: ctx.unknown_ids,
|
||||||
clipboard: ctx.clipboard,
|
clipboard: ctx.clipboard,
|
||||||
i18n: ctx.i18n,
|
i18n: ctx.i18n,
|
||||||
|
global_wallet: ctx.global_wallet,
|
||||||
};
|
};
|
||||||
|
|
||||||
let txn = Transaction::new(note_context.ndb).unwrap();
|
let txn = Transaction::new(note_context.ndb).unwrap();
|
||||||
|
|||||||
@@ -20,8 +20,13 @@ pub fn hover_expand(
|
|||||||
(rect, size, response)
|
(rect, size, response)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn hover_small_size() -> f32 {
|
||||||
|
14.0
|
||||||
|
}
|
||||||
|
|
||||||
pub fn hover_expand_small(ui: &mut egui::Ui, id: egui::Id) -> (egui::Rect, f32, egui::Response) {
|
pub fn hover_expand_small(ui: &mut egui::Ui, id: egui::Id) -> (egui::Rect, f32, egui::Response) {
|
||||||
let size = 10.0;
|
let size = hover_small_size();
|
||||||
let expand_size = 5.0;
|
let expand_size = 5.0;
|
||||||
let anim_speed = 0.05;
|
let anim_speed = 0.05;
|
||||||
|
|
||||||
|
|||||||
@@ -13,9 +13,12 @@ use crate::{
|
|||||||
|
|
||||||
pub use contents::{render_note_contents, render_note_preview, NoteContents};
|
pub use contents::{render_note_contents, render_note_preview, NoteContents};
|
||||||
pub use context::NoteContextButton;
|
pub use context::NoteContextButton;
|
||||||
|
use notedeck::get_current_wallet;
|
||||||
use notedeck::note::MediaAction;
|
use notedeck::note::MediaAction;
|
||||||
use notedeck::note::ZapTargetAmount;
|
use notedeck::note::ZapTargetAmount;
|
||||||
use notedeck::ui::is_narrow;
|
use notedeck::ui::is_narrow;
|
||||||
|
use notedeck::Accounts;
|
||||||
|
use notedeck::GlobalWallet;
|
||||||
use notedeck::Images;
|
use notedeck::Images;
|
||||||
use notedeck::Localization;
|
use notedeck::Localization;
|
||||||
pub use options::NoteOptions;
|
pub use options::NoteOptions;
|
||||||
@@ -451,18 +454,13 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
note_action = contents.action.or(note_action);
|
note_action = contents.action.or(note_action);
|
||||||
|
|
||||||
if self.options().contains(NoteOptions::ActionBar) {
|
if self.options().contains(NoteOptions::ActionBar) {
|
||||||
let zapper = {
|
|
||||||
let cur_acc = self.note_context.accounts.get_selected_account();
|
|
||||||
let has_wallet = cur_acc.wallet.is_some();
|
|
||||||
|
|
||||||
has_wallet.then_some(Zapper {
|
|
||||||
zaps: self.note_context.zaps,
|
|
||||||
cur_acc: cur_acc.keypair(),
|
|
||||||
})
|
|
||||||
};
|
|
||||||
note_action = render_note_actionbar(
|
note_action = render_note_actionbar(
|
||||||
ui,
|
ui,
|
||||||
zapper,
|
get_zapper(
|
||||||
|
self.note_context.accounts,
|
||||||
|
self.note_context.global_wallet,
|
||||||
|
self.note_context.zaps,
|
||||||
|
),
|
||||||
self.note.id(),
|
self.note.id(),
|
||||||
self.note.pubkey(),
|
self.note.pubkey(),
|
||||||
note_key,
|
note_key,
|
||||||
@@ -531,20 +529,14 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
|
|
||||||
note_action = contents.action.or(note_action);
|
note_action = contents.action.or(note_action);
|
||||||
|
|
||||||
let zapper = {
|
|
||||||
let cur_acc = self.note_context.accounts.get_selected_account();
|
|
||||||
let has_wallet = cur_acc.wallet.is_some();
|
|
||||||
|
|
||||||
has_wallet.then_some(Zapper {
|
|
||||||
zaps: self.note_context.zaps,
|
|
||||||
cur_acc: cur_acc.keypair(),
|
|
||||||
})
|
|
||||||
};
|
|
||||||
|
|
||||||
if self.options().contains(NoteOptions::ActionBar) {
|
if self.options().contains(NoteOptions::ActionBar) {
|
||||||
note_action = render_note_actionbar(
|
note_action = render_note_actionbar(
|
||||||
ui,
|
ui,
|
||||||
zapper,
|
get_zapper(
|
||||||
|
self.note_context.accounts,
|
||||||
|
self.note_context.global_wallet,
|
||||||
|
self.note_context.zaps,
|
||||||
|
),
|
||||||
self.note.id(),
|
self.note.id(),
|
||||||
self.note.pubkey(),
|
self.note.pubkey(),
|
||||||
note_key,
|
note_key,
|
||||||
@@ -611,6 +603,20 @@ impl<'a, 'd> NoteView<'a, 'd> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_zapper<'a>(
|
||||||
|
accounts: &'a Accounts,
|
||||||
|
global_wallet: &'a GlobalWallet,
|
||||||
|
zaps: &'a Zaps,
|
||||||
|
) -> Option<Zapper<'a>> {
|
||||||
|
let has_wallet = get_current_wallet(accounts, global_wallet).is_some();
|
||||||
|
let cur_acc = accounts.get_selected_account();
|
||||||
|
|
||||||
|
has_wallet.then_some(Zapper {
|
||||||
|
zaps,
|
||||||
|
cur_acc: cur_acc.keypair(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a Transaction, note: &Note) -> Option<Note<'a>> {
|
fn get_reposted_note<'a>(ndb: &Ndb, txn: &'a Transaction, note: &Note) -> Option<Note<'a>> {
|
||||||
if note.kind() != 6 {
|
if note.kind() != 6 {
|
||||||
return None;
|
return None;
|
||||||
@@ -769,15 +775,19 @@ struct Zapper<'a> {
|
|||||||
#[profiling::function]
|
#[profiling::function]
|
||||||
fn render_note_actionbar(
|
fn render_note_actionbar(
|
||||||
ui: &mut egui::Ui,
|
ui: &mut egui::Ui,
|
||||||
zapper: Option<Zapper>,
|
zapper: Option<Zapper<'_>>,
|
||||||
note_id: &[u8; 32],
|
note_id: &[u8; 32],
|
||||||
note_pubkey: &[u8; 32],
|
note_pubkey: &[u8; 32],
|
||||||
note_key: NoteKey,
|
note_key: NoteKey,
|
||||||
i18n: &mut Localization,
|
i18n: &mut Localization,
|
||||||
) -> egui::InnerResponse<Option<NoteAction>> {
|
) -> egui::InnerResponse<Option<NoteAction>> {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
ui.set_min_height(26.0);
|
||||||
|
ui.spacing_mut().item_spacing.x = 24.0;
|
||||||
|
|
||||||
let reply_resp =
|
let reply_resp =
|
||||||
reply_button(ui, i18n, note_key).on_hover_cursor(egui::CursorIcon::PointingHand);
|
reply_button(ui, i18n, note_key).on_hover_cursor(egui::CursorIcon::PointingHand);
|
||||||
|
|
||||||
let quote_resp =
|
let quote_resp =
|
||||||
quote_repost_button(ui, i18n, note_key).on_hover_cursor(egui::CursorIcon::PointingHand);
|
quote_repost_button(ui, i18n, note_key).on_hover_cursor(egui::CursorIcon::PointingHand);
|
||||||
|
|
||||||
@@ -893,7 +903,7 @@ fn quote_repost_button(
|
|||||||
i18n: &mut Localization,
|
i18n: &mut Localization,
|
||||||
note_key: NoteKey,
|
note_key: NoteKey,
|
||||||
) -> egui::Response {
|
) -> egui::Response {
|
||||||
let size = 14.0;
|
let size = crate::anim::hover_small_size() + 4.0;
|
||||||
let expand_size = 5.0;
|
let expand_size = 5.0;
|
||||||
let anim_speed = 0.05;
|
let anim_speed = 0.05;
|
||||||
let id = ui.id().with(("repost_anim", note_key));
|
let id = ui.id().with(("repost_anim", note_key));
|
||||||
|
|||||||
Reference in New Issue
Block a user