diff --git a/src/libs/util.ts b/src/libs/util.ts index ae056fe6..6f6100ca 100644 --- a/src/libs/util.ts +++ b/src/libs/util.ts @@ -7,7 +7,7 @@ import { useClipboard } from "@vueuse/core"; import { DEFAULT_PUSH_SERVER, NotificationIface } from "../constants/app"; import { Account, AccountEncrypted } from "../db/tables/accounts"; -import { Contact, ContactWithJsonStrings } from "../db/tables/contacts"; +import { Contact } from "../db/tables/contacts"; import { DEFAULT_PASSKEY_EXPIRATION_MINUTES } from "../db/tables/settings"; import { arrayBufferToBase64, @@ -902,13 +902,19 @@ export interface DatabaseExport { export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => { // Convert each contact to a plain object and ensure all fields are included const rows = contacts.map((contact) => { - const exContact: ContactWithJsonStrings = R.omit( - ["contactMethods"], - contact, - ); - exContact.contactMethods = contact.contactMethods - ? JSON.stringify(contact.contactMethods) - : undefined; + // Create a plain object without stringifying contactMethods + const exContact = { + did: contact.did, + iViewContent: contact.iViewContent, + name: contact.name, + nextPubKeyHashB64: contact.nextPubKeyHashB64, + notes: contact.notes, + profileImageUrl: contact.profileImageUrl, + publicKeyBase64: contact.publicKeyBase64, + seesMe: contact.seesMe, + registered: contact.registered, + contactMethods: contact.contactMethods || [], + }; return exContact; }); diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index 47a943c0..11684af3 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -246,6 +246,15 @@ export const PlatformServiceMixin = { // Keep null values as null } + // Handle JSON fields like contactMethods + if (column === "contactMethods" && typeof value === "string") { + try { + value = JSON.parse(value); + } catch { + value = []; + } + } + obj[column] = value; }); return obj; @@ -1051,12 +1060,18 @@ export const PlatformServiceMixin = { contact.profileImageUrl !== undefined ? contact.profileImageUrl : null, + contactMethods: + contact.contactMethods !== undefined + ? (Array.isArray(contact.contactMethods) + ? JSON.stringify(contact.contactMethods) + : contact.contactMethods) + : null, }; await this.$dbExec( `INSERT OR REPLACE INTO contacts - (did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl) - VALUES (?, ?, ?, ?, ?, ?, ?)`, + (did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl, contactMethods) + VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [ safeContact.did, safeContact.name, @@ -1065,6 +1080,7 @@ export const PlatformServiceMixin = { safeContact.registered, safeContact.nextPubKeyHashB64, safeContact.profileImageUrl, + safeContact.contactMethods, ], ); return true;