refactor(onboarding): reuse allowlist merge across channels

This commit is contained in:
Peter Steinberger
2026-02-16 22:53:55 +00:00
parent 486b7379d4
commit 64f5e4a424
4 changed files with 28 additions and 29 deletions

View File

@@ -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);
}

View File

@@ -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);
}

View File

@@ -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 {

View File

@@ -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);
}