diff --git a/package.json b/package.json index cf42a0c4d1..beb34a3bb3 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,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.5.0", + "matrix-widget-api": "^1.6.0", "memoize-one": "^6.0.0", "minimist": "^1.2.5", "oidc-client-ts": "^2.2.4", diff --git a/src/components/views/dialogs/ModalWidgetDialog.tsx b/src/components/views/dialogs/ModalWidgetDialog.tsx index 73a2916e3c..1e1300b281 100644 --- a/src/components/views/dialogs/ModalWidgetDialog.tsx +++ b/src/components/views/dialogs/ModalWidgetDialog.tsx @@ -136,6 +136,7 @@ export default class ModalWidgetDialog extends React.PureComponent { + const client = MatrixClientPeg.safeGet(); + + return await client.getMediaConfig(); + } + + public async uploadFile(file: XMLHttpRequestBodyInit): Promise<{ contentUri: string }> { + const client = MatrixClientPeg.safeGet(); + + const uploadResult = await client.uploadContent(file); + + return { contentUri: uploadResult.content_uri }; + } } diff --git a/test/stores/widgets/StopGapWidget-test.ts b/test/stores/widgets/StopGapWidget-test.ts index f7f7b96993..fce2b05a75 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?user-id=$matrix_user_id&device-id=$org.matrix.msc3819.matrix_device_id", + url: "https://example.org?user-id=$matrix_user_id&device-id=$org.matrix.msc3819.matrix_device_id&base-url=$org.matrix.msc4039.matrix_base_url", roomId: "!1:example.org", }, room: mkRoom(client, "!1:example.org"), @@ -62,7 +62,7 @@ describe("StopGapWidget", () => { 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", + "https://example.org/?user-id=%40userId%3Amatrix.org&device-id=ABCDEFGHI&base-url=https%3A%2F%2Fmatrix-client.matrix.org&widgetId=test&parentUrl=http%3A%2F%2Flocalhost%2F", ); }); diff --git a/test/stores/widgets/StopGapWidgetDriver-test.ts b/test/stores/widgets/StopGapWidgetDriver-test.ts index 15c88ba297..6e51d4ae98 100644 --- a/test/stores/widgets/StopGapWidgetDriver-test.ts +++ b/test/stores/widgets/StopGapWidgetDriver-test.ts @@ -447,4 +447,44 @@ describe("StopGapWidgetDriver", () => { expect(client.searchUserDirectory).toHaveBeenCalledWith({ term: "foo", limit: 25 }); }); }); + + describe("getMediaConfig", () => { + let driver: WidgetDriver; + + beforeEach(() => { + driver = mkDefaultDriver(); + }); + + it("gets the media configuration", async () => { + client.getMediaConfig.mockResolvedValue({ + "m.upload.size": 1000, + }); + + await expect(driver.getMediaConfig()).resolves.toEqual({ + "m.upload.size": 1000, + }); + + expect(client.getMediaConfig).toHaveBeenCalledWith(); + }); + }); + + describe("uploadFile", () => { + let driver: WidgetDriver; + + beforeEach(() => { + driver = mkDefaultDriver(); + }); + + it("uploads a file", async () => { + client.uploadContent.mockResolvedValue({ + content_uri: "mxc://...", + }); + + await expect(driver.uploadFile("data")).resolves.toEqual({ + contentUri: "mxc://...", + }); + + expect(client.uploadContent).toHaveBeenCalledWith("data"); + }); + }); }); diff --git a/test/test-utils/test-utils.ts b/test/test-utils/test-utils.ts index 47f3713364..10a43d8da0 100644 --- a/test/test-utils/test-utils.ts +++ b/test/test-utils/test-utils.ts @@ -249,6 +249,8 @@ export function createTestClient(): MatrixClient { addThreePidOnly: jest.fn(), requestMsisdnToken: jest.fn(), submitMsisdnToken: jest.fn(), + getMediaConfig: jest.fn(), + baseUrl: "https://matrix-client.matrix.org", } as unknown as MatrixClient; client.reEmitter = new ReEmitter(client); diff --git a/yarn.lock b/yarn.lock index 82e4021b69..4f62a0dba1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7589,10 +7589,10 @@ matrix-web-i18n@^2.1.0: lodash "^4.17.21" walk "^2.3.15" -matrix-widget-api@^1.5.0: - version "1.5.0" - resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.5.0.tgz#4ae3e46a7f2854f944ddaf8a5af63d72fba76c45" - integrity sha512-hKGfqQKK5qVMwW0Sp8l2TiuW8UuHafTvUZNSWBPghedB/rSFbVLlr0mufuEV0iq/pQ7ChW96q/WEC6Llie4SnA== +matrix-widget-api@^1.5.0, matrix-widget-api@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/matrix-widget-api/-/matrix-widget-api-1.6.0.tgz#f0075411edffc6de339580ade7e6e6e6edb01af4" + integrity sha512-VXIJyAZ/WnBmT4C7ePqevgMYGneKMCP/0JuCOqntSsaNlCRHJvwvTxmqUU+ufOpzIF5gYNyIrAjbgrEbK3iqJQ== dependencies: "@types/events" "^3.0.0" events "^3.2.0"