diff --git a/res/main_window.glade b/res/main_window.glade
index a0e92f21..a4ec8315 100644
--- a/res/main_window.glade
+++ b/res/main_window.glade
@@ -500,6 +500,20 @@
1
+
+
+
+ noroom
+ No room
+ 2
+
+
False
@@ -645,6 +659,7 @@
-
+
+
+ True
+ False
+ 5
+ 5
+ vertical
+ 2
+
+
+ True
+ True
+ https://matrix.org
+ applications-internet
+ server
+
+
+ False
+ True
+ 0
+
+
+
+
+ Login as Guest
+ True
+ True
+ True
+
+
+ False
+ True
+ 1
+
+
+
+
+ guest
+ Guest
+ 2
+
+
False
diff --git a/src/app.rs b/src/app.rs
index 2d388a32..a2378514 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -53,6 +53,13 @@ enum MsgPos {
Bottom,
}
+#[derive(Debug)]
+enum RoomPanel {
+ Room,
+ NoRoom,
+ Loading,
+}
+
impl AppOp {
pub fn login(&self) {
let user_entry: gtk::Entry = self.gtk_builder.get_object("login_username")
@@ -86,6 +93,7 @@ impl AppOp {
let ser = server_url.clone();
self.backend.send(BKCommand::Login(uname, pass, ser)).unwrap();
self.hide_popup();
+ self.clear_room_list();
}
pub fn connect_guest(&self, server: Option) {
@@ -96,6 +104,8 @@ impl AppOp {
self.show_user_loading();
self.backend.send(BKCommand::Guest(server_url)).unwrap();
+ self.hide_popup();
+ self.clear_room_list();
}
pub fn get_username(&self) {
@@ -138,7 +148,7 @@ impl AppOp {
.expect("Can't find user_button_stack in ui file.")
.set_visible_child_name("user_loading_page");
- self.set_loading(true);
+ self.room_panel(RoomPanel::Loading);
}
pub fn hide_popup(&self) {
@@ -218,16 +228,18 @@ impl AppOp {
}
}
- pub fn set_loading(&self, t: bool) {
+ pub fn room_panel(&self, t: RoomPanel) {
let s = self.gtk_builder
.get_object::("room_view_stack")
.expect("Can't find room_view_stack in ui file.");
- if t {
- s.set_visible_child_name("loading");
- } else {
- s.set_visible_child_name("room_view");
- }
+ let v = match t {
+ RoomPanel::Loading => "loading",
+ RoomPanel::Room => "room_view",
+ RoomPanel::NoRoom => "noroom",
+ };
+
+ s.set_visible_child_name(v);
}
pub fn sync(&self) {
@@ -259,13 +271,21 @@ impl AppOp {
if let Some(def) = default {
self.set_active_room(def.1, def.0);
+ } else {
+ self.room_panel(RoomPanel::NoRoom);
}
}
+ pub fn clear_room_list(&self) {
+ let store: gtk::TreeStore = self.gtk_builder.get_object("rooms_tree_store")
+ .expect("Couldn't find rooms_tree_store in ui file.");
+ store.clear();
+ }
+
pub fn set_active_room(&mut self, room: String, name: String) {
self.active_room = room;
- self.set_loading(true);
+ self.room_panel(RoomPanel::Loading);
let messages = self.gtk_builder
.get_object::("message_list")
@@ -619,7 +639,7 @@ impl App {
theop.lock().unwrap().scroll_down();
}
- theop.lock().unwrap().set_loading(false);
+ theop.lock().unwrap().room_panel(RoomPanel::Room);
},
Ok(BKResponse::RoomMessagesTo(msgs)) => {
for msg in msgs.iter().rev() {
@@ -680,6 +700,7 @@ impl App {
self.connect_user_button();
self.connect_login_button();
+ self.connect_guest_button();
self.connect_room_treeview();
self.connect_member_treeview();
@@ -761,6 +782,19 @@ impl App {
login_btn.connect_clicked(move |_| op.lock().unwrap().login());
}
+ fn connect_guest_button(&self) {
+ let btn: gtk::Button = self.gtk_builder.get_object("guest_button")
+ .expect("Couldn't find guest_button in ui file.");
+
+ let op = self.op.clone();
+ let builder = self.gtk_builder.clone();
+ btn.connect_clicked(move |_| {
+ let server: gtk::Entry = builder.get_object("guest_server")
+ .expect("Can't find guest_server in ui file.");
+ op.lock().unwrap().connect_guest(server.get_text());
+ });
+ }
+
fn connect_room_treeview(&self) {
// room selection
let treeview: gtk::TreeView = self.gtk_builder.get_object("rooms_tree_view")
diff --git a/src/backend.rs b/src/backend.rs
index 8ecde7d8..7b3d757b 100644
--- a/src/backend.rs
+++ b/src/backend.rs
@@ -189,6 +189,9 @@ impl Backend {
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();
},
|err| { tx.send(BKResponse::GuestLoginError(err)).unwrap() }
@@ -216,6 +219,9 @@ impl Backend {
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() }
@@ -226,13 +232,14 @@ impl Backend {
pub fn get_username(&self) -> Result<(), Error> {
let baseu = self.get_base_url()?;
- let id = self.data.lock().unwrap().user_id.clone() + "/";
+ let uid = self.data.lock().unwrap().user_id.clone();
+ let id = uid.clone() + "/";
let url = baseu.join("/_matrix/client/r0/profile/")?.join(&id)?.join("displayname")?;
let tx = self.tx.clone();
get!(&url,
|r: JsonValue| {
- let name = String::from(r["displayname"].as_str().unwrap_or(""));
+ let name = String::from(r["displayname"].as_str().unwrap_or(&uid));
tx.send(BKResponse::Name(name)).unwrap();
},
|err| { tx.send(BKResponse::UserNameError(err)).unwrap() }