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.
This commit is contained in:
@@ -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;
|
||||
});
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user