From 57797e933a4577c4b43f023b6e5c6d52f4af1a0f Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Mon, 1 Dec 2025 09:12:58 +0100 Subject: [PATCH] Can check if rooms are muted --- .../matrix/matrix_room_controller.rs | 44 ++++++++++++++----- .../src/api/matrix/MatrixApiRoom.ts | 1 + .../widgets/messages/MainMessagesWidget.tsx | 5 ++- 3 files changed, 39 insertions(+), 11 deletions(-) diff --git a/matrixgw_backend/src/controllers/matrix/matrix_room_controller.rs b/matrixgw_backend/src/controllers/matrix/matrix_room_controller.rs index 1886169..c106eca 100644 --- a/matrixgw_backend/src/controllers/matrix/matrix_room_controller.rs +++ b/matrixgw_backend/src/controllers/matrix/matrix_room_controller.rs @@ -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, number_unread_messages: u64, + notifications: RoomNotificationMode, latest_event: Option, } impl APIRoomInfo { - async fn from_room(r: &Room) -> anyhow::Result { + async fn from_room(r: &Room, notif: &NotificationSettings) -> anyhow::Result { // Get parent spaces let parent_spaces = r .parent_spaces() @@ -39,19 +43,34 @@ impl APIRoomInfo { }) .collect::>(); + let members = r + .members(RoomMemberships::ACTIVE) + .await? + .into_iter() + .map(|r| r.user_id().to_owned()) + .collect::>(); + + 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::>(), + 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::>() .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::>() .await .into_iter() @@ -91,9 +113,11 @@ pub async fn single_room_info( client: MatrixClientExtractor, path: web::Path, ) -> 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?), }) } diff --git a/matrixgw_frontend/src/api/matrix/MatrixApiRoom.ts b/matrixgw_frontend/src/api/matrix/MatrixApiRoom.ts index fecbd21..8cfbcbc 100644 --- a/matrixgw_frontend/src/api/matrix/MatrixApiRoom.ts +++ b/matrixgw_frontend/src/api/matrix/MatrixApiRoom.ts @@ -11,6 +11,7 @@ export interface Room { is_space?: boolean; parents: string[]; number_unread_messages: number; + notifications: "AllMessages" | "MentionsAndKeywordsOnly" | "Mute"; latest_event?: MatrixEvent; } diff --git a/matrixgw_frontend/src/widgets/messages/MainMessagesWidget.tsx b/matrixgw_frontend/src/widgets/messages/MainMessagesWidget.tsx index 1980e8f..8875faf 100644 --- a/matrixgw_frontend/src/widgets/messages/MainMessagesWidget.tsx +++ b/matrixgw_frontend/src/widgets/messages/MainMessagesWidget.tsx @@ -72,7 +72,10 @@ function _MainMessageWidget(p: { }, [space, p.rooms]); const unreadRooms = React.useMemo( - () => p.rooms.filter((r) => r.number_unread_messages > 0).length, + () => + p.rooms.filter( + (r) => r.number_unread_messages > 0 && r.notifications === "AllMessages" + ).length, [p.rooms] );