mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
implement sigchat account_setup() choice between Register / Link
This commit is contained in:
parent
6ac476ae4f
commit
7b26c04fb0
2 changed files with 77 additions and 12 deletions
|
|
@ -1,7 +1,20 @@
|
||||||
{
|
{
|
||||||
"sigchat.account.failed": {
|
"sigchat.account.failed": {
|
||||||
"en": "Failed to obtain Signal Account",
|
"en": "Failed to setup Signal Account",
|
||||||
"en-tts": "Failed to obtain Signal Account"
|
"en-tts": "Failed to setup Signal Account"
|
||||||
|
},
|
||||||
|
"sigchat.account.link": {
|
||||||
|
"en": "Link to an existing Signal Account",
|
||||||
|
"en-tts": "Link to an existing Signal Account"
|
||||||
|
},
|
||||||
|
"sigchat.account.register": {
|
||||||
|
"en": "Register a new Signal Account",
|
||||||
|
"en-tts": "Register a new Signal Account"
|
||||||
|
},
|
||||||
|
"sigchat.account.title": {
|
||||||
|
"en": "Setup Signal on this device.",
|
||||||
|
"en-tts": "Setup Signal on this device."
|
||||||
|
},
|
||||||
},
|
},
|
||||||
"sigchat.number": {
|
"sigchat.number": {
|
||||||
"en": "Number",
|
"en": "Number",
|
||||||
|
|
|
||||||
|
|
@ -42,14 +42,13 @@ 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) -> 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.account.is_none() {
|
||||||
self.account_modal();
|
self.account_setup();
|
||||||
}
|
}
|
||||||
if let Some(account) = &self.account {
|
if let Some(account) = &self.account {
|
||||||
log::info!(
|
log::info!(
|
||||||
|
|
@ -72,12 +71,68 @@ impl<'a> SigChat<'a> {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Attempts to obtain a phone number from the user and set self.account = a new Account.
|
/// Setup a Signal Account via Registration or Linking
|
||||||
|
///
|
||||||
|
fn account_setup(&mut self) {
|
||||||
|
self.modals
|
||||||
|
.add_list_item(t!("sigchat.account.link", locales::LANG))
|
||||||
|
.expect("failed add list item");
|
||||||
|
self.modals
|
||||||
|
.add_list_item(t!("sigchat.account.register", locales::LANG))
|
||||||
|
.expect("failed add list item");
|
||||||
|
self.modals
|
||||||
|
.get_radiobutton(t!("sigchat.account.title", locales::LANG))
|
||||||
|
.expect("failed radiobutton modal");
|
||||||
|
match self.modals.get_radio_index() {
|
||||||
|
Ok(index) => match index {
|
||||||
|
0 => self.account_link(),
|
||||||
|
1 => self.account_register(),
|
||||||
|
_ => log::warn!("invalid index"),
|
||||||
|
},
|
||||||
|
Err(e) => log::warn!("failed to select register/link {:?}", e),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Link this device to an existing Signal Account
|
||||||
|
///
|
||||||
|
/// Signal allows to link additional devices to your primary device (e.g. Signal-Android).
|
||||||
|
/// Note that currently Signal allows up to three linked devices per primary.
|
||||||
|
///
|
||||||
|
pub fn account_link(&self) {
|
||||||
|
self.modals
|
||||||
|
.show_notification(&"sorry - linking is not implemented yet", None)
|
||||||
|
.expect("notification failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Register a new Signal Account with this as the primary device.
|
||||||
|
///
|
||||||
|
/// A Signal Account requires a phone number to receive SMS or incoming calls for registration & validation.
|
||||||
|
/// 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.
|
||||||
|
///
|
||||||
|
pub fn account_register(&mut self) {
|
||||||
|
self.modals
|
||||||
|
.show_notification(&"sorry - registration is not implemented yet", None)
|
||||||
|
.expect("notification failed");
|
||||||
|
match self.number_modal() {
|
||||||
|
Ok(number) => {
|
||||||
|
log::info!("registration phone number = {:?}", number);
|
||||||
|
match Account::new(SIGCHAT_ACCOUNT, &number.to_string()) {
|
||||||
|
Ok(account) => self.account = Some(account),
|
||||||
|
Err(e) => log::warn!("failed to create new Account: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => log::warn!("failed to get phone number: {e}"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Attempts to obtain a phone number from the user.
|
||||||
///
|
///
|
||||||
/// A Signal Account requires a phone number to receive SMS or incoming calls for registration & validation.
|
/// A Signal Account requires a phone number to receive SMS or incoming calls for registration & validation.
|
||||||
/// 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.
|
||||||
///
|
///
|
||||||
fn account_modal(&mut self) {
|
#[allow(dead_code)]
|
||||||
|
fn number_modal(&mut self) -> Result<String, Error> {
|
||||||
let mut builder = self
|
let mut builder = self
|
||||||
.modals
|
.modals
|
||||||
.alert_builder(t!("sigchat.number.title", locales::LANG));
|
.alert_builder(t!("sigchat.number.title", locales::LANG));
|
||||||
|
|
@ -86,14 +141,11 @@ impl<'a> SigChat<'a> {
|
||||||
Ok(payloads) => match payloads.content()[0].content.as_str() {
|
Ok(payloads) => match payloads.content()[0].content.as_str() {
|
||||||
Ok(number) => {
|
Ok(number) => {
|
||||||
log::info!("registration phone number = {:?}", number);
|
log::info!("registration phone number = {:?}", number);
|
||||||
match Account::new(SIGCHAT_ACCOUNT, &number.to_string()) {
|
Ok(number.to_string())
|
||||||
Ok(account) => self.account = Some(account),
|
|
||||||
Err(e) => log::warn!("failed to create new Account: {e}"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Err(e) => log::warn!("failed to get payload from modal: {e}"),
|
Err(e) => Err(Error::new(ErrorKind::InvalidData, e)),
|
||||||
},
|
},
|
||||||
Err(e) => log::warn!("failed to build modal: {:?}", e),
|
Err(_) => Err(Error::from(ErrorKind::ConnectionRefused)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue