[fractal/fractal-next] sidebar: Hide spaces



commit dc3918fa6685e4bf43c4fe87eb4e874ff20445a4
Author: Kévin Commaille <zecakeh tedomum fr>
Date:   Sat Feb 19 15:37:39 2022 +0100

    sidebar: Hide spaces
    
    Closes #927

 src/session/room/mod.rs              | 39 +++++++++++++++++++++---------------
 src/session/room/room_type.rs        |  3 +++
 src/session/sidebar/category_type.rs | 12 ++++-------
 src/session/sidebar/room_row.rs      |  1 +
 4 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index baeb4d9ae..4e1eba2a7 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -496,6 +496,7 @@ impl Room {
                     }
                     RoomType::Left => room.reject_invitation().await,
                     RoomType::Outdated => unimplemented!(),
+                    RoomType::Space => unimplemented!(),
                 },
                 MatrixRoom::Joined(room) => match category {
                     RoomType::Invited => Ok(()),
@@ -527,6 +528,7 @@ impl Room {
                     }
                     RoomType::Left => room.leave().await,
                     RoomType::Outdated => unimplemented!(),
+                    RoomType::Space => unimplemented!(),
                 },
                 MatrixRoom::Left(room) => match category {
                     RoomType::Invited => Ok(()),
@@ -544,6 +546,7 @@ impl Room {
                     }
                     RoomType::Left => Ok(()),
                     RoomType::Outdated => unimplemented!(),
+                    RoomType::Space => unimplemented!(),
                 },
             }
         });
@@ -594,24 +597,28 @@ impl Room {
 
         match matrix_room {
             MatrixRoom::Joined(_) => {
-                let handle = spawn_tokio!(async move { matrix_room.tags().await });
-
-                spawn!(
-                    glib::PRIORITY_DEFAULT_IDLE,
-                    clone!(@weak self as obj => async move {
-                        let mut category = RoomType::Normal;
-
-                        if let Ok(Some(tags)) = handle.await.unwrap() {
-                            if tags.get(&TagName::Favorite).is_some() {
-                                category = RoomType::Favorite;
-                            } else if tags.get(&TagName::LowPriority).is_some() {
-                                category = RoomType::LowPriority;
+                if matrix_room.is_space() {
+                    self.set_category_internal(RoomType::Space);
+                } else {
+                    let handle = spawn_tokio!(async move { matrix_room.tags().await });
+
+                    spawn!(
+                        glib::PRIORITY_DEFAULT_IDLE,
+                        clone!(@weak self as obj => async move {
+                            let mut category = RoomType::Normal;
+
+                            if let Ok(Some(tags)) = handle.await.unwrap() {
+                                if tags.get(&TagName::Favorite).is_some() {
+                                    category = RoomType::Favorite;
+                                } else if tags.get(&TagName::LowPriority).is_some() {
+                                    category = RoomType::LowPriority;
+                                }
                             }
-                        }
 
-                        obj.set_category_internal(category);
-                    })
-                );
+                            obj.set_category_internal(category);
+                        })
+                    );
+                }
             }
             MatrixRoom::Invited(_) => self.set_category_internal(RoomType::Invited),
             MatrixRoom::Left(_) => self.set_category_internal(RoomType::Left),
diff --git a/src/session/room/room_type.rs b/src/session/room/room_type.rs
index 6570cfec6..bdcdf5893 100644
--- a/src/session/room/room_type.rs
+++ b/src/session/room/room_type.rs
@@ -16,6 +16,7 @@ pub enum RoomType {
     LowPriority = 3,
     Left = 4,
     Outdated = 5,
+    Space = 6,
 }
 
 impl RoomType {
@@ -41,6 +42,7 @@ impl RoomType {
                 matches!(category, Self::Favorite | Self::Normal | Self::LowPriority)
             }
             Self::Outdated => false,
+            Self::Space => false,
         }
     }
 }
@@ -80,6 +82,7 @@ impl TryFrom<&CategoryType> for RoomType {
             CategoryType::VerificationRequest => {
                 Err("CategoryType::VerificationRequest cannot be a RoomType")
             }
+            CategoryType::Space => Ok(Self::Space),
         }
     }
 }
diff --git a/src/session/sidebar/category_type.rs b/src/session/sidebar/category_type.rs
index 165ecd29c..4de7cc579 100644
--- a/src/session/sidebar/category_type.rs
+++ b/src/session/sidebar/category_type.rs
@@ -15,6 +15,7 @@ pub enum CategoryType {
     LowPriority = 4,
     Left = 5,
     Outdated = 6,
+    Space = 7,
 }
 
 impl Default for CategoryType {
@@ -35,20 +36,14 @@ impl ToString for CategoryType {
             CategoryType::Left => gettext("Historical"),
             // Translators: This shouldn't ever be visible to the user,
             CategoryType::Outdated => gettext("Outdated"),
+            CategoryType::Space => gettext("Spaces"),
         }
     }
 }
 
 impl From<RoomType> for CategoryType {
     fn from(room_type: RoomType) -> Self {
-        match room_type {
-            RoomType::Invited => Self::Invited,
-            RoomType::Favorite => Self::Favorite,
-            RoomType::Normal => Self::Normal,
-            RoomType::LowPriority => Self::LowPriority,
-            RoomType::Left => Self::Left,
-            RoomType::Outdated => Self::Outdated,
-        }
+        Self::from(&room_type)
     }
 }
 
@@ -61,6 +56,7 @@ impl From<&RoomType> for CategoryType {
             RoomType::LowPriority => Self::LowPriority,
             RoomType::Left => Self::Left,
             RoomType::Outdated => Self::Outdated,
+            RoomType::Space => Self::Space,
         }
     }
 }
diff --git a/src/session/sidebar/room_row.rs b/src/session/sidebar/room_row.rs
index 1301559c7..fee66a87d 100644
--- a/src/session/sidebar/room_row.rs
+++ b/src/session/sidebar/room_row.rs
@@ -293,6 +293,7 @@ impl RoomRow {
                     return;
                 }
                 RoomType::Outdated => {}
+                RoomType::Space => {}
             }
         }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]