refactor: reuse channel config resolver in matrix extension

Co-authored-by: thewilloftheshadow <thewilloftheshadow@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-17 23:53:05 +00:00
parent 4c12c4fc04
commit 984692cda2

View File

@@ -1,4 +1,8 @@
import type { MatrixConfig, MatrixRoomConfig } from "../../types.js";
import {
buildChannelKeyCandidates,
resolveChannelEntryMatch,
} from "../../../../../src/channels/plugins/channel-config.js";
export type MatrixRoomConfigResolved = {
allowed: boolean;
@@ -15,22 +19,18 @@ export function resolveMatrixRoomConfig(params: {
const rooms = params.rooms ?? {};
const keys = Object.keys(rooms);
const allowlistConfigured = keys.length > 0;
const candidates = [
const candidates = buildChannelKeyCandidates(
params.roomId,
`room:${params.roomId}`,
...params.aliases,
params.name ?? "",
].filter(Boolean);
let matched: MatrixRoomConfigResolved["config"] | undefined;
for (const candidate of candidates) {
if (rooms[candidate]) {
matched = rooms[candidate];
break;
}
}
if (!matched && rooms["*"]) {
matched = rooms["*"];
}
const allowed = matched ? matched.enabled !== false && matched.allow !== false : false;
return { allowed, allowlistConfigured, config: matched };
);
const { entry: matched, wildcardEntry } = resolveChannelEntryMatch({
entries: rooms,
keys: candidates,
wildcardKey: "*",
});
const resolved = matched ?? wildcardEntry;
const allowed = resolved ? resolved.enabled !== false && resolved.allow !== false : false;
return { allowed, allowlistConfigured, config: resolved };
}