diff --git a/crates/matrix-sdk/CHANGELOG.md b/crates/matrix-sdk/CHANGELOG.md index 35a2d1035..efc309ec5 100644 --- a/crates/matrix-sdk/CHANGELOG.md +++ b/crates/matrix-sdk/CHANGELOG.md @@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file. ### Features +- `Client::send_call_notification_if_needed` now returns `Result` instead of `Result<()>` so we can check if + the event was sent. - Added `SendMediaUploadRequest` wrapper for `SendRequest`, which checks the size of the request to upload making sure it doesn't exceed the `m.upload.size` value that can be fetched through `Client::load_or_fetch_max_upload_size`. diff --git a/crates/matrix-sdk/src/room/mod.rs b/crates/matrix-sdk/src/room/mod.rs index 17059c46b..f1d735cc2 100644 --- a/crates/matrix-sdk/src/room/mod.rs +++ b/crates/matrix-sdk/src/room/mod.rs @@ -3311,28 +3311,45 @@ impl Room { /// It will configure the notify type: ring or notify based on: /// - is this a DM room -> ring /// - is this a group with more than one other member -> notify - pub async fn send_call_notification_if_needed(&self) -> Result<()> { + /// + /// Returns: + /// - `Ok(true)` if the event was successfully sent. + /// - `Ok(false)` if we didn't send it because it was unnecessary. + /// - `Err(_)` if sending the event failed. + pub async fn send_call_notification_if_needed(&self) -> Result { + debug!("Sending call notification for room {} if needed", self.inner.room_id()); + if self.has_active_room_call() { - return Ok(()); + warn!("Room {} has active room call, not sending a new notify event.", self.room_id()); + return Ok(false); } if !self.can_user_trigger_room_notification(self.own_user_id()).await? { - return Ok(()); + warn!( + "User can't send notifications to everyone in the room {}. \ + Not sending a new notify event.", + self.room_id() + ); + return Ok(false); } + let notify_type = if self.is_direct().await.unwrap_or(false) { + NotifyType::Ring + } else { + NotifyType::Notify + }; + + debug!("Sending `m.call.notify` event with notify type: {notify_type:?}"); + self.send_call_notification( self.room_id().to_string().to_owned(), ApplicationType::Call, - if self.is_direct().await.unwrap_or(false) { - NotifyType::Ring - } else { - NotifyType::Notify - }, + notify_type, Mentions::with_room_mention(), ) .await?; - Ok(()) + Ok(true) } /// Get the beacon information event in the room for the `user_id`.