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