diff --git a/extensions/matrix/src/matrix/monitor/rooms.ts b/extensions/matrix/src/matrix/monitor/rooms.ts index 12c475699..9628b5f27 100644 --- a/extensions/matrix/src/matrix/monitor/rooms.ts +++ b/extensions/matrix/src/matrix/monitor/rooms.ts @@ -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 }; }