| import { normalizeIMessageHandle } from "../../../imessage/targets.js"; |
| import { looksLikeHandleOrPhoneTarget, trimMessagingTarget } from "./shared.js"; |
|
|
| |
| const SERVICE_PREFIXES = ["imessage:", "sms:", "auto:"] as const; |
| const CHAT_TARGET_PREFIX_RE = |
| /^(chat_id:|chatid:|chat:|chat_guid:|chatguid:|guid:|chat_identifier:|chatidentifier:|chatident:)/i; |
|
|
| export function normalizeIMessageMessagingTarget(raw: string): string | undefined { |
| const trimmed = trimMessagingTarget(raw); |
| if (!trimmed) { |
| return undefined; |
| } |
|
|
| |
| const lower = trimmed.toLowerCase(); |
| for (const prefix of SERVICE_PREFIXES) { |
| if (lower.startsWith(prefix)) { |
| const remainder = trimmed.slice(prefix.length).trim(); |
| const normalizedHandle = normalizeIMessageHandle(remainder); |
| if (!normalizedHandle) { |
| return undefined; |
| } |
| if (CHAT_TARGET_PREFIX_RE.test(normalizedHandle)) { |
| return normalizedHandle; |
| } |
| return `${prefix}${normalizedHandle}`; |
| } |
| } |
|
|
| const normalized = normalizeIMessageHandle(trimmed); |
| return normalized || undefined; |
| } |
|
|
| export function looksLikeIMessageTargetId(raw: string): boolean { |
| const trimmed = trimMessagingTarget(raw); |
| if (!trimmed) { |
| return false; |
| } |
| if (CHAT_TARGET_PREFIX_RE.test(trimmed)) { |
| return true; |
| } |
| return looksLikeHandleOrPhoneTarget({ |
| raw: trimmed, |
| prefixPattern: /^(imessage:|sms:|auto:)/i, |
| }); |
| } |
|
|