From c5bffd545cef11b80545ae5ca7a8c37a579a4fbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Thu, 26 Oct 2017 14:17:05 +0200 Subject: [PATCH 1/2] Limiting the number of members to show in the sidebar This is to avoid out of memory when there's a lot of members --- src/app.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/app.rs b/src/app.rs index fd3db07f..1573c91b 100644 --- a/src/app.rs +++ b/src/app.rs @@ -592,7 +592,10 @@ impl AppOp { let name = m.get_alias(); - store.insert_with_values(None, &[0, 1], &[&name, &(m.uid)]); + // only show 200 members... + if self.members.len() < 200 { + store.insert_with_values(None, &[0, 1], &[&name, &(m.uid)]); + } self.members.insert(m.uid.clone(), m); } From 50327b4bc82e0a98731f0c5ccff62fa741f8368b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= Date: Thu, 26 Oct 2017 14:55:53 +0200 Subject: [PATCH 2/2] Showing a message on login error --- src/app.rs | 29 +++++++++++++++++------------ src/backend.rs | 16 ++++++++++------ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/app.rs b/src/app.rs index 1573c91b..5b65dad3 100644 --- a/src/app.rs +++ b/src/app.rs @@ -131,18 +131,7 @@ impl AppOp { }; if password != passconf { - let window: gtk::Window = self.gtk_builder - .get_object("main_window") - .expect("Couldn't find main_window in ui file."); - let dialog = gtk::MessageDialog::new(Some(&window), - gtk::DIALOG_MODAL, - gtk::MessageType::Warning, - gtk::ButtonsType::Ok, - "Passwords didn't match, try again"); - dialog.show(); - - dialog.connect_response(move |d, _| { d.destroy(); }); - + self.show_error("Passwords didn't match, try again"); return; } @@ -989,6 +978,19 @@ impl AppOp { .expect("Can't find search_button_stack in ui file.") .set_visible_child_name("normal"); } + + pub fn show_error(&self, msg: &str) { + let window: gtk::Window = self.gtk_builder + .get_object("main_window") + .expect("Couldn't find main_window in ui file."); + let dialog = gtk::MessageDialog::new(Some(&window), + gtk::DIALOG_MODAL, + gtk::MessageType::Warning, + gtk::ButtonsType::Ok, + msg); + dialog.show(); + dialog.connect_response(move |d, _| { d.destroy(); }); + } } /// State for the main thread. @@ -1137,6 +1139,9 @@ impl App { } // errors + Ok(BKResponse::LoginError(_)) => { + theop.lock().unwrap().show_error("Can't login, try again"); + }, Ok(BKResponse::SyncError(_)) => { println!("SYNC Error"); theop.lock().unwrap().syncing = false; diff --git a/src/backend.rs b/src/backend.rs index c4a6bb35..eb926d7d 100644 --- a/src/backend.rs +++ b/src/backend.rs @@ -354,12 +354,16 @@ impl Backend { let uid = String::from(r["user_id"].as_str().unwrap_or("")); let tk = String::from(r["access_token"].as_str().unwrap_or("")); - data.lock().unwrap().user_id = uid.clone(); - data.lock().unwrap().access_token = tk.clone(); - data.lock().unwrap().since = String::from(""); - data.lock().unwrap().msgs_batch_end = String::from(""); - data.lock().unwrap().msgs_batch_start = String::from(""); - tx.send(BKResponse::Token(uid, tk)).unwrap(); + if uid.is_empty() || tk.is_empty() { + tx.send(BKResponse::LoginError(Error::BackendError)).unwrap(); + } else { + data.lock().unwrap().user_id = uid.clone(); + data.lock().unwrap().access_token = tk.clone(); + data.lock().unwrap().since = String::from(""); + data.lock().unwrap().msgs_batch_end = String::from(""); + data.lock().unwrap().msgs_batch_start = String::from(""); + tx.send(BKResponse::Token(uid, tk)).unwrap(); + } }, |err| { tx.send(BKResponse::LoginError(err)).unwrap() } );