shieldStatusForRoom: avoid deprecated MatrixClient methods (#10944)

Update this method to use modern crypto methods
This commit is contained in:
Richard van der Hoff
2023-05-19 11:57:45 +01:00
committed by GitHub
parent 606eaa5274
commit cc842aac8a
3 changed files with 22 additions and 6 deletions

View File

@@ -16,6 +16,7 @@ limitations under the License.
import { MatrixClient } from "matrix-js-sdk/src/client";
import { Room } from "matrix-js-sdk/src/models/room";
import { logger } from "matrix-js-sdk/src/logger";
import DMRoomMap from "./DMRoomMap";
import { asyncSome } from "./arrays";
@@ -27,6 +28,11 @@ export enum E2EStatus {
}
export async function shieldStatusForRoom(client: MatrixClient, room: Room): Promise<E2EStatus> {
const crypto = client.getCrypto();
if (!crypto) {
return E2EStatus.Warning;
}
const members = (await room.getEncryptionTargetMembers()).map(({ userId }) => userId);
const inDMMap = !!DMRoomMap.shared().getUserIdForRoomId(room.roomId);
@@ -53,10 +59,18 @@ export async function shieldStatusForRoom(client: MatrixClient, room: Room): Pro
members.length !== 2) || // Don't alarm for self in 1:1 chats with other users
members.length === 1; // Do alarm for self if we're alone in a room
const targets = includeUser ? [...verified, client.getUserId()!] : verified;
const devicesByUser = await crypto.getUserDeviceInfo(targets);
for (const userId of targets) {
const devices = client.getStoredDevicesForUser(userId);
const anyDeviceNotVerified = await asyncSome(devices, async ({ deviceId }) => {
const verificationStatus = await client.getCrypto()?.getDeviceVerificationStatus(userId, deviceId);
const devices = devicesByUser.get(userId);
if (!devices) {
// getUserDeviceInfo returned nothing about this user, which means we know nothing about their device list.
// That seems odd, so treat it as a warning.
logger.warn(`No device info for user ${userId}`);
return E2EStatus.Warning;
}
const anyDeviceNotVerified = await asyncSome(devices.keys(), async (deviceId) => {
const verificationStatus = await crypto.getDeviceVerificationStatus(userId, deviceId);
return !verificationStatus?.isVerified();
});
if (anyDeviceNotVerified) {