Commit 04ed27fa authored by Julian Sparber's avatar Julian Sparber

accountsettings: load threePIDs (email and phone addresses)

* Create entrys for each email and phone address
* Add loading spinner till threePID are loaded

https://gitlab.gnome.org/World/fractal/issues/21
parent a2145046
......@@ -155,6 +155,10 @@ impl Backend {
let r = user::set_username(self, name);
bkerror!(r, tx, BKResponse::SetUserNameError);
}
Ok(BKCommand::GetThreePID) => {
let r = user::get_threepid(self);
bkerror!(r, tx, BKResponse::GetThreePIDError);
}
Ok(BKCommand::GetAvatar) => {
let r = user::get_avatar(self);
bkerror!(r, tx, BKResponse::AvatarError);
......
......@@ -10,6 +10,7 @@ use types::Room;
use types::Event;
use types::StickerGroup;
use types::Sticker;
use types::UserInfo;
use cache::CacheMap;
......@@ -25,6 +26,7 @@ pub enum BKCommand {
Guest(String),
GetUsername,
SetUserName(String),
GetThreePID,
GetAvatar,
SetUserAvatar(String),
Sync,
......@@ -72,6 +74,7 @@ pub enum BKResponse {
Logout,
Name(String),
SetUserName(String),
GetThreePID(Vec<UserInfo>),
Avatar(String),
SetUserAvatar(String),
Sync(String),
......@@ -108,6 +111,7 @@ pub enum BKResponse {
//errors
UserNameError(Error),
SetUserNameError(Error),
GetThreePIDError(Error),
AvatarError(Error),
SetUserAvatarError(Error),
LoginError(Error),
......
......@@ -17,6 +17,7 @@ use backend::types::BKResponse;
use backend::types::Backend;
use types::Member;
use types::UserInfo;
use self::serde_json::Value as JsonValue;
......@@ -53,6 +54,49 @@ pub fn set_username(bk: &Backend, name: String) -> Result<(), Error> {
Ok(())
}
pub fn get_threepid(bk: &Backend) -> Result<(), Error> {
let url = bk.url(&format!("account/3pid"), vec![])?;
let tx = bk.tx.clone();
get!(&url,
|r: JsonValue| {
let mut result: Vec<UserInfo> = vec![];
println!("{}", r);
if let Some(arr) = r["threepids"].as_array() {
for pid in arr.iter() {
let address = match pid["address"].as_str() {
None => "".to_string(),
Some(a) => a.to_string(),
};
let add = match pid["added_at"].as_u64() {
None => 0,
Some(a) => a,
};
let medium = match pid["medium"].as_str() {
None => "".to_string(),
Some(a) => a.to_string(),
};
let val = match pid["validated_at"].as_u64() {
None => 0,
Some(a) => a,
};
result.push(UserInfo{
address: address,
added_at: add,
validated_at: val,
medium: medium,
});
}
}
tx.send(BKResponse::GetThreePID(result)).unwrap();
},
|err| { tx.send(BKResponse::GetThreePIDError(err)).unwrap() }
);
Ok(())
}
pub fn get_avatar(bk: &Backend) -> Result<(), Error> {
let baseu = bk.get_base_url()?;
let userid = bk.data.lock().unwrap().user_id.clone();
......
......@@ -4,3 +4,4 @@ pub mod protocol;
pub mod event;
pub mod message;
pub mod stickers;
pub mod userinfo;
#[derive(Debug, Serialize, Deserialize)]
pub struct UserInfo {
pub added_at: u64,
pub medium: String,
pub validated_at: u64,
pub address: String,
}
impl Clone for UserInfo {
fn clone(&self) -> UserInfo {
UserInfo {
added_at: self.added_at.clone(),
medium: self.medium.clone(),
validated_at: self.validated_at.clone(),
address: self.address.clone(),
}
}
}
......@@ -7,3 +7,4 @@ pub use model::member::Member;
pub use model::member::MemberList;
pub use model::stickers::Sticker;
pub use model::stickers::StickerGroup;
pub use model::userinfo::UserInfo;
......@@ -45,6 +45,13 @@
</child>
<child internal-child="vbox">
<object class="GtkBox">
<child>
<object class="GtkStack" id="account_settings_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="halign">center</property>
......@@ -78,7 +85,7 @@
</object>
</child>
<child>
<object class="GtkGrid">
<object class="GtkGrid" id="account_settings_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
......@@ -113,7 +120,7 @@
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="account_settings_email_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
......@@ -129,7 +136,7 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkBox" id="account_settings_box_email">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
......@@ -181,7 +188,7 @@
</packing>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="account_settings_phone_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
......@@ -197,7 +204,7 @@
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkBox" id="account_settings_box_phone">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
......@@ -535,6 +542,28 @@
</object>
</child>
</object>
<packing>
<property name="name">info</property>
</packing>
</child>
<child>
<object class="GtkBox" id="account_settings_spinner">
<property name="visible">True</property>
<child>
<object class="GtkSpinner">
<property name="visible">True</property>
<property name="active">True</property>
<property name="expand">True</property>
</object>
</child>
</object>
<packing>
<property name="name">loading</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
</interface>
......@@ -49,6 +49,10 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
let u = Some(username);
APPOP!(set_username, (u));
}
Ok(BKResponse::GetThreePID(list)) => {
let l = Some(list);
APPOP!(set_three_pid, (l));
}
Ok(BKResponse::SetUserName(username)) => {
let u = Some(username);
APPOP!(set_username, (u));
......
......@@ -81,6 +81,20 @@ impl App {
}
}));
/*
fn update_password_strength(builder: &gtk::Builder) {
let bar = builder
.get_object::<gtk::LevelBar>("password-dialog-strength-indicator")
.expect("Can't find password-dialog-strength-indicator in ui file.");
let label = builder
.get_object::<gtk::Label>("password-dialog-hint")
.expect("Can't find password-dialog-hint in ui file.");
let strength_level = 10f64;
bar.set_value(strength_level);
label.set_label("text");
}
*/
fn validate_password_input(builder: &gtk::Builder) {
let hint = builder
.get_object::<gtk::Label>("password-dialog-verify-hint")
......@@ -143,10 +157,10 @@ impl App {
/* Body */
verify_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder)
validate_password_input(&builder.clone());
}));
new_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder)
validate_password_input(&builder.clone());
}));
old_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder)
......
......@@ -8,7 +8,17 @@ use backend::BKCommand;
use widgets;
use widgets::AvatarExt;
use fractal_api::types::UserInfo;
impl AppOp {
pub fn set_three_pid(&self, data: Option<Vec<UserInfo>>) {
self.update_address(data);
}
pub fn get_three_pid(&self) {
self.backend.send(BKCommand::GetThreePID).unwrap();
}
pub fn show_account_settings_dialog(&self) {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog")
......@@ -31,7 +41,12 @@ impl AppOp {
let delete_box = self.ui.builder
.get_object::<gtk::Box>("account_settings_delete_box")
.expect("Can't find account_settings_delete_box in ui file.");
let stack = self.ui.builder
.get_object::<gtk::Stack>("account_settings_stack")
.expect("Can't find account_settings_delete_box in ui file.");
stack.set_visible_child_name("loading");
self.get_three_pid();
/* remove all old avatar from the popover */
for w in avatar.get_children().iter() {
avatar.remove(w);
......@@ -53,6 +68,88 @@ impl AppOp {
dialog.present();
}
pub fn update_address(&self, data: Option<Vec<UserInfo>>) {
let grid = self.ui.builder
.get_object::<gtk::Grid>("account_settings_grid")
.expect("Can't find account_settings_grid in ui file.");
let email = self.ui.builder
.get_object::<gtk::Box>("account_settings_box_email")
.expect("Can't find account_settings_box_email in ui file.");
let phone = self.ui.builder
.get_object::<gtk::Box>("account_settings_box_phone")
.expect("Can't find account_settings_box_phone in ui file.");
let email_entry = self.ui.builder
.get_object::<gtk::Entry>("account_settings_email")
.expect("Can't find account_settings_email in ui file.");
let phone_entry = self.ui.builder
.get_object::<gtk::Entry>("account_settings_phone")
.expect("Can't find account_settings_phone in ui file.");
let stack = self.ui.builder
.get_object::<gtk::Stack>("account_settings_stack")
.expect("Can't find account_settings_delete_box in ui file.");
let mut first_email = true;
let mut first_phone = true;
let mut i = 1;
let mut child = grid.get_child_at(1, i);
while child.is_some() {
if let Some(child) = child.clone() {
if child != phone && child != email {
grid.remove_row(i);
}
else {
i = i + 1;
}
}
child = grid.get_child_at(1, i);
}
if let Some(data) = data {
for item in data {
if item.medium == "email" {
if first_email {
email_entry.set_text(&item.address);
let entry = gtk::Entry::new();
entry.show();
grid.insert_next_to(&email, gtk::PositionType::Bottom);
grid.attach_next_to(&entry, &email, gtk::PositionType::Bottom, 1, 1);
first_email = false;
}
else {
let entry = gtk::Entry::new();
entry.set_text(&item.address);
entry.show();
grid.insert_next_to(&email, gtk::PositionType::Bottom);
grid.attach_next_to(&entry, &email, gtk::PositionType::Bottom, 1, 1);
}
}
else if item.medium == "msisdn" {
if first_phone {
let s = String::from("+") + &String::from(item.address);
phone_entry.set_text(&s);
let entry = gtk::Entry::new();
entry.show();
grid.insert_next_to(&phone, gtk::PositionType::Bottom);
grid.attach_next_to(&entry, &phone, gtk::PositionType::Bottom, 1, 1);
first_phone = false;
}
else {
let entry = gtk::Entry::new();
let s = String::from("+") + &String::from(item.address);
entry.set_text(&s);
entry.show();
grid.insert_next_to(&phone, gtk::PositionType::Bottom);
grid.attach_next_to(&entry, &phone, gtk::PositionType::Bottom, 1, 1);
}
}
}
}
stack.set_visible_child_name("info");
}
pub fn show_password_dialog(&self) {
let dialog = self.ui.builder
.get_object::<gtk::Dialog>("password_dialog")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment