commit 4aaec4219bd37972b3479895cbb7f13cf70e5f48
parent fa052966da28a926227a6f97f9e715b088b773b3
Author: Martti Malmi <sirius@iki.fi>
Date: Wed, 5 Nov 2025 12:02:26 +0200
add view as to profile dropdown menu
Changelog-Added: Add "View As User" on profiles
Diffstat:
5 files changed, 60 insertions(+), 8 deletions(-)
diff --git a/crates/notedeck/src/profile/context.rs b/crates/notedeck/src/profile/context.rs
@@ -2,6 +2,7 @@ use enostr::Pubkey;
pub enum ProfileContextSelection {
CopyLink,
+ ViewAs,
}
pub struct ProfileContext {
@@ -11,10 +12,17 @@ pub struct ProfileContext {
impl ProfileContextSelection {
pub fn process(&self, ctx: &egui::Context, pk: &Pubkey) {
- let Some(npub) = pk.npub() else {
- return;
- };
+ match self {
+ ProfileContextSelection::CopyLink => {
+ let Some(npub) = pk.npub() else {
+ return;
+ };
- ctx.copy_text(format!("https://damus.io/{npub}"));
+ ctx.copy_text(format!("https://damus.io/{npub}"));
+ }
+ ProfileContextSelection::ViewAs => {
+ // handled separately in profile.rs
+ }
+ }
}
}
diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs
@@ -741,6 +741,21 @@ fn render_damus_mobile(
ProcessNavResult::PfpClicked => {
app_action = Some(AppAction::ToggleChrome);
}
+
+ ProcessNavResult::SwitchAccount(pubkey) => {
+ // Add as pubkey-only account if not already present
+ let kp = enostr::Keypair::only_pubkey(*pubkey);
+ let _ = app_ctx.accounts.add_account(kp);
+
+ let txn = nostrdb::Transaction::new(app_ctx.ndb).expect("txn");
+ app_ctx.accounts.select_account(
+ pubkey,
+ app_ctx.ndb,
+ &txn,
+ app_ctx.pool,
+ ui.ctx(),
+ );
+ }
}
}
}
@@ -993,6 +1008,16 @@ fn timelines_view(
ProcessNavResult::PfpClicked => {
app_action = Some(AppAction::ToggleChrome);
}
+
+ ProcessNavResult::SwitchAccount(pubkey) => {
+ // Add as pubkey-only account if not already present
+ let kp = enostr::Keypair::only_pubkey(*pubkey);
+ let _ = ctx.accounts.add_account(kp);
+
+ let txn = nostrdb::Transaction::new(ctx.ndb).expect("txn");
+ ctx.accounts
+ .select_account(pubkey, ctx.ndb, &txn, ctx.pool, ui.ctx());
+ }
}
}
}
diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs
@@ -49,6 +49,7 @@ use tracing::error;
pub enum ProcessNavResult {
SwitchOccurred,
PfpClicked,
+ SwitchAccount(enostr::Pubkey),
}
impl ProcessNavResult {
@@ -415,6 +416,7 @@ pub enum RouterAction {
route: Route,
make_new: bool,
},
+ SwitchAccount(enostr::Pubkey),
}
pub enum RouterType {
@@ -480,6 +482,7 @@ impl RouterAction {
sheet_router.after_action = Some(route);
None
}
+ RouterAction::SwitchAccount(pubkey) => Some(ProcessNavResult::SwitchAccount(pubkey)),
}
}
diff --git a/crates/notedeck_columns/src/profile.rs b/crates/notedeck_columns/src/profile.rs
@@ -80,10 +80,18 @@ impl ProfileAction {
None
}
ProfileAction::Context(profile_context) => {
- profile_context
- .selection
- .process(ctx, &profile_context.profile);
- None
+ use notedeck::ProfileContextSelection;
+ match &profile_context.selection {
+ ProfileContextSelection::ViewAs => {
+ Some(RouterAction::SwitchAccount(profile_context.profile))
+ }
+ _ => {
+ profile_context
+ .selection
+ .process(ctx, &profile_context.profile);
+ None
+ }
+ }
}
}
}
diff --git a/crates/notedeck_ui/src/profile/context.rs b/crates/notedeck_ui/src/profile/context.rs
@@ -35,6 +35,14 @@ impl ProfileContextWidget {
ui.set_max_width(100.0);
if ui
+ .button(tr!(i18n, "View as", "Switch active user to this profile"))
+ .clicked()
+ {
+ context_selection = Some(ProfileContextSelection::ViewAs);
+ ui.close_menu();
+ }
+
+ if ui
.button(tr!(
i18n,
"Copy Link",