From 55c0eb6114f2249d9a34c471df9a527dd3d884a2 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Tue, 21 Mar 2023 18:49:40 -0600 Subject: [PATCH] add functions for visibility to contacts --- project.yaml | 1 + src/main.ts | 54 +++++++------- src/views/ContactsView.vue | 140 ++++++++++++++++++++++++++++++++++++- 3 files changed, 168 insertions(+), 27 deletions(-) diff --git a/project.yaml b/project.yaml index 8a72024..32c82a5 100644 --- a/project.yaml +++ b/project.yaml @@ -13,6 +13,7 @@ - contacts v1 : - remove 'copy' until it works + - switch to prod server - 01 show gives with confirmations - .5 Add page to show seed. - 01 Provide a way to import the non-sensitive data. diff --git a/src/main.ts b/src/main.ts index 8fc26a4..4549049 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,46 +10,52 @@ import "./assets/styles/tailwind.css"; import { library } from "@fortawesome/fontawesome-svg-core"; import { + faCalendar, faChevronLeft, - faHouseChimney, - faMagnifyingGlass, - faFolderOpen, - faHand, + faCircleCheck, faCircleUser, faCopy, - faShareNodes, - faQrcode, - faUser, - faUsers, + faEllipsisVertical, + faEye, + faEyeSlash, + faFolderOpen, + faHand, + faHouseChimney, + faMagnifyingGlass, faPen, faPlus, - faTrashCan, - faCalendar, - faEllipsisVertical, + faQrcode, + faRotate, + faShareNodes, faSpinner, - faCircleCheck, + faTrashCan, + faUser, + faUsers, faXmark, } from "@fortawesome/free-solid-svg-icons"; library.add( + faCalendar, faChevronLeft, - faHouseChimney, - faMagnifyingGlass, - faFolderOpen, - faHand, + faCircleCheck, faCircleUser, faCopy, - faShareNodes, - faQrcode, - faUser, - faUsers, + faEllipsisVertical, + faEye, + faEyeSlash, + faFolderOpen, + faHand, + faHouseChimney, + faMagnifyingGlass, faPen, faPlus, - faTrashCan, - faCalendar, - faEllipsisVertical, + faQrcode, + faRotate, + faShareNodes, faSpinner, - faCircleCheck, + faTrashCan, + faUser, + faUsers, faXmark ); diff --git a/src/views/ContactsView.vue b/src/views/ContactsView.vue index 9a57079..3cad6b9 100644 --- a/src/views/ContactsView.vue +++ b/src/views/ContactsView.vue @@ -99,8 +99,26 @@
Public Key (base 64): {{ contact.publicKeyBase64 }}
- + + + +
@@ -310,6 +328,89 @@ export default class ContactsView extends Vue { } } + async setVisibility(contact: Contact, visibility: boolean) { + const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; + const url = + endorserApiServer + + "/api/report/" + + (visibility ? "canSeeMe" : "cannotSeeMe"); + await accountsDB.open(); + const accounts = await accountsDB.accounts.toArray(); + const identity = JSON.parse(accounts[0].identity); + const token = await accessToken(identity); + const headers = { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }; + const payload = JSON.stringify({ did: contact.did }); + + try { + const resp = await this.axios.post(url, payload, { headers }); + if (resp.status === 200) { + contact.seesMe = visibility; + db.contacts.update(contact.did, { seesMe: visibility }); + } else { + this.alertTitle = "Error from Server"; + console.log("Bad response setting visibility: ", resp.data); + if (resp.data.error?.message) { + this.alertMessage = resp.data.error?.message; + } else { + this.alertMessage = "Bad server response of " + resp.status; + } + this.isAlertVisible = true; + } + } catch (err) { + this.alertTitle = "Error from Server"; + this.alertMessage = err as string; + this.isAlertVisible = true; + } + } + + async checkVisibility(contact: Contact) { + const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER; + const url = + endorserApiServer + + "/api/report/canDidExplicitlySeeMe?did=" + + encodeURIComponent(contact.did); + await accountsDB.open(); + const accounts = await accountsDB.accounts.toArray(); + const identity = JSON.parse(accounts[0].identity); + const token = await accessToken(identity); + const headers = { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }; + + try { + const resp = await this.axios.get(url, { headers }); + if (resp.status === 200) { + const visibility = resp.data; + contact.seesMe = visibility; + db.contacts.update(contact.did, { seesMe: visibility }); + this.alertTitle = "Refreshed"; + this.alertMessage = + this.nameForContact(contact, true) + + " can " + + (visibility ? "" : "not ") + + "see your activity."; + this.isAlertVisible = true; + } else { + this.alertTitle = "Error from Server"; + console.log("Bad response checking visibility: ", resp.data); + if (resp.data.error?.message) { + this.alertMessage = resp.data.error?.message; + } else { + this.alertMessage = "Bad server response of " + resp.status; + } + this.isAlertVisible = true; + } + } catch (err) { + this.alertTitle = "Error from Server"; + this.alertMessage = err as string; + this.isAlertVisible = true; + } + } + // from https://stackoverflow.com/a/175787/845494 // private isNumeric(str: string): boolean { @@ -318,7 +419,11 @@ export default class ContactsView extends Vue { private nameForDid(contacts: Array, did: string): string { const contact = R.find((con) => con.did == did, contacts); - return contact?.name || "this unnamed user"; + return this.nameForContact(contact); + } + + private nameForContact(contact?: Contact, capitalize?: boolean): string { + return contact?.name || (capitalize ? "T" : "t") + "this unnamed user"; } async onClickAddGive(fromDid: string, toDid: string): Promise { @@ -479,3 +584,32 @@ export default class ContactsView extends Vue { } } + +