refactor Manager.account

This commit is contained in:
nworbnhoj 2023-11-06 09:28:13 +13:00
parent f51f781c3b
commit 1cbe0c7488
2 changed files with 12 additions and 14 deletions

View file

@ -23,8 +23,8 @@ pub const HOSTED_MODE: bool = false;
//#[derive(Debug)] //#[derive(Debug)]
pub struct SigChat<'a> { pub struct SigChat<'a> {
account: Option<Account>,
chat: &'a Chat, chat: &'a Chat,
manager: Option<Manager>,
netmgr: net::NetManager, netmgr: net::NetManager,
modals: Modals, modals: Modals,
} }
@ -35,8 +35,11 @@ impl<'a> SigChat<'a> {
let pddb = pddb::Pddb::new(); let pddb = pddb::Pddb::new();
pddb.try_mount(); pddb.try_mount();
SigChat { SigChat {
account: Account::read(SIGCHAT_ACCOUNT).ok(),
chat: chat, chat: chat,
manager: match Account::read(SIGCHAT_ACCOUNT) {
Ok(account) => Some(Manager::new(account, TrustMode::OnFirstUse)),
Err(_) => None,
},
netmgr: net::NetManager::new(), netmgr: net::NetManager::new(),
modals: modals, modals: modals,
} }
@ -47,16 +50,11 @@ impl<'a> SigChat<'a> {
pub fn connect(&mut self) -> bool { pub fn connect(&mut self) -> bool {
log::info!("Attempting connect to Signal server"); log::info!("Attempting connect to Signal server");
if self.wifi() { if self.wifi() {
if self.account.is_none() { if self.manager.is_none() {
self.account_setup(); self.account_setup();
} }
if let Some(account) = &self.account { if let Some(manager) = &self.manager {
log::info!( log::info!("Signal manager OK" );
"Signal account OK: {}: {}",
self.account.is_some(),
self.account.as_ref().unwrap().number()
);
let _manager = Manager::new(&account, TrustMode::OnFirstUse);
} else { } else {
self.modals self.modals
.show_notification(t!("sigchat.account.failed", locales::LANG), None) .show_notification(t!("sigchat.account.failed", locales::LANG), None)

View file

@ -13,22 +13,22 @@ pub use trust_mode::TrustMode;
// see signal-cli Manual Page - https://github.com/AsamK/signal-cli/blob/master/man/signal-cli.1.adoc // see signal-cli Manual Page - https://github.com/AsamK/signal-cli/blob/master/man/signal-cli.1.adoc
#[allow(dead_code)] #[allow(dead_code)]
pub struct Manager<'a> { pub struct Manager {
account: &'a Account, account:Account,
trust_mode: TrustMode, trust_mode: TrustMode,
log_verbose: bool, log_verbose: bool,
log_scrub: bool, log_scrub: bool,
log_send: bool, log_send: bool,
} }
impl <'a> Manager<'a> { impl Manager {
/// Create a new Signal account /// Create a new Signal account
/// ///
/// # Arguments /// # Arguments
/// * `live` - Specify the server environment /// * `live` - Specify the server environment
/// * `account` - Specify your phone number, that will be your identifier. The phone number must include the country calling code, i.e. the number must start with a "+" sign. /// * `account` - Specify your phone number, that will be your identifier. The phone number must include the country calling code, i.e. the number must start with a "+" sign.
/// ///
pub fn new(account: &Account, trust_mode: TrustMode) -> Manager { pub fn new(account: Account, trust_mode: TrustMode) -> Manager {
Manager { Manager {
account, account,
trust_mode, trust_mode,