diff --git a/src/components/DataExportSection.vue b/src/components/DataExportSection.vue index f60710296f..16dd992be4 100644 --- a/src/components/DataExportSection.vue +++ b/src/components/DataExportSection.vue @@ -257,12 +257,30 @@ export default class DataExportSection extends Vue { // first remove the contactMethods field, mostly to cast to a clear type (that will end up with JSON objects) const exContact: Contact = R.omit(["contactMethods"], contact); // now add contactMethods as a true array of ContactMethod objects - exContact.contactMethods = contact.contactMethods - ? typeof contact.contactMethods === "string" && - contact.contactMethods.trim() !== "" - ? JSON.parse(contact.contactMethods) - : [] - : []; + // $contacts() returns normalized contacts where contactMethods is already an array, + // but we handle both array and string cases for robustness + if (contact.contactMethods) { + if (Array.isArray(contact.contactMethods)) { + // Already an array, use it directly + exContact.contactMethods = contact.contactMethods; + } else { + // Check if it's a string that needs parsing (shouldn't happen with normalized contacts, but handle for robustness) + const contactMethodsValue = contact.contactMethods as unknown; + if ( + typeof contactMethodsValue === "string" && + contactMethodsValue.trim() !== "" + ) { + // String that needs parsing + exContact.contactMethods = JSON.parse(contactMethodsValue); + } else { + // Invalid data, use empty array + exContact.contactMethods = []; + } + } + } else { + // No contactMethods, use empty array + exContact.contactMethods = []; + } return exContact; }); diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index cc64937370..32424cf3a9 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -1367,6 +1367,9 @@ export const PlatformServiceMixin = { contact.profileImageUrl !== undefined ? contact.profileImageUrl : null, + notes: contact.notes !== undefined ? contact.notes : null, + iViewContent: + contact.iViewContent !== undefined ? contact.iViewContent : null, contactMethods: contact.contactMethods !== undefined ? Array.isArray(contact.contactMethods) @@ -1377,8 +1380,8 @@ export const PlatformServiceMixin = { await this.$dbExec( `INSERT OR REPLACE INTO contacts - (did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl, contactMethods) - VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, + (did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl, notes, iViewContent, contactMethods) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`, [ safeContact.did, safeContact.name, @@ -1387,6 +1390,8 @@ export const PlatformServiceMixin = { safeContact.registered, safeContact.nextPubKeyHashB64, safeContact.profileImageUrl, + safeContact.notes, + safeContact.iViewContent, safeContact.contactMethods, ], ); diff --git a/src/views/ContactEditView.vue b/src/views/ContactEditView.vue index a3ec73cece..a0c9f68051 100644 --- a/src/views/ContactEditView.vue +++ b/src/views/ContactEditView.vue @@ -338,9 +338,10 @@ export default class ContactEditView extends Vue { } // Save to database via PlatformServiceMixin + // Normalize empty strings to null to preserve database consistency await this.$updateContact(this.contact?.did || "", { - name: this.contactName, - notes: this.contactNotes, + name: this.contactName?.trim() || null, + notes: this.contactNotes?.trim() || null, contactMethods: contactMethods, });