[fractal/fractal-next] room: Hide upgraded rooms from sidebar
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] room: Hide upgraded rooms from sidebar
- Date: Wed, 1 Dec 2021 14:57:33 +0000 (UTC)
commit bf1dfcc7e0e4178be61695deef8d369c8cc903ac
Author: Julian Sparber <julian sparber net>
Date: Mon Nov 29 16:49:17 2021 +0100
room: Hide upgraded rooms from sidebar
src/session/room/mod.rs | 85 +++++++++++++++++++++++++++++++++++-
src/session/room/room_type.rs | 1 +
src/session/sidebar/category_type.rs | 5 +++
3 files changed, 90 insertions(+), 1 deletion(-)
---
diff --git a/src/session/room/mod.rs b/src/session/room/mod.rs
index d16edfc9..2a9f4277 100644
--- a/src/session/room/mod.rs
+++ b/src/session/room/mod.rs
@@ -86,6 +86,8 @@ mod imp {
pub members_loaded: Cell<bool>,
pub power_levels: RefCell<PowerLevels>,
pub latest_change: RefCell<Option<glib::DateTime>>,
+ pub predecessor: OnceCell<RoomId>,
+ pub successor: OnceCell<RoomId>,
}
#[glib::object_subclass]
@@ -187,6 +189,20 @@ mod imp {
MemberList::static_type(),
glib::ParamFlags::READABLE,
),
+ glib::ParamSpec::new_string(
+ "predecessor",
+ "Predecessor",
+ "The room id of predecessor of this Room",
+ None,
+ glib::ParamFlags::READABLE,
+ ),
+ glib::ParamSpec::new_string(
+ "successor",
+ "Successor",
+ "The room id of successor of this Room",
+ None,
+ glib::ParamFlags::READABLE,
+ ),
]
});
@@ -251,6 +267,20 @@ mod imp {
.to_value()
}
"latest-change" => obj.latest_change().to_value(),
+ "predecessor" => obj.predecessor().map_or_else(
+ || {
+ let none: Option<&str> = None;
+ none.to_value()
+ },
+ |id| id.as_ref().to_value(),
+ ),
+ "successor" => obj.successor().map_or_else(
+ || {
+ let none: Option<&str> = None;
+ none.to_value()
+ },
+ |id| id.as_ref().to_value(),
+ ),
_ => unimplemented!(),
}
}
@@ -331,6 +361,8 @@ impl Room {
priv_.matrix_room.replace(Some(matrix_room));
self.load_display_name();
+ self.load_predecessor();
+ self.load_successor();
self.load_category();
}
@@ -354,7 +386,7 @@ impl Room {
/// Set the category of this room.
///
/// This makes the necessary to propagate the category to the homeserver.
- /// Note: Rooms can't be moved to the invite category.
+ /// Note: Rooms can't be moved to the invite category and they can't be moved once they are upgraded
pub fn set_category(&self, category: RoomType) {
let matrix_room = self.matrix_room();
let previous_category = self.category();
@@ -368,6 +400,17 @@ impl Room {
return;
}
+ if self.category() == RoomType::Outdated {
+ warn!("Can't set the category of an upgraded room");
+ return;
+ }
+
+ // Outdated rooms don't need to propagate anything to the server
+ if category == RoomType::Outdated {
+ self.set_category_internal(category);
+ return;
+ }
+
let handle = spawn_tokio!(async move {
match matrix_room {
MatrixRoom::Invited(room) => {
@@ -383,6 +426,7 @@ impl Room {
// TODO: set low priority tag
}
RoomType::Left => room.reject_invitation().await,
+ RoomType::Outdated => unimplemented!(),
}
}
MatrixRoom::Joined(room) => {
@@ -401,6 +445,7 @@ impl Room {
Ok(())
}
RoomType::Left => room.leave().await,
+ RoomType::Outdated => unimplemented!(),
}
}
MatrixRoom::Left(room) => {
@@ -419,6 +464,7 @@ impl Room {
// TODO: set low priority tag
}
RoomType::Left => Ok(()),
+ RoomType::Outdated => unimplemented!(),
}
}
}
@@ -461,6 +507,11 @@ impl Room {
}
pub fn load_category(&self) {
+ // Don't load the category if this room was upgraded
+ if self.category() == RoomType::Outdated {
+ return;
+ }
+
let matrix_room = self.matrix_room();
match matrix_room {
@@ -1000,6 +1051,38 @@ impl Room {
})
.unwrap()
}
+
+ pub fn predecessor(&self) -> Option<&RoomId> {
+ let priv_ = imp::Room::from_instance(self);
+ priv_.predecessor.get()
+ }
+
+ fn load_predecessor(&self) -> Option<()> {
+ let priv_ = imp::Room::from_instance(self);
+ let event = self.matrix_room().create_content()?;
+ let room_id = event.predecessor?.room_id;
+
+ priv_.predecessor.set(room_id).unwrap();
+ self.notify("predecessor");
+ Some(())
+ }
+
+ pub fn successor(&self) -> Option<&RoomId> {
+ let priv_ = imp::Room::from_instance(self);
+ priv_.successor.get()
+ }
+
+ pub fn load_successor(&self) -> Option<()> {
+ let priv_ = imp::Room::from_instance(self);
+
+ let room_id = self.matrix_room().tombstone()?.replacement_room;
+
+ priv_.successor.set(room_id).unwrap();
+ self.set_category_internal(RoomType::Outdated);
+ self.notify("successor");
+
+ Some(())
+ }
}
trait GlibDateTime {
diff --git a/src/session/room/room_type.rs b/src/session/room/room_type.rs
index 1b7d88d3..16057d8e 100644
--- a/src/session/room/room_type.rs
+++ b/src/session/room/room_type.rs
@@ -11,6 +11,7 @@ pub enum RoomType {
Normal = 2,
LowPriority = 3,
Left = 4,
+ Outdated = 5,
}
impl Default for RoomType {
diff --git a/src/session/sidebar/category_type.rs b/src/session/sidebar/category_type.rs
index 3a027eba..b5a23d08 100644
--- a/src/session/sidebar/category_type.rs
+++ b/src/session/sidebar/category_type.rs
@@ -12,6 +12,7 @@ pub enum CategoryType {
Normal = 3,
LowPriority = 4,
Left = 5,
+ Outdated = 6,
}
impl Default for CategoryType {
@@ -29,6 +30,8 @@ impl ToString for CategoryType {
CategoryType::Normal => gettext("Rooms"),
CategoryType::LowPriority => gettext("Low Priority"),
CategoryType::Left => gettext("Historical"),
+ // Translators: This shouldn't ever be visible to the user,
+ CategoryType::Outdated => gettext("Outdated"),
}
}
}
@@ -41,6 +44,7 @@ impl From<RoomType> for CategoryType {
RoomType::Normal => Self::Normal,
RoomType::LowPriority => Self::LowPriority,
RoomType::Left => Self::Left,
+ RoomType::Outdated => Self::Outdated,
}
}
}
@@ -53,6 +57,7 @@ impl From<&RoomType> for CategoryType {
RoomType::Normal => Self::Normal,
RoomType::LowPriority => Self::LowPriority,
RoomType::Left => Self::Left,
+ RoomType::Outdated => Self::Outdated,
}
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]