Browse Source

sidebar: Hide spaces

Closes #927
merge-requests/1327/merge
Kévin Commaille 4 years ago committed by Julian Sparber
parent
commit
dc3918fa66
  1. 39
      src/session/room/mod.rs
  2. 3
      src/session/room/room_type.rs
  3. 12
      src/session/sidebar/category_type.rs
  4. 1
      src/session/sidebar/room_row.rs

39
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),

3
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),
}
}
}

12
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,
}
}
}

1
src/session/sidebar/room_row.rs

@ -293,6 +293,7 @@ impl RoomRow {
return;
}
RoomType::Outdated => {}
RoomType::Space => {}
}
}

Loading…
Cancel
Save