Guest registration button available
This commit is contained in:
parent
834dd48444
commit
79efe54ac1
3 changed files with 186 additions and 27 deletions
|
@ -500,6 +500,20 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkLabel">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">No room selected
|
||||
Join a room to start to chat</property>
|
||||
<property name="justify">center</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">noroom</property>
|
||||
<property name="title" translatable="yes">No room</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -645,6 +659,7 @@
|
|||
<child>
|
||||
<object class="GtkStack" id="user_menu_stack">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="vhomogeneous">False</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="name">5</property>
|
||||
|
@ -715,35 +730,96 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid">
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkEntry" id="register_email_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="secondary_icon_name">emblem-mail</property>
|
||||
<property name="placeholder_text" translatable="yes">Email (optional)</property>
|
||||
<property name="input_purpose">email</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkEntry" id="register_username_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="secondary_icon_name">face-wink</property>
|
||||
<property name="placeholder_text" translatable="yes">Username</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkEntry" id="register_password_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="visibility">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="secondary_icon_name">dialog-password</property>
|
||||
<property name="placeholder_text" translatable="yes">Password</property>
|
||||
<property name="input_purpose">password</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkEntry" id="register_password_confirm_entry">
|
||||
<property name="visible">True</property>
|
||||
<property name="visibility">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="secondary_icon_name">dialog-password</property>
|
||||
<property name="placeholder_text" translatable="yes">Repeat the password</property>
|
||||
<property name="input_purpose">password</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkEntry" id="register_server">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="text" translatable="yes">https://matrix.org</property>
|
||||
<property name="secondary_icon_name">applications-internet</property>
|
||||
<property name="secondary_icon_tooltip_text" translatable="yes">server</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder/>
|
||||
<object class="GtkButton" id="register_button">
|
||||
<property name="label" translatable="yes">register</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">5</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -752,6 +828,48 @@
|
|||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="margin_top">5</property>
|
||||
<property name="margin_bottom">5</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">2</property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="guest_server">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="text" translatable="yes">https://matrix.org</property>
|
||||
<property name="secondary_icon_name">applications-internet</property>
|
||||
<property name="secondary_icon_tooltip_text" translatable="yes">server</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="guest_button">
|
||||
<property name="label" translatable="yes">Login as Guest</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">guest</property>
|
||||
<property name="title" translatable="yes">Guest</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
|
52
src/app.rs
52
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<String>) {
|
||||
|
@ -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::<gtk::Stack>("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::<gtk::ListBox>("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")
|
||||
|
|
|
@ -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() }
|
||||
|
|
Loading…
Reference in a new issue