refactor: dedupe matrix trimmed readers

This commit is contained in:
Peter Steinberger
2026-04-08 00:23:22 +01:00
parent df91db906f
commit ae1cc2d6df
12 changed files with 134 additions and 101 deletions

View File

@@ -1,4 +1,5 @@
import type { GatewayRequestHandlerOptions } from "openclaw/plugin-sdk/core";
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
import { formatMatrixErrorMessage } from "./matrix/errors.js";
function sendError(respond: (ok: boolean, payload?: unknown) => void, err: unknown) {
@@ -18,13 +19,12 @@ export async function handleVerifyRecoveryKey({
}: GatewayRequestHandlerOptions): Promise<void> {
try {
const { verifyMatrixRecoveryKey } = await import("./matrix/actions/verification.js");
const key = typeof params?.key === "string" ? params.key : "";
if (!key.trim()) {
const key = normalizeOptionalString(params?.key);
if (!key) {
respond(false, { error: "key required" });
return;
}
const accountId =
typeof params?.accountId === "string" ? params.accountId.trim() || undefined : undefined;
const accountId = normalizeOptionalString(params?.accountId);
const result = await verifyMatrixRecoveryKey(key, { accountId });
respond(result.success, result);
} catch (err) {
@@ -38,8 +38,7 @@ export async function handleVerificationBootstrap({
}: GatewayRequestHandlerOptions): Promise<void> {
try {
const { bootstrapMatrixVerification } = await import("./matrix/actions/verification.js");
const accountId =
typeof params?.accountId === "string" ? params.accountId.trim() || undefined : undefined;
const accountId = normalizeOptionalString(params?.accountId);
const recoveryKey = typeof params?.recoveryKey === "string" ? params.recoveryKey : undefined;
const forceResetCrossSigning = params?.forceResetCrossSigning === true;
const result = await bootstrapMatrixVerification({
@@ -59,8 +58,7 @@ export async function handleVerificationStatus({
}: GatewayRequestHandlerOptions): Promise<void> {
try {
const { getMatrixVerificationStatus } = await import("./matrix/actions/verification.js");
const accountId =
typeof params?.accountId === "string" ? params.accountId.trim() || undefined : undefined;
const accountId = normalizeOptionalString(params?.accountId);
const includeRecoveryKey = params?.includeRecoveryKey === true;
const status = await getMatrixVerificationStatus({ accountId, includeRecoveryKey });
respond(true, status);