Skip to content

Commit 6d8cbf3

Browse files
authored
Replace MatrixClient.isRoomEncrypted by MatrixClient.CryptoApi.isEncryptionEnabledInRoom in EventTile.tsx (#28510)
* Replace `MatrixClient.isRoomEncrypted` by `MatrixClient.CryptoApi.isEncryptionEnabledInRoom` in `EventTile.tsx` * Use `roomContext.isRoomEncrypted`
1 parent b87437d commit 6d8cbf3

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

src/components/views/rooms/EventTile.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
775775
}
776776
}
777777

778-
if (MatrixClientPeg.safeGet().isRoomEncrypted(ev.getRoomId()!)) {
778+
if (this.context.isRoomEncrypted) {
779779
// else if room is encrypted
780780
// and event is being encrypted or is not_sent (Unknown Devices/Network Error)
781781
if (ev.status === EventStatus.ENCRYPTING) {

test/test-utils/test-utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export function createTestClient(): MatrixClient {
135135
loadSessionBackupPrivateKeyFromSecretStorage: jest.fn(),
136136
storeSessionBackupPrivateKey: jest.fn(),
137137
getKeyBackupInfo: jest.fn().mockResolvedValue(null),
138+
getEncryptionInfoForEvent: jest.fn().mockResolvedValue(null),
138139
}),
139140

140141
getPushActionsForEvent: jest.fn(),

test/unit-tests/components/views/dialogs/ForwardDialog-test.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ describe("ForwardDialog", () => {
6767
getAccountData: jest.fn().mockReturnValue(accountDataEvent),
6868
getPushActionsForEvent: jest.fn(),
6969
mxcUrlToHttp: jest.fn().mockReturnValue(""),
70-
isRoomEncrypted: jest.fn().mockReturnValue(false),
7170
getProfileInfo: jest.fn().mockResolvedValue({
7271
displayname: "Alice",
7372
}),

test/unit-tests/components/views/rooms/EventTile-test.tsx

+27-3
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,11 @@ describe("EventTile", () => {
7171
function getComponent(
7272
overrides: Partial<EventTileProps> = {},
7373
renderingType: TimelineRenderingType = TimelineRenderingType.Room,
74+
roomContext: Partial<IRoomState> = {},
7475
) {
7576
const context = getRoomContext(room, {
7677
timelineRenderingType: renderingType,
78+
...roomContext,
7779
});
7880
return render(<WrappedEventTile roomContext={context} eventTilePropertyOverrides={overrides} />);
7981
}
@@ -437,8 +439,6 @@ describe("EventTile", () => {
437439
});
438440

439441
it("should update the warning when the event is replaced with an unencrypted one", async () => {
440-
jest.spyOn(client, "isRoomEncrypted").mockReturnValue(true);
441-
442442
// we start out with an event from the trusted device
443443
mxEvent = await mkEncryptedMatrixEvent({
444444
plainContent: { msgtype: "m.text", body: "msg1" },
@@ -452,7 +452,7 @@ describe("EventTile", () => {
452452
shieldReason: null,
453453
} as EventEncryptionInfo);
454454

455-
const roomContext = getRoomContext(room, {});
455+
const roomContext = getRoomContext(room, { isRoomEncrypted: true });
456456
const { container, rerender } = render(<WrappedEventTile roomContext={roomContext} />);
457457
await flushPromises();
458458

@@ -581,4 +581,28 @@ describe("EventTile", () => {
581581
});
582582
});
583583
});
584+
585+
it("should display the not encrypted status for an unencrypted event when the room becomes encrypted", async () => {
586+
jest.spyOn(client.getCrypto()!, "getEncryptionInfoForEvent").mockResolvedValue({
587+
shieldColour: EventShieldColour.NONE,
588+
shieldReason: null,
589+
});
590+
591+
const { rerender } = getComponent();
592+
await flushPromises();
593+
// The room and the event are unencrypted, the tile should not show the not encrypted status
594+
expect(screen.queryByText("Not encrypted")).toBeNull();
595+
596+
// The room is now encrypted
597+
rerender(
598+
<WrappedEventTile
599+
roomContext={getRoomContext(room, {
600+
isRoomEncrypted: true,
601+
})}
602+
/>,
603+
);
604+
605+
// The event tile should now show the not encrypted status
606+
await waitFor(() => expect(screen.getByText("Not encrypted")).toBeInTheDocument());
607+
});
584608
});

0 commit comments

Comments
 (0)