mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
refine Sigchat::connect() to link/register on first use
This commit is contained in:
parent
404dc29fec
commit
b032a80a18
2 changed files with 40 additions and 23 deletions
|
|
@ -7,6 +7,14 @@
|
||||||
"en": "Link to an existing Signal Account",
|
"en": "Link to an existing Signal Account",
|
||||||
"en-tts": "Link to an existing Signal Account"
|
"en-tts": "Link to an existing Signal Account"
|
||||||
},
|
},
|
||||||
|
"sigchat.account.link.name": {
|
||||||
|
"en": "Please provide a name for this device",
|
||||||
|
"en-tts": "Please provide a name for this device"
|
||||||
|
},
|
||||||
|
"sigchat.account.link.scan": {
|
||||||
|
"en": "Please scan with primary Signal device",
|
||||||
|
"en-tts": "Please scan with primary Signal device"
|
||||||
|
},
|
||||||
"sigchat.account.register": {
|
"sigchat.account.register": {
|
||||||
"en": "Register a new Signal Account",
|
"en": "Register a new Signal Account",
|
||||||
"en-tts": "Register a new Signal Account"
|
"en-tts": "Register a new Signal Account"
|
||||||
|
|
|
||||||
|
|
@ -47,31 +47,33 @@ impl<'a> SigChat<'a> {
|
||||||
|
|
||||||
/// Connect to the Signal servers
|
/// Connect to the Signal servers
|
||||||
///
|
///
|
||||||
pub fn connect(&mut self) -> bool {
|
pub fn connect(&mut self) -> Result<bool, Error> {
|
||||||
log::info!("Attempting connect to Signal server");
|
log::info!("Attempting connect to Signal server");
|
||||||
if self.wifi() {
|
if self.wifi() {
|
||||||
if self.manager.is_none() {
|
if self.manager.is_none() {
|
||||||
self.account_setup();
|
log::info!("Setting up Signal Account Manager");
|
||||||
|
let account = match Account::read(SIGCHAT_ACCOUNT) {
|
||||||
|
Ok(account) => account,
|
||||||
|
Err(e) => self.account_setup()?,
|
||||||
|
};
|
||||||
|
self.manager = Some(Manager::new(account, TrustMode::OnFirstUse));
|
||||||
|
}
|
||||||
|
if let Some(manager) = &self.manager {
|
||||||
|
log::info!("Signal Account Manager OK");
|
||||||
}
|
}
|
||||||
if let Some(_manager) = &self.manager {
|
|
||||||
log::info!("Signal manager OK" );
|
|
||||||
} else {
|
|
||||||
self.modals
|
|
||||||
.show_notification(t!("sigchat.account.failed", locales::LANG), None)
|
|
||||||
.expect("notification failed");
|
|
||||||
};
|
|
||||||
} else {
|
} else {
|
||||||
self.modals
|
self.modals
|
||||||
.show_notification(t!("sigchat.wifi.warning", locales::LANG), None)
|
.show_notification(t!("sigchat.wifi.warning", locales::LANG), None)
|
||||||
.expect("notification failed");
|
.expect("notification failed");
|
||||||
}
|
}
|
||||||
self.dialogue_set(None);
|
self.dialogue_set(None);
|
||||||
false
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Setup a Signal Account via Registration or Linking
|
/// Setup a Signal Account via Registration or Linking
|
||||||
///
|
///
|
||||||
fn account_setup(&mut self) {
|
fn account_setup(&mut self) -> Result<Account, Error> {
|
||||||
|
log::info!("Attempting to setup a Signal Account");
|
||||||
self.modals
|
self.modals
|
||||||
.add_list_item(t!("sigchat.account.link", locales::LANG))
|
.add_list_item(t!("sigchat.account.link", locales::LANG))
|
||||||
.expect("failed add list item");
|
.expect("failed add list item");
|
||||||
|
|
@ -83,11 +85,18 @@ impl<'a> SigChat<'a> {
|
||||||
.expect("failed radiobutton modal");
|
.expect("failed radiobutton modal");
|
||||||
match self.modals.get_radio_index() {
|
match self.modals.get_radio_index() {
|
||||||
Ok(index) => match index {
|
Ok(index) => match index {
|
||||||
0 => self.account_link(),
|
0 => Ok(self.account_link()?),
|
||||||
1 => self.account_register(),
|
1 => Ok(self.account_register()?),
|
||||||
_ => log::warn!("invalid index"),
|
|
||||||
|
_ => {
|
||||||
|
log::warn!("invalid index");
|
||||||
|
Err(Error::new(ErrorKind::Other, "invalid radio index"))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => log::warn!("failed to select register/link {:?}", e),
|
Err(e) => {
|
||||||
|
log::warn!("failed to present account setup radio buttons: {:?}", e);
|
||||||
|
Err(Error::new(ErrorKind::Other, "failed to present account setup radio buttons"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -108,7 +117,8 @@ impl<'a> SigChat<'a> {
|
||||||
/// The phone number must include the country calling code, i.e. the number must start with a "+" sign.
|
/// The phone number must include the country calling code, i.e. the number must start with a "+" sign.
|
||||||
/// Warning: this will disable the authentication of your phone as a primary device.
|
/// Warning: this will disable the authentication of your phone as a primary device.
|
||||||
///
|
///
|
||||||
pub fn account_register(&mut self) {
|
pub fn account_register(&mut self) -> Result<Account, Error> {
|
||||||
|
log::info!("Attempting to Register a new Signal Account");
|
||||||
self.modals
|
self.modals
|
||||||
.show_notification(&"sorry - registration is not implemented yet", None)
|
.show_notification(&"sorry - registration is not implemented yet", None)
|
||||||
.expect("notification failed");
|
.expect("notification failed");
|
||||||
|
|
@ -116,19 +126,18 @@ impl<'a> SigChat<'a> {
|
||||||
Ok(number) => {
|
Ok(number) => {
|
||||||
log::info!("registration phone number = {:?}", number);
|
log::info!("registration phone number = {:?}", number);
|
||||||
match Account::new(SIGCHAT_ACCOUNT) {
|
match Account::new(SIGCHAT_ACCOUNT) {
|
||||||
Ok(mut account) => {
|
Ok(mut account) => match account.set_number(&number.to_string()) {
|
||||||
match account.set_number(&number.to_string()) {
|
Ok(_number) => {
|
||||||
Ok(_number) => {
|
self.manager = Some(Manager::new(account, TrustMode::OnFirstUse));
|
||||||
self.manager = Some(Manager::new(account, TrustMode::OnFirstUse));
|
|
||||||
}
|
|
||||||
Err(e) => log::warn!("failed to set Account number: {e}"),
|
|
||||||
}
|
}
|
||||||
}
|
Err(e) => log::warn!("failed to set Account number: {e}"),
|
||||||
|
},
|
||||||
Err(e) => log::warn!("failed to create new Account: {e}"),
|
Err(e) => log::warn!("failed to create new Account: {e}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(e) => log::warn!("failed to get phone number: {e}"),
|
Err(e) => log::warn!("failed to get phone number: {e}"),
|
||||||
}
|
}
|
||||||
|
Err(Error::new(ErrorKind::Other, "not implmented"))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to obtain a phone number from the user.
|
/// Attempts to obtain a phone number from the user.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue