feat: add matrix room match metadata logs

Co-authored-by: thewilloftheshadow <thewilloftheshadow@users.noreply.github.com>
This commit is contained in:
Peter Steinberger
2026-01-18 00:00:00 +00:00
parent 984692cda2
commit fe00d6aacf
2 changed files with 21 additions and 6 deletions

View File

@@ -184,18 +184,21 @@ export async function monitorMatrixProvider(opts: MonitorMatrixOpts = {}): Promi
aliases: roomAliases, aliases: roomAliases,
name: roomName, name: roomName,
}); });
const roomMatchMeta = `matchKey=${roomConfigInfo.matchKey ?? "none"} matchSource=${
roomConfigInfo.matchSource ?? "none"
}`;
if (roomConfigInfo.config && !roomConfigInfo.allowed) { if (roomConfigInfo.config && !roomConfigInfo.allowed) {
logVerbose(`matrix: room disabled room=${roomId}`); logVerbose(`matrix: room disabled room=${roomId} (${roomMatchMeta})`);
return; return;
} }
if (groupPolicy === "allowlist") { if (groupPolicy === "allowlist") {
if (!roomConfigInfo.allowlistConfigured) { if (!roomConfigInfo.allowlistConfigured) {
logVerbose("matrix: drop room message (no allowlist)"); logVerbose(`matrix: drop room message (no allowlist, ${roomMatchMeta})`);
return; return;
} }
if (!roomConfigInfo.config) { if (!roomConfigInfo.config) {
logVerbose("matrix: drop room message (not in allowlist)"); logVerbose(`matrix: drop room message (not in allowlist, ${roomMatchMeta})`);
return; return;
} }
} }
@@ -252,7 +255,9 @@ export async function monitorMatrixProvider(opts: MonitorMatrixOpts = {}): Promi
userName: senderName, userName: senderName,
}); });
if (!userAllowed) { if (!userAllowed) {
logVerbose(`matrix: blocked sender ${senderId} (room users allowlist)`); logVerbose(
`matrix: blocked sender ${senderId} (room users allowlist, ${roomMatchMeta})`,
);
return; return;
} }
} }

View File

@@ -8,6 +8,8 @@ export type MatrixRoomConfigResolved = {
allowed: boolean; allowed: boolean;
allowlistConfigured: boolean; allowlistConfigured: boolean;
config?: MatrixRoomConfig; config?: MatrixRoomConfig;
matchKey?: string;
matchSource?: "direct" | "wildcard";
}; };
export function resolveMatrixRoomConfig(params: { export function resolveMatrixRoomConfig(params: {
@@ -25,12 +27,20 @@ export function resolveMatrixRoomConfig(params: {
...params.aliases, ...params.aliases,
params.name ?? "", params.name ?? "",
); );
const { entry: matched, wildcardEntry } = resolveChannelEntryMatch({ const { entry: matched, key: matchedKey, wildcardEntry, wildcardKey } = resolveChannelEntryMatch({
entries: rooms, entries: rooms,
keys: candidates, keys: candidates,
wildcardKey: "*", wildcardKey: "*",
}); });
const resolved = matched ?? wildcardEntry; const resolved = matched ?? wildcardEntry;
const allowed = resolved ? resolved.enabled !== false && resolved.allow !== false : false; const allowed = resolved ? resolved.enabled !== false && resolved.allow !== false : false;
return { allowed, allowlistConfigured, config: resolved }; const matchKey = matchedKey ?? wildcardKey;
const matchSource = matched ? "direct" : wildcardEntry ? "wildcard" : undefined;
return {
allowed,
allowlistConfigured,
config: resolved,
matchKey,
matchSource,
};
} }