Add support for hiding videos (#29496)

* start hide

* Move useSettingsValueWithSetter to useSettings

* Add new setting showMediaEventIds

* Add a migration path

* Add an action button to hide settings.

* Tweaks to MImageBody to support new setting.

* Fixup and add tests

* add description for migration

* docs fixes

* add type

* i18n

* appese prettier

* Add tests for HideActionButton

* lint

* lint

* First pass at support for previewing/hiding images.

* Add a test for video files.

* First pass at supporting hiding video files.

* Use a hook for media visibility.

* Drop setting hook usage.

* Fixup MImageBody test

* Fixup tests

* Support functional components for message body rendering.

* Add a comment

* Move props into IProps

* Use new wrapping logic

* lint

* fixup

* allow for a delay for the image to render

* remove .only

* lint

* Fix jest test

* Fixup tests.

* make tests happy

* Improve comments

* review fixes

* unbreak test
This commit is contained in:
Will Hunt
2025-03-24 14:38:34 +00:00
committed by GitHub
parent 74da64db63
commit 13c4ab2cf4
14 changed files with 290 additions and 115 deletions
@@ -7,7 +7,7 @@ Please see LICENSE files in the repository root for full details.
*/
import React, { act } from "react";
import { fireEvent, render, screen, waitForElementToBeRemoved } from "jest-matrix-react";
import { fireEvent, render, screen, waitFor, waitForElementToBeRemoved } from "jest-matrix-react";
import { EventType, getHttpUriForMxc, MatrixEvent, Room } from "matrix-js-sdk/src/matrix";
import fetchMock from "fetch-mock-jest";
import encrypt from "matrix-encrypt-attachment";
@@ -85,6 +85,10 @@ describe("<MImageBody/>", () => {
fetchMock.mockReset();
});
afterEach(() => {
mocked(encrypt.decryptAttachment).mockReset();
});
it("should show a thumbnail while image is being downloaded", async () => {
fetchMock.getOnce(url, { status: 200 });
@@ -166,6 +170,8 @@ describe("<MImageBody/>", () => {
/>,
);
expect(screen.getByText("Show image")).toBeInTheDocument();
expect(fetchMock).not.toHaveFetched(url);
});
@@ -186,8 +192,12 @@ describe("<MImageBody/>", () => {
expect(fetchMock).toHaveFetched(url);
// spinner while downloading image
expect(screen.getByRole("progressbar")).toBeInTheDocument();
// Show image is asynchronous since it applies through a settings watcher hook, so
// be sure to wait here.
await waitFor(() => {
// spinner while downloading image
expect(screen.getByRole("progressbar")).toBeInTheDocument();
});
});
});