From 55812b79334907b7dd898ffe558a154d99edb3bd Mon Sep 17 00:00:00 2001 From: Gustavo Madeira Santana Date: Wed, 1 Apr 2026 12:36:58 -0400 Subject: [PATCH] fix(matrix): preserve empty room overrides --- extensions/matrix/src/matrix/accounts.test.ts | 46 +++++++++++++++++++ extensions/matrix/src/matrix/accounts.ts | 6 +++ 2 files changed, 52 insertions(+) diff --git a/extensions/matrix/src/matrix/accounts.test.ts b/extensions/matrix/src/matrix/accounts.test.ts index 3b1372950e7..a046828d55f 100644 --- a/extensions/matrix/src/matrix/accounts.test.ts +++ b/extensions/matrix/src/matrix/accounts.test.ts @@ -685,4 +685,50 @@ describe("resolveMatrixAccount", () => { }, }); }); + + it("lets an account clear inherited groups with an explicit empty map", () => { + const cfg = { + channels: { + matrix: { + groups: { + "!shared-room:example.org": { + allow: true, + }, + }, + accounts: { + ops: { + homeserver: "https://matrix.example.org", + accessToken: "ops-token", + groups: {}, + }, + }, + }, + }, + } as unknown as CoreConfig; + + expect(resolveMatrixAccount({ cfg, accountId: "ops" }).config.groups).toBeUndefined(); + }); + + it("lets an account clear inherited legacy rooms with an explicit empty map", () => { + const cfg = { + channels: { + matrix: { + rooms: { + "!shared-room:example.org": { + allow: true, + }, + }, + accounts: { + ops: { + homeserver: "https://matrix.example.org", + accessToken: "ops-token", + rooms: {}, + }, + }, + }, + }, + } as unknown as CoreConfig; + + expect(resolveMatrixAccount({ cfg, accountId: "ops" }).config.rooms).toBeUndefined(); + }); }); diff --git a/extensions/matrix/src/matrix/accounts.ts b/extensions/matrix/src/matrix/accounts.ts index 445b9403901..e4cd177a7ef 100644 --- a/extensions/matrix/src/matrix/accounts.ts +++ b/extensions/matrix/src/matrix/accounts.ts @@ -37,10 +37,14 @@ function selectInheritedMatrixRoomEntries(params: { function mergeMatrixRoomEntries( inherited: MatrixRoomEntries | undefined, accountEntries: MatrixRoomEntries | undefined, + hasAccountOverride: boolean, ): MatrixRoomEntries | undefined { if (!inherited && !accountEntries) { return undefined; } + if (hasAccountOverride && Object.keys(accountEntries ?? {}).length === 0) { + return undefined; + } const merged: MatrixRoomEntries = { ...(inherited ?? {}), }; @@ -203,6 +207,7 @@ export function resolveMatrixAccountConfig(params: { isMultiAccount, }), accountConfig?.groups, + Boolean(accountConfig && Object.hasOwn(accountConfig, "groups")), ); const rooms = mergeMatrixRoomEntries( selectInheritedMatrixRoomEntries({ @@ -211,6 +216,7 @@ export function resolveMatrixAccountConfig(params: { isMultiAccount, }), accountConfig?.rooms, + Boolean(accountConfig && Object.hasOwn(accountConfig, "rooms")), ); // Room maps need custom scoping, so keep the generic merge for all other fields. const { groups: _ignoredGroups, rooms: _ignoredRooms, ...rest } = merged;