diff --git a/extensions/bluebubbles/src/setup-surface.test.ts b/extensions/bluebubbles/src/setup-surface.test.ts index 10162929524..be0cc78516b 100644 --- a/extensions/bluebubbles/src/setup-surface.test.ts +++ b/extensions/bluebubbles/src/setup-surface.test.ts @@ -185,6 +185,37 @@ describe("bluebubbles setup surface", () => { }); }); + it("uses configured defaultAccount for omitted DM policy account context", async () => { + const { blueBubblesSetupWizard } = await import("./setup-surface.js"); + + const cfg = { + channels: { + bluebubbles: { + defaultAccount: "work", + dmPolicy: "disabled", + allowFrom: ["user@example.com"], + accounts: { + work: { + serverUrl: "http://localhost:1234", + password: "secret", + dmPolicy: "allowlist", + }, + }, + }, + }, + } as OpenClawConfig; + + expect(blueBubblesSetupWizard.dmPolicy?.getCurrent(cfg)).toBe("allowlist"); + expect(blueBubblesSetupWizard.dmPolicy?.resolveConfigKeys?.(cfg)).toEqual({ + policyKey: "channels.bluebubbles.accounts.work.dmPolicy", + allowFromKey: "channels.bluebubbles.accounts.work.allowFrom", + }); + + const next = blueBubblesSetupWizard.dmPolicy?.setPolicy(cfg, "open"); + expect(next?.channels?.bluebubbles?.dmPolicy).toBe("disabled"); + expect(next?.channels?.bluebubbles?.accounts?.work?.dmPolicy).toBe("open"); + }); + it('writes open policy state to the named account and preserves inherited allowFrom with "*"', async () => { const { blueBubblesSetupWizard } = await import("./setup-surface.js"); diff --git a/extensions/bluebubbles/src/setup-surface.ts b/extensions/bluebubbles/src/setup-surface.ts index 06ef4faf551..6c5dcdb5ffb 100644 --- a/extensions/bluebubbles/src/setup-surface.ts +++ b/extensions/bluebubbles/src/setup-surface.ts @@ -135,21 +135,28 @@ const dmPolicy: ChannelSetupDmPolicy = { channel, policyKey: "channels.bluebubbles.dmPolicy", allowFromKey: "channels.bluebubbles.allowFrom", - resolveConfigKeys: (_cfg, accountId) => - accountId && accountId !== DEFAULT_ACCOUNT_ID + resolveConfigKeys: (cfg, accountId) => + (accountId ?? resolveDefaultBlueBubblesAccountId(cfg)) !== DEFAULT_ACCOUNT_ID ? { - policyKey: `channels.bluebubbles.accounts.${accountId}.dmPolicy`, - allowFromKey: `channels.bluebubbles.accounts.${accountId}.allowFrom`, + policyKey: `channels.bluebubbles.accounts.${accountId ?? resolveDefaultBlueBubblesAccountId(cfg)}.dmPolicy`, + allowFromKey: `channels.bluebubbles.accounts.${accountId ?? resolveDefaultBlueBubblesAccountId(cfg)}.allowFrom`, } : { policyKey: "channels.bluebubbles.dmPolicy", allowFromKey: "channels.bluebubbles.allowFrom", }, getCurrent: (cfg, accountId) => - resolveBlueBubblesAccount({ cfg, accountId: accountId ?? DEFAULT_ACCOUNT_ID }).config + resolveBlueBubblesAccount({ + cfg, + accountId: accountId ?? resolveDefaultBlueBubblesAccountId(cfg), + }).config .dmPolicy ?? "pairing", setPolicy: (cfg, policy, accountId) => - setBlueBubblesDmPolicy(cfg, accountId ?? DEFAULT_ACCOUNT_ID, policy), + setBlueBubblesDmPolicy( + cfg, + accountId ?? resolveDefaultBlueBubblesAccountId(cfg), + policy, + ), promptAllowFrom: promptBlueBubblesAllowFrom, };