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 { ...@@ -155,6 +155,10 @@ impl Backend {
let r = user::set_username(self, name); let r = user::set_username(self, name);
bkerror!(r, tx, BKResponse::SetUserNameError); bkerror!(r, tx, BKResponse::SetUserNameError);
} }
Ok(BKCommand::GetThreePID) => {
let r = user::get_threepid(self);
bkerror!(r, tx, BKResponse::GetThreePIDError);
}
Ok(BKCommand::GetAvatar) => { Ok(BKCommand::GetAvatar) => {
let r = user::get_avatar(self); let r = user::get_avatar(self);
bkerror!(r, tx, BKResponse::AvatarError); bkerror!(r, tx, BKResponse::AvatarError);
......
...@@ -10,6 +10,7 @@ use types::Room; ...@@ -10,6 +10,7 @@ use types::Room;
use types::Event; use types::Event;
use types::StickerGroup; use types::StickerGroup;
use types::Sticker; use types::Sticker;
use types::UserInfo;
use cache::CacheMap; use cache::CacheMap;
...@@ -25,6 +26,7 @@ pub enum BKCommand { ...@@ -25,6 +26,7 @@ pub enum BKCommand {
Guest(String), Guest(String),
GetUsername, GetUsername,
SetUserName(String), SetUserName(String),
GetThreePID,
GetAvatar, GetAvatar,
SetUserAvatar(String), SetUserAvatar(String),
Sync, Sync,
...@@ -72,6 +74,7 @@ pub enum BKResponse { ...@@ -72,6 +74,7 @@ pub enum BKResponse {
Logout, Logout,
Name(String), Name(String),
SetUserName(String), SetUserName(String),
GetThreePID(Vec<UserInfo>),
Avatar(String), Avatar(String),
SetUserAvatar(String), SetUserAvatar(String),
Sync(String), Sync(String),
...@@ -108,6 +111,7 @@ pub enum BKResponse { ...@@ -108,6 +111,7 @@ pub enum BKResponse {
//errors //errors
UserNameError(Error), UserNameError(Error),
SetUserNameError(Error), SetUserNameError(Error),
GetThreePIDError(Error),
AvatarError(Error), AvatarError(Error),
SetUserAvatarError(Error), SetUserAvatarError(Error),
LoginError(Error), LoginError(Error),
......
...@@ -17,6 +17,7 @@ use backend::types::BKResponse; ...@@ -17,6 +17,7 @@ use backend::types::BKResponse;
use backend::types::Backend; use backend::types::Backend;
use types::Member; use types::Member;
use types::UserInfo;
use self::serde_json::Value as JsonValue; use self::serde_json::Value as JsonValue;
...@@ -53,6 +54,49 @@ pub fn set_username(bk: &Backend, name: String) -> Result<(), Error> { ...@@ -53,6 +54,49 @@ pub fn set_username(bk: &Backend, name: String) -> Result<(), Error> {
Ok(()) 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> { pub fn get_avatar(bk: &Backend) -> Result<(), Error> {
let baseu = bk.get_base_url()?; let baseu = bk.get_base_url()?;
let userid = bk.data.lock().unwrap().user_id.clone(); let userid = bk.data.lock().unwrap().user_id.clone();
......
...@@ -4,3 +4,4 @@ pub mod protocol; ...@@ -4,3 +4,4 @@ pub mod protocol;
pub mod event; pub mod event;
pub mod message; pub mod message;
pub mod stickers; 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; ...@@ -7,3 +7,4 @@ pub use model::member::Member;
pub use model::member::MemberList; pub use model::member::MemberList;
pub use model::stickers::Sticker; pub use model::stickers::Sticker;
pub use model::stickers::StickerGroup; pub use model::stickers::StickerGroup;
pub use model::userinfo::UserInfo;
This diff is collapsed.
...@@ -49,6 +49,10 @@ pub fn backend_loop(rx: Receiver<BKResponse>) { ...@@ -49,6 +49,10 @@ pub fn backend_loop(rx: Receiver<BKResponse>) {
let u = Some(username); let u = Some(username);
APPOP!(set_username, (u)); APPOP!(set_username, (u));
} }
Ok(BKResponse::GetThreePID(list)) => {
let l = Some(list);
APPOP!(set_three_pid, (l));
}
Ok(BKResponse::SetUserName(username)) => { Ok(BKResponse::SetUserName(username)) => {
let u = Some(username); let u = Some(username);
APPOP!(set_username, (u)); APPOP!(set_username, (u));
......
...@@ -81,6 +81,20 @@ impl App { ...@@ -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) { fn validate_password_input(builder: &gtk::Builder) {
let hint = builder let hint = builder
.get_object::<gtk::Label>("password-dialog-verify-hint") .get_object::<gtk::Label>("password-dialog-verify-hint")
...@@ -143,10 +157,10 @@ impl App { ...@@ -143,10 +157,10 @@ impl App {
/* Body */ /* Body */
verify_password.connect_property_text_notify(clone!(op, builder => move |_| { 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 |_| { 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 |_| { old_password.connect_property_text_notify(clone!(op, builder => move |_| {
validate_password_input(&builder) validate_password_input(&builder)
......
...@@ -8,7 +8,17 @@ use backend::BKCommand; ...@@ -8,7 +8,17 @@ use backend::BKCommand;
use widgets; use widgets;
use widgets::AvatarExt; use widgets::AvatarExt;
use fractal_api::types::UserInfo;
impl AppOp { 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) { pub fn show_account_settings_dialog(&self) {
let dialog = self.ui.builder let dialog = self.ui.builder
.get_object::<gtk::Dialog>("account_settings_dialog") .get_object::<gtk::Dialog>("account_settings_dialog")
...@@ -31,7 +41,12 @@ impl AppOp { ...@@ -31,7 +41,12 @@ impl AppOp {
let delete_box = self.ui.builder let delete_box = self.ui.builder
.get_object::<gtk::Box>("account_settings_delete_box") .get_object::<gtk::Box>("account_settings_delete_box")
.expect("Can't find account_settings_delete_box in ui file."); .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 */ /* remove all old avatar from the popover */
for w in avatar.get_children().iter() { for w in avatar.get_children().iter() {
avatar.remove(w); avatar.remove(w);
...@@ -53,6 +68,88 @@ impl AppOp { ...@@ -53,6 +68,88 @@ impl AppOp {
dialog.present(); 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) { pub fn show_password_dialog(&self) {
let dialog = self.ui.builder let dialog = self.ui.builder
.get_object::<gtk::Dialog>("password_dialog") .get_object::<gtk::Dialog>("password_dialog")
...@@ -60,7 +157,7 @@ impl AppOp { ...@@ -60,7 +157,7 @@ impl AppOp {
let confirm_password = self.ui.builder let confirm_password = self.ui.builder
.get_object::<gtk::Button>("password-dialog-apply") .get_object::<gtk::Button>("password-dialog-apply")
.expect("Can't find password-dialog-apply in ui file."); .expect("Can't find password-dialog-apply in ui file.");
confirm_password.set_sensitive(false); confirm_password.set_sensitive(false);
dialog.present(); dialog.present();
} }
...@@ -99,18 +196,18 @@ impl AppOp { ...@@ -99,18 +196,18 @@ impl AppOp {
.get_object::<gtk::Entry>("account_settings_name") .get_object::<gtk::Entry>("account_settings_name")
.expect("Can't find account_settings_name in ui file."); .expect("Can't find account_settings_name in ui file.");
*/ */
let advanced = self.ui.builder let advanced = self.ui.builder
.get_object::<gtk::Revealer>("account_settings_advanced") .get_object::<gtk::Revealer>("account_settings_advanced")
.expect("Can't find account_settings_advanced in ui file."); .expect("Can't find account_settings_advanced in ui file.");
let delete = self.ui.builder let delete = self.ui.builder
.get_object::<gtk::Revealer>("account_settings_delete") .get_object::<gtk::Revealer>("account_settings_delete")
.expect("Can't find account_settings_delete in ui file."); .expect("Can't find account_settings_delete in ui file.");
let advanced_toggle = self.ui.builder let advanced_toggle = self.ui.builder
.get_object::<gtk::EventBox>("account_settings_advanced_toggle") .get_object::<gtk::EventBox>("account_settings_advanced_toggle")
.expect("Can't find account_settings_advanced_toggle in ui file."); .expect("Can't find account_settings_advanced_toggle in ui file.");
let delete_toggle = self.ui.builder let delete_toggle = self.ui.builder
.get_object::<gtk::EventBox>("account_settings_delete_toggle") .get_object::<gtk::EventBox>("account_settings_delete_toggle")
.expect("Can't find account_settings_delete_toggle in ui file."); .expect("Can't find account_settings_delete_toggle in ui file.");
self.tmp_avatar = None; self.tmp_avatar = None;
......
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