fix(matrix): require unique allowlist matches in wizard
parent
d3ba57b7d7
commit
41d2993f7b
|
|
@ -8,9 +8,9 @@ import {
|
||||||
} from "openclaw/plugin-sdk";
|
} from "openclaw/plugin-sdk";
|
||||||
import type { CoreConfig, DmPolicy } from "./types.js";
|
import type { CoreConfig, DmPolicy } from "./types.js";
|
||||||
import { listMatrixDirectoryGroupsLive } from "./directory-live.js";
|
import { listMatrixDirectoryGroupsLive } from "./directory-live.js";
|
||||||
import { listMatrixDirectoryPeersLive } from "./directory-live.js";
|
|
||||||
import { resolveMatrixAccount } from "./matrix/accounts.js";
|
import { resolveMatrixAccount } from "./matrix/accounts.js";
|
||||||
import { ensureMatrixSdkInstalled, isMatrixSdkAvailable } from "./matrix/deps.js";
|
import { ensureMatrixSdkInstalled, isMatrixSdkAvailable } from "./matrix/deps.js";
|
||||||
|
import { resolveMatrixTargets } from "./resolve-targets.js";
|
||||||
|
|
||||||
const channel = "matrix" as const;
|
const channel = "matrix" as const;
|
||||||
|
|
||||||
|
|
@ -65,14 +65,16 @@ async function promptMatrixAllowFrom(params: {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
const entry = await prompter.text({
|
const entry = await prompter.text({
|
||||||
message: "Matrix allowFrom (username or user id)",
|
message: "Matrix allowFrom (full @user:server; display name only if unique)",
|
||||||
placeholder: "@user:server",
|
placeholder: "@user:server",
|
||||||
initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : undefined,
|
initialValue: existingAllowFrom[0] ? String(existingAllowFrom[0]) : undefined,
|
||||||
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
|
validate: (value) => (String(value ?? "").trim() ? undefined : "Required"),
|
||||||
});
|
});
|
||||||
const parts = parseInput(String(entry));
|
const parts = parseInput(String(entry));
|
||||||
const resolvedIds: string[] = [];
|
const resolvedIds: string[] = [];
|
||||||
let unresolved: string[] = [];
|
const pending: string[] = [];
|
||||||
|
const unresolved: string[] = [];
|
||||||
|
const unresolvedNotes: string[] = [];
|
||||||
|
|
||||||
for (const part of parts) {
|
for (const part of parts) {
|
||||||
if (isFullUserId(part)) {
|
if (isFullUserId(part)) {
|
||||||
|
|
@ -83,28 +85,33 @@ async function promptMatrixAllowFrom(params: {
|
||||||
unresolved.push(part);
|
unresolved.push(part);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const results = await listMatrixDirectoryPeersLive({
|
pending.push(part);
|
||||||
cfg,
|
}
|
||||||
query: part,
|
|
||||||
limit: 5,
|
if (pending.length > 0) {
|
||||||
}).catch(() => []);
|
const results = await resolveMatrixTargets({
|
||||||
const match = results.find((result) => result.id);
|
cfg,
|
||||||
if (match?.id) {
|
inputs: pending,
|
||||||
resolvedIds.push(match.id);
|
kind: "user",
|
||||||
if (results.length > 1) {
|
}).catch(() => []);
|
||||||
await prompter.note(
|
for (const result of results) {
|
||||||
`Multiple matches for "${part}", using ${match.id}.`,
|
if (result?.resolved && result.id) {
|
||||||
"Matrix allowlist",
|
resolvedIds.push(result.id);
|
||||||
);
|
continue;
|
||||||
|
}
|
||||||
|
if (result?.input) {
|
||||||
|
unresolved.push(result.input);
|
||||||
|
if (result.note) {
|
||||||
|
unresolvedNotes.push(`${result.input}: ${result.note}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
unresolved.push(part);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unresolved.length > 0) {
|
if (unresolved.length > 0) {
|
||||||
|
const details = unresolvedNotes.length > 0 ? unresolvedNotes : unresolved;
|
||||||
await prompter.note(
|
await prompter.note(
|
||||||
`Could not resolve: ${unresolved.join(", ")}. Use full @user:server IDs.`,
|
`Could not resolve:\n${details.join("\n")}\nUse full @user:server IDs.`,
|
||||||
"Matrix allowlist",
|
"Matrix allowlist",
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue