2020-03-10 16:31:40 +01:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2019, 2020 , 2021 The Matrix.org Foundation C.I.C.
|
2020-03-10 16:31:40 +01:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
2024-09-09 14:57:16 +01:00
|
|
|
Please see LICENSE files in the repository root for full details.
|
2020-03-10 16:31:40 +01:00
|
|
|
*/
|
|
|
|
|
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type User, type MatrixClient, type RoomMember } from "matrix-js-sdk/src/matrix";
|
2025-07-03 09:34:05 -04:00
|
|
|
import { type VerificationRequest } from "matrix-js-sdk/src/crypto-api";
|
2021-05-12 17:08:44 +01:00
|
|
|
|
2020-05-13 20:41:41 -06:00
|
|
|
import dis from "./dispatcher/dispatcher";
|
2022-01-05 16:14:44 +01:00
|
|
|
import { RightPanelPhases } from "./stores/right-panel/RightPanelStorePhases";
|
|
|
|
|
import RightPanelStore from "./stores/right-panel/RightPanelStore";
|
2025-02-05 13:25:06 +00:00
|
|
|
import { type IRightPanelCardState } from "./stores/right-panel/RightPanelStoreIPanelState";
|
2022-07-25 10:17:40 +02:00
|
|
|
import { findDMForUser } from "./utils/dm/findDMForUser";
|
2020-03-10 16:31:40 +01:00
|
|
|
|
2025-07-03 09:34:05 -04:00
|
|
|
/**
|
|
|
|
|
* Verify another user.
|
|
|
|
|
*
|
|
|
|
|
* Note: cross-signing must be set up before calling this function.
|
|
|
|
|
*/
|
2023-06-01 14:43:24 +01:00
|
|
|
export async function verifyUser(matrixClient: MatrixClient, user: User): Promise<void> {
|
|
|
|
|
if (matrixClient.isGuest()) {
|
2021-06-29 13:11:58 +01:00
|
|
|
dis.dispatch({ action: "require_registration" });
|
2021-01-26 11:00:56 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2023-06-01 14:43:24 +01:00
|
|
|
const existingRequest = pendingVerificationRequestForUser(matrixClient, user);
|
2022-01-05 17:25:41 +01:00
|
|
|
setRightPanel({ member: user, verificationRequest: existingRequest });
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 13:25:14 +00:00
|
|
|
function setRightPanel(state: IRightPanelCardState): void {
|
2022-01-05 17:25:41 +01:00
|
|
|
if (RightPanelStore.instance.roomPhaseHistory.some((card) => card.phase == RightPanelPhases.RoomSummary)) {
|
|
|
|
|
RightPanelStore.instance.pushCard({ phase: RightPanelPhases.EncryptionPanel, state });
|
|
|
|
|
} else {
|
|
|
|
|
RightPanelStore.instance.setCards([
|
|
|
|
|
{ phase: RightPanelPhases.RoomSummary },
|
2024-11-25 17:29:32 +00:00
|
|
|
{ phase: RightPanelPhases.MemberInfo, state: { member: state.member } },
|
2022-01-05 17:25:41 +01:00
|
|
|
{ phase: RightPanelPhases.EncryptionPanel, state },
|
|
|
|
|
]);
|
|
|
|
|
}
|
2020-03-10 16:31:40 +01:00
|
|
|
}
|
2020-03-26 17:31:31 +01:00
|
|
|
|
2023-06-01 14:43:24 +01:00
|
|
|
export function pendingVerificationRequestForUser(
|
|
|
|
|
matrixClient: MatrixClient,
|
|
|
|
|
user: User | RoomMember,
|
|
|
|
|
): VerificationRequest | undefined {
|
|
|
|
|
const dmRoom = findDMForUser(matrixClient, user.userId);
|
2020-03-26 17:31:31 +01:00
|
|
|
if (dmRoom) {
|
2023-08-01 10:18:34 +02:00
|
|
|
return matrixClient.getCrypto()!.findVerificationRequestDMInProgress(dmRoom.roomId, user.userId);
|
2020-03-26 17:31:31 +01:00
|
|
|
}
|
|
|
|
|
}
|