From c843a4163a4f03dbca2bc78ffb1ed64c247e53b9 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Tue, 16 Jul 2024 21:46:17 +0900 Subject: [PATCH] Let Element Call widget set session memberships (#12713) * Let Element Call widget set session memberships Grant Element Call widgets permission to set device-specific session membership state events. * Lint * Test that call widgets can set session membership * Add comments for each membership type --- src/stores/widgets/StopGapWidgetDriver.ts | 28 +++++++++++++++---- .../widgets/StopGapWidgetDriver-test.ts | 2 ++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/stores/widgets/StopGapWidgetDriver.ts b/src/stores/widgets/StopGapWidgetDriver.ts index 248c520ddd5..f6bffca3d29 100644 --- a/src/stores/widgets/StopGapWidgetDriver.ts +++ b/src/stores/widgets/StopGapWidgetDriver.ts @@ -144,13 +144,31 @@ export class StopGapWidgetDriver extends WidgetDriver { this.allowedCapabilities.add( WidgetEventCapability.forStateEvent(EventDirection.Receive, EventType.RoomEncryption).raw, ); + const clientUserId = MatrixClientPeg.safeGet().getSafeUserId(); + // For the legacy membership type this.allowedCapabilities.add( - WidgetEventCapability.forStateEvent( - EventDirection.Send, - "org.matrix.msc3401.call.member", - MatrixClientPeg.safeGet().getSafeUserId(), - ).raw, + WidgetEventCapability.forStateEvent(EventDirection.Send, "org.matrix.msc3401.call.member", clientUserId) + .raw, ); + const clientDeviceId = MatrixClientPeg.safeGet().getDeviceId(); + if (clientDeviceId !== null) { + // For the session membership type compliant with MSC4143 + this.allowedCapabilities.add( + WidgetEventCapability.forStateEvent( + EventDirection.Send, + "org.matrix.msc3401.call.member", + `_${clientUserId}_${clientDeviceId}`, + ).raw, + ); + // MSC3779 version, with no leading underscore + this.allowedCapabilities.add( + WidgetEventCapability.forStateEvent( + EventDirection.Send, + "org.matrix.msc3401.call.member", + `${clientUserId}_${clientDeviceId}`, + ).raw, + ); + } this.allowedCapabilities.add( WidgetEventCapability.forStateEvent(EventDirection.Receive, "org.matrix.msc3401.call.member").raw, ); diff --git a/test/stores/widgets/StopGapWidgetDriver-test.ts b/test/stores/widgets/StopGapWidgetDriver-test.ts index 6e51d4ae980..5ba95d901dd 100644 --- a/test/stores/widgets/StopGapWidgetDriver-test.ts +++ b/test/stores/widgets/StopGapWidgetDriver-test.ts @@ -99,6 +99,8 @@ describe("StopGapWidgetDriver", () => { "org.matrix.msc2762.receive.state_event:org.matrix.msc3401.call", "org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#@alice:example.org", "org.matrix.msc2762.receive.state_event:org.matrix.msc3401.call.member", + `org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#_@alice:example.org_${client.deviceId}`, + `org.matrix.msc2762.send.state_event:org.matrix.msc3401.call.member#@alice:example.org_${client.deviceId}`, "org.matrix.msc3819.send.to_device:m.call.invite", "org.matrix.msc3819.receive.to_device:m.call.invite", "org.matrix.msc3819.send.to_device:m.call.candidates",