Edit: Add from phone contacts

This commit is contained in:
2026-09-21 20:04:18 +03:30
parent f4cb41d96f
commit 5d9a572ff8
3 changed files with 237 additions and 89 deletions
+11 -2
View File
@@ -99,12 +99,15 @@ function draftFromParts(input: {
};
}
export async function pickPhoneContacts(): Promise<PhoneContactDraft[]> {
export async function pickPhoneContacts(options?: {
multiple?: boolean;
}): Promise<PhoneContactDraft[]> {
const api = contactsApi();
if (!api) {
throw new Error('CONTACT_PICKER_UNSUPPORTED');
}
const rows = await api.select(['name', 'email', 'tel'], { multiple: true });
const multiple = options?.multiple !== false;
const rows = await api.select(['name', 'email', 'tel'], { multiple });
const drafts: PhoneContactDraft[] = [];
const seen = new Set<string>();
for (const row of rows) {
@@ -121,6 +124,12 @@ export async function pickPhoneContacts(): Promise<PhoneContactDraft[]> {
return drafts;
}
/** یک مخاطب برای پر کردن فرم (نه ورود گروهی) */
export async function pickOnePhoneContact(): Promise<PhoneContactDraft | null> {
const rows = await pickPhoneContacts({ multiple: false });
return rows[0] ?? null;
}
function unfoldVcard(text: string): string[] {
const raw = text.replace(/\r\n/g, '\n').replace(/\r/g, '\n').split('\n');
const lines: string[] = [];