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,493 +45,522 @@
</child>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="halign">center</property>
<property name="margin">18</property>
<child>
<object class="GtkButton" id="account_settings_avatar_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_bottom">18</property>
<child>
<object class="GtkBox" id="account_settings_avatar">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="halign">center</property>
<property name="wrap">True</property>
<property name="max-width-chars">35</property>
<property name="label" translatable="yes">Other people can find you by searching for any of these identifiers.</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkGrid">
<object class="GtkStack" id="account_settings_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="width-request">300</property>
<property name="margin-top">6</property>
<property name="column-spacing">6</property>
<property name="row-spacing">6</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Name</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="account_settings_name">
<property name="visible">True</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Email</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">1</property>
<property name="left-attach">0</property>
</packing>
</child>
<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>
<property name="margin">18</property>
<child>
<object class="GtkEntry" id="account_settings_email">
<object class="GtkButton" id="account_settings_avatar_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="account_settings_email_add">
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="margin_bottom">18</property>
<child>
<object class="GtkImage">
<object class="GtkBox" id="account_settings_avatar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
<child>
<object class="GtkButton" id="account_settings_email_remove">
<property name="visible">False</property>
<property name="can_focus">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">user-trash-symbolic</property>
</object>
</child>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="top-attach">1</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Phone</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="account_settings_phone">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
</child>
<child>
<object class="GtkButton" id="account_settings_phone_add">
<property name="visible">False</property>
<property name="can_focus">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
<property name="can_focus">False</property>
<property name="valign">end</property>
<property name="halign">center</property>
<property name="wrap">True</property>
<property name="max-width-chars">35</property>
<property name="label" translatable="yes">Other people can find you by searching for any of these identifiers.</property>
<style>
<class name="suggested-action"/>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkButton" id="account_settings_phone_remove">
<property name="visible">False</property>
<property name="can_focus">True</property>
<object class="GtkGrid" id="account_settings_grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="width-request">300</property>
<property name="margin-top">6</property>
<property name="column-spacing">6</property>
<property name="row-spacing">6</property>
<child>
<object class="GtkImage">
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">user-trash-symbolic</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Name</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">0</property>
</packing>
</child>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="margin-top">18</property>
<property name="label" translatable="yes">Password</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">3</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="account_settings_password">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin-top">18</property>
<property name="label" translatable="yes">●●●●●</property>
</object>
<packing>
<property name="top-attach">3</property>
<property name="left-attach">1</property>
</packing>
</child>
</object>
</child>
<child>
<object class="GtkBox" id="account_settings_advanced_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="margin-top">24</property>
<child>
<object class="GtkEventBox" id="account_settings_advanced_toggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<object class="GtkEntry" id="account_settings_name">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Advanced Information</property>
<property name="can_focus">True</property>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkImage">
<object class="GtkLabel" id="account_settings_email_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">pan-end-symbolic</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Email</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="pack_type">end</property>
<property name="top-attach">1</property>
<property name="left-attach">0</property>
</packing>
</child>
<style>
<class name="advanced_revealer_header"/>
</style>
</object>
</child>
</object>
</child>
<child>
<object class="GtkRevealer" id="account_settings_advanced">
<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>
<child>
<object class="GtkGrid">
<object class="GtkBox" id="account_settings_box_email">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="hexpand">True</property>
<property name="column-spacing">6</property>
<property name="row-spacing">6</property>
<child>
<object class="GtkLabel">
<object class="GtkEntry" id="account_settings_email">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Homeserver</property>
<style>
<class name="dim-label"/>
</style>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="account_settings_homeserver">
<property name="visible">True</property>
<object class="GtkButton" id="account_settings_email_add">
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">None</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="top-attach">0</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Matrix ID</property>
<object class="GtkButton" id="account_settings_email_remove">
<property name="visible">False</property>
<property name="can_focus">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">user-trash-symbolic</property>
</object>
</child>
<style>
<class name="dim-label"/>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="top-attach">1</property>
<property name="left-attach">0</property>
</packing>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="top-attach">1</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="account_settings_phone_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Phone</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkBox" id="account_settings_box_phone">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="account_settings_uid">
<object class="GtkEntry" id="account_settings_phone">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">None</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="top-attach">1</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Device ID</property>
<object class="GtkButton" id="account_settings_phone_add">
<property name="visible">False</property>
<property name="can_focus">True</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">list-add-symbolic</property>
</object>
</child>
<style>
<class name="dim-label"/>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="account_settings_device_id">
<property name="visible">True</property>
<object class="GtkButton" id="account_settings_phone_remove">
<property name="visible">False</property>
<property name="can_focus">True</property>
<property name="halign">start</property>
<property name="label" translatable="yes">None</property>
<child>
<object class="GtkImage">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">user-trash-symbolic</property>
</object>
</child>
<style>
<class name="suggested-action"/>
</style>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">1</property>
</packing>
</child>
<style>
<class name="linked"/>
</style>
</object>
<packing>
<property name="top-attach">2</property>
<property name="left-attach">1</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="valign">center</property>
<property name="halign">end</property>
<property name="margin-top">18</property>
<property name="label" translatable="yes">Password</property>
<style>
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="top-attach">3</property>
<property name="left-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="account_settings_password">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="margin-top">18</property>
<property name="label" translatable="yes">●●●●●</property>
</object>
<packing>
<property name="top-attach">3</property>
<property name="left-attach">1</property>
</packing>
</child>
<style>
<class name="advanced_revealer_body"/>
</style>
</object>
</child>
</object>
</child>
<style>
<class name="advanced_revealer"/>
</style>
</object>
</child>
<child>
<object class="GtkBox" id="account_settings_delete_box">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="orientation">vertical</property>
<property name="margin-top">24</property>
<child>
<object class="GtkEventBox" id="account_settings_delete_toggle">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">True</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Deactivate Account</property>
</object>
</child>
<child>
<object class="GtkImage">