From ce3cc019bb1a3be21b0653eb7d6d10ea496e4df3 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Tue, 21 Feb 2023 17:32:03 +0100 Subject: [PATCH] Pass device id to widget Implement the [comment in MSC 3819](https://github.com/matrix-org/matrix-spec-proposals/pull/3819#discussion_r1099833846) which requests passing a device id to a widget. This is based on the previous work in the matrix-widget-api: https://github.com/matrix-org/matrix-widget-api/pull/78 Signed-off-by: Oliver Sand --- src/stores/widgets/StopGapWidget.ts | 1 + test/stores/widgets/StopGapWidget-test.ts | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/stores/widgets/StopGapWidget.ts b/src/stores/widgets/StopGapWidget.ts index da5f956bbe9..25479653d84 100644 --- a/src/stores/widgets/StopGapWidget.ts +++ b/src/stores/widgets/StopGapWidget.ts @@ -221,6 +221,7 @@ export class StopGapWidget extends EventEmitter { clientId: ELEMENT_CLIENT_ID, clientTheme: SettingsStore.getValue("theme"), clientLanguage: getUserLanguage(), + deviceId: this.client.getDeviceId(), }; const templated = this.mockWidget.getCompleteUrl(Object.assign(defaults, fromCustomisation), opts?.asPopout); diff --git a/test/stores/widgets/StopGapWidget-test.ts b/test/stores/widgets/StopGapWidget-test.ts index 38e9983d49b..da7612a3bf1 100644 --- a/test/stores/widgets/StopGapWidget-test.ts +++ b/test/stores/widgets/StopGapWidget-test.ts @@ -42,7 +42,7 @@ describe("StopGapWidget", () => { id: "test", creatorUserId: "@alice:example.org", type: "example", - url: "https://example.org", + url: "https://example.org?user-id=$matrix_user_id&device-id=$org.matrix.msc3819.device_id", roomId: "!1:example.org", }, room: mkRoom(client, "!1:example.org"), @@ -60,6 +60,12 @@ describe("StopGapWidget", () => { widget.stopMessaging(); }); + it("should replace parameters in widget url template", () => { + expect(widget.embedUrl).toBe( + "https://example.org/?user-id=%40userId%3Amatrix.org&device-id=ABCDEFGHI&widgetId=test&parentUrl=http%3A%2F%2Flocalhost%2F", + ); + }); + it("feeds incoming to-device messages to the widget", async () => { const event = mkEvent({ event: true,