Skip to content

Commit baf6824

Browse files
jmartinespHywan
authored andcommitted
refactor: Add extra logs to Client::send_call_notifications_if_needed
Also make it return `Result<bool>` instead of `Result<()>` so we can check if the event was sent.
1 parent c1ce92b commit baf6824

File tree

2 files changed

+28
-9
lines changed

2 files changed

+28
-9
lines changed

crates/matrix-sdk/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ All notable changes to this project will be documented in this file.
88

99
### Features
1010

11+
- `Client::send_call_notification_if_needed` now returns `Result<bool>` instead of `Result<()>` so we can check if
12+
the event was sent.
1113
- Added `SendMediaUploadRequest` wrapper for `SendRequest`, which checks the size of the request to
1214
upload making sure it doesn't exceed the `m.upload.size` value that can be fetched through
1315
`Client::load_or_fetch_max_upload_size`.

crates/matrix-sdk/src/room/mod.rs

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,28 +3311,45 @@ impl Room {
33113311
/// It will configure the notify type: ring or notify based on:
33123312
/// - is this a DM room -> ring
33133313
/// - is this a group with more than one other member -> notify
3314-
pub async fn send_call_notification_if_needed(&self) -> Result<()> {
3314+
///
3315+
/// Returns:
3316+
/// - `Ok(true)` if the event was successfully sent.
3317+
/// - `Ok(false)` if we didn't send it because it was unnecessary.
3318+
/// - `Err(_)` if sending the event failed.
3319+
pub async fn send_call_notification_if_needed(&self) -> Result<bool> {
3320+
debug!("Sending call notification for room {} if needed", self.inner.room_id());
3321+
33153322
if self.has_active_room_call() {
3316-
return Ok(());
3323+
warn!("Room {} has active room call, not sending a new notify event.", self.room_id());
3324+
return Ok(false);
33173325
}
33183326

33193327
if !self.can_user_trigger_room_notification(self.own_user_id()).await? {
3320-
return Ok(());
3328+
warn!(
3329+
"User can't send notifications to everyone in the room {}. \
3330+
Not sending a new notify event.",
3331+
self.room_id()
3332+
);
3333+
return Ok(false);
33213334
}
33223335

3336+
let notify_type = if self.is_direct().await.unwrap_or(false) {
3337+
NotifyType::Ring
3338+
} else {
3339+
NotifyType::Notify
3340+
};
3341+
3342+
debug!("Sending `m.call.notify` event with notify type: {notify_type:?}");
3343+
33233344
self.send_call_notification(
33243345
self.room_id().to_string().to_owned(),
33253346
ApplicationType::Call,
3326-
if self.is_direct().await.unwrap_or(false) {
3327-
NotifyType::Ring
3328-
} else {
3329-
NotifyType::Notify
3330-
},
3347+
notify_type,
33313348
Mentions::with_room_mention(),
33323349
)
33333350
.await?;
33343351

3335-
Ok(())
3352+
Ok(true)
33363353
}
33373354

33383355
/// Get the beacon information event in the room for the `user_id`.

0 commit comments

Comments
 (0)