Commit f45d4d9c authored by Daniel García Moreno's avatar Daniel García Moreno

directory: Disable search entry when loading

I've disabled the search entry when we're search for rooms to avoid
multiple requests. Right now you can't cancel a search request.

I've also moved the initial request to the set_protocols method so we
don't call the search rooms every time we enter in the room directory,
the room directory will be the same if you go back to chat and go to
directory again.

see #250
parent 21f45d61
Pipeline #13416 passed with stages
in 18 minutes and 58 seconds
......@@ -112,7 +112,7 @@ fn fetch_rooms(bk: &Backend,
room_sender: Sender<Vec<Room>>)
-> Result<(), Error> {
let mut attrs = json!({"limit": 20});
let mut attrs = json!({"limit": globals::ROOM_DIRECTORY_LIMIT});
if let Some(q) = query {
attrs["filter"] = json!({
......@@ -155,7 +155,10 @@ fn fetch_rooms(bk: &Backend,
room_sender.send(rooms).unwrap();
},
|err| { tx.send(BKResponse::DirectoryError(err)).unwrap(); }
|err| {
room_sender.send(vec![]).unwrap();
tx.send(BKResponse::DirectoryError(err)).unwrap();
}
);
Ok(())
......
pub static TIMEOUT: u64 = 80;
pub static PAGE_LIMIT: i32 = 40;
pub static ROOM_DIRECTORY_LIMIT: i32 = 10;
......@@ -17,6 +17,7 @@ impl AppOp {
pub fn set_protocols(&mut self, protocols: Vec<Protocol>) {
self.protocols = protocols;
self.search_rooms(false);
}
pub fn search_rooms(&mut self, more: bool) {
......@@ -62,6 +63,8 @@ impl AppOp {
self.directory.clear();
}
q.set_sensitive(false);
self.backend
.send(BKCommand::DirectorySearch(homeserver, q.get_text().unwrap_or_default(), requested_protocols, more))
.unwrap();
......@@ -75,11 +78,14 @@ impl AppOp {
let directory = self.ui.builder
.get_object::<gtk::ListBox>("directory_room_list")
.expect("Can't find directory_room_list in ui file.");
for ch in directory.get_children() {
if ch.is::<gtk::Spinner>() {
directory.remove(&ch);
}
let q = self.ui.builder
.get_object::<gtk::Entry>("directory_search_entry")
.expect("Can't find directory_search_entry in ui file.");
for ch in directory.get_children().iter().take(1) {
directory.remove(ch);
}
q.set_sensitive(true);
}
pub fn set_directory_rooms(&mut self, rooms: Vec<Room>) {
......@@ -99,10 +105,8 @@ impl AppOp {
.get_object::<gtk::ListBox>("directory_room_list")
.expect("Can't find directory_room_list in ui file.");
for ch in directory.get_children() {
if !ch.is::<gtk::Spinner>() {
directory.remove(&ch);
}
for ch in directory.get_children().iter().skip(1) {
directory.remove(ch);
}
for r in self.directory.iter() {
......
......@@ -39,7 +39,6 @@ impl AppOp {
self.sync();
self.init_protocols();
}
......
......@@ -60,10 +60,6 @@ impl AppOp {
.expect("Can't find widget to set focus in ui file.")
.grab_focus();
}
if let AppState::Directory = self.state {
self.search_rooms(false);
}
}
pub fn escape(&mut self) {
......
......@@ -54,7 +54,7 @@ impl<'a> RoomBox<'a> {
let name_label = gtk::Label::new("");
name_label.set_line_wrap(true);
name_label.set_line_wrap_mode(pango::WrapMode::WordChar);
name_label.set_markup(&format!("<b>{}</b>", name.unwrap_or_default()));
name_label.set_markup(&format!("<b>{}</b>", markup_text(&name.unwrap_or_default())));
name_label.set_justify(gtk::Justification::Left);
name_label.set_halign(gtk::Align::Start);
name_label.set_valign(gtk::Align::Start);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment