From b267d1bc66739806ed18f09f9919f88d3c5df2ea Mon Sep 17 00:00:00 2001 From: Matthew Raymer Date: Thu, 7 Aug 2025 01:49:22 +0000 Subject: [PATCH] Fix contact backup export: contactMethods now exports as JSON arrays instead of strings - Fixed contactsToExportJson to export contactMethods as proper arrays instead of stringified JSON - Added JSON parsing for contactMethods in _mapColumnsToValues when retrieving from database - Updated $insertContact to properly handle contactMethods field storage - Removed unused ContactWithJsonStrings import ref: https://app.clickup.com/t/86b63ffpb Resolves issue where contact backup exports showed contactMethods as "[]" strings instead of proper JSON arrays. --- src/libs/util.ts | 22 ++++++++++++++-------- src/utils/PlatformServiceMixin.ts | 20 ++++++++++++++++++-- 2 files changed, 32 insertions(+), 10 deletions(-) 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;