From 34b0ae2747de968a32786c22ebcb1c1fa82fadea Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Wed, 2 Jun 2021 17:13:42 +0100 Subject: [PATCH] accounts: Allow otter prep_access_account to never update it Signed-off-by: Ian Jackson --- src/bin/otter.rs | 10 +++++++--- src/commands.rs | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/bin/otter.rs b/src/bin/otter.rs index c74e3b69..e43cfb50 100644 --- a/src/bin/otter.rs +++ b/src/bin/otter.rs @@ -120,7 +120,7 @@ impl MainOpts { #[throws(AE)] fn access_account(&self) -> Conn { let mut conn = connect(self)?; - conn.prep_access_account(self)?; + conn.prep_access_account(self, true)?; conn } @@ -566,7 +566,8 @@ deref_to_field_mut!{Conn, MgmtChannel, chan} impl Conn { #[throws(AE)] - fn prep_access_account(&mut self, ma: &MainOpts) { + fn prep_access_account(&mut self, ma: &MainOpts, + maybe_update_account: bool) { #[derive(Debug)] struct Wantup(bool); impl Wantup { @@ -576,12 +577,15 @@ impl Conn { } } let mut wantup = Wantup(false); - let mut ad = AccountDetails { + + let mut ad = if maybe_update_account { AccountDetails { account: ma.account.clone(), nick: wantup.u(&ma.nick), timezone: wantup.u(&ma.timezone), layout: wantup.u(&ma.layout), access: wantup.u(&ma.access).map(Into::into), + } } else { + AccountDetails::default(ma.account.clone()) }; fn is_no_account(r: &Result) -> bool { diff --git a/src/commands.rs b/src/commands.rs index d4e4d23f..83e59c36 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -280,6 +280,13 @@ pub enum MgmtError { #[error("command forbides account specified")] AccountSpecified, } +impl AccountDetails { + pub fn default(account: AccountName) -> AccountDetails { AccountDetails { + account, + nick: None, timezone: None, layout: None, access: None, + } } +} + impl From for MgmtError { fn from(e: InternalError) -> MgmtError { MgmtError::ServerFailure(format!("internal error: {}", &e)) -- 2.30.2