Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 64c2c85

Browse files
committed
More fixes, for replacing the event with an unencrypted one
1 parent 8724204 commit 64c2c85

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/components/views/rooms/EventTile.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ export class UnwrappedEventTile extends React.Component<EventTileProps, IState>
621621
mxEvent = mxEvent.replacingEvent() ?? mxEvent;
622622

623623
if (!mxEvent.isEncrypted() || mxEvent.isRedacted()) {
624+
this.setState({ verified: null });
624625
return;
625626
}
626627

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,5 +287,51 @@ describe("EventTile", () => {
287287
"mx_EventTile_e2eIcon_warning",
288288
);
289289
});
290+
291+
it("should update the warning when the event is replaced with an unencrypted one", async () => {
292+
jest.spyOn(client, "isRoomEncrypted").mockReturnValue(true);
293+
294+
// we start out with an event from the trusted device
295+
mxEvent = await mkEncryptedEvent({
296+
plainContent: { msgtype: "m.text", body: "msg1" },
297+
plainType: "m.room.message",
298+
user: "@alice:example.org",
299+
room: room.roomId,
300+
});
301+
eventToEncryptionInfoMap.set(mxEvent.getId()!, {
302+
authenticated: true,
303+
sender: TRUSTED_DEVICE,
304+
} as IEncryptedEventInfo);
305+
306+
const { container } = getComponent();
307+
308+
const eventTiles = container.getElementsByClassName("mx_EventTile");
309+
expect(eventTiles).toHaveLength(1);
310+
const eventTile = eventTiles[0];
311+
312+
expect(eventTile.classList).toContain("mx_EventTile_verified");
313+
314+
// there should be no warning
315+
expect(container.getElementsByClassName("mx_EventTile_e2eIcon")).toHaveLength(0);
316+
317+
// then we replace the event with an unencrypted one
318+
const replacementEvent = await mkMessage({
319+
msg: "msg2",
320+
user: "@alice:example.org",
321+
room: room.roomId,
322+
event: true,
323+
});
324+
325+
act(() => {
326+
mxEvent.makeReplaced(replacementEvent);
327+
});
328+
329+
// check it was updated
330+
expect(eventTile.classList).not.toContain("mx_EventTile_verified");
331+
expect(container.getElementsByClassName("mx_EventTile_e2eIcon")).toHaveLength(1);
332+
expect(container.getElementsByClassName("mx_EventTile_e2eIcon")[0].classList).toContain(
333+
"mx_EventTile_e2eIcon_warning",
334+
);
335+
});
290336
});
291337
});

0 commit comments

Comments
 (0)