Skip to content

Commit ca99fd1

Browse files
committed
feat(ffi): Auto approve the required widget capabilities for element call raise hand and reaction feature.
1 parent 8d07f36 commit ca99fd1

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

bindings/matrix-sdk-ffi/src/widget.rs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use matrix_sdk::{
55
async_trait,
66
widget::{MessageLikeEventFilter, StateEventFilter},
77
};
8+
use ruma::events::MessageLikeEventType;
89
use tracing::error;
910

1011
use crate::{room::Room, RUNTIME};
@@ -268,6 +269,31 @@ pub fn get_element_call_required_permissions(
268269
) -> WidgetCapabilities {
269270
use ruma::events::StateEventType;
270271

272+
let read_send = vec![
273+
// To read and send rageshake requests from other room members
274+
WidgetEventFilter::MessageLikeWithType {
275+
event_type: "org.matrix.rageshake_request".to_owned(),
276+
},
277+
// To read and send encryption keys
278+
// TODO change this to the appropriate to-device version once ready
279+
WidgetEventFilter::MessageLikeWithType {
280+
event_type: "io.element.call.encryption_keys".to_owned(),
281+
},
282+
// To read and send custom EC reactions. They are different to normal `m.reaction`
283+
// because they can be send multiple times to the same event.
284+
WidgetEventFilter::MessageLikeWithType {
285+
event_type: "io.element.call.reaction".to_owned(),
286+
},
287+
// This allows send raise hand reactions.
288+
WidgetEventFilter::MessageLikeWithType {
289+
event_type: MessageLikeEventType::Reaction.to_string(),
290+
},
291+
// This allows to detect if someone does not raise their hand anymore.
292+
WidgetEventFilter::MessageLikeWithType {
293+
event_type: MessageLikeEventType::RoomRedaction.to_string(),
294+
},
295+
];
296+
271297
WidgetCapabilities {
272298
read: vec![
273299
// To compute the current state of the matrixRTC session.
@@ -278,19 +304,13 @@ pub fn get_element_call_required_permissions(
278304
WidgetEventFilter::StateWithType {
279305
event_type: StateEventType::RoomEncryption.to_string(),
280306
},
281-
// To read rageshake requests from other room members
282-
WidgetEventFilter::MessageLikeWithType {
283-
event_type: "org.matrix.rageshake_request".to_owned(),
284-
},
285-
// To read encryption keys
286-
// TODO change this to the appropriate to-device version once ready
287-
WidgetEventFilter::MessageLikeWithType {
288-
event_type: "io.element.call.encryption_keys".to_owned(),
289-
},
290307
// This allows the widget to check the room version, so it can know about
291308
// version-specific auth rules (namely MSC3779).
292309
WidgetEventFilter::StateWithType { event_type: StateEventType::RoomCreate.to_string() },
293-
],
310+
]
311+
.into_iter()
312+
.chain(read_send.clone())
313+
.collect(),
294314
send: vec![
295315
// To send the call participation state event (main MatrixRTC event).
296316
// This is required for legacy state events (using only one event for all devices with
@@ -313,15 +333,10 @@ pub fn get_element_call_required_permissions(
313333
event_type: StateEventType::CallMember.to_string(),
314334
state_key: format!("_{own_user_id}_{own_device_id}"),
315335
},
316-
// To request other room members to send rageshakes
317-
WidgetEventFilter::MessageLikeWithType {
318-
event_type: "org.matrix.rageshake_request".to_owned(),
319-
},
320-
// To send this user's encryption keys
321-
WidgetEventFilter::MessageLikeWithType {
322-
event_type: "io.element.call.encryption_keys".to_owned(),
323-
},
324-
],
336+
]
337+
.into_iter()
338+
.chain(read_send)
339+
.collect(),
325340
requires_client: true,
326341
update_delayed_event: true,
327342
send_delayed_event: true,
@@ -417,7 +432,7 @@ impl From<matrix_sdk::widget::Capabilities> for WidgetCapabilities {
417432
}
418433

419434
/// Different kinds of filters that could be applied to the timeline events.
420-
#[derive(uniffi::Enum)]
435+
#[derive(uniffi::Enum, Clone)]
421436
pub enum WidgetEventFilter {
422437
/// Matches message-like events with the given `type`.
423438
MessageLikeWithType { event_type: String },

0 commit comments

Comments
 (0)