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)]
pub struct SigChat<'a> {
account: Option<Account>,
chat: &'a Chat,
manager: Option<Manager>,
netmgr: net::NetManager,
modals: Modals,
}
@ -35,8 +35,11 @@ impl<'a> SigChat<'a> {
let pddb = pddb::Pddb::new();
pddb.try_mount();
SigChat {
account: Account::read(SIGCHAT_ACCOUNT).ok(),
chat: chat,
manager: match Account::read(SIGCHAT_ACCOUNT) {
Ok(account) => Some(Manager::new(account, TrustMode::OnFirstUse)),
Err(_) => None,
},
netmgr: net::NetManager::new(),
modals: modals,
}
@ -47,16 +50,11 @@ impl<'a> SigChat<'a> {
pub fn connect(&mut self) -> bool {
log::info!("Attempting connect to Signal server");
if self.wifi() {
if self.account.is_none() {
if self.manager.is_none() {
self.account_setup();
}
if let Some(account) = &self.account {
log::info!(
"Signal account OK: {}: {}",
self.account.is_some(),
self.account.as_ref().unwrap().number()
);
let _manager = Manager::new(&account, TrustMode::OnFirstUse);
if let Some(manager) = &self.manager {
log::info!("Signal manager OK" );
} else {
self.modals
.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
#[allow(dead_code)]
pub struct Manager<'a> {
account: &'a Account,
pub struct Manager {
account:Account,
trust_mode: TrustMode,
log_verbose: bool,
log_scrub: bool,
log_send: bool,
}
impl <'a> Manager<'a> {
impl Manager {
/// Create a new Signal account
///
/// # Arguments
/// * `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.
///
pub fn new(account: &Account, trust_mode: TrustMode) -> Manager {
pub fn new(account: Account, trust_mode: TrustMode) -> Manager {
Manager {
account,
trust_mode,