fix: preserve contact methods and notes in export/import workflow

- Fix contactMethods not being exported (was checking for string instead of array)
- Add missing notes and iViewContent fields to $insertContact method
- Normalize empty strings to null when saving contacts in ContactEditView

This ensures contact data integrity is maintained during export/import operations.
This commit is contained in:
Jose Olarte III
2025-11-20 18:11:27 +08:00
parent 203cf6b078
commit 36eb9a16b0
3 changed files with 34 additions and 10 deletions

View File

@@ -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) // 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); const exContact: Contact = R.omit(["contactMethods"], contact);
// now add contactMethods as a true array of ContactMethod objects // now add contactMethods as a true array of ContactMethod objects
exContact.contactMethods = contact.contactMethods // $contacts() returns normalized contacts where contactMethods is already an array,
? typeof contact.contactMethods === "string" && // but we handle both array and string cases for robustness
contact.contactMethods.trim() !== "" if (contact.contactMethods) {
? JSON.parse(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; return exContact;
}); });

View File

@@ -1367,6 +1367,9 @@ export const PlatformServiceMixin = {
contact.profileImageUrl !== undefined contact.profileImageUrl !== undefined
? contact.profileImageUrl ? contact.profileImageUrl
: null, : null,
notes: contact.notes !== undefined ? contact.notes : null,
iViewContent:
contact.iViewContent !== undefined ? contact.iViewContent : null,
contactMethods: contactMethods:
contact.contactMethods !== undefined contact.contactMethods !== undefined
? Array.isArray(contact.contactMethods) ? Array.isArray(contact.contactMethods)
@@ -1377,8 +1380,8 @@ export const PlatformServiceMixin = {
await this.$dbExec( await this.$dbExec(
`INSERT OR REPLACE INTO contacts `INSERT OR REPLACE INTO contacts
(did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl, contactMethods) (did, name, publicKeyBase64, seesMe, registered, nextPubKeyHashB64, profileImageUrl, notes, iViewContent, contactMethods)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[ [
safeContact.did, safeContact.did,
safeContact.name, safeContact.name,
@@ -1387,6 +1390,8 @@ export const PlatformServiceMixin = {
safeContact.registered, safeContact.registered,
safeContact.nextPubKeyHashB64, safeContact.nextPubKeyHashB64,
safeContact.profileImageUrl, safeContact.profileImageUrl,
safeContact.notes,
safeContact.iViewContent,
safeContact.contactMethods, safeContact.contactMethods,
], ],
); );

View File

@@ -338,9 +338,10 @@ export default class ContactEditView extends Vue {
} }
// Save to database via PlatformServiceMixin // Save to database via PlatformServiceMixin
// Normalize empty strings to null to preserve database consistency
await this.$updateContact(this.contact?.did || "", { await this.$updateContact(this.contact?.did || "", {
name: this.contactName, name: this.contactName?.trim() || null,
notes: this.contactNotes, notes: this.contactNotes?.trim() || null,
contactMethods: contactMethods, contactMethods: contactMethods,
}); });