Skip to content

Commit 642c981

Browse files
authored
MatrixRTC: fix call member parsing by using the correct focus_active format. (ruma#1888)
`focus_select` -> `focus_selection`
1 parent 82417e3 commit 642c981

File tree

3 files changed

+33
-26
lines changed

3 files changed

+33
-26
lines changed

crates/ruma-events/src/call/member.rs

+29-22
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ impl CallMemberEventContent {
7272
pub fn new_empty(leave_reason: Option<LeaveReason>) -> Self {
7373
Self::Empty(EmptyMembershipData { leave_reason })
7474
}
75+
7576
/// All non expired memberships in this member event.
7677
///
7778
/// In most cases you want to use this method instead of the public memberships field.
@@ -268,7 +269,7 @@ mod tests {
268269
}),
269270
"ABCDE".to_owned(),
270271
ActiveFocus::Livekit(ActiveLivekitFocus {
271-
focus_select: FocusSelection::OldestMembership,
272+
focus_selection: FocusSelection::OldestMembership,
272273
}),
273274
vec![Focus::Livekit(LivekitFocus {
274275
alias: "1".to_owned(),
@@ -294,7 +295,7 @@ mod tests {
294295
],
295296
"focus_active":{
296297
"type":"livekit",
297-
"focus_select":"oldest_membership"
298+
"focus_selection":"oldest_membership"
298299
}
299300
});
300301
assert_eq!(
@@ -348,7 +349,7 @@ mod tests {
348349
}),
349350
"THIS_DEVICE".to_owned(),
350351
ActiveFocus::Livekit(ActiveLivekitFocus {
351-
focus_select: FocusSelection::OldestMembership,
352+
focus_selection: FocusSelection::OldestMembership,
352353
}),
353354
vec![Focus::Livekit(LivekitFocus {
354355
alias: "room1".to_owned(),
@@ -364,7 +365,7 @@ mod tests {
364365
"device_id": "THIS_DEVICE",
365366
"focus_active":{
366367
"type": "livekit",
367-
"focus_select": "oldest_membership"
368+
"focus_selection": "oldest_membership"
368369
},
369370
"foci_preferred": [
370371
{
@@ -473,7 +474,7 @@ mod tests {
473474
"device_id": "THIS_DEVICE",
474475
"focus_active":{
475476
"type": "livekit",
476-
"focus_select": "oldest_membership"
477+
"focus_selection": "oldest_membership"
477478
},
478479
"foci_preferred": [
479480
{
@@ -509,26 +510,32 @@ mod tests {
509510
assert_eq!(member_event.sender, sender);
510511
assert_eq!(member_event.room_id, room_id);
511512
assert_eq!(member_event.origin_server_ts, TS(js_int::UInt::new(111).unwrap()));
513+
let membership = SessionMembershipData {
514+
application: Application::Call(CallApplicationContent {
515+
call_id: "".to_owned(),
516+
scope: CallScope::Room,
517+
}),
518+
device_id: "THIS_DEVICE".to_owned(),
519+
foci_preferred: [Focus::Livekit(LivekitFocus {
520+
alias: "room1".to_owned(),
521+
service_url: "https://livekit1.com".to_owned(),
522+
})]
523+
.to_vec(),
524+
focus_active: ActiveFocus::Livekit(ActiveLivekitFocus {
525+
focus_selection: FocusSelection::OldestMembership,
526+
}),
527+
created_ts: None,
528+
};
512529
assert_eq!(
513530
member_event.content,
514-
CallMemberEventContent::SessionContent(SessionMembershipData {
515-
application: Application::Call(CallApplicationContent {
516-
call_id: "".to_owned(),
517-
scope: CallScope::Room
518-
}),
519-
device_id: "THIS_DEVICE".to_owned(),
520-
foci_preferred: [Focus::Livekit(LivekitFocus {
521-
alias: "room1".to_owned(),
522-
service_url: "https://livekit1.com".to_owned()
523-
})]
524-
.to_vec(),
525-
focus_active: ActiveFocus::Livekit(ActiveLivekitFocus {
526-
focus_select: FocusSelection::OldestMembership
527-
}),
528-
created_ts: None
529-
})
531+
CallMemberEventContent::SessionContent(membership.clone())
530532
);
531533

534+
// Correctly computes the active_memberships array.
535+
assert_eq!(
536+
member_event.content.active_memberships(None)[0],
537+
vec![MembershipData::Session(&membership)][0]
538+
);
532539
assert_eq!(js_int::Int::new(10), member_event.unsigned.age);
533540
assert_eq!(
534541
CallMemberEventContent::Empty(EmptyMembershipData { leave_reason: None }),
@@ -568,7 +575,7 @@ mod tests {
568575
}
569576

570577
#[test]
571-
fn memberships_do_expire() {
578+
fn legacy_memberships_do_expire() {
572579
let content_legacy = create_call_member_legacy_event_content();
573580
let (now, one_second_ago, two_hours_ago) = timestamps();
574581

crates/ruma-events/src/call/member/focus.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@ pub enum ActiveFocus {
5959
#[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)]
6060
pub struct ActiveLivekitFocus {
6161
/// The selection method used to select the LiveKit focus for the rtc session.
62-
pub focus_select: FocusSelection,
62+
pub focus_selection: FocusSelection,
6363
}
6464

6565
impl ActiveLivekitFocus {
6666
/// Initialize a [`ActiveLivekitFocus`].
6767
///
6868
/// # Arguments
6969
///
70-
/// * `focus_select` - The selection method used to select the LiveKit focus for the rtc
70+
/// * `focus_selection` - The selection method used to select the LiveKit focus for the rtc
7171
/// session.
7272
pub fn new() -> Self {
73-
Self { focus_select: FocusSelection::OldestMembership }
73+
Self { focus_selection: FocusSelection::OldestMembership }
7474
}
7575
}
7676

crates/ruma-events/src/call/member/member_data.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl<'a> MembershipData<'a> {
5858
pub fn focus_active(&self) -> &ActiveFocus {
5959
match self {
6060
MembershipData::Legacy(_) => &ActiveFocus::Livekit(ActiveLivekitFocus {
61-
focus_select: super::focus::FocusSelection::OldestMembership,
61+
focus_selection: super::focus::FocusSelection::OldestMembership,
6262
}),
6363
MembershipData::Session(data) => &data.focus_active,
6464
}

0 commit comments

Comments
 (0)