refactor: reuse channel config resolver in matrix extension
Co-authored-by: thewilloftheshadow <thewilloftheshadow@users.noreply.github.com>
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user