From ce3cc019bb1a3be21b0653eb7d6d10ea496e4df3 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Tue, 21 Feb 2023 17:32:03 +0100 Subject: [PATCH 1/4] 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, From da5f06a4bc9543e0476d7d4195139c2eec375dd0 Mon Sep 17 00:00:00 2001 From: Oliver Sand Date: Tue, 7 Mar 2023 17:11:57 +0100 Subject: [PATCH 2/4] Include all data that is shared in the permissions screen --- src/components/views/elements/AppPermission.tsx | 2 ++ src/i18n/strings/en_EN.json | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/components/views/elements/AppPermission.tsx b/src/components/views/elements/AppPermission.tsx index 33ca2ba4d4c..43ce66d6d1a 100644 --- a/src/components/views/elements/AppPermission.tsx +++ b/src/components/views/elements/AppPermission.tsx @@ -105,7 +105,9 @@ export default class AppPermission extends React.Component {
  • {_t("Your display name")}
  • {_t("Your avatar URL")}
  • {_t("Your user ID")}
  • +
  • {_t("Your device ID")}
  • {_t("Your theme")}
  • +
  • {_t("Your language")}
  • {_t("%(brand)s URL", { brand })}
  • {_t("Room ID")}
  • {_t("Widget ID")}
  • diff --git a/src/i18n/strings/en_EN.json b/src/i18n/strings/en_EN.json index 277da44a9c4..93d069689f8 100644 --- a/src/i18n/strings/en_EN.json +++ b/src/i18n/strings/en_EN.json @@ -2520,7 +2520,9 @@ "Your display name": "Your display name", "Your avatar URL": "Your avatar URL", "Your user ID": "Your user ID", + "Your device ID": "Your device ID", "Your theme": "Your theme", + "Your language": "Your language", "%(brand)s URL": "%(brand)s URL", "Room ID": "Room ID", "Widget ID": "Widget ID", From b0fb14615ef90a246b7d0955a5603d39300f0396 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Mon, 8 May 2023 10:59:29 +0200 Subject: [PATCH 3/4] Update matrix-widget-api to version 1.4.0 Signed-off-by: Dominik Henneke --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index bf7a093494f..e60902f879e 100644 --- a/package.json +++ b/package.json @@ -97,7 +97,7 @@ "matrix-encrypt-attachment": "^1.0.3", "matrix-events-sdk": "0.0.1", "matrix-js-sdk": "github:matrix-org/matrix-js-sdk#develop", - "matrix-widget-api": "^1.3.1", + "matrix-widget-api": "^1.4.0", "memoize-one": "^6.0.0", "minimist": "^1.2.5", "opus-recorder": "^8.0.3", diff --git a/yarn.lock b/yarn.lock index c5950a31238..dc8342658b3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6499,10 +6499,10 @@ matrix-web-i18n@^1.4.0: "@babel/traverse" "^7.18.5" walk "^2.3.15" -matrix-widget-api@^1.3.1: - version "1.3.1" - resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.3.1.tgz#e38f404c76bb15c113909505c1c1a5b4d781c2f5" - integrity sha512-+rN6vGvnXm+fn0uq9r2KWSL/aPtehD6ObC50jYmUcEfgo8CUpf9eUurmjbRlwZkWq3XHXFuKQBUCI9UzqWg37Q== +matrix-widget-api@^1.3.1, matrix-widget-api@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.4.0.tgz#e426ec16a013897f3a4a9c2bff423f54ab0ba745" + integrity sha512-dw0dRylGQzDUoiaY/g5xx1tBbS7aoov31PRtFMAvG58/4uerYllV9Gfou7w+I1aglwB6hihTREzKltVjARWV6A== dependencies: "@types/events" "^3.0.0" events "^3.2.0" From 3d536dd986c833e08d8dac57dd090ec9061a73e0 Mon Sep 17 00:00:00 2001 From: Dominik Henneke Date: Mon, 8 May 2023 11:58:34 +0200 Subject: [PATCH 4/4] Fix type and test Signed-off-by: Dominik Henneke --- src/stores/widgets/StopGapWidget.ts | 2 +- test/stores/widgets/StopGapWidget-test.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/stores/widgets/StopGapWidget.ts b/src/stores/widgets/StopGapWidget.ts index 25479653d84..3f63a9705e6 100644 --- a/src/stores/widgets/StopGapWidget.ts +++ b/src/stores/widgets/StopGapWidget.ts @@ -221,7 +221,7 @@ export class StopGapWidget extends EventEmitter { clientId: ELEMENT_CLIENT_ID, clientTheme: SettingsStore.getValue("theme"), clientLanguage: getUserLanguage(), - deviceId: this.client.getDeviceId(), + deviceId: this.client.getDeviceId() ?? undefined, }; 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 da7612a3bf1..89e626a4f02 100644 --- a/test/stores/widgets/StopGapWidget-test.ts +++ b/test/stores/widgets/StopGapWidget-test.ts @@ -15,6 +15,7 @@ limitations under the License. */ import { mocked, MockedObject } from "jest-mock"; +import { last } from "lodash"; import { MatrixEvent } from "matrix-js-sdk/src/matrix"; import { MatrixClient, ClientEvent } from "matrix-js-sdk/src/client"; import { ClientWidgetApi } from "matrix-widget-api"; @@ -42,7 +43,7 @@ describe("StopGapWidget", () => { id: "test", creatorUserId: "@alice:example.org", type: "example", - url: "https://example.org?user-id=$matrix_user_id&device-id=$org.matrix.msc3819.device_id", + url: "https://example.org?user-id=$matrix_user_id&device-id=$org.matrix.msc3819.matrix_device_id", roomId: "!1:example.org", }, room: mkRoom(client, "!1:example.org"), @@ -53,7 +54,7 @@ describe("StopGapWidget", () => { }); // Start messaging without an iframe, since ClientWidgetApi is mocked widget.startMessaging(null as unknown as HTMLIFrameElement); - messaging = mocked(mocked(ClientWidgetApi).mock.instances[0]); + messaging = mocked(last(mocked(ClientWidgetApi).mock.instances)!); }); afterEach(() => {