From 8a1689c57a46f1f401c553c58c70bc8b0dbc9ce3 Mon Sep 17 00:00:00 2001
From: Trent Larson <trent@trentlarson.com>
Date: Fri, 3 Jan 2025 09:47:42 -0700
Subject: [PATCH] fix error where visibility was set on all imported contacts
 even if not selected (and specify more types)

---
 src/views/ContactImportView.vue | 48 ++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 18 deletions(-)

diff --git a/src/views/ContactImportView.vue b/src/views/ContactImportView.vue
index 9946e28a7..198c7e1d4 100644
--- a/src/views/ContactImportView.vue
+++ b/src/views/ContactImportView.vue
@@ -124,7 +124,10 @@ export default class ContactImportView extends Vue {
   contactsSelected: Array<boolean> = []; // whether each contact in contactsImporting is selected
   contactDifferences: Record<
     string,
-    Record<string, { new: string; old: string }>
+    Record<
+      string,
+      { new: string | boolean | undefined; old: string | boolean | undefined }
+    >
   > = {}; // for existing contacts, it shows the difference between imported and existing contacts for each key
   importing = false;
   makeVisible = true;
@@ -170,12 +173,19 @@ export default class ContactImportView extends Vue {
       if (existingContact) {
         this.contactsExisting[contactIn.did] = existingContact;
 
-        const differences: Record<string, { new: string; old: string }> = {};
+        const differences: Record<
+          string,
+          {
+            new: string | boolean | undefined;
+            old: string | boolean | undefined;
+          }
+        > = {};
         Object.keys(contactIn).forEach((key) => {
-          if (contactIn[key] !== existingContact[key]) {
+          // eslint-disable-next-line prettier/prettier
+          if (contactIn[key as keyof Contact] !== existingContact[key as keyof Contact]) {
             differences[key] = {
-              old: existingContact[key],
-              new: contactIn[key],
+              old: existingContact[key as keyof Contact],
+              new: contactIn[key as keyof Contact],
             };
           }
         });
@@ -211,22 +221,24 @@ export default class ContactImportView extends Vue {
     if (this.makeVisible) {
       const failedVisibileToContacts = [];
       for (let i = 0; i < this.contactsImporting.length; i++) {
-        const contact = this.contactsImporting[i];
-        if (contact) {
-          const visResult = await setVisibilityUtil(
-            this.activeDid,
-            this.apiServer,
-            this.axios,
-            db,
-            contact,
-            true,
-          );
-          if (!visResult.success) {
-            failedVisibileToContacts.push(contact);
+        if (this.contactsSelected[i]) {
+          const contact = this.contactsImporting[i];
+          if (contact) {
+            const visResult = await setVisibilityUtil(
+              this.activeDid,
+              this.apiServer,
+              this.axios,
+              db,
+              contact,
+              true,
+            );
+            if (!visResult.success) {
+              failedVisibileToContacts.push(contact);
+            }
           }
         }
       }
-      if (failedVisibileToContacts.length) {
+      if (failedVisibileToContacts.length > 0) {
         this.$notify(
           {
             group: "alert",