Pass device id to widgets (#10209)

* 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 <oliver.sand@nordeck.net>

* Include all data that is shared in the permissions screen

* Update matrix-widget-api to version 1.4.0

Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net>

* Fix type and test

Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net>

---------

Signed-off-by: Oliver Sand <oliver.sand@nordeck.net>
Signed-off-by: Dominik Henneke <dominik.henneke@nordeck.net>
Co-authored-by: Dominik Henneke <dominik.henneke@nordeck.net>
This commit is contained in:
Oliver Sand 2023-05-23 15:35:31 +02:00 committed by GitHub
parent 72d1bd910a
commit a0c2676c38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 16 additions and 4 deletions

View file

@ -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",
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,13 +54,19 @@ 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(() => {
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,