nextcloud-server/dist/user_status-menu.mjs

4 lines
26 KiB
JavaScript

const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=[window.OC.filePath('', '', 'dist/SetStatusModal-DFKMBQe-.chunk.mjs'),window.OC.filePath('', '', 'dist/Plus-DDsJI2iW.chunk.mjs'),window.OC.filePath('', '', 'dist/TrashCanOutline-avc1vI9P.chunk.mjs'),window.OC.filePath('', '', 'dist/TrayArrowDown-sRwZP_WA.chunk.mjs'),window.OC.filePath('', '', 'dist/TrayArrowDown-D7mIRwIy.chunk.css'),window.OC.filePath('', '', 'dist/TrashCanOutline-CKjk9wDJ.chunk.css'),window.OC.filePath('', '', 'dist/ContentCopy-BEfKgtZW.chunk.mjs'),window.OC.filePath('', '', 'dist/ContentCopy-Ck29Gkyh.chunk.css'),window.OC.filePath('', '', 'dist/Plus-CeFTF6zT.chunk.css'),window.OC.filePath('', '', 'dist/index-C2fUbm9n.chunk.mjs'),window.OC.filePath('', '', 'dist/user_status-SetStatusModal-HX2qTI0C.chunk.css')])))=>i.map(i=>d[i]);
import{J as ht,A as gt,T as K,j as yt,e as h,g,d as y,_ as _t,ag as vt,r as k,v as G,o as E,c as B,m as bt,w as T,a as P,n as L,z as V,b as wt,t as St,F as It,E as b,af as Mt,s as Y,Y as M,l as Ot,f as Z}from"./TrayArrowDown-sRwZP_WA.chunk.mjs";import{g as At,b as kt,j as Et}from"./TrashCanOutline-avc1vI9P.chunk.mjs";import{N as Ct,m as O}from"./index-C2fUbm9n.chunk.mjs";import{s as jt,l as Tt}from"./Plus-DDsJI2iW.chunk.mjs";import"./ContentCopy-BEfKgtZW.chunk.mjs";const Pt="modulepreload",Lt=function(t,e){return new URL(t,e).href},H={},xt=function(t,e,s){let a=Promise.resolve();if(e&&e.length>0){let o=function(u){return Promise.all(u.map(c=>Promise.resolve(c).then(d=>({status:"fulfilled",value:d}),d=>({status:"rejected",reason:d}))))};const n=document.getElementsByTagName("link"),i=document.querySelector("meta[property=csp-nonce]"),l=i?.nonce||i?.getAttribute("nonce");a=o(e.map(u=>{if(u=Lt(u,s),u in H)return;H[u]=!0;const c=u.endsWith(".css"),d=c?'[rel="stylesheet"]':"";if(s)for(let _=n.length-1;_>=0;_--){const A=n[_];if(A.href===u&&(!c||A.rel==="stylesheet"))return}else if(document.querySelector(`link[href="${u}"]${d}`))return;const p=document.createElement("link");if(p.rel=c?"stylesheet":Pt,c||(p.as="script"),p.crossOrigin="",p.href=u,l&&p.setAttribute("nonce",l),document.head.appendChild(p),c)return new Promise((_,A)=>{p.addEventListener("load",_),p.addEventListener("error",()=>A(new Error(`Unable to preload CSS for ${u}`)))})}))}function r(o){const n=new Event("vite:preloadError",{cancelable:!0});if(n.payload=o,window.dispatchEvent(n),!n.defaultPrevented)throw o}return a.then(o=>{for(const n of o||[])n.status==="rejected"&&r(n.reason);return t().catch(r)})};function Ut(){return tt().__VUE_DEVTOOLS_GLOBAL_HOOK__}function tt(){return typeof navigator<"u"&&typeof window<"u"?window:typeof globalThis<"u"?globalThis:{}}const Dt=typeof Proxy=="function",Ft="devtools-plugin:setup",Nt="plugin:settings:set";let I,D;function $t(){var t;return I!==void 0||(typeof window<"u"&&window.performance?(I=!0,D=window.performance):typeof globalThis<"u"&&!((t=globalThis.perf_hooks)===null||t===void 0)&&t.performance?(I=!0,D=globalThis.perf_hooks.performance):I=!1),I}function Gt(){return $t()?D.now():Date.now()}class Bt{constructor(e,s){this.target=null,this.targetQueue=[],this.onQueue=[],this.plugin=e,this.hook=s;const a={};if(e.settings)for(const n in e.settings){const i=e.settings[n];a[n]=i.defaultValue}const r=`__vue-devtools-plugin-settings__${e.id}`;let o=Object.assign({},a);try{const n=localStorage.getItem(r),i=JSON.parse(n);Object.assign(o,i)}catch{}this.fallbacks={getSettings(){return o},setSettings(n){try{localStorage.setItem(r,JSON.stringify(n))}catch{}o=n},now(){return Gt()}},s&&s.on(Nt,(n,i)=>{n===this.plugin.id&&this.fallbacks.setSettings(i)}),this.proxiedOn=new Proxy({},{get:(n,i)=>this.target?this.target.on[i]:(...l)=>{this.onQueue.push({method:i,args:l})}}),this.proxiedTarget=new Proxy({},{get:(n,i)=>this.target?this.target[i]:i==="on"?this.proxiedOn:Object.keys(this.fallbacks).includes(i)?(...l)=>(this.targetQueue.push({method:i,args:l,resolve:()=>{}}),this.fallbacks[i](...l)):(...l)=>new Promise(u=>{this.targetQueue.push({method:i,args:l,resolve:u})})})}async setRealTarget(e){this.target=e;for(const s of this.onQueue)this.target.on[s.method](...s.args);for(const s of this.targetQueue)s.resolve(await this.target[s.method](...s.args))}}function Vt(t,e){const s=t,a=tt(),r=Ut(),o=Dt&&s.enableEarlyProxy;if(r&&(a.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__||!o))r.emit(Ft,t,e);else{const n=o?new Bt(s,r):null;(a.__VUE_DEVTOOLS_PLUGINS__=a.__VUE_DEVTOOLS_PLUGINS__||[]).push({pluginDescriptor:s,setupFn:e,proxy:n}),n&&e(n.proxiedTarget)}}const et=At().detectLogLevel().setApp("user_status").build();var Ht="store";function S(t,e){Object.keys(t).forEach(function(s){return e(t[s],s)})}function st(t){return t!==null&&typeof t=="object"}function Qt(t){return t&&typeof t.then=="function"}function Rt(t,e){return function(){return t(e)}}function Q(t,e,s){return e.indexOf(t)<0&&(s&&s.prepend?e.unshift(t):e.push(t)),function(){var a=e.indexOf(t);a>-1&&e.splice(a,1)}}function R(t,e){t._actions=Object.create(null),t._mutations=Object.create(null),t._wrappedGetters=Object.create(null),t._modulesNamespaceMap=Object.create(null);var s=t.state;j(t,s,[],t._modules.root,!0),N(t,s,e)}function N(t,e,s){var a=t._state,r=t._scope;t.getters={},t._makeLocalGettersCache=Object.create(null);var o=t._wrappedGetters,n={},i={},l=ht(!0);l.run(function(){S(o,function(u,c){n[c]=Rt(u,t),i[c]=yt(function(){return n[c]()}),Object.defineProperty(t.getters,c,{get:function(){return i[c].value},enumerable:!0})})}),t._state=gt({data:e}),t._scope=l,t.strict&&Xt(t),a&&s&&t._withCommit(function(){a.data=null}),r&&r.stop()}function j(t,e,s,a,r){var o=!s.length,n=t._modules.getNamespace(s);if(a.namespaced&&(t._modulesNamespaceMap[n],t._modulesNamespaceMap[n]=a),!o&&!r){var i=$(e,s.slice(0,-1)),l=s[s.length-1];t._withCommit(function(){i[l]=a.state})}var u=a.context=Wt(t,n,s);a.forEachMutation(function(c,d){var p=n+d;zt(t,p,c,u)}),a.forEachAction(function(c,d){var p=c.root?d:n+d,_=c.handler||c;Jt(t,p,_,u)}),a.forEachGetter(function(c,d){var p=n+d;qt(t,p,c,u)}),a.forEachChild(function(c,d){j(t,e,s.concat(d),c,r)})}function Wt(t,e,s){var a=e==="",r={dispatch:a?t.dispatch:function(o,n,i){var l=C(o,n,i),u=l.payload,c=l.options,d=l.type;return(!c||!c.root)&&(d=e+d),t.dispatch(d,u)},commit:a?t.commit:function(o,n,i){var l=C(o,n,i),u=l.payload,c=l.options,d=l.type;(!c||!c.root)&&(d=e+d),t.commit(d,u,c)}};return Object.defineProperties(r,{getters:{get:a?function(){return t.getters}:function(){return at(t,e)}},state:{get:function(){return $(t.state,s)}}}),r}function at(t,e){if(!t._makeLocalGettersCache[e]){var s={},a=e.length;Object.keys(t.getters).forEach(function(r){if(r.slice(0,a)===e){var o=r.slice(a);Object.defineProperty(s,o,{get:function(){return t.getters[r]},enumerable:!0})}}),t._makeLocalGettersCache[e]=s}return t._makeLocalGettersCache[e]}function zt(t,e,s,a){var r=t._mutations[e]||(t._mutations[e]=[]);r.push(function(o){s.call(t,a.state,o)})}function Jt(t,e,s,a){var r=t._actions[e]||(t._actions[e]=[]);r.push(function(o){var n=s.call(t,{dispatch:a.dispatch,commit:a.commit,getters:a.getters,state:a.state,rootGetters:t.getters,rootState:t.state},o);return Qt(n)||(n=Promise.resolve(n)),t._devtoolHook?n.catch(function(i){throw t._devtoolHook.emit("vuex:error",i),i}):n})}function qt(t,e,s,a){t._wrappedGetters[e]||(t._wrappedGetters[e]=function(r){return s(a.state,a.getters,r.state,r.getters)})}function Xt(t){K(function(){return t._state.data},function(){},{deep:!0,flush:"sync"})}function $(t,e){return e.reduce(function(s,a){return s[a]},t)}function C(t,e,s){return st(t)&&t.type&&(s=e,e=t,t=t.type),{type:t,payload:e,options:s}}var Kt="vuex bindings",W="vuex:mutations",x="vuex:actions",w="vuex",Yt=0;function Zt(t,e){Vt({id:"org.vuejs.vuex",app:t,label:"Vuex",homepage:"https://next.vuex.vuejs.org/",logo:"https://vuejs.org/images/icons/favicon-96x96.png",packageName:"vuex",componentStateTypes:[Kt]},function(s){s.addTimelineLayer({id:W,label:"Vuex Mutations",color:z}),s.addTimelineLayer({id:x,label:"Vuex Actions",color:z}),s.addInspector({id:w,label:"Vuex",icon:"storage",treeFilterPlaceholder:"Filter stores..."}),s.on.getInspectorTree(function(a){if(a.app===t&&a.inspectorId===w)if(a.filter){var r=[];it(r,e._modules.root,a.filter,""),a.rootNodes=r}else a.rootNodes=[ot(e._modules.root,"")]}),s.on.getInspectorState(function(a){if(a.app===t&&a.inspectorId===w){var r=a.nodeId;at(e,r),a.state=se(ne(e._modules,r),r==="root"?e.getters:e._makeLocalGettersCache,r)}}),s.on.editInspectorState(function(a){if(a.app===t&&a.inspectorId===w){var r=a.nodeId,o=a.path;r!=="root"&&(o=r.split("/").filter(Boolean).concat(o)),e._withCommit(function(){a.set(e._state.data,o,a.state.value)})}}),e.subscribe(function(a,r){var o={};a.payload&&(o.payload=a.payload),o.state=r,s.notifyComponentUpdate(),s.sendInspectorTree(w),s.sendInspectorState(w),s.addTimelineEvent({layerId:W,event:{time:Date.now(),title:a.type,data:o}})}),e.subscribeAction({before:function(a,r){var o={};a.payload&&(o.payload=a.payload),a._id=Yt++,a._time=Date.now(),o.state=r,s.addTimelineEvent({layerId:x,event:{time:a._time,title:a.type,groupId:a._id,subtitle:"start",data:o}})},after:function(a,r){var o={},n=Date.now()-a._time;o.duration={_custom:{type:"duration",display:n+"ms",tooltip:"Action duration",value:n}},a.payload&&(o.payload=a.payload),o.state=r,s.addTimelineEvent({layerId:x,event:{time:Date.now(),title:a.type,groupId:a._id,subtitle:"end",data:o}})}})})}var z=8702998,te=6710886,ee=16777215,nt={label:"namespaced",textColor:ee,backgroundColor:te};function rt(t){return t&&t!=="root"?t.split("/").slice(-2,-1)[0]:"Root"}function ot(t,e){return{id:e||"root",label:rt(e),tags:t.namespaced?[nt]:[],children:Object.keys(t._children).map(function(s){return ot(t._children[s],e+s+"/")})}}function it(t,e,s,a){a.includes(s)&&t.push({id:a||"root",label:a.endsWith("/")?a.slice(0,a.length-1):a||"Root",tags:e.namespaced?[nt]:[]}),Object.keys(e._children).forEach(function(r){it(t,e._children[r],s,a+r+"/")})}function se(t,e,s){e=s==="root"?e:e[s];var a=Object.keys(e),r={state:Object.keys(t.state).map(function(n){return{key:n,editable:!0,value:t.state[n]}})};if(a.length){var o=ae(e);r.getters=Object.keys(o).map(function(n){return{key:n.endsWith("/")?rt(n):n,editable:!1,value:F(function(){return o[n]})}})}return r}function ae(t){var e={};return Object.keys(t).forEach(function(s){var a=s.split("/");if(a.length>1){var r=e,o=a.pop();a.forEach(function(n){r[n]||(r[n]={_custom:{value:{},display:n,tooltip:"Module",abstract:!0}}),r=r[n]._custom.value}),r[o]=F(function(){return t[s]})}else e[s]=F(function(){return t[s]})}),e}function ne(t,e){var s=e.split("/").filter(function(a){return a});return s.reduce(function(a,r,o){var n=a[r];if(!n)throw new Error('Missing module "'+r+'" for path "'+e+'".');return o===s.length-1?n:n._children},e==="root"?t:t.root._children)}function F(t){try{return t()}catch(e){return e}}var m=function(t,e){this.runtime=e,this._children=Object.create(null),this._rawModule=t;var s=t.state;this.state=(typeof s=="function"?s():s)||{}},J={namespaced:{configurable:!0}};J.namespaced.get=function(){return!!this._rawModule.namespaced},m.prototype.addChild=function(t,e){this._children[t]=e},m.prototype.removeChild=function(t){delete this._children[t]},m.prototype.getChild=function(t){return this._children[t]},m.prototype.hasChild=function(t){return t in this._children},m.prototype.update=function(t){this._rawModule.namespaced=t.namespaced,t.actions&&(this._rawModule.actions=t.actions),t.mutations&&(this._rawModule.mutations=t.mutations),t.getters&&(this._rawModule.getters=t.getters)},m.prototype.forEachChild=function(t){S(this._children,t)},m.prototype.forEachGetter=function(t){this._rawModule.getters&&S(this._rawModule.getters,t)},m.prototype.forEachAction=function(t){this._rawModule.actions&&S(this._rawModule.actions,t)},m.prototype.forEachMutation=function(t){this._rawModule.mutations&&S(this._rawModule.mutations,t)},Object.defineProperties(m.prototype,J);var v=function(t){this.register([],t,!1)};v.prototype.get=function(t){return t.reduce(function(e,s){return e.getChild(s)},this.root)},v.prototype.getNamespace=function(t){var e=this.root;return t.reduce(function(s,a){return e=e.getChild(a),s+(e.namespaced?a+"/":"")},"")},v.prototype.update=function(t){ut([],this.root,t)},v.prototype.register=function(t,e,s){var a=this;s===void 0&&(s=!0);var r=new m(e,s);if(t.length===0)this.root=r;else{var o=this.get(t.slice(0,-1));o.addChild(t[t.length-1],r)}e.modules&&S(e.modules,function(n,i){a.register(t.concat(i),n,s)})},v.prototype.unregister=function(t){var e=this.get(t.slice(0,-1)),s=t[t.length-1],a=e.getChild(s);a&&a.runtime&&e.removeChild(s)},v.prototype.isRegistered=function(t){var e=this.get(t.slice(0,-1)),s=t[t.length-1];return e?e.hasChild(s):!1};function ut(t,e,s){if(e.update(s),s.modules)for(var a in s.modules){if(!e.getChild(a))return;ut(t.concat(a),e.getChild(a),s.modules[a])}}function re(t){return new f(t)}var f=function(t){var e=this;t===void 0&&(t={});var s=t.plugins;s===void 0&&(s=[]);var a=t.strict;a===void 0&&(a=!1);var r=t.devtools;this._committing=!1,this._actions=Object.create(null),this._actionSubscribers=[],this._mutations=Object.create(null),this._wrappedGetters=Object.create(null),this._modules=new v(t),this._modulesNamespaceMap=Object.create(null),this._subscribers=[],this._makeLocalGettersCache=Object.create(null),this._scope=null,this._devtools=r;var o=this,n=this,i=n.dispatch,l=n.commit;this.dispatch=function(c,d){return i.call(o,c,d)},this.commit=function(c,d,p){return l.call(o,c,d,p)},this.strict=a;var u=this._modules.root.state;j(this,u,[],this._modules.root),N(this,u),s.forEach(function(c){return c(e)})},U={state:{configurable:!0}};f.prototype.install=function(t,e){t.provide(e||Ht,this),t.config.globalProperties.$store=this;var s=this._devtools!==void 0?this._devtools:!1;s&&Zt(t,this)},U.state.get=function(){return this._state.data},U.state.set=function(t){},f.prototype.commit=function(t,e,s){var a=this,r=C(t,e,s),o=r.type,n=r.payload,i={type:o,payload:n},l=this._mutations[o];l&&(this._withCommit(function(){l.forEach(function(u){u(n)})}),this._subscribers.slice().forEach(function(u){return u(i,a.state)}))},f.prototype.dispatch=function(t,e){var s=this,a=C(t,e),r=a.type,o=a.payload,n={type:r,payload:o},i=this._actions[r];if(i){try{this._actionSubscribers.slice().filter(function(u){return u.before}).forEach(function(u){return u.before(n,s.state)})}catch{}var l=i.length>1?Promise.all(i.map(function(u){return u(o)})):i[0](o);return new Promise(function(u,c){l.then(function(d){try{s._actionSubscribers.filter(function(p){return p.after}).forEach(function(p){return p.after(n,s.state)})}catch{}u(d)},function(d){try{s._actionSubscribers.filter(function(p){return p.error}).forEach(function(p){return p.error(n,s.state,d)})}catch{}c(d)})})}},f.prototype.subscribe=function(t,e){return Q(t,this._subscribers,e)},f.prototype.subscribeAction=function(t,e){var s=typeof t=="function"?{before:t}:t;return Q(s,this._actionSubscribers,e)},f.prototype.watch=function(t,e,s){var a=this;return K(function(){return t(a.state,a.getters)},e,Object.assign({},s))},f.prototype.replaceState=function(t){var e=this;this._withCommit(function(){e._state.data=t})},f.prototype.registerModule=function(t,e,s){s===void 0&&(s={}),typeof t=="string"&&(t=[t]),this._modules.register(t,e),j(this,this.state,t,this._modules.get(t),s.preserveState),N(this,this.state)},f.prototype.unregisterModule=function(t){var e=this;typeof t=="string"&&(t=[t]),this._modules.unregister(t),this._withCommit(function(){var s=$(e.state,t.slice(0,-1));delete s[t[t.length-1]]}),R(this)},f.prototype.hasModule=function(t){return typeof t=="string"&&(t=[t]),this._modules.isRegistered(t)},f.prototype.hotUpdate=function(t){this._modules.update(t),R(this,!0)},f.prototype._withCommit=function(t){var e=this._committing;this._committing=!0,t(),this._committing=e},Object.defineProperties(f.prototype,U);var oe=lt(function(t,e){var s={};return ct(e).forEach(function(a){var r=a.key,o=a.val;s[r]=function(){var n=this.$store.state,i=this.$store.getters;if(t){var l=dt(this.$store,"mapState",t);if(!l)return;n=l.context.state,i=l.context.getters}return typeof o=="function"?o.call(this,n,i):n[o]},s[r].vuex=!0}),s}),We=lt(function(t,e){var s={};return ct(e).forEach(function(a){var r=a.key,o=a.val;o=t+o,s[r]=function(){if(!(t&&!dt(this.$store,"mapGetters",t)))return this.$store.getters[o]},s[r].vuex=!0}),s});function ct(t){return ie(t)?Array.isArray(t)?t.map(function(e){return{key:e,val:e}}):Object.keys(t).map(function(e){return{key:e,val:t[e]}}):[]}function ie(t){return Array.isArray(t)||st(t)}function lt(t){return function(e,s){return typeof e!="string"?(s=e,e=""):e.charAt(e.length-1)!=="/"&&(e+="/"),t(e,s)}}function dt(t,e,s){var a=t._modulesNamespaceMap[s];return a}const ue={computed:{...oe({statusType:t=>t.userStatus.status,statusIsUserDefined:t=>t.userStatus.statusIsUserDefined,customIcon:t=>t.userStatus.icon,customMessage:t=>t.userStatus.message}),visibleMessage(){if(this.customIcon&&this.customMessage)return`${this.customIcon} ${this.customMessage}`;if(this.customMessage)return this.customMessage;if(this.statusIsUserDefined)switch(this.statusType){case"online":return h("user_status","Online");case"away":return h("user_status","Away");case"busy":return h("user_status","Busy");case"dnd":return h("user_status","Do not disturb");case"invisible":return h("user_status","Invisible");case"offline":return h("user_status","Offline")}return h("user_status","Set status")}},methods:{async changeStatus(t){try{await this.$store.dispatch("setStatus",{statusType:t})}catch(e){jt(h("user_status","There was an error saving the new status")),et.debug(e)}}}};async function ce(t){const e=g("apps/user_status/api/v1/heartbeat?format=json");return(await y.put(e,{status:t?"away":"online"})).data.ocs.data}const le="_userStatusMenuItem_1rva6_1",de="_userStatusIcon_1rva6_6",pe={userStatusMenuItem:le,userStatusIcon:de},fe={name:"UserStatus",components:{NcButton:kt,NcListItem:Ct,NcUserStatusIcon:Tt,SetStatusModal:vt(()=>xt(()=>import("./SetStatusModal-DFKMBQe-.chunk.mjs"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10]),import.meta.url))},mixins:[ue],props:{inline:{type:Boolean,default:!1}},data(){return{heartbeatInterval:null,isAway:!1,isModalOpen:!1,mouseMoveListener:null,setAwayTimeout:null}},mounted(){this.$store.dispatch("loadStatusFromInitialState"),OC.config.session_keepalive&&(this.heartbeatInterval=setInterval(this._backgroundHeartbeat.bind(this),1e3*60*5),this.setAwayTimeout=()=>{this.isAway=!0},this.mouseMoveListener=Et(()=>{const t=this.isAway;this.isAway=!1,clearTimeout(this.setAwayTimeout),setTimeout(this.setAwayTimeout,1e3*60*2),t&&this._backgroundHeartbeat()},1e3*2,{immediate:!0}),window.addEventListener("mousemove",this.mouseMoveListener,{capture:!0,passive:!0}),this._backgroundHeartbeat()),Y("user_status:status.updated",this.handleUserStatusUpdated)},beforeUnmount(){window.removeEventListener("mouseMove",this.mouseMoveListener),clearInterval(this.heartbeatInterval),Mt("user_status:status.updated",this.handleUserStatusUpdated)},methods:{openModal(){this.isModalOpen=!0},closeModal(){this.isModalOpen=!1},async _backgroundHeartbeat(){try{const t=await ce(this.isAway);t?.userId?this.$store.dispatch("setStatusFromHeartbeat",t):await this.$store.dispatch("reFetchStatusFromServer")}catch(t){et.debug("Failed sending heartbeat, got: "+t.response?.status)}},handleUserStatusUpdated(t){b()?.uid===t.userId&&this.$store.dispatch("setStatusFromObject",{status:t.status,icon:t.icon,message:t.message})}}},me={key:1};function he(t,e,s,a,r,o){const n=k("NcUserStatusIcon"),i=k("NcListItem"),l=k("NcButton"),u=k("SetStatusModal");return E(),G(It,null,[s.inline?(E(),G("div",me,[P(l,{onClick:V(o.openModal,["stop"])},{icon:T(()=>[P(n,{class:L(t.$style.userStatusIcon),status:t.statusType,"aria-hidden":"true"},null,8,["class","status"])]),default:T(()=>[wt(" "+St(t.visibleMessage),1)]),_:1},8,["onClick"])])):(E(),B(i,{key:0,class:L(t.$style.userStatusMenuItem),compact:"",name:t.visibleMessage,onClick:V(o.openModal,["stop"])},{icon:T(()=>[P(n,{class:L(t.$style.userStatusIcon),status:t.statusType,"aria-hidden":"true"},null,8,["class","status"])]),_:1},8,["class","name","onClick"])),r.isModalOpen?(E(),B(u,{key:2,inline:s.inline,onClose:o.closeModal},null,8,["inline","onClose"])):bt("",!0)],64)}const ge={$style:pe},pt=_t(fe,[["render",he],["__cssModules",ge]]);async function ye(){const t=g("apps/user_status/api/v1/predefined_statuses?format=json");return(await y.get(t)).data.ocs.data}const _e=()=>({predefinedStatuses:[]}),ve={addPredefinedStatus(t,e){t.predefinedStatuses=[...t.predefinedStatuses,e]}},be={statusesHaveLoaded(t){return t.predefinedStatuses.length>0}},we={async loadAllPredefinedStatuses({state:t,commit:e}){if(t.predefinedStatuses.length>0)return;const s=await ye();for(const a of s)e("addPredefinedStatus",a)}},Se={state:_e,mutations:ve,getters:be,actions:we};async function Ie(){const t=g("apps/user_status/api/v1/user_status");return(await y.get(t)).data.ocs.data}async function Me(t){const e=g("apps/user_status/api/v1/statuses/{userId}",{userId:"_"+t});return(await y.get(e)).data.ocs.data}async function Oe(t){const e=g("apps/user_status/api/v1/user_status/status");await y.put(e,{statusType:t})}async function Ae(t,e=null){const s=g("apps/user_status/api/v1/user_status/message/predefined?format=json");await y.put(s,{messageId:t,clearAt:e})}async function ke(t,e=null,s=null){const a=g("apps/user_status/api/v1/user_status/message/custom?format=json");await y.put(a,{message:t,statusIcon:e,clearAt:s})}async function Ee(){const t=g("apps/user_status/api/v1/user_status/message?format=json");await y.delete(t)}async function Ce(t){const e=g("apps/user_status/api/v1/user_status/revert/{messageId}",{messageId:t});return(await y.delete(e)).data.ocs.data}const je=()=>({status:null,statusIsUserDefined:null,message:null,icon:null,clearAt:null,messageIsPredefined:null,messageId:null}),Te={loadBackupStatusFromServer(t,{status:e,statusIsUserDefined:s,message:a,icon:r,clearAt:o,messageIsPredefined:n,messageId:i}){t.status=e,t.message=a,t.icon=r,typeof s<"u"&&(t.statusIsUserDefined=s),typeof o<"u"&&(t.clearAt=o),typeof n<"u"&&(t.messageIsPredefined=n),typeof i<"u"&&(t.messageId=i)}},Pe={},Le={async fetchBackupFromServer({commit:t}){try{const e=await Me(b()?.uid);t("loadBackupStatusFromServer",e)}catch{}},async revertBackupFromServer({commit:t},{messageId:e}){const s=await Ce(e);s&&(t("loadBackupStatusFromServer",{}),t("loadStatusFromServer",s),M("user_status:status.updated",{status:s.status,message:s.message,icon:s.icon,clearAt:s.clearAt,userId:b()?.uid}))}},xe={state:je,mutations:Te,getters:Pe,actions:Le};function ft(){return new Date}function q(t){if(t===null)return null;const e=ft();if(t.type==="period")return e.setSeconds(e.getSeconds()+t.time),Math.floor(e.getTime()/1e3);if(t.type==="end-of")switch(t.time){case"day":case"week":return Number(O(e).endOf(t.time).format("X"))}return t.type==="_time"?t.time:null}function ze(t){if(t===null)return h("user_status","Don't clear");if(t.type==="end-of")switch(t.time){case"day":return h("user_status","Today");case"week":return h("user_status","This week");default:return null}if(t.type==="period")return O.duration(t.time*1e3).humanize();if(t.type==="_time"){const e=O(ft()),s=O(t.time,"X");return O.duration(e.diff(s)).humanize()}return null}const Ue=()=>({status:null,statusIsUserDefined:null,message:null,icon:null,clearAt:null,messageIsPredefined:null,messageId:null}),De={setStatus(t,{statusType:e}){t.status=e,t.statusIsUserDefined=!0},setPredefinedMessage(t,{messageId:e,clearAt:s,message:a,icon:r}){t.messageId=e,t.messageIsPredefined=!0,t.message=a,t.icon=r,t.clearAt=s},setCustomMessage(t,{message:e,icon:s,clearAt:a}){t.messageId=null,t.messageIsPredefined=!1,t.message=e,t.icon=s,t.clearAt=a},clearMessage(t){t.messageId=null,t.messageIsPredefined=!1,t.message=null,t.icon=null,t.clearAt=null},loadStatusFromServer(t,{status:e,statusIsUserDefined:s,message:a,icon:r,clearAt:o,messageIsPredefined:n,messageId:i}){t.status=e,t.message=a,t.icon=r,typeof s<"u"&&(t.statusIsUserDefined=s),typeof o<"u"&&(t.clearAt=o),typeof n<"u"&&(t.messageIsPredefined=n),typeof i<"u"&&(t.messageId=i)}},Fe={},Ne={async setStatus({commit:t,state:e},{statusType:s}){await Oe(s),t("setStatus",{statusType:s}),M("user_status:status.updated",{status:e.status,message:e.message,icon:e.icon,clearAt:e.clearAt,userId:b()?.uid})},async setStatusFromObject({commit:t},e){t("loadStatusFromServer",e)},async setPredefinedMessage({commit:t,rootState:e,state:s},{messageId:a,clearAt:r}){const o=q(r);await Ae(a,o);const n=e.predefinedStatuses.predefinedStatuses.find(u=>u.id===a),{message:i,icon:l}=n;t("setPredefinedMessage",{messageId:a,clearAt:o,message:i,icon:l}),M("user_status:status.updated",{status:s.status,message:s.message,icon:s.icon,clearAt:s.clearAt,userId:b()?.uid})},async setCustomMessage({commit:t,state:e},{message:s,icon:a,clearAt:r}){const o=q(r);await ke(s,a,o),t("setCustomMessage",{message:s,icon:a,clearAt:o}),M("user_status:status.updated",{status:e.status,message:e.message,icon:e.icon,clearAt:e.clearAt,userId:b()?.uid})},async clearMessage({commit:t,state:e}){await Ee(),t("clearMessage"),M("user_status:status.updated",{status:e.status,message:e.message,icon:e.icon,clearAt:e.clearAt,userId:b()?.uid})},async reFetchStatusFromServer({commit:t}){const e=await Ie();t("loadStatusFromServer",e)},async setStatusFromHeartbeat({commit:t},e){t("loadStatusFromServer",e)},loadStatusFromInitialState({commit:t}){const e=Ot("user_status","status");t("loadStatusFromServer",e)}},$e={state:Ue,mutations:De,getters:Fe,actions:Ne},mt=re({modules:{predefinedStatuses:Se,userStatus:$e,userBackupStatus:xe},strict:!0}),Ge=document.getElementById("user_status-menu-entry");function X(){const t=document.getElementById("user_status-menu-entry"),e=document.createElement("div");e.style.display="contents",t.replaceWith(e),Z(pt).use(mt).mount(e)}Ge?X():Y("core:user-menu:mounted",X),document.addEventListener("DOMContentLoaded",function(){OCA.Dashboard&&OCA.Dashboard.registerStatus("status",t=>{Z(pt,{inline:!0}).use(mt).mount(t)})});export{ue as O,oe as a,ze as c,et as l,We as m};
//# sourceMappingURL=user_status-menu.mjs.map