Merge branch 'sql-absurd-sql-back'
This commit is contained in:
@@ -104,23 +104,26 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import QRCodeVue3 from "qr-code-generator-vue3";
|
||||
import { Component, Vue } from "vue-facing-decorator";
|
||||
import { Router } from "vue-router";
|
||||
import { useClipboard } from "@vueuse/core";
|
||||
|
||||
import { logger } from "../utils/logger";
|
||||
import { QRScannerFactory } from "../services/QRScanner/QRScannerFactory";
|
||||
import QuickNav from "../components/QuickNav.vue";
|
||||
import { NotificationIface } from "../constants/app";
|
||||
import { NotificationIface, USE_DEXIE_DB } from "../constants/app";
|
||||
import { db } from "../db/index";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import { getContactJwtFromJwtUrl } from "../libs/crypto";
|
||||
import { decodeEndorserJwt, ETHR_DID_PREFIX } from "../libs/crypto/vc";
|
||||
import { retrieveSettingsForActiveAccount } from "../db/index";
|
||||
import * as databaseUtil from "../db/databaseUtil";
|
||||
import { setVisibilityUtil } from "../libs/endorserServer";
|
||||
import { useClipboard } from "@vueuse/core";
|
||||
import QRCodeVue3 from "qr-code-generator-vue3";
|
||||
import UserNameDialog from "../components/UserNameDialog.vue";
|
||||
import { generateEndorserJwtUrlForAccount } from "../libs/endorserServer";
|
||||
import { retrieveAccountMetadata } from "../libs/util";
|
||||
import { PlatformServiceFactory } from "@/services/PlatformServiceFactory";
|
||||
|
||||
interface QRScanResult {
|
||||
rawValue?: string;
|
||||
@@ -161,7 +164,10 @@ export default class ContactQRScan extends Vue {
|
||||
|
||||
async created() {
|
||||
try {
|
||||
const settings = await retrieveSettingsForActiveAccount();
|
||||
let settings = await databaseUtil.retrieveSettingsForActiveAccount();
|
||||
if (USE_DEXIE_DB) {
|
||||
settings = await retrieveSettingsForActiveAccount();
|
||||
}
|
||||
this.activeDid = settings.activeDid || "";
|
||||
this.apiServer = settings.apiServer || "";
|
||||
this.givenName = settings.firstName || "";
|
||||
@@ -435,13 +441,22 @@ export default class ContactQRScan extends Vue {
|
||||
async addNewContact(contact: Contact) {
|
||||
try {
|
||||
logger.info("Opening database connection for new contact");
|
||||
await db.open();
|
||||
|
||||
// Check if contact already exists
|
||||
const existingContacts = await db.contacts.toArray();
|
||||
const existingContact = existingContacts.find(
|
||||
(c) => c.did === contact.did,
|
||||
const platformService = PlatformServiceFactory.getInstance();
|
||||
const dbAllContacts = await platformService.dbQuery(
|
||||
"SELECT * FROM contacts WHERE did = ?",
|
||||
[contact.did],
|
||||
);
|
||||
const existingContacts = databaseUtil.mapQueryResultToValues(
|
||||
dbAllContacts,
|
||||
) as unknown as Contact[];
|
||||
let existingContact: Contact | undefined = existingContacts[0];
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.open();
|
||||
const existingContacts = await db.contacts.toArray();
|
||||
existingContact = existingContacts.find((c) => c.did === contact.did);
|
||||
}
|
||||
|
||||
if (existingContact) {
|
||||
logger.info("Contact already exists", { did: contact.did });
|
||||
@@ -458,7 +473,16 @@ export default class ContactQRScan extends Vue {
|
||||
}
|
||||
|
||||
// Add new contact
|
||||
await db.contacts.add(contact);
|
||||
// @ts-expect-error because we're just using the value to store to the DB
|
||||
contact.contactMethods = JSON.stringify(contact.contactMethods);
|
||||
const { sql, params } = databaseUtil.generateInsertStatement(
|
||||
contact as unknown as Record<string, unknown>,
|
||||
"contacts",
|
||||
);
|
||||
await platformService.dbExec(sql, params);
|
||||
if (USE_DEXIE_DB) {
|
||||
await db.contacts.add(contact);
|
||||
}
|
||||
|
||||
if (this.activeDid) {
|
||||
logger.info("Setting contact visibility", { did: contact.did });
|
||||
|
||||
Reference in New Issue
Block a user