display name setting, partial error messages

This commit is contained in:
Amanda Graven 2020-12-08 09:36:29 +01:00
parent 8f07d92b99
commit 67e51d234b
Signed by: amanda
GPG key ID: 45C461CDC9286390
2 changed files with 95 additions and 29 deletions

View file

@ -23,6 +23,6 @@ tracing-subscriber = { version = "0.2", features = ["parking_lot"] }
[dependencies.matrix-sdk] [dependencies.matrix-sdk]
git = "https://github.com/matrix-org/matrix-rust-sdk" git = "https://github.com/matrix-org/matrix-rust-sdk"
rev = "e65915e" rev = "bca7f41"
default_features = false default_features = false
features = ["encryption", "sqlite_cryptostore", "messages", "rustls-tls"] features = ["encryption", "sqlite_cryptostore", "messages", "rustls-tls"]

View file

@ -125,6 +125,7 @@ pub struct MainView {
client: matrix_sdk::Client, client: matrix_sdk::Client,
session: matrix::Session, session: matrix::Session,
draft: String, draft: String,
error: Option<(String, iced::button::State)>,
selected: Option<RoomId>, selected: Option<RoomId>,
sas: Option<matrix_sdk::Sas>, sas: Option<matrix_sdk::Sas>,
sorting: RoomSorting, sorting: RoomSorting,
@ -148,6 +149,7 @@ impl MainView {
session, session,
settings_view: None, settings_view: None,
settings_button: Default::default(), settings_button: Default::default(),
error: None,
sas: None, sas: None,
rooms: Default::default(), rooms: Default::default(),
selected: None, selected: None,
@ -417,23 +419,44 @@ pub enum Message {
// Main state messages // Main state messages
ResetRooms(BTreeMap<RoomId, String>), ResetRooms(BTreeMap<RoomId, String>),
SelectRoom(RoomId), SelectRoom(RoomId),
/// Set error message
ErrorMessage(String),
/// Close error message
ClearError,
SetVerification(Option<matrix_sdk::Sas>), SetVerification(Option<matrix_sdk::Sas>),
/// Accept verification flow
VerificationAccept, VerificationAccept,
/// Accept sent
VerificationAccepted, VerificationAccepted,
/// Confirm keys match
VerificationConfirm, VerificationConfirm,
/// Confirmation sent
VerificationConfirmed, VerificationConfirmed,
/// Cancel verification flow
VerificationCancel, VerificationCancel,
/// Verification flow cancelled
VerificationCancelled, VerificationCancelled,
/// Matrix event received
Sync(matrix::Event), Sync(matrix::Event),
/// Set contents of message compose box
SetMessage(String), SetMessage(String),
/// Send the contents of the compose box to the selected room
SendMessage, SendMessage,
// Settings messages // Settings messages
/// Open settings menu
OpenSettings, OpenSettings,
/// Close settings menu
CloseSettings, CloseSettings,
/// Set display name input field
SetDisplayNameInput(String),
/// Save new display name
SaveDisplayName,
/// New display name saved successfully
DisplayNameSaved,
/// Set key import path /// Set key import path
SetKeyPath(String), SetKeyPath(String),
/// Set password key backup is encrypted with
SetKeyPassword(String), SetKeyPassword(String),
/// Import encryption keys /// Import encryption keys
ImportKeys, ImportKeys,
@ -441,6 +464,14 @@ pub enum Message {
#[derive(Clone, Default, Debug)] #[derive(Clone, Default, Debug)]
pub struct SettingsView { pub struct SettingsView {
/// Display name to set
display_name: String,
/// Display name text input
display_name_input: iced::text_input::State,
/// Button to set display name
display_name_button: iced::button::State,
/// Path to import encryption keys from /// Path to import encryption keys from
key_path: String, key_path: String,
/// Password to decrypt the keys with /// Password to decrypt the keys with
@ -464,6 +495,30 @@ impl SettingsView {
fn view(&mut self) -> Element<Message> { fn view(&mut self) -> Element<Message> {
let content = Column::new() let content = Column::new()
.width(500.into()) .width(500.into())
.spacing(15)
.push(Text::new("Profile").size(20))
.push(
Column::new().push(Text::new("Display name")).push(
Row::new()
.push(
TextInput::new(
&mut self.display_name_input,
"Alice",
&self.display_name,
Message::SetDisplayNameInput,
)
.width(Length::Fill)
.padding(5),
)
.push(
Button::new(&mut self.display_name_button, Text::new("Save"))
.on_press(Message::SaveDisplayName),
),
),
)
.push(Text::new("Encryption").size(20))
.push(
Column::new()
.push(Text::new("Import key (enter path)")) .push(Text::new("Import key (enter path)"))
.push( .push(
TextInput::new( TextInput::new(
@ -473,9 +528,10 @@ impl SettingsView {
Message::SetKeyPath, Message::SetKeyPath,
) )
.padding(5), .padding(5),
),
) )
.push(Text::new("Key password"))
.push( .push(
Column::new().push(Text::new("Key password")).push(
TextInput::new( TextInput::new(
&mut self.key_password_input, &mut self.key_password_input,
"SecretPassword42", "SecretPassword42",
@ -484,6 +540,7 @@ impl SettingsView {
) )
.password() .password()
.padding(5), .padding(5),
),
) )
.push( .push(
Button::new(&mut self.key_import_button, Text::new("Import keys")) Button::new(&mut self.key_import_button, Text::new("Import keys"))
@ -597,21 +654,12 @@ impl Application for Retrix {
}, },
Retrix::LoggedIn(view) => { Retrix::LoggedIn(view) => {
match message { match message {
Message::ErrorMessage(e) => view.error = Some((e, Default::default())),
Message::ResetRooms(r) => view.rooms = r, Message::ResetRooms(r) => view.rooms = r,
Message::SelectRoom(r) => view.selected = Some(r), Message::SelectRoom(r) => view.selected = Some(r),
Message::Sync(event) => match event { Message::Sync(event) => match event {
matrix::Event::Room(_) => (), matrix::Event::Room(_) => (),
matrix::Event::ToDevice(event) => match event { matrix::Event::ToDevice(event) => match event {
/*AnyToDeviceEvent::KeyVerificationRequest(request) => {
let client = view.client.clone();
return Command::perform(
async move {
let request = matrix_sdk::api::r0::devi
client.send(m)
},
|sas| Message::SetVerification(sas),
);
}*/
AnyToDeviceEvent::KeyVerificationStart(start) => { AnyToDeviceEvent::KeyVerificationStart(start) => {
let client = view.client.clone(); let client = view.client.clone();
return Command::perform( return Command::perform(
@ -694,6 +742,24 @@ impl Application for Retrix {
); );
} }
Message::OpenSettings => view.settings_view = Some(SettingsView::new()), Message::OpenSettings => view.settings_view = Some(SettingsView::new()),
Message::SetDisplayNameInput(name) => {
if let Some(ref mut settings) = view.settings_view {
settings.display_name = name;
}
}
Message::SaveDisplayName => {
if let Some(ref mut settings) = view.settings_view {
let client = view.client.clone();
let name = settings.display_name.clone();
return Command::perform(
async move { client.set_display_name(Some(&name)).await },
|result| match result {
Ok(()) => Message::DisplayNameSaved,
Err(e) => Message::ErrorMessage(e.to_string()),
},
);
}
}
Message::SetKeyPath(p) => { Message::SetKeyPath(p) => {
if let Some(ref mut settings) = view.settings_view { if let Some(ref mut settings) = view.settings_view {
settings.key_path = p; settings.key_path = p;