[fractal/fractal-next] room: Use room tags for the category
- From: Julian Sparber <jsparber src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal/fractal-next] room: Use room tags for the category
- Date: Tue, 11 May 2021 08:45:29 +0000 (UTC)
commit d33964a99d6d6805f675494d1d2514044beb5a49
Author: Kévin Commaille <zecakeh tedomum fr>
Date: Mon May 10 21:12:21 2021 +0200
room: Use room tags for the category
src/session/room/room.rs | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
---
diff --git a/src/session/room/room.rs b/src/session/room/room.rs
index dbe30ebd..bf591371 100644
--- a/src/session/room/room.rs
+++ b/src/session/room/room.rs
@@ -11,6 +11,7 @@ use matrix_sdk::{
TextMessageEventContent,
},
},
+ tag::TagName,
AnyMessageEvent, AnyRoomEvent, AnyStateEvent, MessageEvent, StateEvent, Unsigned,
},
identifiers::{EventId, UserId},
@@ -191,12 +192,6 @@ impl Room {
fn set_matrix_room(&self, matrix_room: MatrixRoom) {
let priv_ = imp::Room::from_instance(self);
- let category = match matrix_room {
- MatrixRoom::Joined(_) => CategoryType::Normal,
- MatrixRoom::Invited(_) => CategoryType::Invited,
- MatrixRoom::Left(_) => CategoryType::Left,
- };
-
priv_.matrix_room.set(matrix_room).unwrap();
priv_.timeline.set(Timeline::new(self)).unwrap();
@@ -204,7 +199,7 @@ impl Room {
self.load_members();
self.load_display_name();
// TODO: change category when room type changes
- self.set_category(category);
+ self.load_category();
}
pub fn user(&self) -> &User {
@@ -228,6 +223,33 @@ impl Room {
self.notify("category");
}
+ pub fn load_category(&self) {
+ let matrix_room = self.matrix_room().clone();
+
+ match matrix_room {
+ MatrixRoom::Joined(_) => {
+ do_async(
+ async move { matrix_room.tags().await },
+ clone!(@weak self as obj => move |tags_result| async move {
+ let mut category = CategoryType::Normal;
+
+ if let Ok(Some(tags)) = tags_result {
+ if tags.get(&TagName::Favorite).is_some() {
+ category = CategoryType::Favorite;
+ } else if tags.get(&TagName::LowPriority).is_some() {
+ category = CategoryType::LowPriority;
+ }
+ }
+
+ obj.set_category(category);
+ }),
+ );
+ }
+ MatrixRoom::Invited(_) => self.set_category(CategoryType::Invited),
+ MatrixRoom::Left(_) => self.set_category(CategoryType::Left),
+ };
+ }
+
pub fn timeline(&self) -> &Timeline {
let priv_ = imp::Room::from_instance(self);
priv_.timeline.get().unwrap()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]