diff --git a/src/db/databaseUtil.ts b/src/db/databaseUtil.ts index 9b96475d..85b7192f 100644 --- a/src/db/databaseUtil.ts +++ b/src/db/databaseUtil.ts @@ -567,6 +567,8 @@ export async function debugSettingsData(did?: string): Promise { * - Web SQLite (wa-sqlite/absurd-sql): Auto-parses JSON strings to objects * - Capacitor SQLite: Returns raw strings that need manual parsing * + * Maybe consolidate with PlatformServiceMixin._parseJsonField + * * @param value The value to parse (could be string or already parsed object) * @param defaultValue Default value if parsing fails * @returns Parsed object or default value diff --git a/src/db/tables/contacts.ts b/src/db/tables/contacts.ts index cfb88798..fe81cbe4 100644 --- a/src/db/tables/contacts.ts +++ b/src/db/tables/contacts.ts @@ -9,6 +9,8 @@ export type Contact = { // When adding a property: // - Consider whether it should be added when exporting & sharing contacts, eg. DataExportSection // - If it's a boolean, it should be converted from a 0/1 integer in PlatformServiceMixin._mapColumnsToValues + // - If it's a JSON string, it should be converted to an object/array in PlatformServiceMixin._mapColumnsToValues + // did: string; contactMethods?: Array; diff --git a/src/db/tables/settings.ts b/src/db/tables/settings.ts index ff43e0f8..4c00b46e 100644 --- a/src/db/tables/settings.ts +++ b/src/db/tables/settings.ts @@ -14,6 +14,12 @@ export type BoundingBox = { * New entries that are boolean should also be added to PlatformServiceMixin._mapColumnsToValues */ export type Settings = { + // + // When adding a property: + // - If it's a boolean, it should be converted from a 0/1 integer in PlatformServiceMixin._mapColumnsToValues + // - If it's a JSON string, it should be converted to an object/array in PlatformServiceMixin._mapColumnsToValues + // + // default entry is keyed with MASTER_SETTINGS_KEY; other entries are linked to an account with account ID id?: string | number; // this is erased for all those entries that are keyed with accountDid diff --git a/src/libs/endorserServer.ts b/src/libs/endorserServer.ts index 02702afc..30bb7316 100644 --- a/src/libs/endorserServer.ts +++ b/src/libs/endorserServer.ts @@ -315,7 +315,7 @@ export function didInfoForContact( return { displayName: "You", known: true }; } else if (contact) { return { - displayName: contact.name || "Contact With No Name", + displayName: contact.name || "Contact Without a Name", known: true, profileImageUrl: contact.profileImageUrl, }; diff --git a/src/test/index.ts b/src/test/index.ts index 914cb2be..d1badb67 100644 --- a/src/test/index.ts +++ b/src/test/index.ts @@ -66,7 +66,7 @@ export async function testServerRegisterUser() { // Make a payload for the claim const vcPayload = { - sub: "RegisterAction", + sub: identity0.did, vc: { "@context": ["https://www.w3.org/2018/credentials/v1"], type: ["VerifiableCredential"], diff --git a/src/utils/PlatformServiceMixin.ts b/src/utils/PlatformServiceMixin.ts index c4912afd..254a8396 100644 --- a/src/utils/PlatformServiceMixin.ts +++ b/src/utils/PlatformServiceMixin.ts @@ -275,16 +275,22 @@ export const PlatformServiceMixin = { // Convert SQLite integer booleans to JavaScript booleans if ( + // settings column === "isRegistered" || column === "finishedOnboarding" || column === "filterFeedByVisible" || column === "filterFeedByNearby" || + column === "hasBackedUpSeed" || column === "hideRegisterPromptOnNewContact" || column === "showContactGivesInline" || column === "showGeneralAdvanced" || column === "showShortcutBvc" || column === "warnIfProdServer" || - column === "warnIfTestServer" + column === "warnIfTestServer" || + // contacts + column === "iViewContent" || + column === "registered" || + column === "seesMe" ) { if (value === 1) { value = true; @@ -294,13 +300,9 @@ 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 = []; - } + // Convert SQLite JSON strings to objects/arrays + if (column === "contactMethods" || column === "searchBoxes") { + value = this._parseJsonField(value, []); } obj[column] = value; @@ -310,10 +312,13 @@ export const PlatformServiceMixin = { }, /** - * Self-contained implementation of parseJsonField - * Safely parses JSON strings with fallback to default value + * Safely parses JSON strings with fallback to default value. + * Handles different SQLite implementations: + * - Web SQLite (wa-sqlite/absurd-sql): Auto-parses JSON strings to objects + * - Capacitor SQLite: Returns raw strings that need manual parsing * - * Consolidate this with src/libs/util.ts parseJsonField + * See also src/db/databaseUtil.ts parseJsonField + * and maybe consolidate */ _parseJsonField(value: unknown, defaultValue: T): T { if (typeof value === "string") {