add registration for new contacts that are unregistered
This commit is contained in:
@@ -118,11 +118,13 @@ import {
|
|||||||
CONTACT_CSV_HEADER,
|
CONTACT_CSV_HEADER,
|
||||||
CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI,
|
CONTACT_IMPORT_CONFIRM_URL_PATH_TIME_SAFARI,
|
||||||
generateEndorserJwtUrlForAccount,
|
generateEndorserJwtUrlForAccount,
|
||||||
|
register,
|
||||||
setVisibilityUtil,
|
setVisibilityUtil,
|
||||||
} from "../libs/endorserServer";
|
} from "../libs/endorserServer";
|
||||||
import UserNameDialog from "../components/UserNameDialog.vue";
|
import UserNameDialog from "../components/UserNameDialog.vue";
|
||||||
import { retrieveAccountMetadata } from "../libs/util";
|
import { retrieveAccountMetadata } from "../libs/util";
|
||||||
|
|
||||||
|
import { AxiosError } from "axios";
|
||||||
import { Account } from "@/db/tables/accounts";
|
import { Account } from "@/db/tables/accounts";
|
||||||
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
|
||||||
import {
|
import {
|
||||||
@@ -139,7 +141,10 @@ import {
|
|||||||
NOTIFY_QR_URL_COPIED,
|
NOTIFY_QR_URL_COPIED,
|
||||||
NOTIFY_QR_CODE_HELP,
|
NOTIFY_QR_CODE_HELP,
|
||||||
NOTIFY_QR_DID_COPIED,
|
NOTIFY_QR_DID_COPIED,
|
||||||
|
NOTIFY_QR_REGISTRATION_SUBMITTED,
|
||||||
|
NOTIFY_QR_REGISTRATION_ERROR,
|
||||||
createQRContactAddedMessage,
|
createQRContactAddedMessage,
|
||||||
|
createQRRegistrationSuccessMessage,
|
||||||
QR_TIMEOUT_MEDIUM,
|
QR_TIMEOUT_MEDIUM,
|
||||||
QR_TIMEOUT_STANDARD,
|
QR_TIMEOUT_STANDARD,
|
||||||
QR_TIMEOUT_LONG,
|
QR_TIMEOUT_LONG,
|
||||||
@@ -204,6 +209,7 @@ export default class ContactQRScanFull extends Vue {
|
|||||||
activeDid = "";
|
activeDid = "";
|
||||||
apiServer = "";
|
apiServer = "";
|
||||||
givenName = "";
|
givenName = "";
|
||||||
|
hideRegisterPromptOnNewContact = false;
|
||||||
isRegistered = false;
|
isRegistered = false;
|
||||||
profileImageUrl = "";
|
profileImageUrl = "";
|
||||||
qrValue = "";
|
qrValue = "";
|
||||||
@@ -278,6 +284,8 @@ export default class ContactQRScanFull extends Vue {
|
|||||||
|
|
||||||
this.apiServer = settings.apiServer || "";
|
this.apiServer = settings.apiServer || "";
|
||||||
this.givenName = settings.firstName || "";
|
this.givenName = settings.firstName || "";
|
||||||
|
this.hideRegisterPromptOnNewContact =
|
||||||
|
!!settings.hideRegisterPromptOnNewContact;
|
||||||
this.isRegistered = !!settings.isRegistered;
|
this.isRegistered = !!settings.isRegistered;
|
||||||
this.profileImageUrl = settings.profileImageUrl || "";
|
this.profileImageUrl = settings.profileImageUrl || "";
|
||||||
|
|
||||||
@@ -575,6 +583,34 @@ export default class ContactQRScanFull extends Vue {
|
|||||||
createQRContactAddedMessage(!!this.activeDid),
|
createQRContactAddedMessage(!!this.activeDid),
|
||||||
QR_TIMEOUT_STANDARD,
|
QR_TIMEOUT_STANDARD,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (
|
||||||
|
this.isRegistered &&
|
||||||
|
!this.hideRegisterPromptOnNewContact &&
|
||||||
|
!contact.registered
|
||||||
|
) {
|
||||||
|
setTimeout(() => {
|
||||||
|
this.$notify(
|
||||||
|
{
|
||||||
|
group: "modal",
|
||||||
|
type: "confirm",
|
||||||
|
title: "Register",
|
||||||
|
text: "Do you want to register them?",
|
||||||
|
onCancel: async (stopAsking?: boolean) => {
|
||||||
|
await this.handleRegistrationPromptResponse(stopAsking);
|
||||||
|
},
|
||||||
|
onNo: async (stopAsking?: boolean) => {
|
||||||
|
await this.handleRegistrationPromptResponse(stopAsking);
|
||||||
|
},
|
||||||
|
onYes: async () => {
|
||||||
|
await this.register(contact);
|
||||||
|
},
|
||||||
|
promptToStopAsking: true,
|
||||||
|
},
|
||||||
|
-1,
|
||||||
|
);
|
||||||
|
}, 500);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error saving contact to database:", {
|
logger.error("Error saving contact to database:", {
|
||||||
did: contact.did,
|
did: contact.did,
|
||||||
@@ -585,6 +621,74 @@ export default class ContactQRScanFull extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async register(contact: Contact) {
|
||||||
|
logger.debug("Submitting contact registration", {
|
||||||
|
did: contact.did,
|
||||||
|
name: contact.name,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const regResult = await register(
|
||||||
|
this.activeDid,
|
||||||
|
this.apiServer,
|
||||||
|
this.axios,
|
||||||
|
contact,
|
||||||
|
);
|
||||||
|
this.notify.toast("Submitted", NOTIFY_QR_REGISTRATION_SUBMITTED.message);
|
||||||
|
if (regResult.success) {
|
||||||
|
contact.registered = true;
|
||||||
|
await this.$updateContact(contact.did, { registered: true });
|
||||||
|
logger.debug("Contact registration successful", { did: contact.did });
|
||||||
|
|
||||||
|
this.notify.success(
|
||||||
|
createQRRegistrationSuccessMessage(contact.name || ""),
|
||||||
|
QR_TIMEOUT_LONG,
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.notify.error(
|
||||||
|
(regResult.error as string) || NOTIFY_QR_REGISTRATION_ERROR.message,
|
||||||
|
QR_TIMEOUT_LONG,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error("Error registering contact:", {
|
||||||
|
did: contact.did,
|
||||||
|
error: error instanceof Error ? error.message : String(error),
|
||||||
|
stack: error instanceof Error ? error.stack : undefined,
|
||||||
|
});
|
||||||
|
let userMessage = "There was an error.";
|
||||||
|
const serverError = error as AxiosError;
|
||||||
|
if (serverError) {
|
||||||
|
if (
|
||||||
|
serverError.response?.data &&
|
||||||
|
typeof serverError.response.data === "object" &&
|
||||||
|
"message" in serverError.response.data
|
||||||
|
) {
|
||||||
|
userMessage = (serverError.response.data as { message: string })
|
||||||
|
.message;
|
||||||
|
} else if (serverError.message) {
|
||||||
|
userMessage = serverError.message;
|
||||||
|
} else {
|
||||||
|
userMessage = JSON.stringify(serverError.toJSON());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
userMessage = error as string;
|
||||||
|
}
|
||||||
|
this.notify.error(userMessage, QR_TIMEOUT_LONG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleRegistrationPromptResponse(
|
||||||
|
stopAsking?: boolean,
|
||||||
|
): Promise<void> {
|
||||||
|
if (stopAsking) {
|
||||||
|
await this.$saveSettings({
|
||||||
|
hideRegisterPromptOnNewContact: stopAsking,
|
||||||
|
});
|
||||||
|
this.hideRegisterPromptOnNewContact = stopAsking;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vue lifecycle hook - component mounted
|
* Vue lifecycle hook - component mounted
|
||||||
* Sets up event listeners and starts scanning automatically
|
* Sets up event listeners and starts scanning automatically
|
||||||
|
|||||||
Reference in New Issue
Block a user