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.
 
 
 

1 lines
14 KiB

var R=Object.defineProperty;var B=(e,i,t)=>i in e?R(e,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):e[i]=t;var d=(e,i,t)=>B(e,typeof i!="symbol"?i+"":i,t);import{y as _,d as G}from"./js-yaml-CxlQHuPU.js";import{V as z,f as Y,e as g,C as P,_ as Q,g as v,h as p,i as h,j as s,k as C,t as f,p as w,l as y,m as q,s as J,w as H,F as M,x as r,z as K}from"./index-BLqts8WY.js";import{Q as W}from"./QuickNav-DgCyvgDx.js";import{I as X}from"./InfiniteScroll-B5tl9k_n.js";import{T as Z}from"./TopMessage-BE0GBIgW.js";import{l as ee,al as te,am as ie,A as k,e as se,an as I,ae as oe,g as L,K as ne}from"./index-MyY_xqVN.js";import{E as ae}from"./EntityIcon-CF1RwQI5.js";import"./index-CsfPLOYu.js";var re=Object.defineProperty,le=Object.getOwnPropertyDescriptor,de=(e,i,t,o)=>{for(var n=o>1?void 0:o?le(i,t):i,c=e.length-1,a;c>=0;c--)(a=e[c])&&(n=(o?a(i,t,n):a(n))||n);return o&&n&&re(i,t,n),n};let x=class extends z{constructor(){super(...arguments);d(this,"$notify");d(this,"libsUtil",ee);d(this,"yaml",_);d(this,"activeDid","");d(this,"apiServer","");d(this,"claims",[]);d(this,"contactFromDid");d(this,"contactEdit",!1);d(this,"contactNewName","");d(this,"contactYaml","");d(this,"hitEnd",!1);d(this,"isLoading",!1);d(this,"isMyDid",!1);d(this,"searchBox",null);d(this,"showDidDetails",!1);d(this,"showLargeIdenticonId");d(this,"showLargeIdenticonUrl");d(this,"viewingDid");d(this,"capitalizeAndInsertSpacesBeforeCaps",te);d(this,"didInfoForContact",ie);d(this,"displayAmount",k)}async mounted(){const t=await Y();this.activeDid=t.activeDid||"",this.apiServer=t.apiServer||"";const o=window.location.pathname.substring(5);if(o){this.viewingDid=decodeURIComponent(o),this.contactFromDid=await g.contacts.get(this.viewingDid),this.contactFromDid&&(this.contactYaml=G(this.contactFromDid)),await this.loadClaimsAbout();const n=await se();this.isMyDid=n.includes(this.viewingDid)}}async loadMoreData(t){this.claims.length>0&&!this.hitEnd&&t&&this.loadClaimsAbout()}confirmDeleteContact(t){let o="Are you sure you want to remove "+I(t,!1)+" from your contact list?";t.seesMe&&(o+=" Note that they can see your activity, so if you want to hide your activity from them then you should do that first."),this.$notify({group:"modal",type:"confirm",title:"Delete",text:o,onYes:async()=>{await this.deleteContact(t)}},-1)}async deleteContact(t){await g.open(),await g.contacts.delete(t.did),this.$notify({group:"alert",type:"success",title:"Deleted",text:"Contact has been removed."},3e3),this.$router.push({name:"contacts"})}async confirmRegister(t){this.$notify({group:"modal",type:"confirm",title:"Register",text:"Are you sure you want to register "+I(this.contactFromDid,!1)+(t.registered?" -- especially since they are already marked as registered":"")+"?",onYes:async()=>{await this.register(t)}},-1)}async register(t){var o,n,c;this.$notify({group:"alert",type:"toast",title:"Sent..."},1e3);try{const a=await oe(this.activeDid,this.apiServer,this.axios,t);a.success?(t.registered=!0,await g.contacts.update(t.did,{registered:!0}),this.$notify({group:"alert",type:"success",title:"Registration Success",text:(t.name||"That unnamed person")+" has been registered."},5e3)):this.$notify({group:"alert",type:"danger",title:"Registration Error",text:a.error||"Something went wrong during registration."},5e3)}catch(a){console.error("Error when registering:",a);let l="There was an error.";const m=a;m?(c=(n=(o=m.response)==null?void 0:o.data)==null?void 0:n.error)!=null&&c.message?l=m.response.data.error.message:m.message?l=m.message:l=JSON.stringify(m.toJSON()):l=a,this.$notify({group:"alert",type:"danger",title:"Registration Error",text:l},5e3)}}async loadClaimsAbout(){if(!this.viewingDid){console.error("This should never be called without a DID.");return}const t="claimContents="+encodeURIComponent(this.viewingDid);let o="";this.claims.length>0&&(o="&beforeId="+this.claims[this.claims.length-1].id);try{this.isLoading=!0;const n=await fetch(this.apiServer+"/api/v2/report/claims?"+t+o,{method:"GET",headers:await L(this.activeDid)});if(n.status!==200){const a=await n.text();console.error("Problem with full search:",a),this.$notify({group:"alert",type:"danger",title:"Error",text:"There was a problem accessing the server. Try again later."},5e3);return}const c=await n.json();this.claims=this.claims.concat(c.data),this.hitEnd=!c.hitLimit}catch(n){console.error("Error with feed load:",n),this.$notify({group:"alert",type:"danger",title:"Error",text:n.userMessage||"There was a problem retrieving claims."},-1)}finally{this.isLoading=!1}}onClickLoadClaim(t){const o={path:"/claim/"+encodeURIComponent(t)};this.$router.push(o)}claimAmount(t){var o,n,c,a;if(t.claimType==="GiveAction"){const l=t.claim;return(o=l.object)!=null&&o.unitCode&&((n=l.object)!=null&&n.amountOfThisGood)?k(l.object.unitCode,l.object.amountOfThisGood):""}else if(t.claimType==="Offer"){const l=t.claim;return(c=l.includesObject)!=null&&c.unitCode&&((a=l.includesObject)!=null&&a.amountOfThisGood)?k(l.includesObject.unitCode,l.includesObject.amountOfThisGood):""}return""}claimDescription(t){return t.claim.name||t.claim.description||""}async onClickCancelName(){this.contactEdit=!1}async onClickSaveName(t){if(!this.contactFromDid){this.$notify({group:"alert",type:"danger",title:"Not A Contact",text:"First add this on the contact page, then you can edit here."},5e3);return}return this.contactFromDid.name=t,g.contacts.update(this.contactFromDid.did,{name:t}).then(()=>this.contactEdit=!1)}async confirmSetVisibility(t,o){const n=o?"Are you sure you want to make your activity visible to them?":"Are you sure you want to hide all your activity from them?";this.$notify({group:"modal",type:"confirm",title:"Set Visibility",text:n,onYes:async()=>{await this.setVisibility(t,o,!0)&&(t.seesMe=o)}},-1)}async setVisibility(t,o,n){const c=await ne(this.activeDid,this.apiServer,this.axios,g,t,o);if(c.success)return n&&this.$notify({group:"alert",type:"success",title:"Visibility Set",text:(t.name||"That user")+" can "+(o?"":"not ")+"see your activity."},3e3),!0;{console.error("Got strange result from setting visibility:",c);const a=c.error||"Could not set visibility on the server.";return this.$notify({group:"alert",type:"danger",title:"Error Setting Visibility",text:a},5e3),!1}}async checkVisibility(t){var c;const o=this.apiServer+"/api/report/canDidExplicitlySeeMe?did="+encodeURIComponent(t.did),n=await L(this.activeDid);if(!n.Authorization){this.$notify({group:"alert",type:"danger",title:"No Identity",text:"There is no identity to use to check visibility."},3e3);return}try{const a=await this.axios.get(o,{headers:n});if(a.status===200){const l=a.data;t.seesMe=l,await g.contacts.update(t.did,{seesMe:l}),this.$notify({group:"alert",type:"info",title:"Visibility Refreshed",text:I(t,!0)+" can "+(l?"":"not ")+"see your activity."},3e3)}else{console.error("Got bad server response checking visibility:",a);const l=((c=a.data.error)==null?void 0:c.message)||"Got bad server response.";this.$notify({group:"alert",type:"danger",title:"Error Checking Visibility",text:l},5e3)}}catch(a){console.error("Caught error from request to check visibility:",a),this.$notify({group:"alert",type:"danger",title:"Error Checking Visibility",text:"Check connectivity and try again."},3e3)}}};x=de([P({components:{EntityIcon:ae,InfiniteScroll:X,QuickNav:W,TopMessage:Z}})],x);const ce={id:"Content",class:"p-6 pb-24 max-w-3xl mx-auto"},me={id:"ViewBreadcrumb",class:"mb-8"},ue={class:"text-lg text-center font-light relative px-7"},pe={key:0,class:"bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4"},he={class:"text-xl font-semibold"},ye={key:0,class:"text-sm overflow-x-scroll px-4 py-3 bg-slate-100 rounded-md"},fe={class:"flex justify-center mt-4"},ge={key:0,class:"flex justify-between"},be={class:"flex justify-between mt-4"},ve={class:"flex items-center"},we={key:0,class:"flex justify-between"},De={key:0},Ce={class:"flex justify-center"},ke={key:0,class:"fixed z-[100] top-0 inset-x-0 w-full"},Ie={class:"absolute inset-0 h-screen flex flex-col items-center justify-center bg-slate-900/50"},xe={key:1,class:"bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4"},$e={class:"text-xl font-semibold"},Fe={key:2,class:"dialog-overlay"},Se={class:"dialog"},Ee={class:"flex justify-between"},Ne={key:3,class:"fixed left-6 bottom-24 text-center text-4xl leading-none bg-slate-400 text-white w-14 py-2.5 rounded-full"},Te={key:4,class:"mt-4"},Ve={class:"text-l font-bold text-center"},Ae={class:"grid grid-cols-12 gap-4"},Ue={class:"col-span-2"},je={class:"col-span-2"},Me={class:"col-span-2"},Le={class:"col-span-5"},Oe={class:"col-span-1"},Re=["onClick"],Be={key:5,class:"flex justify-center mt-4"},_e={key:0},Ge={key:1};function ze(e,i,t,o,n,c){var $,F,S,E,N,T,V,A,U,j;const a=v("QuickNav"),l=v("TopMessage"),m=v("fa"),D=v("EntityIcon"),O=v("InfiniteScroll");return r(),p(M,null,[h(a,{selected:"Contacts"}),h(l),s("section",ce,[s("div",me,[s("h1",ue,[s("button",{onClick:i[0]||(i[0]=u=>e.$router.go(-1)),class:"text-lg text-center px-2 py-1 absolute -left-2 -top-1"},[h(m,{icon:"chevron-left",class:"fa-fw"})]),i[14]||(i[14]=C(" Identifier Details "))])]),e.contactFromDid?(r(),p("div",pe,[s("div",null,[s("h2",he,[C(f((($=e.contactFromDid)==null?void 0:$.name)||"(no name)")+" ",1),s("button",{onClick:i[1]||(i[1]=u=>{var b;e.contactEdit=!0,e.contactNewName=((b=e.contactFromDid)==null?void 0:b.name)||""}),title:"Edit"},[h(m,{icon:"pen",class:"text-sm text-blue-500 ml-2 mb-1"})])]),s("button",{onClick:i[2]||(i[2]=u=>e.showDidDetails=!e.showDidDetails),class:"ml-2 mr-2 mt-4"},[i[15]||(i[15]=C(" Details ")),e.showDidDetails?(r(),w(m,{key:0,icon:"chevron-down",class:"text-blue-400"})):(r(),w(m,{key:1,icon:"chevron-right",class:"text-blue-400"}))]),e.showDidDetails?(r(),p("pre",ye,f(e.contactYaml),1)):y("",!0)]),s("div",fe,[(F=e.contactFromDid)!=null&&F.profileImageUrl?(r(),p("span",ge,[h(D,{"icon-size":96,profileImageUrl:(S=e.contactFromDid)==null?void 0:S.profileImageUrl,class:"inline-block align-text-bottom border border-slate-300 rounded",onClick:i[3]||(i[3]=u=>{var b;return e.showLargeIdenticonUrl=(b=e.contactFromDid)==null?void 0:b.profileImageUrl})},null,8,["profileImageUrl"])])):y("",!0)]),s("div",be,[s("div",ve,[e.activeDid?(r(),p("div",we,[s("div",null,[(E=e.contactFromDid)!=null&&E.seesMe&&e.contactFromDid.did!==e.activeDid?(r(),p("button",{key:0,class:"text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md",onClick:i[4]||(i[4]=u=>e.confirmSetVisibility(e.contactFromDid,!1)),title:"They can see you"},[h(m,{icon:"eye",class:"fa-fw"})])):!((N=e.contactFromDid)!=null&&N.seesMe)&&((T=e.contactFromDid)==null?void 0:T.did)!==e.activeDid?(r(),p("button",{key:1,class:"text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md",onClick:i[5]||(i[5]=u=>e.confirmSetVisibility(e.contactFromDid,!0)),title:"They cannot see you"},[h(m,{icon:"eye-slash",class:"fa-fw"})])):y("",!0),((V=e.contactFromDid)==null?void 0:V.did)!==e.activeDid?(r(),p("button",{key:2,class:"text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white mx-0.5 my-0.5 px-2 py-1.5 rounded-md",onClick:i[6]||(i[6]=u=>e.checkVisibility(e.contactFromDid)),title:"Check Visibility"},[h(m,{icon:"rotate",class:"fa-fw"})])):y("",!0)]),((A=e.contactFromDid)==null?void 0:A.did)!==e.activeDid?(r(),p("button",{key:0,onClick:i[7]||(i[7]=u=>e.confirmRegister(e.contactFromDid)),class:"text-sm uppercase bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-6 mx-0.5 my-0.5 px-2 py-1.5 rounded-md",title:"Registration"},[(U=e.contactFromDid)!=null&&U.registered?(r(),w(m,{key:0,icon:"person-circle-check",class:"fa-fw"})):(r(),w(m,{key:1,icon:"person-circle-question",class:"fa-fw"}))])):y("",!0)])):y("",!0),s("button",{onClick:i[8]||(i[8]=u=>e.confirmDeleteContact(e.contactFromDid)),class:"text-sm uppercase bg-gradient-to-b from-rose-500 to-rose-800 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white ml-6 mx-0.5 my-0.5 px-2 py-1.5 rounded-md",title:"Delete"},[h(m,{icon:"trash-can",class:"fa-fw"})])]),(j=e.contactFromDid)!=null&&j.profileImageUrl?y("",!0):(r(),p("div",De,[i[16]||(i[16]=s("div",null,"Auto-Generated Icon",-1)),s("div",Ce,[h(D,{entityId:e.viewingDid,iconSize:64,class:"inline-block align-middle border border-slate-300 rounded-md mr-1",onClick:i[9]||(i[9]=u=>e.showLargeIdenticonId=e.viewingDid)},null,8,["entityId"])])]))]),e.showLargeIdenticonId||e.showLargeIdenticonUrl?(r(),p("div",ke,[s("div",Ie,[h(D,{entityId:e.showLargeIdenticonId,iconSize:512,profileImageUrl:e.showLargeIdenticonUrl,class:"flex w-11/12 max-w-sm mx-auto mb-3 overflow-hidden bg-white rounded-lg shadow-lg",onClick:i[10]||(i[10]=u=>{e.showLargeIdenticonId=void 0,e.showLargeIdenticonUrl=void 0})},null,8,["entityId","profileImageUrl"])])])):y("",!0)])):(r(),p("div",xe,[s("div",null,[s("h2",$e,f(e.isMyDid?"You":"(no name)"),1)])])),e.contactEdit?(r(),p("div",Fe,[s("div",Se,[i[18]||(i[18]=s("h1",{class:"text-xl font-bold text-center mb-4"},"Edit Name",-1)),q(s("input",{type:"text",class:"block w-full rounded border border-slate-400 mb-2 px-3 py-2",placeholder:"Name","onUpdate:modelValue":i[11]||(i[11]=u=>e.contactNewName=u)},null,512),[[J,e.contactNewName]]),s("div",Ee,[s("button",{class:"text-sm bg-blue-600 text-white px-2 py-1.5 rounded -ml-1.5 border-l border-blue-400",onClick:i[12]||(i[12]=u=>e.onClickSaveName(e.contactNewName))},[h(m,{icon:"save"})]),i[17]||(i[17]=s("span",{class:"inline-block w-2"},null,-1)),s("button",{class:"text-sm bg-blue-600 text-white px-2 py-1.5 rounded -ml-1.5 border-l border-blue-400",onClick:i[13]||(i[13]=u=>e.onClickCancelName())},[h(m,{icon:"ban"})])])])])):y("",!0),e.isLoading?(r(),p("div",Ne,[h(m,{icon:"spinner",class:"fa-spin-pulse"})])):y("",!0),e.claims.length>0?(r(),p("div",Te,[s("div",Ve," Claims That Involve "+f(e.isMyDid?"You":"Them"),1)])):y("",!0),h(O,{onReachedBottom:e.loadMoreData},{default:H(()=>[s("ul",null,[(r(!0),p(M,null,K(e.claims,u=>(r(),p("li",{class:"border-b border-slate-300",key:u.handleId},[s("div",Ae,[s("span",Ue,f(u.issuedAt.substring(0,10)),1),s("span",je,f(e.capitalizeAndInsertSpacesBeforeCaps(u.claimType)),1),s("span",Me,f(e.claimAmount(u)),1),s("span",Le,f(e.claimDescription(u)),1),s("span",Oe,[s("a",{onClick:b=>e.onClickLoadClaim(u.id),class:"cursor-pointer"},[h(m,{icon:"file-lines",class:"pl-2 pt-1 text-blue-500"})],8,Re)])])]))),128))])]),_:1},8,["onReachedBottom"]),!e.isLoading&&e.claims.length===0?(r(),p("div",Be,[e.isMyDid?(r(),p("span",_e,"You have no claims yet.")):(r(),p("span",Ge,"They are in no claims visible to you."))])):y("",!0)])],64)}const et=Q(x,[["render",ze]]);export{et as default};