diff --git a/src/channels/plugins/onboarding/imessage.ts b/src/channels/plugins/onboarding/imessage.ts index 61167fe7005..085285a4a42 100644 --- a/src/channels/plugins/onboarding/imessage.ts +++ b/src/channels/plugins/onboarding/imessage.ts @@ -11,7 +11,7 @@ import { import { normalizeIMessageHandle } from "../../../imessage/targets.js"; import { DEFAULT_ACCOUNT_ID, normalizeAccountId } from "../../../routing/session-key.js"; import { formatDocsLink } from "../../../terminal/links.js"; -import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; +import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js"; const channel = "imessage" as const; @@ -138,7 +138,7 @@ async function promptIMessageAllowFrom(params: { }, }); const parts = parseIMessageAllowFromInput(String(entry)); - const unique = [...new Set(parts)]; + const unique = mergeAllowFromEntries(undefined, parts); return setIMessageAllowFrom(params.cfg, accountId, unique); } diff --git a/src/channels/plugins/onboarding/signal.ts b/src/channels/plugins/onboarding/signal.ts index 1e0bc3db60b..5e7ca152d88 100644 --- a/src/channels/plugins/onboarding/signal.ts +++ b/src/channels/plugins/onboarding/signal.ts @@ -13,7 +13,7 @@ import { } from "../../../signal/accounts.js"; import { formatDocsLink } from "../../../terminal/links.js"; import { normalizeE164 } from "../../../utils.js"; -import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; +import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js"; const channel = "signal" as const; const MIN_E164_DIGITS = 5; @@ -153,21 +153,22 @@ async function promptSignalAllowFrom(params: { }, }); const parts = parseSignalAllowFromInput(String(entry)); - const normalized = parts - .map((part) => { - if (part === "*") { - return "*"; - } - if (part.toLowerCase().startsWith("uuid:")) { - return `uuid:${part.slice(5).trim()}`; - } - if (isUuidLike(part)) { - return `uuid:${part}`; - } - return normalizeE164(part); - }) - .filter(Boolean); - const unique = [...new Set(normalized)]; + const normalized = parts.map((part) => { + if (part === "*") { + return "*"; + } + if (part.toLowerCase().startsWith("uuid:")) { + return `uuid:${part.slice(5).trim()}`; + } + if (isUuidLike(part)) { + return `uuid:${part}`; + } + return normalizeE164(part); + }); + const unique = mergeAllowFromEntries( + undefined, + normalized.filter((part): part is string => typeof part === "string" && part.trim().length > 0), + ); return setSignalAllowFrom(params.cfg, accountId, unique); } diff --git a/src/channels/plugins/onboarding/telegram.ts b/src/channels/plugins/onboarding/telegram.ts index f5916ef4515..a9b3c5d8ee7 100644 --- a/src/channels/plugins/onboarding/telegram.ts +++ b/src/channels/plugins/onboarding/telegram.ts @@ -10,7 +10,7 @@ import { resolveTelegramAccount, } from "../../../telegram/accounts.js"; import { formatDocsLink } from "../../../terminal/links.js"; -import { addWildcardAllowFrom, promptAccountId } from "./helpers.js"; +import { addWildcardAllowFrom, mergeAllowFromEntries, promptAccountId } from "./helpers.js"; const channel = "telegram" as const; @@ -133,11 +133,7 @@ async function promptTelegramAllowFrom(params: { resolvedIds = results.filter(Boolean) as string[]; } - const merged = [ - ...existingAllowFrom.map((item) => String(item).trim()).filter(Boolean), - ...resolvedIds, - ]; - const unique = [...new Set(merged)]; + const unique = mergeAllowFromEntries(existingAllowFrom, resolvedIds); if (accountId === DEFAULT_ACCOUNT_ID) { return { diff --git a/src/channels/plugins/onboarding/whatsapp.ts b/src/channels/plugins/onboarding/whatsapp.ts index e640c8a3989..4d0c5125e34 100644 --- a/src/channels/plugins/onboarding/whatsapp.ts +++ b/src/channels/plugins/onboarding/whatsapp.ts @@ -15,7 +15,7 @@ import { resolveDefaultWhatsAppAccountId, resolveWhatsAppAuthDir, } from "../../../web/accounts.js"; -import { promptAccountId } from "./helpers.js"; +import { mergeAllowFromEntries, promptAccountId } from "./helpers.js"; const channel = "whatsapp" as const; @@ -72,10 +72,10 @@ async function promptWhatsAppOwnerAllowFrom(params: { ...existingAllowFrom .filter((item) => item !== "*") .map((item) => normalizeE164(item)) - .filter(Boolean), + .filter((item): item is string => typeof item === "string" && item.trim().length > 0), normalized, ]; - const allowFrom = [...new Set(merged.filter(Boolean))]; + const allowFrom = mergeAllowFromEntries(undefined, merged); return { normalized, allowFrom }; } @@ -234,8 +234,10 @@ async function promptWhatsAppAllowFrom( .split(/[\n,;]+/g) .map((p) => p.trim()) .filter(Boolean); - const normalized = parts.map((part) => (part === "*" ? "*" : normalizeE164(part))); - const unique = [...new Set(normalized.filter(Boolean))]; + const normalized = parts + .map((part) => (part === "*" ? "*" : normalizeE164(part))) + .filter((part): part is string => typeof part === "string" && part.trim().length > 0); + const unique = mergeAllowFromEntries(undefined, normalized); next = setWhatsAppAllowFrom(next, unique); }