mirror of https://github.com/vector-im/riot-web
use Crypto API to determine if room is encrypted
parent
4e8a990887
commit
d2b244f972
|
@ -125,6 +125,12 @@ export const UserIdentityWarning: React.FC<UserIdentityWarningProps> = ({ room }
|
|||
if (!crypto || initialisedRef.current) {
|
||||
return;
|
||||
}
|
||||
// If encryption is not enabled in the room, we don't need to do
|
||||
// anything. If encryption gets enabled later, we will retry, via
|
||||
// onRoomStateEvent.
|
||||
if (!(await crypto.isEncryptionEnabledInRoom(room.roomId))) {
|
||||
return;
|
||||
}
|
||||
initialisedRef.current = true;
|
||||
|
||||
const gotVerificationStatusUpdate = gotVerificationStatusUpdateRef.current;
|
||||
|
@ -151,14 +157,9 @@ export const UserIdentityWarning: React.FC<UserIdentityWarningProps> = ({ room }
|
|||
selectCurrentPrompt();
|
||||
}, [crypto, room, initialisedRef, gotVerificationStatusUpdateRef, membersNeedingApprovalRef, selectCurrentPrompt]);
|
||||
|
||||
// If the room has encryption enabled, we load the room members right away.
|
||||
// If not, we wait until encryption is enabled before loading the room
|
||||
// members, since we don't need to display anything in unencrypted rooms.
|
||||
if (crypto && room.hasEncryptionStateEvent()) {
|
||||
loadMembers().catch((e) => {
|
||||
logger.error("Error initialising UserIdentityWarning:", e);
|
||||
});
|
||||
}
|
||||
loadMembers().catch((e) => {
|
||||
logger.error("Error initialising UserIdentityWarning:", e);
|
||||
});
|
||||
|
||||
// When a user's verification status changes, we check if they need to be
|
||||
// added/removed from the set of members needing approval.
|
||||
|
|
|
@ -32,7 +32,6 @@ function mockRoom(): Room {
|
|||
getMember: jest.fn((userId) => {}),
|
||||
roomId: ROOM_ID,
|
||||
shouldEncryptForInvitedMembers: jest.fn(() => true),
|
||||
hasEncryptionStateEvent: jest.fn(() => true),
|
||||
} as unknown as Room;
|
||||
|
||||
return room;
|
||||
|
@ -80,6 +79,7 @@ describe("UserIdentityWarning", () => {
|
|||
beforeEach(async () => {
|
||||
client = stubClient();
|
||||
room = mockRoom();
|
||||
jest.spyOn(client.getCrypto()!, "isEncryptionEnabledInRoom").mockResolvedValue(true);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
|
@ -117,8 +117,8 @@ describe("UserIdentityWarning", () => {
|
|||
mockRoomMember("@alice:example.org", "Alice"),
|
||||
]);
|
||||
// Start the room off unencrypted. We shouldn't display anything.
|
||||
jest.spyOn(room, "hasEncryptionStateEvent").mockReturnValue(false);
|
||||
const crypto = client.getCrypto()!;
|
||||
jest.spyOn(crypto, "isEncryptionEnabledInRoom").mockResolvedValue(false);
|
||||
jest.spyOn(crypto, "getUserVerificationStatus").mockResolvedValue(
|
||||
new UserVerificationStatus(false, false, false, true),
|
||||
);
|
||||
|
@ -129,6 +129,7 @@ describe("UserIdentityWarning", () => {
|
|||
|
||||
// Encryption gets enabled in the room. We should now warn that Alice's
|
||||
// identity changed.
|
||||
jest.spyOn(crypto, "isEncryptionEnabledInRoom").mockResolvedValue(true);
|
||||
client.emit(
|
||||
RoomStateEvent.Events,
|
||||
new MatrixEvent({
|
||||
|
|
Loading…
Reference in New Issue