Add setting to hide avatars of rooms you have been invited to. (#29497)
* Add ability to block images of rooms you have been invited to. * strings * Add tests * fix snapshot * tweaks * lint
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2024 New Vector Ltd.
|
||||
Copyright 2024, 2025 New Vector Ltd.
|
||||
Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
|
||||
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
@@ -17,6 +17,8 @@ import DMRoomMap from "../../../../../src/utils/DMRoomMap";
|
||||
import { LocalRoom } from "../../../../../src/models/LocalRoom";
|
||||
import * as AvatarModule from "../../../../../src/Avatar";
|
||||
import { DirectoryMember } from "../../../../../src/utils/direct-messages";
|
||||
import SettingsStore from "../../../../../src/settings/SettingsStore";
|
||||
import { SettingLevel } from "../../../../../src/settings/SettingLevel";
|
||||
|
||||
describe("RoomAvatar", () => {
|
||||
let client: MatrixClient;
|
||||
@@ -41,6 +43,12 @@ describe("RoomAvatar", () => {
|
||||
afterEach(() => {
|
||||
mocked(DMRoomMap.shared().getUserIdForRoomId).mockReset();
|
||||
mocked(AvatarModule.defaultAvatarUrlForString).mockClear();
|
||||
SettingsStore.setValue(
|
||||
"showAvatarsOnInvites",
|
||||
null,
|
||||
SettingLevel.ACCOUNT,
|
||||
SettingsStore.getDefaultValue("showAvatarsOnInvites"),
|
||||
);
|
||||
});
|
||||
|
||||
it("should render as expected for a Room", () => {
|
||||
@@ -64,4 +72,19 @@ describe("RoomAvatar", () => {
|
||||
localRoom.targets.push(new DirectoryMember({ user_id: userId }));
|
||||
expect(render(<RoomAvatar room={localRoom} />).container).toMatchSnapshot();
|
||||
});
|
||||
it("should render an avatar for a room the user is invited to", () => {
|
||||
SettingsStore.setValue("showAvatarsOnInvites", null, SettingLevel.ACCOUNT, true);
|
||||
const room = new Room("!room:example.com", client, client.getSafeUserId());
|
||||
jest.spyOn(room, "getMxcAvatarUrl").mockImplementation(() => "mxc://example.com/foobar");
|
||||
room.name = "test room";
|
||||
room.updateMyMembership("invite");
|
||||
expect(render(<RoomAvatar room={room} />).container).toMatchSnapshot();
|
||||
});
|
||||
it("should not render an invite avatar if the user has disabled it", () => {
|
||||
SettingsStore.setValue("showAvatarsOnInvites", null, SettingLevel.ACCOUNT, false);
|
||||
const room = new Room("!room:example.com", client, client.getSafeUserId());
|
||||
room.name = "test room";
|
||||
room.updateMyMembership("invite");
|
||||
expect(render(<RoomAvatar room={room} />).container).toMatchSnapshot();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,5 +1,44 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`RoomAvatar should not render an invite avatar if the user has disabled it 1`] = `
|
||||
<div>
|
||||
<span
|
||||
class="_avatar_1qbcf_8 mx_BaseAvatar _avatar-imageless_1qbcf_52"
|
||||
data-color="6"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
role="presentation"
|
||||
style="--cpd-avatar-size: 36px;"
|
||||
>
|
||||
t
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`RoomAvatar should render an avatar for a room the user is invited to 1`] = `
|
||||
<div>
|
||||
<span
|
||||
aria-label="Avatar"
|
||||
class="_avatar_1qbcf_8 mx_BaseAvatar"
|
||||
data-color="6"
|
||||
data-testid="avatar-img"
|
||||
data-type="round"
|
||||
style="--cpd-avatar-size: 36px;"
|
||||
>
|
||||
<img
|
||||
alt=""
|
||||
class="_image_1qbcf_41"
|
||||
data-type="round"
|
||||
height="36px"
|
||||
loading="lazy"
|
||||
referrerpolicy="no-referrer"
|
||||
src="http://this.is.a.url/example.com/foobar"
|
||||
width="36px"
|
||||
/>
|
||||
</span>
|
||||
</div>
|
||||
`;
|
||||
|
||||
exports[`RoomAvatar should render as expected for a DM room 1`] = `
|
||||
<div>
|
||||
<span
|
||||
|
||||
Reference in New Issue
Block a user