You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
5.7 KiB

var S=Object.defineProperty;var $=(t,s,n)=>s in t?S(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var p=(t,s,n)=>$(t,typeof s!="symbol"?s+"":s,n);import{R as D,i as E}from"./index-BH4jUAKp.js";import{V as N,A as O,f as A,e as u,C as j,_ as U,g as w,h as r,i as _,j as l,m as k,o as V,k as x,l as g,t as f,F as b,z as I,p as R,x as c}from"./index-BLqts8WY.js";import{Q as T}from"./QuickNav-DgCyvgDx.js";import{E as B}from"./EntityIcon-CF1RwQI5.js";import{O as F}from"./OfferDialog-BFpCo0de.js";import{l as J,J as P,H as Q,K as M}from"./index-MyY_xqVN.js";import"./concat-BK8PKeDS.js";import"./sort-Dh4GzQVc.js";import"./index-CsfPLOYu.js";var H=Object.defineProperty,q=Object.getOwnPropertyDescriptor,z=(t,s,n,d)=>{for(var e=d>1?void 0:d?q(s,n):s,i=t.length-1,a;i>=0;i--)(a=t[i])&&(e=(d?a(s,n,e):a(e))||e);return d&&e&&H(s,n,e),e};let v=class extends N{constructor(){super(...arguments);p(this,"$notify");p(this,"AppString",O);p(this,"libsUtil",J);p(this,"R",D);p(this,"activeDid","");p(this,"apiServer","");p(this,"contactsExisting",{});p(this,"contactsImporting",[]);p(this,"contactsSelected",[]);p(this,"contactDifferences",{});p(this,"importing",!1);p(this,"makeVisible",!0);p(this,"sameCount",0)}async created(){var i;const n=await A();this.activeDid=n.activeDid||"",this.apiServer=n.apiServer||"";const d=this.$route.query.contacts;d&&await this.setContactsSelected(JSON.parse(d));const e=(i=window.location.pathname.match(/\/contact-import\/(ey.+)$/))==null?void 0:i[1];if(e){const a=await P(e);await this.setContactsSelected(a.payload.contacts)}}async setContactsSelected(n){this.contactsImporting=n,this.contactsSelected=new Array(this.contactsImporting.length).fill(!0),await u.open();const d=await u.contacts.toArray();for(let e=0;e<this.contactsImporting.length;e++){const i=this.contactsImporting[e],a=d.find(m=>m.did===i.did);if(a){this.contactsExisting[i.did]=a;const m={};Object.keys(i).forEach(o=>{i[o]!==a[o]&&(m[o]={old:a[o],new:i[o]})}),this.contactDifferences[i.did]=m,E(m)&&this.sameCount++,this.contactsSelected[e]=!1}}}async importContacts(){this.importing=!0;let n=0,d=0;for(let e=0;e<this.contactsImporting.length;e++)if(this.contactsSelected[e]){const i=this.contactsImporting[e];this.contactsExisting[i.did]?(await u.contacts.update(i.did,i),d++):(await u.contacts.add(Q(i)),n++)}if(this.makeVisible){const e=[];for(let i=0;i<this.contactsImporting.length;i++){const a=this.contactsImporting[i];a&&((await M(this.activeDid,this.apiServer,this.axios,u,a,!0)).success||e.push(a))}e.length&&this.$notify({group:"alert",type:"danger",title:"Visibility Error",text:`Failed to set visibility for ${e.length} contact${e.length==1?"":"s"}. You must set them individually: ${e.map(i=>i.name).join(", ")}`},-1)}this.importing=!1,this.$notify({group:"alert",type:"success",title:"Imported",text:`${n} contact${n==1?"":"s"} imported.`+(d?` ${d} updated.`:"")},3e3),this.$router.push({name:"contacts"})}};v=z([j({components:{EntityIcon:B,OfferDialog:F,QuickNav:T}})],v);const K={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},L={class:"text-lg text-center font-light relative px-7"},Y={key:0,class:"flex justify-center"},G={key:1},W={key:0},X={key:1},Z={key:2,class:"border-t border-slate-300"},tt={key:0,class:"grow overflow-hidden border-b border-slate-300 pt-2.5 pb-4"},et={class:"text-base font-semibold"},st=["onUpdate:modelValue"],it={key:0,class:"text-orange-500"},ot={key:1,class:"text-green-500"},nt={class:"text-sm truncate"},at={key:0},ct={class:"border p-1"},rt={class:"border p-1"},lt={class:"border p-1"},dt={key:3};function pt(t,s,n,d,e,i){const a=w("QuickNav"),m=w("fa");return c(),r(b,null,[_(a,{selected:"Contacts"}),l("section",K,[l("div",L,[l("h1",{class:"text-lg text-center px-2 py-1 absolute -left-2 -top-1",onClick:s[0]||(s[0]=o=>t.$router.back())},[_(m,{icon:"chevron-left",class:"fa-fw"})])]),s[5]||(s[5]=l("h1",{id:"ViewHeading",class:"text-4xl text-center font-light pt-4 mb-8"}," Contact Import ",-1)),t.contactsImporting.length>t.sameCount?(c(),r("span",Y,[k(l("input",{type:"checkbox","onUpdate:modelValue":s[1]||(s[1]=o=>t.makeV