mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-09 16:21:15 +00:00
fix(matrix): preserve empty room overrides
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user