Can check if rooms are muted
This commit is contained in:
@@ -4,6 +4,9 @@ use crate::controllers::matrix::matrix_media_controller;
|
||||
use crate::extractors::matrix_client_extractor::MatrixClientExtractor;
|
||||
use actix_web::{HttpRequest, HttpResponse, web};
|
||||
use futures_util::{StreamExt, stream};
|
||||
use matrix_sdk::notification_settings::{
|
||||
IsEncrypted, IsOneToOne, NotificationSettings, RoomNotificationMode,
|
||||
};
|
||||
use matrix_sdk::room::ParentSpace;
|
||||
use matrix_sdk::ruma::{OwnedMxcUri, OwnedRoomId, OwnedUserId};
|
||||
use matrix_sdk::{Room, RoomMemberships};
|
||||
@@ -17,11 +20,12 @@ pub struct APIRoomInfo {
|
||||
is_space: bool,
|
||||
parents: Vec<OwnedRoomId>,
|
||||
number_unread_messages: u64,
|
||||
notifications: RoomNotificationMode,
|
||||
latest_event: Option<APIEvent>,
|
||||
}
|
||||
|
||||
impl APIRoomInfo {
|
||||
async fn from_room(r: &Room) -> anyhow::Result<Self> {
|
||||
async fn from_room(r: &Room, notif: &NotificationSettings) -> anyhow::Result<Self> {
|
||||
// Get parent spaces
|
||||
let parent_spaces = r
|
||||
.parent_spaces()
|
||||
@@ -39,19 +43,34 @@ impl APIRoomInfo {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let members = r
|
||||
.members(RoomMemberships::ACTIVE)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|r| r.user_id().to_owned())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let notifications = notif
|
||||
.get_user_defined_room_notification_mode(r.room_id())
|
||||
.await
|
||||
.unwrap_or(
|
||||
notif
|
||||
.get_default_room_notification_mode(
|
||||
IsEncrypted::from(r.encryption_state().is_encrypted()),
|
||||
IsOneToOne::from(members.len() == 2),
|
||||
)
|
||||
.await,
|
||||
);
|
||||
|
||||
Ok(Self {
|
||||
id: r.room_id().to_owned(),
|
||||
name: r.name(),
|
||||
members: r
|
||||
.members(RoomMemberships::ACTIVE)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|r| r.user_id().to_owned())
|
||||
.collect::<Vec<_>>(),
|
||||
members,
|
||||
avatar: r.avatar_url(),
|
||||
is_space: r.is_space(),
|
||||
parents: parent_spaces,
|
||||
number_unread_messages: r.unread_notification_counts().notification_count,
|
||||
notifications,
|
||||
latest_event: get_events(r, 1, None).await?.events.into_iter().next(),
|
||||
})
|
||||
}
|
||||
@@ -59,8 +78,9 @@ impl APIRoomInfo {
|
||||
|
||||
/// Get the list of joined rooms of the user
|
||||
pub async fn joined_rooms(client: MatrixClientExtractor) -> HttpResult {
|
||||
let notifs = client.client.client.notification_settings().await;
|
||||
let list = stream::iter(client.client.client.joined_rooms())
|
||||
.then(async |room| APIRoomInfo::from_room(&room).await)
|
||||
.then(async |room| APIRoomInfo::from_room(&room, ¬ifs).await)
|
||||
.collect::<Vec<_>>()
|
||||
.await
|
||||
.into_iter()
|
||||
@@ -71,8 +91,10 @@ pub async fn joined_rooms(client: MatrixClientExtractor) -> HttpResult {
|
||||
|
||||
/// Get joined spaces rooms of user
|
||||
pub async fn get_joined_spaces(client: MatrixClientExtractor) -> HttpResult {
|
||||
let notifs = client.client.client.notification_settings().await;
|
||||
|
||||
let list = stream::iter(client.client.client.joined_space_rooms())
|
||||
.then(async |room| APIRoomInfo::from_room(&room).await)
|
||||
.then(async |room| APIRoomInfo::from_room(&room, ¬ifs).await)
|
||||
.collect::<Vec<_>>()
|
||||
.await
|
||||
.into_iter()
|
||||
@@ -91,9 +113,11 @@ pub async fn single_room_info(
|
||||
client: MatrixClientExtractor,
|
||||
path: web::Path<RoomIdInPath>,
|
||||
) -> HttpResult {
|
||||
let notifs = client.client.client.notification_settings().await;
|
||||
|
||||
Ok(match client.client.client.get_room(&path.room_id) {
|
||||
None => HttpResponse::NotFound().json("Room not found"),
|
||||
Some(r) => HttpResponse::Ok().json(APIRoomInfo::from_room(&r).await?),
|
||||
Some(r) => HttpResponse::Ok().json(APIRoomInfo::from_room(&r, ¬ifs).await?),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user