fix(matrix): keep local promotion on unknown room info

This commit is contained in:
Gustavo Madeira Santana 2026-03-31 00:03:33 -04:00
parent 59df972693
commit 6638d4b505
No known key found for this signature in database
2 changed files with 27 additions and 1 deletions

View File

@ -6,6 +6,9 @@ import type { MatrixRoomInfo } from "./room-info.js";
type DirectRoomTrackerOptions = {
canPromoteRecentInvite?: (roomId: string) => boolean | Promise<boolean>;
shouldKeepLocallyPromotedDirectRoom?:
| ((roomId: string) => boolean | undefined | Promise<boolean | undefined>)
| undefined;
};
const hoisted = vi.hoisted(() => {
@ -555,6 +558,25 @@ describe("monitorMatrixProvider", () => {
await expect(trackerOpts.canPromoteRecentInvite("!room:example.org")).resolves.toBe(false);
});
it("treats unresolved room metadata as indeterminate for local promotion revalidation", async () => {
await startMonitorAndAbortAfterStartup();
const trackerOpts = hoisted.createDirectRoomTracker.mock.calls[0]?.[1];
if (!trackerOpts?.shouldKeepLocallyPromotedDirectRoom) {
throw new Error("local promotion revalidation callback was not wired");
}
hoisted.getRoomInfo.mockResolvedValueOnce({
altAliases: [],
nameResolved: false,
aliasesResolved: false,
});
await expect(
trackerOpts.shouldKeepLocallyPromotedDirectRoom("!room:example.org"),
).resolves.toBeUndefined();
});
});
describe("matrix plugin registration", () => {

View File

@ -226,9 +226,13 @@ export async function monitorMatrixProvider(opts: MonitorMatrixOpts = {}): Promi
}),
shouldKeepLocallyPromotedDirectRoom: async (roomId) => {
try {
const roomInfo = await getRoomInfo(roomId, { includeAliases: true });
if (!roomInfo.nameResolved || !roomInfo.aliasesResolved) {
return undefined;
}
return shouldPromoteRecentInviteRoom({
roomId,
roomInfo: await getRoomInfo(roomId, { includeAliases: true }),
roomInfo,
rooms: roomsConfig,
});
} catch (err) {