fix: cap pairing requests and suppress outbound pairing replies
This commit is contained in:
@@ -223,8 +223,6 @@ export async function monitorWebInbox(options: {
|
||||
const isSamePhone = from === selfE164;
|
||||
const isSelfChat = isSelfChatMode(selfE164, configuredAllowFrom);
|
||||
const isFromMe = Boolean(msg.key?.fromMe);
|
||||
const selfChatMode = account.selfChatMode ?? false;
|
||||
const selfPhoneMode = selfChatMode || isSelfChat;
|
||||
|
||||
// Pre-compute normalized allowlists for filtering
|
||||
const dmHasWildcard = allowFrom?.includes("*") ?? false;
|
||||
@@ -269,10 +267,8 @@ export async function monitorWebInbox(options: {
|
||||
|
||||
// DM access control (secure defaults): "pairing" (default) / "allowlist" / "open" / "disabled"
|
||||
if (!group) {
|
||||
if (isFromMe && !isSamePhone && selfPhoneMode) {
|
||||
logVerbose(
|
||||
"Skipping outbound self-phone DM (fromMe); no pairing reply needed.",
|
||||
);
|
||||
if (isFromMe && !isSamePhone) {
|
||||
logVerbose("Skipping outbound DM (fromMe); no pairing reply needed.");
|
||||
continue;
|
||||
}
|
||||
if (dmPolicy === "disabled") {
|
||||
|
||||
@@ -1312,7 +1312,7 @@ describe("web monitor inbox", () => {
|
||||
await listener.close();
|
||||
});
|
||||
|
||||
it("still pairs outbound DMs when same-phone mode is disabled", async () => {
|
||||
it("skips pairing replies for outbound DMs when same-phone mode is disabled", async () => {
|
||||
mockLoadConfig.mockReturnValue({
|
||||
whatsapp: {
|
||||
dmPolicy: "pairing",
|
||||
@@ -1347,13 +1347,8 @@ describe("web monitor inbox", () => {
|
||||
await new Promise((resolve) => setImmediate(resolve));
|
||||
|
||||
expect(onMessage).not.toHaveBeenCalled();
|
||||
expect(upsertPairingRequestMock).toHaveBeenCalledTimes(1);
|
||||
expect(sock.sendMessage).toHaveBeenCalledWith("999@s.whatsapp.net", {
|
||||
text: expect.stringContaining("Your WhatsApp phone number: +999"),
|
||||
});
|
||||
expect(sock.sendMessage).toHaveBeenCalledWith("999@s.whatsapp.net", {
|
||||
text: expect.stringContaining("Pairing code: PAIRCODE"),
|
||||
});
|
||||
expect(upsertPairingRequestMock).not.toHaveBeenCalled();
|
||||
expect(sock.sendMessage).not.toHaveBeenCalled();
|
||||
|
||||
mockLoadConfig.mockReturnValue({
|
||||
whatsapp: {
|
||||
|
||||
Reference in New Issue
Block a user