[fractal/split-async-state-ui-appop-mgmt: 5/13] Take UI querying out of AppOp::search_rooms
- From: Alejandro Domínguez <aledomu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/split-async-state-ui-appop-mgmt: 5/13] Take UI querying out of AppOp::search_rooms
- Date: Sun, 20 Dec 2020 18:50:58 +0000 (UTC)
commit bdd3f78b65805547d9e571f183de08db9b22d82d
Author: Alejandro Domínguez <adomu net-c com>
Date: Thu Dec 3 16:51:41 2020 +0100
Take UI querying out of AppOp::search_rooms
fractal-gtk/src/appop/directory.rs | 81 +-------------------------------------
fractal-gtk/src/appop/mod.rs | 6 +--
fractal-gtk/src/ui/directory.rs | 78 ++++++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+), 84 deletions(-)
---
diff --git a/fractal-gtk/src/appop/directory.rs b/fractal-gtk/src/appop/directory.rs
index 638f7d1e..a8d33e8a 100644
--- a/fractal-gtk/src/appop/directory.rs
+++ b/fractal-gtk/src/appop/directory.rs
@@ -3,7 +3,6 @@ use crate::app::RUNTIME;
use crate::appop::AppOp;
use crate::backend::{directory, HandleError};
use crate::model::room::Room;
-use gtk::prelude::*;
use matrix_sdk::directory::RoomNetwork;
use matrix_sdk::thirdparty::ProtocolInstance;
@@ -30,86 +29,11 @@ impl AppOp {
pub fn search_rooms(&mut self) {
let session_client =
unwrap_or_unit_return!(self.login_data.as_ref().map(|ld| ld.session_client.clone()));
- let other_protocol_radio = self
- .ui
- .builder
- .get_object::<gtk::RadioButton>("other_protocol_radio")
- .expect("Can't find other_protocol_radio in ui file.");
-
- let protocol: Option<String> = if other_protocol_radio.get_active() {
- let protocol_combo = self
- .ui
- .builder
- .get_object::<gtk::ComboBox>("protocol_combo")
- .expect("Can't find protocol_combo in ui file.");
-
- let protocol_model = self
- .ui
- .builder
- .get_object::<gtk::ListStore>("protocol_model")
- .expect("Can't find protocol_model in ui file.");
-
- let active = protocol_combo.get_active().map_or(-1, |uint| uint as i32);
-
- protocol_model
- .iter_nth_child(None, active)
- .and_then(|it| protocol_model.get_value(&it, 1).get().ok()?)
- } else {
- None
- };
-
- let q = self
- .ui
- .builder
- .get_object::<gtk::Entry>("directory_search_entry")
- .expect("Can't find directory_search_entry in ui file.");
-
- let other_homeserver_radio = self
- .ui
- .builder
- .get_object::<gtk::RadioButton>("other_homeserver_radio")
- .expect("Can't find other_homeserver_radio in ui file.");
- let other_homeserver_url = self
+ let (protocol, homeserver, search_term) = self
.ui
- .builder
- .get_object::<gtk::EntryBuffer>("other_homeserver_url")
- .expect("Can't find other_homeserver_url in ui file.");
-
- let homeserver = if other_homeserver_radio.get_active() {
- Some(other_homeserver_url.get_text())
- } else {
- None
- };
-
- if !self.directory_pagination.has_more() {
- 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() {
- directory.remove(&ch);
- }
-
- let directory_stack = self
- .ui
- .builder
- .get_object::<gtk::Stack>("directory_stack")
- .expect("Can't find directory_stack in ui file.");
- let directory_spinner = self
- .ui
- .builder
- .get_object::<gtk::Box>("directory_spinner")
- .expect("Can't find directory_spinner in ui file.");
- directory_stack.set_visible_child(&directory_spinner);
-
- self.directory.clear();
-
- q.set_sensitive(false);
- }
+ .get_search_rooms_query(self.directory_pagination.clone());
- let search_term = Some(q.get_text().to_string()).filter(|s| !s.is_empty());
if let RoomSearchPagination::NoMorePages = self.directory_pagination {
// there are no more rooms. We don't need to request for more
return;
@@ -148,7 +72,6 @@ impl AppOp {
let session_client =
unwrap_or_unit_return!(self.login_data.as_ref().map(|ld| ld.session_client.clone()));
rooms.sort_by_key(|a| -i128::from(a.n_members));
- self.directory.extend(rooms.clone());
self.directory_pagination = rooms_since
.map(RoomSearchPagination::Next)
.unwrap_or(RoomSearchPagination::NoMorePages);
diff --git a/fractal-gtk/src/appop/mod.rs b/fractal-gtk/src/appop/mod.rs
index 4ddee2a8..77fe3739 100644
--- a/fractal-gtk/src/appop/mod.rs
+++ b/fractal-gtk/src/appop/mod.rs
@@ -13,7 +13,7 @@ use crate::cache::CacheMap;
use crate::util::i18n;
-use crate::model::room::{Room, RoomList};
+use crate::model::room::RoomList;
use crate::passwd::PasswordStorage;
use crate::actions::AppState;
@@ -100,8 +100,6 @@ pub struct AppOp {
pub md_enabled: bool,
search_type: SearchType,
- pub directory: Vec<Room>,
-
pub user_info_cache: UserInfoCache,
}
@@ -130,8 +128,6 @@ impl AppOp {
invitation_roomid: None,
search_type: SearchType::Invite,
- directory: vec![],
-
user_info_cache: Arc::new(Mutex::new(
CacheMap::new().timeout(Duration::from_secs(60 * 60)),
)),
diff --git a/fractal-gtk/src/ui/directory.rs b/fractal-gtk/src/ui/directory.rs
index 21f2ef6b..977c4e16 100644
--- a/fractal-gtk/src/ui/directory.rs
+++ b/fractal-gtk/src/ui/directory.rs
@@ -1,5 +1,6 @@
use super::UI;
use crate::app::RUNTIME;
+use crate::appop::RoomSearchPagination;
use crate::backend::room;
use crate::backend::HandleError;
use crate::model::room::Room;
@@ -29,6 +30,83 @@ impl UI {
}
}
+ pub fn get_search_rooms_query(
+ &self,
+ directory_pagination: RoomSearchPagination,
+ ) -> (Option<String>, Option<String>, Option<String>) {
+ let other_protocol_radio = self
+ .builder
+ .get_object::<gtk::RadioButton>("other_protocol_radio")
+ .expect("Can't find other_protocol_radio in ui file.");
+
+ let protocol: Option<String> = if other_protocol_radio.get_active() {
+ let protocol_combo = self
+ .builder
+ .get_object::<gtk::ComboBox>("protocol_combo")
+ .expect("Can't find protocol_combo in ui file.");
+
+ let protocol_model = self
+ .builder
+ .get_object::<gtk::ListStore>("protocol_model")
+ .expect("Can't find protocol_model in ui file.");
+
+ let active = protocol_combo.get_active().map_or(-1, |uint| uint as i32);
+
+ protocol_model
+ .iter_nth_child(None, active)
+ .and_then(|it| protocol_model.get_value(&it, 1).get().ok()?)
+ } else {
+ None
+ };
+
+ let other_homeserver_radio = self
+ .builder
+ .get_object::<gtk::RadioButton>("other_homeserver_radio")
+ .expect("Can't find other_homeserver_radio in ui file.");
+
+ let other_homeserver_url = self
+ .builder
+ .get_object::<gtk::EntryBuffer>("other_homeserver_url")
+ .expect("Can't find other_homeserver_url in ui file.");
+
+ let homeserver = if other_homeserver_radio.get_active() {
+ Some(other_homeserver_url.get_text())
+ } else {
+ None
+ };
+
+ let q = self
+ .builder
+ .get_object::<gtk::Entry>("directory_search_entry")
+ .expect("Can't find directory_search_entry in ui file.");
+
+ if !directory_pagination.has_more() {
+ let directory = self
+ .builder
+ .get_object::<gtk::ListBox>("directory_room_list")
+ .expect("Can't find directory_room_list in ui file.");
+ for ch in directory.get_children() {
+ directory.remove(&ch);
+ }
+
+ let directory_stack = self
+ .builder
+ .get_object::<gtk::Stack>("directory_stack")
+ .expect("Can't find directory_stack in ui file.");
+ let directory_spinner = self
+ .builder
+ .get_object::<gtk::Box>("directory_spinner")
+ .expect("Can't find directory_spinner in ui file.");
+ directory_stack.set_visible_child(&directory_spinner);
+
+ q.set_sensitive(false);
+ }
+
+ let search_term = Some(q.get_text().to_string()).filter(|s| !s.is_empty());
+
+ (protocol, homeserver, search_term)
+ }
+
pub fn append_directory_rooms(&mut self, rooms: Vec<Room>, session_client: MatrixClient) {
let directory = self
.builder
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]