Râu Cao 929188bc2b
All checks were successful
continuous-integration/drone/push Build is passing
2.1.1
2022-08-12 16:08:34 +01:00

3 lines
25 KiB
JavaScript

/*! For license information please see build.js.LICENSE.txt */
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("ChatMessages",[],e):"object"==typeof exports?exports.ChatMessages=e():t.ChatMessages=e()}(this,(()=>(()=>{var t={666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,a=Object.create(o.prototype),i=new P(n||[]);return a._invoke=function(t,e,r){var n=l;return function(o,a){if(n===p)throw new Error("Generator is already running");if(n===y){if("throw"===o)throw a;return M()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=k(i,r);if(c){if(c===d)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===l)throw n=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=p;var s=h(t,e,r);if("normal"===s.type){if(n=r.done?y:f,s.arg===d)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n=y,r.method="throw",r.arg=s.arg)}}}(t,r,i),a}function h(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=u;var l="suspendedStart",f="suspendedYield",p="executing",y="completed",d={};function v(){}function g(){}function m(){}var b={};s(b,a,(function(){return this}));var w=Object.getPrototypeOf,x=w&&w(w(N([])));x&&x!==r&&n.call(x,a)&&(b=x);var j=m.prototype=v.prototype=Object.create(b);function L(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function _(t,e){function r(o,a,i,c){var s=h(t[o],t,a);if("throw"!==s.type){var u=s.arg,l=u.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,i,c)}),(function(t){r("throw",t,i,c)})):e.resolve(l).then((function(t){u.value=t,i(u)}),(function(t){return r("throw",t,i,c)}))}c(s.arg)}var o;this._invoke=function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}}function k(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator.return&&(r.method="return",r.arg=e,k(t,r),"throw"===r.method))return d;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return d}var o=h(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,d;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,d):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,d)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function O(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function N(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:M}}function M(){return{value:e,done:!0}}return g.prototype=m,s(j,"constructor",m),s(m,"constructor",g),g.displayName=s(m,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===g||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,s(t,c,"GeneratorFunction")),t.prototype=Object.create(j),t},t.awrap=function(t){return{__await:t}},L(_.prototype),s(_.prototype,i,(function(){return this})),t.AsyncIterator=_,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new _(u(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},L(j),s(j,c,"Generator"),s(j,a,(function(){return this})),s(j,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=N,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(O),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var s=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(s&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,d):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),d},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),O(r),d}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;O(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:N(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),d}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var a=e[n]={exports:{}};return t[n](a,a.exports,r),a.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e);var n={};return(()=>{"use strict";function t(t){return function(t){if(Array.isArray(t))return e(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||function(t,r){if(t){if("string"==typeof t)return e(t,r);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?e(t,r):void 0}}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function e(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(){o=function(){return t};var t={},e=Object.prototype,r=e.hasOwnProperty,n="function"==typeof Symbol?Symbol:{},a=n.iterator||"@@iterator",i=n.asyncIterator||"@@asyncIterator",s=n.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(t){u=function(t,e,r){return t[e]=r}}function h(t,e,r,n){var o=e&&e.prototype instanceof p?e:p,a=Object.create(o.prototype),i=new k(n||[]);return a._invoke=function(t,e,r){var n="suspendedStart";return function(o,a){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw a;return{value:void 0,done:!0}}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=j(i,r);if(c){if(c===f)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var s=l(t,e,r);if("normal"===s.type){if(n=r.done?"completed":"suspendedYield",s.arg===f)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(n="completed",r.method="throw",r.arg=s.arg)}}}(t,r,i),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}t.wrap=h;var f={};function p(){}function y(){}function d(){}var v={};u(v,a,(function(){return this}));var g=Object.getPrototypeOf,m=g&&g(g(E([])));m&&m!==e&&r.call(m,a)&&(v=m);var b=d.prototype=p.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function n(o,a,i,s){var u=l(t[o],t,a);if("throw"!==u.type){var h=u.arg,f=h.value;return f&&"object"==c(f)&&r.call(f,"__await")?e.resolve(f.__await).then((function(t){n("next",t,i,s)}),(function(t){n("throw",t,i,s)})):e.resolve(f).then((function(t){h.value=t,i(h)}),(function(t){return n("throw",t,i,s)}))}s(u.arg)}var o;this._invoke=function(t,r){function a(){return new e((function(e,o){n(t,r,e,o)}))}return o=o?o.then(a,a):a()}}function j(t,e){var r=t.iterator[e.method];if(void 0===r){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,j(t,e),"throw"===e.method))return f;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}var n=l(r,t.iterator,e.arg);if("throw"===n.type)return e.method="throw",e.arg=n.arg,e.delegate=null,f;var o=n.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,f):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,f)}function L(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function E(t){if(t){var e=t[a];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var n=-1,o=function e(){for(;++n<t.length;)if(r.call(t,n))return e.value=t[n],e.done=!1,e;return e.value=void 0,e.done=!0,e};return o.next=o}}return{next:O}}function O(){return{value:void 0,done:!0}}return y.prototype=d,u(b,"constructor",d),u(d,"constructor",y),y.displayName=u(d,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,d):(t.__proto__=d,u(t,s,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},w(x.prototype),u(x.prototype,i,(function(){return this})),t.AsyncIterator=x,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new x(h(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(b),u(b,s,"Generator"),u(b,a,(function(){return this})),u(b,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function r(){for(;e.length;){var n=e.pop();if(n in t)return r.value=n,r.done=!1,r}return r.done=!0,r}},t.values=E,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&r.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function n(r,n){return i.type="throw",i.arg=t,e.next=r,n&&(e.method="next",e.arg=void 0),!!n}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],i=a.completion;if("root"===a.tryLoc)return n("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return n(a.catchLoc,!0);if(this.prev<a.finallyLoc)return n(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return n(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return n(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,f):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),f},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),_(r),f}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;_(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:E(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},t}function a(t,e,r,n,o,a,i){try{var c=t[a](i),s=c.value}catch(t){return void r(t)}c.done?e(s):Promise.resolve(s).then(n,o)}function i(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function c(t){a(i,n,o,c,s,"next",t)}function s(t){a(i,n,o,c,s,"throw",t)}c(void 0)}))}}function c(t){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},c(t)}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function u(t){return 1===(t=String(t)).length&&(t="0"+t),t}function h(t){return Object.keys(t).map((function(t){return parseInt(t)})).filter((function(t){return!Number.isNaN(t)})).sort()[0]}r.d(n,{default:()=>l}),r(666);const l={name:"chat-messages",builder:function(e,r){var n={type:"object",properties:{"@context":{type:"string",default:"https://kosmos.org/ns/v2/chat-channel"},"@id":{type:"string",required:!0},"@type":{type:"string",default:"ChatChannel",enum:["ChatChannel"]},service:{type:"object",properties:{domain:{type:"string",required:!0},protocol:{type:"string",required:!0}}},name:{type:"string",required:!0},type:{type:"string",required:!0,enum:["room","person"]},today:{type:"object",properties:{"@id":{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$",required:!0},"@type":{type:"string",default:"ChatLog",pattern:"^ChatLog$"},messageType:{type:"string",default:"InstantMessage",pattern:"^InstantMessage$"},previous:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},next:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},messages:{type:"array",required:!0,items:{type:"object",properties:{date:{type:"string",format:"date-time"},user:{type:"string"},text:{type:"string"},type:"string",default:"text",enum:["text","join","leave","action"]}}}}}},required:[]};e.declareType("daily-archive","https://kosmos.org/ns/v2/chat-channel",n),r.declareType("daily-archive","https://kosmos.org/ns/v2/chat-channel",n);var a={type:"object",properties:{"@context":{type:"string",default:"https://kosmos.org/ns/v2/chat-channel-meta"},"@id":{type:"string"},"@type":{type:"string",default:"ChatChannelMeta",enum:["ChatChannelMeta"]},first:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"},last:{type:"string",pattern:"^[0-9]{4}/[0-9]{2}/[0-9]{2}$"}},required:["@id","first","last"]};e.declareType("daily-archive-meta","https://kosmos.org/ns/v2/chat-channel-meta",a),r.declareType("daily-archive-meta","https://kosmos.org/ns/v2/chat-channel-meta",a);var l=function(){function n(t){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,n),t.isPublic=t.isPublic||!1,t.channelType=t.channelType||"room","object"!==c(t))throw"options must be an object";if("object"!==c(t.service)||"string"!=typeof t.service.protocol||"string"!=typeof t.service.domain)throw'service must be an object containing at least service "protocol" and "domain"';if("string"!=typeof t.channelName)throw"channelName must be a string";if(!(t.date instanceof Date))throw"date must be a date object";if("boolean"!=typeof t.isPublic)throw"isPublic must be a boolean value";var o;if(this.service=t.service,this.channelName=t.channelName,this.channelType=t.channelType,this.date=t.date,this.isPublic=t.isPublic||!1,this.parsedDate={year:(o=this.date).getUTCFullYear(),month:u(o.getUTCMonth()+1),day:u(o.getUTCDate())},this.dateId=this.parsedDate.year+"/"+this.parsedDate.month+"/"+this.parsedDate.day,"room"===this.channelType){var a=this.channelName.replace(/^#/,"");this.channelPath="".concat(this.service.domain,"/channels/").concat(a)}else this.channelPath="".concat(this.service.domain,"/users/").concat(this.channelName);this.path="".concat(this.channelPath,"/").concat(this.dateId),this.metaPath="".concat(this.channelPath,"/meta"),this.client=this.isPublic?r:e,this.previous=t.previous,this.next=t.next}var a,l,f,p,y,d,v,g;return a=n,l=[{key:"addMessage",value:function(t){var e=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(t.type=t.type||"text",this.client.getObject(this.path).then((function(r){return"object"===c(r)?e._updateDocument(r,t):e._createDocument(t)})))}},{key:"addMessages",value:function(t,e){var r=this;return this.isPublic&&!this.channelName.match(/^#/)?Promise.resolve(!1):(e=e||!1,t.forEach((function(t){t.type=t.type||"text"})),e?this._createDocument(t):this.client.getObject(this.path).then((function(e){return"object"===c(e)?r._updateDocument(e,t):r._createDocument(t)})))}},{key:"remove",value:function(){return this.client.remove(this.path)}},{key:"_updateDocument",value:(g=i(o().mark((function t(e,r){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return console.debug("[chat-messages] Updating archive document"),Array.isArray(r)?r.forEach((function(t){e.today.messages.push(t)})):e.today.messages.push(r),t.abrupt("return",this._sync(e));case 3:case"end":return t.stop()}}),t,this)}))),function(t,e){return g.apply(this,arguments)})},{key:"_createDocument",value:(v=i(o().mark((function t(e){var r,n;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(console.debug("[chat-messages] Creating new archive document"),r=this._buildArchiveObject(),Array.isArray(e)?e.forEach((function(t){r.today.messages.push(t)})):r.today.messages.push(e),!this.previous&&!this.next){t.next=8;break}this.previous&&(r.today.previous=this.previous),this.next&&(r.today.next=this.next),t.next=12;break;case 8:return t.next=10,this._updatePreviousArchive();case 10:"object"===c(n=t.sent)&&(r.today.previous=n.today["@id"]);case 12:return t.next=14,this._sync(r);case 14:return t.next=16,this._updateArchiveMetaDocument();case 16:return t.abrupt("return");case 17:case"end":return t.stop()}}),t,this)}))),function(t){return v.apply(this,arguments)})},{key:"_buildArchiveObject",value:function(){var t=this.channelName.replace(/^#/,""),e={"@id":"chat-messages/"+this.service.domain+"/channels/"+t+"/","@type":"ChatChannel",service:this.service,name:this.channelName,type:this.channelType,today:{"@id":this.dateId,"@type":"ChatLog",messageType:"InstantMessage",messages:[]}};return"IRC"===this.service.protocol&&(this.channelName.match(/^#/)||(e["@id"]="chat-messages/"+this.service.domain+"/users/"+this.channelName+"/")),e}},{key:"_updatePreviousArchive",value:function(){var t=this;return this._findPreviousArchive().then((function(e){if("object"===c(e)&&e.today){e.today.next=t.dateId;var r=t.path.substring(0,t.path.length-t.dateId.length)+e.today["@id"];return t.client.storeObject("daily-archive",r,e).then((function(){return console.debug("[chat-messages] Previous archive written to remote storage at",r),e}))}return console.debug("[chat-messages] Previous archive not found"),!1}))}},{key:"_findPreviousArchive",value:function(){var e=this,r=this.path.substring(0,this.path.length-2),n=this.path.substring(0,this.path.length-5),o=this.path.substring(0,this.path.length-10);return this.client.getListing(r).then((function(a){var i=Object.keys(a).map((function(t){return parseInt(t)})).map((function(t){return t<parseInt(e.parsedDate.day)?t:null})).filter((function(t){return null!=t}));if(i.length>0){var c=u(Math.max.apply(Math,t(i)).toString());return e.client.getObject(r+c)}return e.client.getListing(n).then((function(r){var a=Object.keys(r).map((function(t){return parseInt(t.substr(0,2))})).map((function(t){return t<parseInt(e.parsedDate.month)?t:null})).filter((function(t){return null!=t}));if(a.length>0){var i=u(Math.max.apply(Math,t(a)).toString());return e.client.getListing(n+i+"/").then((function(r){var o=Object.keys(r).map((function(t){return parseInt(t)})),a=u(Math.max.apply(Math,t(o)).toString());return e.client.getObject(n+i+"/"+a)}))}return e.client.getListing(o).then((function(r){var n=Object.keys(r).map((function(t){return parseInt(t.substr(0,4))})).map((function(t){return t<parseInt(e.parsedDate.year)?t:null})).filter((function(t){return null!=t}));if(n.length>0){var a=Math.max.apply(Math,t(n)).toString();return e.client.getListing(o+a+"/").then((function(r){var n=Object.keys(r).map((function(t){return parseInt(t.substr(0,2))})),i=u(Math.max.apply(Math,t(n)).toString());return e.client.getListing(o+a+"/"+i+"/").then((function(r){var n=Object.keys(r).map((function(t){return parseInt(t)})),c=u(Math.max.apply(Math,t(n)).toString());return e.client.getObject(o+a+"/"+i+"/"+c)}))}))}return!1}))}))}))}},{key:"_updateArchiveMetaDocument",value:(d=i(o().mark((function t(){var e;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.client.getObject(this.metaPath);case 2:if("object"===c(e=t.sent)){t.next=5;break}return t.abrupt("return",this._createArchiveMetaDocument());case 5:if(!(Date.parse(e.last.replace(/\//g,"-"))<Date.parse(this.date))){t.next=10;break}return console.debug("[chat-messages]","Updating meta document for channel"),e.last=this.dateId,t.next=10,this.client.storeObject("daily-archive-meta",this.metaPath,e);case 10:return t.abrupt("return");case 11:case"end":return t.stop()}}),t,this)}))),function(){return d.apply(this,arguments)})},{key:"_createArchiveMetaDocument",value:(y=i(o().mark((function t(){var e,r,n,a=this;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return console.debug("[chat-messages]","Creating new meta document for channel"),t.next=3,this._findFirstArchive();case 3:return e=t.sent,r=this.channelName.replace(/^#/,""),n={"@id":"chat-messages/".concat(this.service.domain,"/channels/").concat(r,"/meta"),"@type":"ChatChannelMeta",first:e,last:this.dateId},t.abrupt("return",this.client.storeObject("daily-archive-meta",this.metaPath,n).then((function(){return console.debug("[chat-messages]","Meta document written to remote storage")})).catch((function(t){console.log("[chat-messages]","Failed to store ".concat(a.metaPath)),console.error(t)})));case 7:case"end":return t.stop()}}),t,this)}))),function(){return y.apply(this,arguments)})},{key:"_findFirstArchive",value:(p=i(o().mark((function t(){var e,r,n,a,i,c,s;return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return console.debug("[chat-messages]","Finding first archive for channel"),t.next=3,this.client.getListing("".concat(this.channelPath,"/"));case 3:return e=t.sent,r=h(e),t.next=7,this.client.getListing("".concat(this.channelPath,"/").concat(r,"/"));case 7:return n=t.sent,a=h(n),t.next=11,this.client.getListing("".concat(this.channelPath,"/").concat(r,"/").concat(u(a),"/"));case 11:return i=t.sent,c=h(i),s="".concat(r,"/").concat(u(a),"/").concat(u(c)),console.debug("[chat-messages]","First is",s),t.abrupt("return",s);case 16:case"end":return t.stop()}}),t,this)}))),function(){return p.apply(this,arguments)})},{key:"_sync",value:(f=i(o().mark((function t(e){return o().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return console.debug("[chat-messages] Writing archive object with ".concat(e.today.messages.length," messages")),t.abrupt("return",this.client.storeObject("daily-archive",this.path,e).then((function(){return console.debug("[chat-messages] Archive written to remote storage"),!0}),(function(t){return console.warn("[chat-messages] Error trying to store object",t),t})));case 2:case"end":return t.stop()}}),t,this)}))),function(t){return f.apply(this,arguments)})}],l&&s(a.prototype,l),Object.defineProperty(a,"prototype",{writable:!1}),n}();return{exports:{DailyArchive:l,privateClient:e,publicClient:r}}}}})(),n.default})()));
//# sourceMappingURL=build.js.map