forked from jsnbuchanan/crowd-funder-for-time-pwa
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 { DEFAULT_PUSH_SERVER, NotificationIface } from "../constants/app";
|
||||||
import { Account, AccountEncrypted } from "../db/tables/accounts";
|
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 { DEFAULT_PASSKEY_EXPIRATION_MINUTES } from "../db/tables/settings";
|
||||||
import {
|
import {
|
||||||
arrayBufferToBase64,
|
arrayBufferToBase64,
|
||||||
@@ -902,13 +902,19 @@ export interface DatabaseExport {
|
|||||||
export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
|
export const contactsToExportJson = (contacts: Contact[]): DatabaseExport => {
|
||||||
// Convert each contact to a plain object and ensure all fields are included
|
// Convert each contact to a plain object and ensure all fields are included
|
||||||
const rows = contacts.map((contact) => {
|
const rows = contacts.map((contact) => {
|
||||||
const exContact: ContactWithJsonStrings = R.omit(
|
// Create a plain object without stringifying contactMethods
|
||||||
["contactMethods"],
|
const exContact = {
|
||||||
contact,
|
did: contact.did,
|
||||||
);
|
iViewContent: contact.iViewContent,
|
||||||
exContact.contactMethods = contact.contactMethods
|
name: contact.name,
|
||||||
? JSON.stringify(contact.contactMethods)
|
nextPubKeyHashB64: contact.nextPubKeyHashB64,
|
||||||
: undefined;
|
notes: contact.notes,
|
||||||
|
profileImageUrl: contact.profileImageUrl,
|
||||||
|
publicKeyBase64: contact.publicKeyBase64,
|
||||||
|
seesMe: contact.seesMe,
|
||||||
|
registered: contact.registered,
|
||||||
|
contactMethods: contact.contactMethods || [],
|
||||||
|
};
|
||||||
return exContact;
|
return exContact;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -246,6 +246,15 @@ export const PlatformServiceMixin = {
|
|||||||
// Keep null values as null
|
// 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;
|
obj[column] = value;
|
||||||
});
|
});
|
||||||
return obj;
|
return obj;
|
||||||
@@ -1051,12 +1060,18 @@ export const PlatformServiceMixin = {
|
|||||||
contact.profileImageUrl !== undefined
|
contact.profileImageUrl !== undefined
|
||||||
? contact.profileImageUrl
|
? contact.profileImageUrl
|
||||||
: null,
|
: null,
|
||||||
|
contactMethods:
|
||||||
|
contact.contactMethods !== undefined
|
||||||
|
? (Array.isArray(contact.contactMethods)
|
||||||
|
? JSON.stringify(contact.contactMethods)
|
||||||
|
: contact.contactMethods)
|
||||||
|
: null,
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.$dbExec(
|
await this.$dbExec(
|
||||||
`INSERT OR REPLACE INTO contacts
|
`INSERT OR REPLACE INTO contacts
|
||||||
(did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl)
|
(did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl, contactMethods)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
||||||
[
|
[
|
||||||
safeContact.did,
|
safeContact.did,
|
||||||
safeContact.name,
|
safeContact.name,
|
||||||
@@ -1065,6 +1080,7 @@ export const PlatformServiceMixin = {
|
|||||||
safeContact.registered,
|
safeContact.registered,
|
||||||
safeContact.nextPubKeyHashB64,
|
safeContact.nextPubKeyHashB64,
|
||||||
safeContact.profileImageUrl,
|
safeContact.profileImageUrl,
|
||||||
|
safeContact.contactMethods,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user