!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var r in n)("object"==typeof exports?exports:e)[r]=n[r]}}(window,function(){return function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=18)}([function(e,t,n){"use strict";e.exports=n(19)},function(e,t,n){"use strict";n.r(t),n.d(t,"__extends",function(){return o}),n.d(t,"__assign",function(){return i}),n.d(t,"__rest",function(){return a}),n.d(t,"__decorate",function(){return s}),n.d(t,"__param",function(){return l}),n.d(t,"__metadata",function(){return u}),n.d(t,"__awaiter",function(){return c}),n.d(t,"__generator",function(){return d}),n.d(t,"__exportStar",function(){return f}),n.d(t,"__values",function(){return p}),n.d(t,"__read",function(){return h}),n.d(t,"__spread",function(){return m}),n.d(t,"__await",function(){return y}),n.d(t,"__asyncGenerator",function(){return v}),n.d(t,"__asyncDelegator",function(){return g}),n.d(t,"__asyncValues",function(){return b}),n.d(t,"__makeTemplateObject",function(){return _}),n.d(t,"__importStar",function(){return w}),n.d(t,"__importDefault",function(){return E}); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABLITY OR NON-INFRINGEMENT. See the Apache Version 2.0 License for specific language governing permissions and limitations under the License. ***************************************************************************** */ var r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])};function o(e,t){function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function l(e,t){return function(n,r){t(n,r,e)}}function u(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function c(e,t,n,r){return new(n||(n=Promise))(function(o,i){function a(e){try{l(r.next(e))}catch(e){i(e)}}function s(e){try{l(r.throw(e))}catch(e){i(e)}}function l(e){e.done?o(e.value):new n(function(t){t(e.value)}).then(a,s)}l((r=r.apply(e,t||[])).next())})}function d(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=r[2&i[0]?"return":i[0]?"throw":"next"])&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[0,o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!(o=(o=a.trys).length>0&&o[o.length-1])&&(6===i[0]||2===i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}}}function h(e,t){var n="function"==typeof Symbol&&e[Symbol.iterator];if(!n)return e;var r,o,i=n.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(r=i.next()).done;)a.push(r.value)}catch(e){o={error:e}}finally{try{r&&!r.done&&(n=i.return)&&n.call(i)}finally{if(o)throw o.error}}return a}function m(){for(var e=[],t=0;t1||s(e,t)})})}function s(e,t){try{!function(e){e.value instanceof y?Promise.resolve(e.value.v).then(l,u):c(i[0][2],e)}(o[e](t))}catch(e){c(i[0][3],e)}}function l(e){s("next",e)}function u(e){s("throw",e)}function c(e,t){e(t),i.shift(),i.length&&s(i[0][0],i[0][1])}}function g(e){var t,n;return t={},r("next"),r("throw",function(e){throw e}),r("return"),t[Symbol.iterator]=function(){return this},t;function r(r,o){e[r]&&(t[r]=function(t){return(n=!n)?{value:y(e[r](t)),done:"return"===r}:o?o(t):t})}}function b(e){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=e[Symbol.asyncIterator];return t?t.call(e):p(e)}function _(e,t){return Object.defineProperty?Object.defineProperty(e,"raw",{value:t}):e.raw=t,e}function w(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var n in e)Object.hasOwnProperty.call(e,n)&&(t[n]=e[n]);return t.default=e,t}function E(e){return e&&e.__esModule?e:{default:e}}},function(e,t,n){(function(t){e.exports=function(){var e={},n=[{name:"ST",start:/(?:^|\W)(\*)[^\s*]/,end:/[^\s*](\*)(?=$|\W)/},{name:"EM",start:/(?:^|[\W_])(_)[^\s_]/,end:/[^\s_](_)(?=$|[\W_])/},{name:"DL",start:/(?:^|\W)(~)[^\s~]/,end:/[^\s~](~)(?=$|\W)/},{name:"CO",start:/(?:^|\W)(`)[^`]/,end:/[^`](`)(?=$|\W)/}],r=[{name:"LN",dataName:"url",pack:function(e){return/^[a-z]+:\/\//i.test(e)||(e="http://"+e),{url:e}},re:/(?:(?:https?|ftp):\/\/|www\.|ftp\.)[-A-Z0-9+&@#\/%=~_|$?!:,.]*[A-Z0-9+&@#\/%=~_|$]/gi},{name:"MN",dataName:"val",pack:function(e){return{val:e.slice(1)}},re:/\B@(\w\w+)/g},{name:"HT",dataName:"val",pack:function(e){return{val:e.slice(1)}},re:/\B#(\w\w+)/g}],o={ST:{name:"b",isVoid:!1},EM:{name:"i",isVoid:!1},DL:{name:"del",isVoid:!1},CO:{name:"tt",isVoid:!1},BR:{name:"br",isVoid:!0},LN:{name:"a",isVoid:!1},MN:{name:"a",isVoid:!1},HT:{name:"a",isVoid:!1},IM:{name:"img",isVoid:!0}};function i(e,t){var n;try{n=atob(e)}catch(e){console.log("Drafty: failed to decode base64-encoded object",e.message),n=atob("")}for(var r=n.length,o=new ArrayBuffer(r),i=new Uint8Array(o),a=0;a"},close:function(){return""}},EM:{open:function(){return""},close:function(){return""}},DL:{open:function(){return""},close:function(){return""}},CO:{open:function(){return""},close:function(){return""}},BR:{open:function(){return""},close:function(){return"
"}},LN:{open:function(e){return''},close:function(e){return""},props:function(e){return{href:e.url,target:"_blank"}}},MN:{open:function(e){return''},close:function(e){return""},props:function(e){return{name:e.val}}},HT:{open:function(e){return''},close:function(e){return""},props:function(e){return{name:e.val}}},IM:{open:function(e){var t=i(e.val,e.mime),n=e.ref?e.ref:t,r=(e.name?'':"")+'';return console.log("open: "+r),r},close:function(e){return e.name?"":""},props:function(e){return{src:i(e.val,e.mime),title:e.name,"data-width":e.width,"data-height":e.height,"data-name":e.name,"data-size":.75*e.val.length|0,"data-mime":e.mime}}}},s=function(){};s.parse=function(e){if("string"!=typeof e)return null;var t=e.split(/\r?\n/),o=[],i={},a=[];t.map(function(e){var t,s,l=[];if(n.map(function(t){l=l.concat(function(e,t,n,r){for(var o=[],i=0,a=e.slice(0);a.length>0;){var s=t.exec(a);if(null==s)break;var l=s.index+s[0].lastIndexOf(s[1]);a=a.slice(l+1),i=(l+=i)+1;var u=n?n.exec(a):null;if(null==u)break;var c=u.index+u[0].indexOf(u[1]);a=a.slice(c+1),i=(c+=i)+1,o.push({text:e.slice(l+1,c),children:[],start:l,end:c,type:r})}return o}(e,t.start,t.end,t.name))}),0==l.length)s={txt:e};else{l.sort(function(e,t){return e.start-t.start}),l=function e(t){if(0==t.length)return[];for(var n=[t[0]],r=t[0],o=1;or.end?(n.push(t[o]),r=t[o]):t[o].endn&&i.push({text:t.slice(n,s.start)});var l={type:s.type},u=e(t,s.start+1,s.end-1,s.children);u.length>0?l.children=u:l.text=s.text,i.push(l),n=s.end+1}return no;return o=e.offset+e.len,t})}(s.txt)).length>0){var c=[];for(var d in t){var f=t[d],p=i[f.unique];p||(p=o.length,i[f.unique]=p,o.push({tp:f.type,data:f.data})),c.push({at:f.offset,len:f.len,key:p})}s.ent=c}a.push(s)});var s={txt:""};if(a.length>0){s.txt=a[0].txt,s.fmt=(a[0].fmt||[]).concat(a[0].ent||[]);for(var l=1;l0&&(s.ent=o)}return s},s.insertImage=function(e,t,n,r,o,i,a,s,l){return(e=e||{txt:" "}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:t,len:1,key:e.ent.length}),e.ent.push({tp:"IM",data:{mime:n,val:r,width:o,height:i,name:a,ref:l,size:0|s}}),e},s.attachFile=function(e,t,n,r,o,i){(e=e||{txt:""}).ent=e.ent||[],e.fmt=e.fmt||[],e.fmt.push({at:-1,len:0,key:e.ent.length});var a={tp:"EX",data:{mime:t,val:n,name:r,ref:i,size:0|o}};return i instanceof Promise&&(a.data.ref=i.then(function(e){a.data.ref=e},function(e){})),e.ent.push(a),e},s.UNSAFE_toHTML=function(e){var t,n,r,o=e.txt,i=e.fmt,s=e.ent,l=[];if(i)for(var u in i){var c,d=i[u],f=d.tp;if(!f){var p=s[d.key];p&&(f=p.tp,c=p.data)}a[f]&&(l.push({idx:d.at+d.len,what:a[f].close(c)}),l.push({idx:d.at,what:a[f].open(c)}))}for(var u in l.sort(function(e,t){return t.idx-e.idx}),l)l[u].what&&(t=o,n=l[u].idx,r=l[u].what,o=t.slice(0,n)+r+t.slice(n));return o},s.format=function(e,t,n){var r=e.txt,i=e.fmt,a=e.ent;if(r=r||"",!i)return[r];var s=[].concat(i);return s.map(function(e){e.at=e.at||0,e.len=e.len||0}),s.sort(function(e,t){return e.at-t.at==0?t.len-e.len:e.at-t.at}),s=s.map(function(e){var t,n=e.tp;return n||(e.key=e.key||0,t=a[e.key].data,n=a[e.key].tp),{tp:n,data:t,at:e.at,len:e.len}}),function e(t,n,r,i,a,s){for(var l=[],u=0;u0)for(var t in e.ent)if("EX"==e.ent[t].tp)return!0;return!1},s.attachments=function(e,t,n){if(e.ent&&e.ent.length>0)for(var r in e.ent)"EX"==e.ent[r].tp&&t.call(n,e.ent[r].data,r)},s.getDownloadUrl=function(e){var t=null;return e.val?t=i(e.val,e.mime):"string"==typeof e.ref&&(t=e.ref),t},s.isUploading=function(e){return e.ref instanceof Promise},s.getPreviewUrl=function(e){return e.val?i(e.val,e.mime):null},s.getEntitySize=function(e){return e.size?e.size:e.val?.75*e.val.length|0:0},s.getEntityMimeType=function(e){return e.mime||"text/plain"},s.tagName=function(e){return o[e]?o[e].name:void 0},s.attrValue=function(e,t){if(t&&a[e])return a[e].props(t)},s.getContentType=function(){return"text/x-drafty"},e=s;var l={};return function(t){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}var r,o="0.15.8-rc1";"undefined"!=typeof WebSocket&&(r=WebSocket),"undefined"==typeof btoa&&(t.btoa=function(){for(var e,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n="",r=0,o=0,i="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.charAt(0|o)||(i="=",o%1);n+=i.charAt(63&r>>8-o%1*8)){if((e=t.charCodeAt(o+=.75))>255)throw new Error("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");r=r<<8|e}return n}),"undefined"==typeof atob&&(t.atob=function(){var e=(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"").replace(/=+$/,""),t="";if(e.length%4==1)throw new Error("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,r=0,o=0,i=0;n=e.charAt(i++);~n&&(o=r%4?64*o+n:n,r++%4)?t+=String.fromCharCode(255&o>>(-2*r&6)):0)n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(n);return t}),"undefined"==typeof window&&(t.window={WebSocket:r,URL:{createObjectURL:function(){throw new Error("Unable to use window.URL in a non browser application")}}});var i="0",a=o||"0.15",s="tinodejs/"+a,u=503,c="Connection failed";function d(e){return btoa(encodeURIComponent(e).replace(/%([0-9A-F]{2})/g,function(e,t){return String.fromCharCode("0x"+t)}))}function f(e,t,r){if(null==t)return e;if("object"!==n(t))return t||e;if(t instanceof Date)return t;if(t instanceof w)return new w(t);if(t instanceof Array)return t.length>0?t:e;for(var o in e||(e=t.constructor()),t)!t.hasOwnProperty(o)||!t[o]&&!1!==t[o]||r&&r[o]||"_generated"==o||(e[o]=f(e[o],t[o]));return e}function p(e,t,n,r){return e[t]=f(e[t],n,r),e[t]}function h(){var e=null;if("withCredentials"in new XMLHttpRequest)e=new XMLHttpRequest;else{if("undefined"==typeof XDomainRequest)throw new Error("browser not supported");e=new XDomainRequest}return e}function m(e,t){if("ts"===e&&"string"==typeof t&&t.length>=20&&t.length<=24){var r=new Date(t);if(r)return r}else if("acs"===e&&"object"===n(t))return new w(t);return t}function y(e,t){return"string"==typeof t&&t.length>128?"<"+t.length+", bytes: "+t.substring(0,12)+"..."+t.substring(t.length-12)+">":function(e,t){if(t instanceof Date)t=function(e){if(e&&0!=e.getTime()){var t=e.getUTCMilliseconds();return e.getUTCFullYear()+"-"+n(e.getUTCMonth()+1)+"-"+n(e.getUTCDate())+"T"+n(e.getUTCHours())+":"+n(e.getUTCMinutes())+":"+n(e.getUTCSeconds())+(t?"."+n(t,3):"")+"Z"}function n(e,t){return"0".repeat((t=t||2)-(""+e).length)+e}}(t);else if(null==t||!1===t||Array.isArray(t)&&0==t.length||"object"===n(t)&&0===Object.keys(t).length)return;return t}(0,t)}function v(e,t,n){var r=null;return"http"!==t&&"https"!==t&&"ws"!==t&&"wss"!==t||(r=t+"://","/"!==(r+=e).charAt(r.length-1)&&(r+="/"),r+="v"+i+"/channels","http"!==t&&"https"!==t||(r+="/lp"),r+="?apikey="+n),r}var g=function(e,t,o,i,a){var s=this,l=e,d=i,f=t,p=a,y=2e3,g=10,b=.3,_=null,w=0,E=!1,S=function(e){s.logger&&s.logger(e)};function T(e){var t=null;e.connect=function(n){return t&&1===t.readyState?Promise.resolve():(n&&(l=n),new Promise(function(n,o){var i=v(l,d?"wss":"ws",f);S("Connecting to: "+i);var a=new r(i);a.onopen=function(t){E=!1,e.onOpen&&e.onOpen(),n(),p&&(clearTimeout(_),_=null,w=0)},a.onclose=function(n){t=null,e.onDisconnect&&e.onDisconnect(null),!E&&p&&function(){var e=this;clearTimeout(_);var t=y*(Math.pow(2,w)*(1+b*Math.random()));w=w>=g?w:w+1,_=setTimeout(function(){S("Reconnecting, iter="+w+", timeout="+t),E||e.connect().catch(function(){})},t)}.call(e)},a.onerror=function(e){o(e)},a.onmessage=function(t){e.onMessage&&e.onMessage(t.data)},t=a}))},e.disconnect=function(){t&&(E=!0,t.close()),t=null},e.sendText=function(e){if(!t||t.readyState!=t.OPEN)throw new Error("Websocket is not connected");t.send(e)},e.isConnected=function(){return t&&1===t.readyState},e.transport=function(){return"ws"}}function k(e){var t=null,n=null,r=null;e.connect=function(r){return n?Promise.resolve():(r&&(l=r),new Promise(function(r,o){var i=v(l,d?"https":"http",f);S("Connecting to: "+i),(n=function n(r,o,i){var a=h();return a.onreadystatechange=function(s){if(4==a.readyState)if(201==a.status){var l=JSON.parse(a.responseText,m);a.responseText,t=r+"&sid="+l.ctrl.params.sid,(a=n(t)).send(null),e.onOpen&&e.onOpen(),o&&o()}else if(200==a.status)e.onMessage&&e.onMessage(a.responseText),(a=n(t)).send(null);else if(i&&i(a.responseText),e.onMessage&&a.responseText&&e.onMessage(a.responseText),e.onDisconnect){var d=a.status||u,f=a.responseText||c;e.onDisconnect(new Error(f+"("+d+")"))}},a.open("GET",r,!0),a}(i,r,o)).send(null)}).catch(function(){}))},e.disconnect=function(){r&&(r.onreadystatechange=void 0,r.abort(),r=null),n&&(n.onreadystatechange=void 0,n.abort(),n=null),e.onDisconnect&&e.onDisconnect(null),t=null},e.sendText=function(e){var n,o;if(n=t,(o=h()).onreadystatechange=function(e){if(4==o.readyState&&o.status>=400)throw new Error("LP sender failed, "+o.status)},o.open("POST",n,!0),!(r=o)||1!=r.readyState)throw new Error("Long poller failed to connect");r.send(e)},e.isConnected=function(){return n&&!0},e.transport=function(){return"lp"}}"lp"===o?k(this):"ws"===o?T(this):"object"==("undefined"==typeof window?"undefined":n(window))&&window.WebSocket?T(this):k(this),this.onMessage=void 0,this.onDisconnect=void 0,this.onOpen=void 0,this.logger=void 0},b=function(e,t,r,o,i){var l=this;this._appName=e||"Undefined",this._apiKey=r,this._browser="",this._platform="undefined",this._humanLanguage="xx","undefined"!=typeof navigator&&(this._browser=function(e){var t,n=(e=(e||"").replace(" (KHTML, like Gecko)","")).match(/(AppleWebKit\/[.\d]+)/i);if(n){for(var r=["chrome","safari","mobile","version"],o=e.substr(n.index+n[0].length).split(" "),i=[],a=0;a0?i[0][0]+"/"+i[0][1]:n[1]}else t=/trident/i.test(e)?(n=/(?:\brv[ :]+([.\d]+))|(?:\bMSIE ([.\d]+))/g.exec(e))?"MSIE/"+(n[1]||n[2]):"MSIE/?":/firefox/i.test(e)?(n=/Firefox\/([.\d]+)/g.exec(e))?"Firefox/"+n[1]:"Firefox/?":/presto/i.test(e)?(n=/Opera\/([.\d]+)/g.exec(e))?"Opera/"+n[1]:"Opera/?":(n=/([\w.]+)\/([.\d]+)/.exec(e))?n[1]+"/"+n[2]:(n=e.split(" "))[0];if((n=t.split("/")).length>1){var l=n[1].split(".");t=n[0]+"/"+l[0]+(l[1]?"."+l[1]:"")}return t}(navigator.userAgent),this._platform=navigator.platform,this._humanLanguage=navigator.language||"en-US"),this._loggingEnabled=!1,this._trimLongStrings=!1,this._myUID=null,this._authenticated=!1,this._login=null,this._authToken=null,this._inPacketCount=0,this._messageId=Math.floor(65535*Math.random()+65535),this._serverInfo=null,this._deviceToken=null,this._pendingPromises={},this._connection=new g(t,r,o,i,!0),this.logger=function(e){if(l._loggingEnabled){var t=new Date,n=("0"+t.getUTCHours()).slice(-2)+":"+("0"+t.getUTCMinutes()).slice(-2)+":"+("0"+t.getUTCSeconds()).slice(-2)+":"+("0"+t.getUTCMilliseconds()).slice(-3);console.log("["+n+"] "+e)}},this._connection.logger=this.logger,this._cache={};var d=this.cachePut=function(e,t,n){l._cache[e+":"+t]=n},p=this.cacheGet=function(e,t){return l._cache[e+":"+t]},h=this.cacheDel=function(e,t){delete l._cache[e+":"+t]},v=this.cacheMap=function(e,t){for(var n in l._cache)if(e(l._cache[n],n,t))break};this.attachCacheToTopic=function(e){e._tinode=l,e._cacheGetUser=function(e){var t=p("user",e);if(t)return{user:e,public:f({},t)}},e._cachePutUser=function(e,t){return d("user",e,f({},t.public))},e._cacheDelUser=function(e){return h("user",e)},e._cachePutSelf=function(){return d("topic",e.name,e)},e._cacheDelSelf=function(){return h("topic",e.name)}};var b=function(e,t,n,r){var o=l._pendingPromises[e];o&&(delete l._pendingPromises[e],t>=200&&t<400?o.resolve&&o.resolve(n):o.reject&&o.reject(new Error("Error: "+r+" ("+t+")")))},_=this.getNextUniqueId=function(){return 0!=l._messageId?""+l._messageId++:void 0};this.initPacket=function(e,t){switch(e){case"hi":return{hi:{id:_(),ver:a,ua:l._appName+" ("+(l._browser?l._browser+"; ":"")+l._platform+"); "+s,dev:l._deviceToken,lang:l._humanLanguage}};case"acc":return{acc:{id:_(),user:null,scheme:null,secret:null,login:!1,tags:null,desc:{},cred:{}}};case"login":return{login:{id:_(),scheme:null,secret:null}};case"sub":return{sub:{id:_(),topic:t,set:{},get:{}}};case"leave":return{leave:{id:_(),topic:t,unsub:!1}};case"pub":return{pub:{id:_(),topic:t,noecho:!1,head:null,content:{}}};case"get":return{get:{id:_(),topic:t,what:null,desc:{},sub:{},data:{}}};case"set":return{set:{id:_(),topic:t,desc:{},sub:{},tags:[]}};case"del":return{del:{id:_(),topic:t,what:null,delseq:null,user:null,hard:!1}};case"note":return{note:{topic:t,what:null,seq:void 0}};default:throw new Error("Unknown packet type requested: "+e)}},this.send=function(e,t){var r;t&&(r=function(e){var t=null;return e&&(t=new Promise(function(t,n){l._pendingPromises[e]={resolve:t,reject:n}})),t}(t)),e=function e(t){return Object.keys(t).forEach(function(r){"_"==r[0]?delete t[r]:t[r]?Array.isArray(t[r])&&0==t[r].length?delete t[r]:t[r]?"object"!=n(t[r])||t[r]instanceof Date||(e(t[r]),0==Object.getOwnPropertyNames(t[r]).length&&delete t[r]):delete t[r]:delete t[r]}),t}(e);var o=JSON.stringify(e);l.logger("out: "+(l._trimLongStrings?JSON.stringify(e,y):o));try{l._connection.sendText(o)}catch(e){if(!t)throw e;b(t,u,null,e.message)}return r},this.loginSuccessful=function(e){e.params&&e.params.user&&(l._myUID=e.params.user,l._authenticated=e&&e.code>=200&&e.code<300,e.params&&e.params.token&&e.params.expires?l._authToken={token:e.params.token,expires:new Date(e.params.expires)}:l._authToken=null,l.onLogin&&l.onLogin(e.code,e.text))},this._connection.onMessage=function(e){if(e){l._inPacketCount++,l.onRawMessage&&l.onRawMessage(e);var t=JSON.parse(e,m);if(t)if(l.logger("in: "+(l._trimLongStrings?JSON.stringify(t,y):e)),l.onMessage&&l.onMessage(t),t.ctrl)l.onCtrlMessage&&l.onCtrlMessage(t.ctrl),t.ctrl.id&&b(t.ctrl.id,t.ctrl.code,t.ctrl,t.ctrl.text),t.ctrl.params&&"data"==t.ctrl.params.what&&(n=p("topic",t.ctrl.topic))&&n._allMessagesReceived(t.ctrl.params.count);else if(t.meta)(n=p("topic",t.meta.topic))&&n._routeMeta(t.meta),l.onMetaMessage&&l.onMetaMessage(t.meta);else if(t.data)(n=p("topic",t.data.topic))&&n._routeData(t.data),l.onDataMessage&&l.onDataMessage(t.data);else if(t.pres)(n=p("topic",t.pres.topic))&&n._routePres(t.pres),l.onPresMessage&&l.onPresMessage(t.pres);else if(t.info){var n;(n=p("topic",t.info.topic))&&n._routeInfo(t.info),l.onInfoMessage&&l.onInfoMessage(t.info)}else l.logger("ERROR: Unknown packet received.");else l.logger("in: "+e),l.logger("ERROR: failed to parse data")}},this._connection.onOpen=function(){l.hello()},this._connection.onDisconnect=function(e){for(var t in l._inPacketCount=0,l._serverInfo=null,l._authenticated=!1,l._pendingPromises){var n=l._pendingPromises[t];n&&n.reject&&n.reject(new Error(c+" ("+u+")"))}l._pendingPromises={},v(function(e,t){0===t.lastIndexOf("topic:",0)&&e._resetSub()}),l.onDisconnect&&l.onDisconnect(e)}};b.credential=function(e,t,r,o){if("object"==n(e)){var i=e;t=i.val,r=i.params,o=i.resp,e=i.meth}return e&&(t||o)?[{meth:e,val:t,resp:o,params:r}]:null},b.topicType=function(e){return{me:"me",fnd:"fnd",grp:"grp",new:"grp",usr:"p2p"}["string"==typeof e?e.substring(0,3):"xxx"]},b.isNewGroupTopicName=function(e){return"string"==typeof e&&"new"==e.substring(0,3)},b.getVersion=function(){return a},b.setWebSocketProvider=function(e){r=e},b.getLibrary=function(){return s},b.MESSAGE_STATUS_NONE=0,b.MESSAGE_STATUS_QUEUED=1,b.MESSAGE_STATUS_SENDING=2,b.MESSAGE_STATUS_FAILED=3,b.MESSAGE_STATUS_SENT=4,b.MESSAGE_STATUS_RECEIVED=5,b.MESSAGE_STATUS_READ=6,b.MESSAGE_STATUS_TO_ME=7,b.DEL_CHAR="␡",b.prototype={connect:function(e){return this._connection.connect(e)},disconnect:function(){this._connection&&this._connection.disconnect()},isConnected:function(){return this._connection&&this._connection.isConnected()},isAuthenticated:function(){return this._authenticated},account:function(e,t,n,r,o){var i=this.initPacket("acc");return i.acc.user=e,i.acc.scheme=t,i.acc.secret=n,i.acc.login=r,o&&(i.acc.desc.defacs=o.defacs,i.acc.desc.public=o.public,i.acc.desc.private=o.private,i.acc.tags=o.tags,i.acc.cred=o.cred,i.acc.token=o.token),this.send(i,i.acc.id)},createAccount:function(e,t,n,r){var o=this,i=this.account("new",e,t,n,r);return n&&(i=i.then(function(e){return o.loginSuccessful(e),e})),i},createAccountBasic:function(e,t,n){return e=e||"",t=t||"",this.createAccount("basic",d(e+":"+t),!0,n)},updateAccountBasic:function(e,t,n,r){return t=t||"",n=n||"",this.account(e,"basic",d(t+":"+n),!1,r)},hello:function(){var e=this,t=this.initPacket("hi");return this.send(t,t.hi.id).then(function(t){return t.params&&(e._serverInfo=t.params),e.onConnect&&e.onConnect(),t}).catch(function(t){e.onDisconnect&&e.onDisconnect(t)})},setDeviceToken:function(e,t){var n=!1;return e&&e!=this._deviceToken&&(this._deviceToken=e,t&&this.isConnected()&&this.isAuthenticated()&&(this.send({hi:{dev:e}}),n=!0)),n},login:function(e,t,n){var r=this,o=this.initPacket("login");return o.login.scheme=e,o.login.secret=t,o.login.cred=n,this.send(o,o.login.id).then(function(e){return r.loginSuccessful(e),e})},loginBasic:function(e,t,n){var r=this;return this.login("basic",d(e+":"+t),n).then(function(t){return r._login=e,t})},loginToken:function(e,t){return this.login("token",e,t)},requestResetAuthSecret:function(e,t,n){return this.login("reset",d(e+":"+t+":"+n))},getAuthToken:function(){return this._authToken&&this._authToken.expires.getTime()>Date.now()?this._authToken:(this._authToken=null,null)},setAuthToken:function(e){this._authToken=e},subscribe:function(e,t,n){var r=this.initPacket("sub",e);return e||(e="new"),r.sub.get=t,n&&(n.sub&&(r.sub.set.sub=n.sub),b.isNewGroupTopicName(e)&&n.desc&&(r.sub.set.desc=n.desc),n.tags&&(r.sub.set.tags=n.tags)),this.send(r,r.sub.id)},leave:function(e,t){var n=this.initPacket("leave",e);return n.leave.unsub=t,this.send(n,n.leave.id)},createMessage:function(t,n,r){var o=this.initPacket("pub",t),i="string"==typeof n?e.parse(n):n;return i&&!e.isPlainText(i)&&(o.pub.head={mime:e.getContentType()},n=i),o.pub.noecho=r,o.pub.content=n,o.pub},publish:function(e,t,n){return this.publishMessage(this.createMessage(e,t,n))},publishMessage:function(e){return(e=Object.assign({},e)).seq=void 0,e.from=void 0,e.ts=void 0,this.send({pub:e},e.id)},getMeta:function(e,t){var n=this.initPacket("get",e);return n.get=f(n.get,t),this.send(n,n.get.id)},setMeta:function(e,t){var n=this.initPacket("set",e),r=[];return t&&["desc","sub","tags"].map(function(e){t.hasOwnProperty(e)&&(r.push(e),n.set[e]=t[e])}),0==r.length?Promise.reject(new Error("Invalid {set} parameters")):this.send(n,n.set.id)},delMessages:function(e,t,n){var r=this.initPacket("del",e);return r.del.what="msg",r.del.delseq=t,r.del.hard=n,this.send(r,r.del.id)},delTopic:function(e){var t=this,n=this.initPacket("del",e);return n.del.what="topic",this.send(n,n.del.id).then(function(n){return t.cacheDel("topic",e),t.ctrl})},delSubscription:function(e,t){var n=this.initPacket("del",e);return n.del.what="sub",n.del.user=t,this.send(n,n.del.id)},note:function(e,t,n){if(n<=0||n>=268435455)throw new Error("Invalid message id "+n);var r=this.initPacket("note",e);r.note.what=t,r.note.seq=n,this.send(r)},noteKeyPress:function(e){var t=this.initPacket("note",e);t.note.what="kp",this.send(t)},getTopic:function(e){var t=this.cacheGet("topic",e);return!t&&e&&(t="me"==e?new S:"fnd"==e?new T:new E(e),this.cachePut("topic",e,t),this.attachCacheToTopic(t)),t},newTopic:function(e){var t=new E("new",e);return this.attachCacheToTopic(t),t},newGroupTopicName:function(){return"new"+this.getNextUniqueId()},newTopicWith:function(e,t){var n=new E(e,t);return this.attachCacheToTopic(n),n},getMeTopic:function(){return this.getTopic("me")},getFndTopic:function(){return this.getTopic("fnd")},getLargeFileHelper:function(){return new k(this)},getCurrentUserID:function(){return this._myUID},getCurrentLogin:function(){return this._login},getServerInfo:function(){return this._serverInfo},enableLogging:function(e,t){this._loggingEnabled=e,this._trimLongStrings=e&&t},isTopicOnline:function(e){var t=this.getMeTopic(),n=t&&t.getContact(e);return n&&n.online},wantAkn:function(e){this._messageId=e?Math.floor(16777215*Math.random()+16777215):0},onWebsocketOpen:void 0,onConnect:void 0,onDisconnect:void 0,onLogin:void 0,onCtrlMessage:void 0,onDataMessage:void 0,onPresMessage:void 0,onMessage:void 0,onRawMessage:void 0};var _=function(e){this.topic=e;var t=e._tinode.getMeTopic();this.contact=t&&t.getContact(e.name),this.what={}};_.prototype={_get_ims:function(){var e=this.contact&&this.contact.updated,t=this.topic._lastDescUpdate||0;return e>t?e:t},withData:function(e,t,n){return this.what.data={since:e,before:t,limit:n},this},withLaterData:function(e){return this.withData(this.topic._maxSeq>0?this.topic._maxSeq+1:void 0,void 0,e)},withEarlierData:function(e){return this.withData(void 0,this.topic._minSeq>0?this.topic._minSeq:void 0,e)},withDesc:function(e){return this.what.desc={ims:e},this},withLaterDesc:function(){return this.withDesc(this._get_ims())},withSub:function(e,t,n){var r={ims:e,limit:t};return"me"==this.topic.getType()?r.topic=n:r.user=n,this.what.sub=r,this},withOneSub:function(e,t){return this.withSub(e,void 0,t)},withLaterOneSub:function(e){return this.withOneSub(this.topic._lastSubsUpdate,e)},withLaterSub:function(e){return this.withSub("p2p"==this.topic.getType()?this._get_ims():this.topic._lastSubsUpdate,e)},withTags:function(){return this.what.tags=!0,this},withDel:function(e,t){return(e||t)&&(this.what.del={since:e,limit:t}),this},withLaterDel:function(e){return this.withDel(this.topic._maxSeq>0?this.topic._maxDel+1:void 0,e)},build:function(){var e={},t=[],n=this;return["data","sub","desc","tags","del"].map(function(r){n.what.hasOwnProperty(r)&&(t.push(r),Object.getOwnPropertyNames(n.what[r]).length>0&&(e[r]=n.what[r]))}),t.length>0?e.what=t.join(" "):e=void 0,e}};var w=function e(t){t&&(this.given="number"==typeof t.given?t.given:e.decode(t.given),this.want="number"==typeof t.want?t.want:e.decode(t.want),this.mode=t.mode?"number"==typeof t.mode?t.mode:e.decode(t.mode):this.given&this.want)};w._NONE=0,w._JOIN=1,w._READ=2,w._WRITE=4,w._PRES=8,w._APPROVE=16,w._SHARE=32,w._DELETE=64,w._OWNER=128,w._BITMASK=w._JOIN|w._READ|w._WRITE|w._PRES|w._APPROVE|w._SHARE|w._DELETE|w._OWNER,w._INVALID=1048576,w.decode=function(e){if(!e)return null;if("number"==typeof e)return e&w._BITMASK;if("N"===e||"n"===e)return w._NONE;for(var t={J:w._JOIN,R:w._READ,W:w._WRITE,P:w._PRES,A:w._APPROVE,S:w._SHARE,D:w._DELETE,O:w._OWNER},n=w._NONE,r=0;r0)){l=!0;break}i=a-1}return l?a:r?-1:s<0?a+1:a}function r(e,t){var r=n(e,t,!1);return t.splice(r,0,e),t}return e=e||function(e,t){return e===t?0:e0)return n[0]},delRange:function(e,n){return t.splice(e,n-e)},size:function(){return t.length},reset:function(e){t=[]},forEach:function(e,n,r,o){n|=0,r=r||t.length;for(var i=n;i=300)return e;if(n._subscribed=!0,n.acs=e.params&&e.params.acs?e.params.acs:n.acs,n._new){n._new=!1,n.name=e.topic,n.created=e.ts,n.updated=e.ts,n.touched=e.ts,n._cachePutSelf();var r=n._tinode.getMeTopic();r&&r._processMetaSub([{_generated:!0,topic:n.name,created:e.ts,updated:e.ts,touched:e.ts,acs:n.acs}]),t&&t.desc&&(t.desc._generated=!0,n._processMetaDesc(t.desc))}return e})},createMessage:function(e,t){return this._tinode.createMessage(this.name,e,t)},publish:function(e,t){return this.publishMessage(this.createMessage(e,t))},publishMessage:function(t){var n=this;if(!this._subscribed)return Promise.reject(new Error("Cannot publish on inactive topic"));if(e.hasAttachments(t.content)&&!t.head.attachments){var r=[];e.attachments(t.content,function(e){r.push(e.ref)}),t.head.attachments=r}return t._sending=!0,this._tinode.publishMessage(t).then(function(e){return t._sending=!1,t.seq=e.params.seq,t.ts=e.ts,n._routeData(t),e}).catch(function(e){t._sending=!1,t._failed=!0})},publishDraft:function(e,t){var n=this;if(!t&&!this._subscribed)return Promise.reject(new Error("Cannot publish on inactive topic"));var r=e.seq||this._getQueuedSeqId();return e._generated||(e._generated=!0,e.seq=r,e.ts=new Date,e.from=this._tinode.getCurrentUserID(),e.noecho=!0,this._messages.put(e),this.onData&&this.onData(e)),(t||Promise.resolve()).then(function(){return e._cancelled?{code:300,text:"cancelled"}:n.publishMessage(e)},function(t){e._sending=!1,n._messages.delAt(n._messages.find(e)),n.onData&&n.onData()})},leave:function(e){var t=this;return this._subscribed||e?this._tinode.leave(this.name,e).then(function(n){return t._resetSub(),e&&t._gone(),n}):Promise.reject(new Error("Cannot leave inactive topic"))},getMeta:function(e){return this._subscribed?this._tinode.getMeta(this.name,e):Promise.reject(new Error("Cannot query inactive topic"))},getMessagesPage:function(e,t){var n=this,r=this.startMetaQuery();t?r.withLaterData(e):r.withEarlierData(e);var o=this.getMeta(r.build());return t||(o=o.then(function(e){e&&e.params&&!e.params.count&&(n._noEarlierMsgs=!0)})),o},setMeta:function(e){var t=this;return this._subscribed?(e.tags&&(e.tags=function(e){var t=[];if(Array.isArray(e)){for(var n=0,r=e.length;n1&&t.push(o)}t.sort().filter(function(e,t,n){return!t||e!=n[t-1]})}return 0==t.length&&t.push(b.DEL_CHAR),t}(e.tags)),this._tinode.setMeta(this.name,e).then(function(n){return n&&n.code>=300?n:(e.sub&&(n.params&&n.params.acs&&(e.sub.acs=n.params.acs,e.sub.updated=n.ts),e.sub.user||(e.sub.user=t._tinode.getCurrentUserID(),e.desc||(e.desc={})),e.sub._generated=!0,t._processMetaSub([e.sub])),e.desc&&(n.params&&n.params.acs&&(e.desc.acs=n.params.acs,e.desc.updated=n.ts),t._processMetaDesc(e.desc)),e.tags&&t._processMetaTags(e.tags),n)})):Promise.reject(new Error("Cannot update inactive topic"))},invite:function(e,t){return this.setMeta({sub:{user:e,mode:t}})},delMessages:function(e,t){var n=this;if(!this._subscribed)return Promise.reject(new Error("Cannot delete messages in inactive topic"));e.sort(function(e,t){return e.low=t.hi)});var r=e.reduce(function(e,t){return t.low<268435455&&(!t.hi||t.hi<268435455?e.push(t):e.push({low:t.low,hi:n._maxSeq+1})),e},[]);return(e.length>0?this._tinode.delMessages(this.name,r,t):Promise.resolve({params:{del:0}})).then(function(t){return t.params.del>n._maxDel&&(n._maxDel=t.params.del),e.map(function(e){e.hi?n.flushMessageRange(e.low,e.hi):n.flushMessage(e.low)}),n.onData&&n.onData(),t})},delMessagesAll:function(e){return this.delMessages([{low:1,hi:this._maxSeq+1,_all:!0}],e)},delMessagesList:function(e,t){e.sort(function(e,t){return e-t});var n=e.reduce(function(e,t){if(0==e.length)e.push({low:t});else{var n=e[e.length-1];!n.hi&&t!=n.low+1||t>n.hi?e.push({low:t}):n.hi=n.hi?Math.max(n.hi,t+1):t+1}return e},[]);return this.delMessages(n,t)},delTopic:function(){var e=this;return this._tinode.delTopic(this.name).then(function(t){return e._resetSub(),e._gone(),t})},delSubscription:function(e){var t=this;return this._subscribed?this._tinode.delSubscription(this.name,e).then(function(n){return delete t._users[e],t.onSubsUpdated&&t.onSubsUpdated(Object.keys(t._users)),n}):Promise.reject(new Error("Cannot delete subscription in inactive topic"))},note:function(e,t){var n=this._users[this._tinode.getCurrentUserID()];n?((!n[e]||n[e]0)for(var o in this._users){var i=this._users[o];i.user!==r&&i[e]>=t&&n++}return n},msgReadCount:function(e){return this.msgReceiptCount("read",e)},msgRecvCount:function(e){return this.msgReceiptCount("recv",e)},msgHasMoreMessages:function(e){return e?this.seq>this._maxSeq:this._minSeq>1&&!this._noEarlierMsgs},isNewMessage:function(e){return this._maxSeq<=e},flushMessage:function(e){var t=this._messages.find({seq:e});return t>=0?this._messages.delAt(t):void 0},flushMessageRange:function(e,t){var n=this._messages.find({seq:e});return n>=0?this._messages.delRange(n,this._messages.find({seq:t},!0)):[]},cancelSend:function(e){var t=this._messages.find({seq:e});if(t>=0){var n=this._messages.getAt(t);if(1==this.msgStatus(n))return n._cancelled=!0,this._messages.delAt(t),!0}return!1},getType:function(){return b.topicType(this.name)},getAccessMode:function(){return this.acs},getDefaultAccess:function(){return this.defacs},startMetaQuery:function(){return new _(this)},msgStatus:function(e){var t=0;return e.from==this._tinode.getCurrentUserID()?e._sending?t=2:e._failed?t=3:e.seq>=268435455?t=1:this.msgReadCount(e.seq)>0?t=6:this.msgRecvCount(e.seq)>0?t=5:e.seq>0&&(t=4):t=7,t},_routeData:function(e){e.content&&((!this.touched||this.touchedthis._maxSeq&&(this._maxSeq=e.seq),(e.seq0&&(this._lastSubsUpdate=e.ts,this._processMetaSub(e.sub)),e.del&&this._processDelMessages(e.del.clear,e.del.delseq),e.tags&&this._processMetaTags(e.tags),this.onMeta&&this.onMeta(e)},_routePres:function(e){var t;switch(e.what){case"del":this._processDelMessages(e.clear,e.delseq);break;case"on":case"off":(t=this._users[e.src])?t.online="on"==e.what:this._tinode.logger("Presence update for an unknown user",this.name,e.src);break;case"acs":var n="me"==e.src?this._tinode.getCurrentUserID():e.src;if(t=this._users[n])t.acs.updateAll(e.dacs),n==this._tinode.getCurrentUserID()&&this.acs.updateAll(e.dacs),t.acs&&t.acs.mode!=w._NONE||("p2p"==this.getType()&&this.leave(),this._processMetaSub([{user:n,deleted:new Date,_generated:!0}]));else{var r=(new w).updateAll(e.dacs);r&&r.mode!=w._NONE&&((t=this._cacheGetUser(n))?t.acs=r:(t={user:n,acs:r},this.getMeta(this.startMetaQuery().withOneSub(void 0,n).build())),t._generated=!0,t.updated=new Date,this._processMetaSub([t]))}break;default:this._tinode.logger("Ignored presence update",e.what)}this.onPres&&this.onPres(e)},_routeInfo:function(e){if("kp"!==e.what){var t=this._users[e.from];t&&(t[e.what]=e.seq)}this.onInfo&&this.onInfo(e)},_processMetaDesc:function(e,t){if(f(this,e),"string"==typeof this.created&&(this.created=new Date(this.created)),"string"==typeof this.updated&&(this.updated=new Date(this.updated)),"string"==typeof this.touched&&(this.touched=new Date(this.touched)),"me"!==this.name&&!t&&!e._generated){var n=this._tinode.getMeTopic();n&&n._processMetaSub([{_generated:!0,topic:this.name,updated:this.updated,touched:this.touched,acs:this.acs,public:this.public,private:this.private}])}this.onMetaDesc&&this.onMetaDesc(this)},_processMetaSub:function(e){var t=void 0;for(var n in e){var r=e[n];if(r.user){r.updated=new Date(r.updated),r.deleted=r.deleted?new Date(r.deleted):null;var o=null;r.deleted?(delete this._users[r.user],o=r):((o=this._users[r.user])||(o=this._cacheGetUser(r.user)),o=this._updateCachedUser(r.user,r,r._generated)),this.onMetaSub&&this.onMetaSub(o)}else r._generated||(t=r)}t&&this.onMetaDesc&&this.onMetaDesc(t),this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._users))},_processMetaTags:function(e){1==e.length&&e[0]==b.DEL_CHAR&&(e=[]),this._tags=e,this.onTagsUpdated&&this.onTagsUpdated(e)},_processDelMessages:function(e,t){this._maxDel=Math.max(e,this._maxDel),this.clear=Math.max(e,this.clear);var n=this,r=0;Array.isArray(t)&&t.map(function(e){if(e.hi)for(var t=e.low;t0&&this.onData&&this.onData()},_allMessagesReceived:function(e){this.onAllMessagesReceived&&this.onAllMessagesReceived(e)},_resetSub:function(){this._subscribed=!1},_gone:function(){this._messages.reset(),this._users={},this.acs=new w(null),this.private=null,this.public=null,this._maxSeq=0,this._minSeq=0,this._subscribed=!1;var e=this._tinode.getMeTopic();e&&e._routePres({_generated:!0,what:"gone",topic:"me",src:this.name}),this.onDeleteTopic&&this.onDeleteTopic()},_updateCachedUser:function(e,t,n){var r=this._cacheGetUser(e);return r?r=f(r,t):(n&&this.getMeta(this.startMetaQuery().withLaterOneSub(e).build()),r=f({},t)),this._cachePutUser(e,r),p(this._users,e,r)},_getQueuedSeqId:function(){return this._queuedSeqId++}};var S=function(e){E.call(this,"me",e),this._contacts={},e&&(this.onContactUpdate=e.onContactUpdate)};S.prototype=Object.create(E.prototype,{_processMetaSub:{value:function(e){var t=0;for(var n in e){var r=e[n],o=r.topic;if("fnd"!=o&&"me"!=o){r.updated=new Date(r.updated),r.touched=r.touched?new Date(r.touched):null,r.deleted=r.deleted?new Date(r.deleted):null,r.seq=0|r.seq,r.recv=0|r.recv,r.read=0|r.read,r.unread=r.seq-r.read;var i=null;if(r.deleted)i=r,delete this._contacts[o];else if(r.seen&&r.seen.when&&(r.seen.when=new Date(r.seen.when)),i=p(this._contacts,o,r),"p2p"==b.topicType(o)&&this._cachePutUser(o,i),!r._generated){var a=this._tinode.getTopic(o);a&&a._processMetaDesc(r,!0)}t++,this.onMetaSub&&this.onMetaSub(i)}}t>0&&this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._contacts))},enumerable:!0,configurable:!0,writable:!1},_routePres:{value:function(e){var t=this._contacts[e.src];if(t){switch(e.what){case"on":t.online=!0;break;case"off":t.online&&(t.online=!1,t.seen?t.seen.when=new Date:t.seen={when:new Date});break;case"msg":t.touched=new Date,t.seq=0|e.seq,t.unread=t.seq-t.read;break;case"upd":this.getMeta(this.startMetaQuery().withLaterOneSub(e.src).build());break;case"acs":t.acs?t.acs.updateAll(e.dacs):t.acs=(new w).updateAll(e.dacs);break;case"ua":t.seen={when:new Date,ua:e.ua};break;case"recv":t.recv=t.recv?Math.max(t.recv,e.seq):0|e.seq;break;case"read":t.read=t.read?Math.max(t.read,e.seq):0|e.seq,t.unread=t.seq-t.read;break;case"gone":delete this._contacts[e.src]}this.onContactUpdate&&this.onContactUpdate(e.what,t)}else if("acs"==e.what){var n=new w(e.dacs);if(!n||n.mode==w._INVALID)return void this._tinode.logger("Invalid access mode update",e.src,e.dacs);if(n.mode==w._NONE)return void this._tinode.logger("Removing non-existent subscription",e.src,e.dacs);this.getMeta(this.startMetaQuery().withOneSub(void 0,e.src).build()),this._contacts[e.src]={topic:e.src,online:!1,acs:n}}this.onPres&&this.onPres(e)},enumerable:!0,configurable:!0,writable:!1},publish:{value:function(){return Promise.reject(new Error("Publishing to 'me' is not supported"))},enumerable:!0,configurable:!0,writable:!1},contacts:{value:function(e,t){var n=e||this.onMetaSub;if(n)for(var r in this._contacts)n.call(t,this._contacts[r],r,this._contacts)},enumerable:!0,configurable:!0,writable:!0},setMsgReadRecv:{value:function(e,t,n,r){var o,i=this._contacts[e],a=!1;i&&(n|=0,"recv"===t?(o=i.recv,i.recv=i.recv?Math.max(i.recv,n):n,a=o!=i.recv):"read"===t?(o=i.read,i.read=i.read?Math.max(i.read,n):n,i.unread=i.seq-i.read,a=o!=i.read,i.recv0&&this.onSubsUpdated&&this.onSubsUpdated(Object.keys(this._contacts))},enumerable:!0,configurable:!0,writable:!1},publish:{value:function(){return Promise.reject(new Error("Publishing to 'fnd' is not supported"))},enumerable:!0,configurable:!0,writable:!1},setMeta:{value:function(e){var t=this;return Object.getPrototypeOf(T.prototype).setMeta.call(this,e).then(function(){Object.keys(t._contacts).length>0&&(t._contacts={},t.onSubsUpdated&&t.onSubsUpdated([]))})},enumerable:!0,configurable:!0,writable:!1},contacts:{value:function(e,t){var n=e||this.onMetaSub;if(n)for(var r in this._contacts)n.call(t,this._contacts[r],r,this._contacts)},enumerable:!0,configurable:!0,writable:!0}}),T.prototype.constructor=T;var k=function(e){this._tinode=e,this._apiKey=e._apiKey,this._authToken=e.getAuthToken(),this._msgId=e.getNextUniqueId(),this.xhr=h(),this.toResolve=null,this.toReject=null,this.onProgress=null,this.onSuccess=null,this.onFailure=null};k.prototype={upload:function(e,t,n,r){var o=this;if(!this._authToken)throw new Error("Must authenticate first");var a=this;this.xhr.open("POST","/v"+i+"/file/u/",!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token);var s=new Promise(function(e,t){o.toResolve=e,o.toReject=t});this.onProgress=t,this.onSuccess=n,this.onFailure=r,this.xhr.upload.onprogress=function(e){e.lengthComputable&&a.onProgress&&a.onProgress(e.loaded/e.total)},this.xhr.onload=function(){var e;try{e=JSON.parse(this.response,m)}catch(e){a._tinode.logger("Invalid server response in LargeFileHelper",this.response)}this.status>=200&&this.status<300?(a.toResolve&&a.toResolve(e.ctrl.params.url),a.onSuccess&&a.onSuccess(e.ctrl)):this.status>=400?(a.toReject&&a.toReject(new Error(e.ctrl.text+" ("+e.ctrl.code+")")),a.onFailure&&a.onFailure(e.ctrl)):a._tinode.logger("Unexpected server response status",this.status,this.response)},this.xhr.onerror=function(e){a.toReject&&a.toReject(new Error("failed")),a.onFailure&&a.onFailure(null)},this.xhr.onabort=function(e){a.toReject&&a.toReject(new Error("upload cancelled by user")),a.onFailure&&a.onFailure(null)};try{var l=new FormData;l.append("file",e),l.set("id",this._msgId),this.xhr.send(l)}catch(e){this.toReject&&this.toReject(e),this.onFailure&&this.onFailure(null)}return s},download:function(e,t,n,r){var o=this;if(/^(?:(?:[a-z]+:)?\/\/)/i.test(e))throw new Error("The URL '"+e+"' must be relative, not absolute");if(!this._authToken)throw new Error("Must authenticate first");var i=this;this.xhr.open("GET",e,!0),this.xhr.setRequestHeader("X-Tinode-APIKey",this._apiKey),this.xhr.setRequestHeader("X-Tinode-Auth","Token "+this._authToken.token),this.xhr.responseType="blob",this.onProgress=r,this.xhr.onprogress=function(e){i.onProgress&&i.onProgress(e.loaded)};var a=new Promise(function(e,t){o.toResolve=e,o.toReject=t});this.xhr.onload=function(){if(200==this.status){var e=document.createElement("a");e.href=window.URL.createObjectURL(new Blob([this.response],{type:n})),e.style.display="none",e.setAttribute("download",t),document.body.appendChild(e),e.click(),document.body.removeChild(e),window.URL.revokeObjectURL(e.href),i.toResolve&&i.toResolve()}else if(this.status>=400&&i.toReject){var r=new FileReader;r.onload=function(){try{var e=JSON.parse(this.result,m);i.toReject(new Error(e.ctrl.text+" ("+e.ctrl.code+")"))}catch(e){i._tinode.logger("Invalid server response in LargeFileHelper",this.result),i.toReject(e)}},r.readAsText(this.response)}},this.xhr.onerror=function(e){i.toReject&&i.toReject(new Error("failed"))},this.xhr.onabort=function(){i.toReject&&i.toReject(null)};try{this.xhr.send()}catch(e){this.toReject&&this.toReject(e)}return a},cancel:function(){this.xhr&&this.xhr.readyState<4&&this.xhr.abort()},getId:function(){return this._msgId}};var C=function e(t,n){this.status=e.STATUS_NONE,this.topic=t,this.content=n};C.STATUS_NONE=0,C.STATUS_QUEUED=1,C.STATUS_SENDING=2,C.STATUS_FAILED=3,C.STATUS_SENT=4,C.STATUS_RECEIVED=5,C.STATUS_READ=6,C.STATUS_TO_ME=7,(C.prototype={toJSON:function(){},fromJSON:function(e){}}).constructor=C,(l=b).Drafty=e}.call(this,void 0!==t?t:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{}),l}()}).call(this,n(10))},function(e,t,n){e.exports=n(37)()},function(e,t,n){"use strict";!function e(){if("undefined"!=typeof __REACT_DEVTOOLS_GLOBAL_HOOK__&&"function"==typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE)try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(e)}catch(e){console.error(e)}}(),e.exports=n(20)},function(e,t,n){"use strict";var r=n(23).default;n(30),(t=e.exports=r).default=t},function(e,t,n){"use strict";(t=e.exports=n(39).default).default=t},function(e,t,n){"use strict";var r=n(31).default;n(36),(t=e.exports=r).default=t},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(1),o={NODE_CLIENT:!1,NODE_ADMIN:!1,SDK_VERSION:"${JSCORE_VERSION}"},i=function(e,t){if(!e)throw a(t)},a=function(e){return new Error("Firebase Database ("+o.SDK_VERSION+") INTERNAL ASSERT FAILED: "+e)},s=function(e){for(var t=[],n=0,r=0;r>6|192,t[n++]=63&o|128):55296==(64512&o)&&r+1>18|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128,t[n++]=63&o|128):(t[n++]=o>>12|224,t[n++]=o>>6&63|128,t[n++]=63&o|128)}return t},l={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray:function(e,t){if(!Array.isArray(e))throw Error("encodeByteArray takes an array as a parameter");this.init_();for(var n=t?this.byteToCharMapWebSafe_:this.byteToCharMap_,r=[],o=0;o>2,d=(3&i)<<4|s>>4,f=(15&s)<<2|u>>6,p=63&u;l||(p=64,a||(f=64)),r.push(n[c],n[d],n[f],n[p])}return r.join("")},encodeString:function(e,t){return this.HAS_NATIVE_SUPPORT&&!t?btoa(e):this.encodeByteArray(s(e),t)},decodeString:function(e,t){return this.HAS_NATIVE_SUPPORT&&!t?atob(e):function(e){for(var t=[],n=0,r=0;n191&&o<224){var i=e[n++];t[r++]=String.fromCharCode((31&o)<<6|63&i)}else if(o>239&&o<365){var a=((7&o)<<18|(63&(i=e[n++]))<<12|(63&(s=e[n++]))<<6|63&e[n++])-65536;t[r++]=String.fromCharCode(55296+(a>>10)),t[r++]=String.fromCharCode(56320+(1023&a))}else{i=e[n++];var s=e[n++];t[r++]=String.fromCharCode((15&o)<<12|(63&i)<<6|63&s)}}return t.join("")}(this.decodeStringToByteArray(e,t))},decodeStringToByteArray:function(e,t){this.init_();for(var n=t?this.charToByteMapWebSafe_:this.charToByteMap_,r=[],o=0;o>4;if(r.push(u),64!=s){var c=a<<4&240|s>>2;if(r.push(c),64!=l){var d=s<<6&192|l;r.push(d)}}}return r},init_:function(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(var e=0;e=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(e)]=e,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(e)]=e)}}},u=function(e){try{return l.decodeString(e,!0)}catch(e){console.error("base64Decode failed: ",e)}return null};function c(e,t){if(!(t instanceof Object))return t;switch(t.constructor){case Date:return new Date(t.getTime());case Object:void 0===e&&(e={});break;case Array:e=[];break;default:return t}for(var n in t)t.hasOwnProperty(n)&&(e[n]=c(e[n],t[n]));return e}var d=function(){function e(){var e=this;this.promise=new Promise(function(t,n){e.resolve=t,e.reject=n})}return e.prototype.wrapCallback=function(e){var t=this;return function(n,r){n?t.reject(n):t.resolve(r),"function"==typeof e&&(t.promise.catch(function(){}),1===e.length?e(n):e(n,r))}},e}(),f=function(){return"undefined"!=typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:""},p="FirebaseError",h=Error.captureStackTrace;var m=function(){return function(e,t){if(this.code=e,this.message=t,h)h(this,y.prototype.create);else try{throw Error.apply(this,arguments)}catch(e){this.name=p,Object.defineProperty(this,"stack",{get:function(){return e.stack}})}}}();m.prototype=Object.create(Error.prototype),m.prototype.constructor=m,m.prototype.name=p;var y=function(){function e(e,t,n){this.service=e,this.serviceName=t,this.errors=n,this.pattern=/\{\$([^}]+)}/g}return e.prototype.create=function(e,t){void 0===t&&(t={});var n,r=this.errors[e],o=this.service+"/"+e;n=void 0===r?"Error":r.replace(this.pattern,function(e,n){var r=t[n];return void 0!==r?r.toString():"<"+n+"?>"}),n=this.serviceName+": "+n+" ("+o+").";var i=new m(o,n);for(var a in t)t.hasOwnProperty(a)&&"_"!==a.slice(-1)&&(i[a]=t[a]);return i},e}();function v(e){return JSON.parse(e)}var g=function(e){var t={},n={},r={},o="";try{var i=e.split(".");t=v(u(i[0])||""),n=v(u(i[1])||""),o=i[2],r=n.d||{},delete n.d}catch(e){}return{header:t,claims:n,data:r,signature:o}},b=function(e,t){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t(n,e[n])},_=function(e,t){return b(t,function(t,n){e[t]=n}),e},w=function(e,t,n){for(var r in e)if(t.call(n,e[r],r,e))return r},E=function(e){function t(){var t=e.call(this)||this;t.chain_=[],t.buf_=[],t.W_=[],t.pad_=[],t.inbuf_=0,t.total_=0,t.blockSize=64,t.pad_[0]=128;for(var n=1;n>>31)}var i,a,s=this.chain_[0],l=this.chain_[1],u=this.chain_[2],c=this.chain_[3],d=this.chain_[4];for(r=0;r<80;r++){r<40?r<20?(i=c^l&(u^c),a=1518500249):(i=l^u^c,a=1859775393):r<60?(i=l&u|c&(l|u),a=2400959708):(i=l^u^c,a=3395469782);o=(s<<5|s>>>27)+i+d+a+n[r]&4294967295;d=c,c=u,u=4294967295&(l<<30|l>>>2),l=s,s=o}this.chain_[0]=this.chain_[0]+s&4294967295,this.chain_[1]=this.chain_[1]+l&4294967295,this.chain_[2]=this.chain_[2]+u&4294967295,this.chain_[3]=this.chain_[3]+c&4294967295,this.chain_[4]=this.chain_[4]+d&4294967295},t.prototype.update=function(e,t){if(null!=e){void 0===t&&(t=e.length);for(var n=t-this.blockSize,r=0,o=this.buf_,i=this.inbuf_;r=56;n--)this.buf_[n]=255&t,t/=256;this.compress_(this.buf_);var r=0;for(n=0;n<5;n++)for(var o=24;o>=0;o-=8)e[r]=this.chain_[n]>>o&255,++r;return e},t}(function(){return function(){this.blockSize=-1}}());var S=function(){function e(e,t){var n=this;this.observers=[],this.unsubscribes=[],this.observerCount=0,this.task=Promise.resolve(),this.finalized=!1,this.onNoObservers=t,this.task.then(function(){e(n)}).catch(function(e){n.error(e)})}return e.prototype.next=function(e){this.forEachObserver(function(t){t.next(e)})},e.prototype.error=function(e){this.forEachObserver(function(t){t.error(e)}),this.close(e)},e.prototype.complete=function(){this.forEachObserver(function(e){e.complete()}),this.close()},e.prototype.subscribe=function(e,t,n){var r,o=this;if(void 0===e&&void 0===t&&void 0===n)throw new Error("Missing Observer.");void 0===(r=function(e,t){if("object"!=typeof e||null===e)return!1;for(var n=0,r=t;n 4. Need to update it?")}var o=e+" failed: ";return o+=r+" argument "}t.assert=i,t.assertionError=a,t.base64=l,t.base64Decode=u,t.base64Encode=function(e){var t=s(e);return l.encodeByteArray(t,!0)},t.CONSTANTS=o,t.deepCopy=function(e){return c(void 0,e)},t.deepExtend=c,t.patchProperty=function(e,t,n){e[t]=n},t.Deferred=d,t.getUA=f,t.isMobileCordova=function(){return"undefined"!=typeof window&&!!(window.cordova||window.phonegap||window.PhoneGap)&&/ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test(f())},t.isNodeSdk=function(){return!0===o.NODE_CLIENT||!0===o.NODE_ADMIN},t.isReactNative=function(){return"object"==typeof navigator&&"ReactNative"===navigator.product},t.ErrorFactory=y,t.FirebaseError=m,t.patchCapture=function(e){var t=h;return h=e,t},t.jsonEval=v,t.stringify=function(e){return JSON.stringify(e)},t.decode=g,t.isAdmin=function(e){var t=g(e).claims;return"object"==typeof t&&!0===t.admin},t.issuedAtTime=function(e){var t=g(e).claims;return"object"==typeof t&&t.hasOwnProperty("iat")?t.iat:null},t.isValidFormat=function(e){var t=g(e).claims;return!!t&&"object"==typeof t&&t.hasOwnProperty("iat")},t.isValidTimestamp=function(e){var t,n,r=g(e).claims,o=Math.floor((new Date).getTime()/1e3);return"object"==typeof r&&(r.hasOwnProperty("nbf")?t=r.nbf:r.hasOwnProperty("iat")&&(t=r.iat),n=r.hasOwnProperty("exp")?r.exp:t+86400),o&&t&&n&&o>=t&&o<=n},t.clone=function(e){return _({},e)},t.contains=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.every=function(e,t){for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)&&!t(n,e[n]))return!1;return!0},t.extend=_,t.findKey=w,t.findValue=function(e,t,n){var r=w(e,t,n);return r&&e[r]},t.forEach=b,t.getAnyKey=function(e){for(var t in e)return t},t.getCount=function(e){var t=0;for(var n in e)t++;return t},t.getValues=function(e){var t=[],n=0;for(var r in e)t[n++]=e[r];return t},t.isEmpty=function(e){for(var t in e)return!1;return!0},t.isNonNullObject=function(e){return"object"==typeof e&&null!==e},t.map=function(e,t,n){var r={};for(var o in e)r[o]=t.call(n,e[o],o,e);return r},t.safeGet=function(e,t){if(Object.prototype.hasOwnProperty.call(e,t))return e[t]},t.querystring=function(e){var t=[];return b(e,function(e,n){Array.isArray(n)?n.forEach(function(n){t.push(encodeURIComponent(e)+"="+encodeURIComponent(n))}):t.push(encodeURIComponent(e)+"="+encodeURIComponent(n))}),t.length?"&"+t.join("&"):""},t.querystringDecode=function(e){var t={};return e.replace(/^\?/,"").split("&").forEach(function(e){if(e){var n=e.split("=");t[n[0]]=n[1]}}),t},t.Sha1=E,t.async=function(e,t){return function(){for(var n=[],r=0;rn&&(o=0===n?"none":"no more than "+n),o)throw new Error(e+" failed: Was called with "+r+(1===r?" argument.":" arguments.")+" Expects "+o+".")},t.validateCallback=function(e,t,n,r){if((!r||n)&&"function"!=typeof n)throw new Error(k(e,t,r)+"must be a valid function.")},t.validateContextObject=function(e,t,n,r){if((!r||n)&&("object"!=typeof n||null===n))throw new Error(k(e,t,r)+"must be a valid context object.")},t.validateNamespace=function(e,t,n,r){if((!r||n)&&"string"!=typeof n)throw new Error(k(e,t,r)+"must be a valid firebase namespace.")},t.stringLength=function(e){for(var t=0,n=0;n=55296&&r<=56319?(t+=4,n++):t+=3}return t},t.stringToByteArray=function(e){for(var t=[],n=0,r=0;r=55296&&o<=56319){var a=o-55296;i(++r>6|192,t[n++]=63&o|128):o<65536?(t[n++]=o>>12|224,t[n++]=o>>6&63|128,t[n++]=63&o|128):(t[n++]=o>>18|240,t[n++]=o>>12&63|128,t[n++]=o>>6&63|128,t[n++]=63&o|128)}return t}},function(e,t,n){"use strict";e.exports=function(e,t,n,r,o,i,a,s){if(!e){var l;if(void 0===t)l=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{var u=[n,r,o,i,a,s],c=0;(l=new Error(t.replace(/%s/g,function(){return u[c++]}))).name="Invariant Violation"}throw l.framesToPop=1,l}}},function(e,t){var n;n=function(){return this}();try{n=n||Function("return this")()||(0,eval)("this")}catch(e){"object"==typeof window&&(n=window)}e.exports=n},function(e){e.exports={en:{contacts_not_found:"You have no chats
¯\\\\_(ツ)_/¯",full_name_prompt:"Full name, e.g. John Doe",email_prompt:"Email, e.g. jdoe@example.com",button_sign_up:"Sign up",label_your_name:"Your name",label_password:"Password",password_unchanged_prompt:"Unchanged",label_user_id:"Address:",label_default_access_mode:"Default access mode:",label_message_sound:"Message sound:",label_push_notifications:"Notification alerts:",label_push_notifications_disabled:"Notification alerts (requires HTTPS):",title_tag_manager:"Tags (user discovery)",button_logout:"Logout",login_prompt:"Login",password_prompt:"Password",stay_logged_in:"Stay logged in",forgot_password_link:"Forgot password?",button_sign_in:"Sign in",label_client:"Client:",label_server:"Server:",online_now:"online now",last_seen_timestamp:"Last seen",title_not_found:"Not found",unnamed_topic:"Unnamed",messages_not_readable:"no access to messages",tabtitle_find_user:"find",tabtitle_new_group:"new group",tabtitle_group_by_id:"by id",search_for_contacts:"Use search to find contacts",label_server_to_use:"Server to use:",label_wire_transport:"Wire transport:",button_update:"Update",sidepanel_title_login:"Sign In",sidepanel_title_register:"Create Account",sidepanel_title_settings:"Settings",sidepanel_title_edit_account:"Edit Account",sidepanel_title_newtpk:"Start New Chat",sidepanel_title_cred:"Confirm Credentials",sidepanel_title_reset:"Reset Password",phone:"phone",email:"email",enter_confirmation_code_prompt:"Enter confirmation code sent to you by {method}:",numeric_confirmation_code_prompt:"Numbers only",button_confirm:"Confirm",invalid_content:"invalid content",button_ok:"OK",button_cancel:"Cancel",label_file_name:"File name:",label_content_type:"Content type:",label_size:"Size:",message_sending:"sending...",message_sending_failed:"failed",search_placeholder:"List like email:alice@example.com, tel:17025550003...",messaging_disabled_prompt:"Messaging disabled",new_message_prompt:"New message",file_attachment_too_large:"The file size {size} exceeds the {limit} limit.",cannot_initiate_file_upload:"Cannot initiate file upload.",tags_not_found:"No tags defined. Add some.",tags_editor_no_tags:"Add some tags",title_manage_tags:"Manage tags"},ru:{contacts_not_found:"Чатов нет
¯\\\\_(ツ)_/¯",full_name_prompt:"Полное имя, напр. Иван Петров",email_prompt:"Email, напр. ivan@example.com",button_sign_up:"Создать счет",label_your_name:"Ваше имя",label_password:"Пароль",password_unchanged_prompt:"Не изменен",label_user_id:"Адрес:",label_default_access_mode:"Доступ по умолчанию:",label_message_sound:"Звук нового сообщения:",label_push_notifications:"Уведомления:",label_push_notifications_disabled:"Уведомления (требуют HTTPS):",title_tag_manager:"Таги для поиска",button_logout:"Выйти",login_prompt:"Логин",password_prompt:"Пароль",stay_logged_in:"Запомнить",forgot_password_link:"Напомнить пароль",button_sign_in:"Войти",label_client:"Клиент:",label_server:"Сервер:",online_now:"онлайн",last_seen_timestamp:"Был активен",title_not_found:"Не найден",unnamed_topic:"Без названия",messages_not_readable:"нет доступа к сообщениям",tabtitle_find_user:"найти",tabtitle_new_group:"создать",tabtitle_group_by_id:"по id",label_server_to_use:"Использовать сервер:",label_wire_transport:"Соединение:",button_update:"Применить",sidepanel_title_login:"Авторизация",sidepanel_title_register:"Зарегистрироваться",sidepanel_title_settings:"Настройки",sidepanel_title_edit_account:"Редактировать счет",sidepanel_title_newtpk:"Новый чат",sidepanel_title_cred:"Подтвердить",sidepanel_title_reset:"Сменить пароль",tags_not_found:"Тагов нет. Добавьте",tags_editor_no_tags:"Добавьте таги",title_manage_tags:"Редактор тагов",message_sending:"шлём...",message_sending_failed:"ошибка",search_placeholder:"Список, напр. email:alice@example.com, tel:17025550003...",messaging_disabled_prompt:"Отправка недоступна",new_message_prompt:"Новое сообщение",file_attachment_too_large:"Размер файла {size} превышает {limit} лимит.",cannot_initiate_file_upload:"Ошибка загрузки файла."}}},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var r=n(8),o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i="[DEFAULT]",a=[],s=function(){function e(e,t,n){this.firebase_=n,this.isDeleted_=!1,this.services_={},this.name_=t.name,this._automaticDataCollectionEnabled=t.automaticDataCollectionEnabled||!1,this.options_=r.deepCopy(e),this.INTERNAL={getUid:function(){return null},getToken:function(){return Promise.resolve(null)},addAuthTokenListener:function(e){a.push(e),setTimeout(function(){return e(null)},0)},removeAuthTokenListener:function(e){a=a.filter(function(t){return t!==e})}}}return Object.defineProperty(e.prototype,"automaticDataCollectionEnabled",{get:function(){return this.checkDestroyed_(),this._automaticDataCollectionEnabled},set:function(e){this.checkDestroyed_(),this._automaticDataCollectionEnabled=e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"name",{get:function(){return this.checkDestroyed_(),this.name_},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"options",{get:function(){return this.checkDestroyed_(),this.options_},enumerable:!0,configurable:!0}),e.prototype.delete=function(){var e=this;return new Promise(function(t){e.checkDestroyed_(),t()}).then(function(){e.firebase_.INTERNAL.removeApp(e.name_);var t=[];return Object.keys(e.services_).forEach(function(n){Object.keys(e.services_[n]).forEach(function(r){t.push(e.services_[n][r])})}),Promise.all(t.map(function(e){return e.INTERNAL.delete()}))}).then(function(){e.isDeleted_=!0,e.services_={}})},e.prototype._getService=function(e,t){if(void 0===t&&(t=i),this.checkDestroyed_(),this.services_[e]||(this.services_[e]={}),!this.services_[e][t]){var n=t!==i?t:void 0,r=this.firebase_.INTERNAL.factories[e](this,this.extendApp.bind(this),n);this.services_[e][t]=r}return this.services_[e][t]},e.prototype.extendApp=function(e){var t=this;r.deepExtend(this,e),e.INTERNAL&&e.INTERNAL.addAuthTokenListener&&(a.forEach(function(e){t.INTERNAL.addAuthTokenListener(e)}),a=[])},e.prototype.checkDestroyed_=function(){this.isDeleted_&&l("app-deleted",{name:this.name_})},e}();function l(e,t){throw u.create(e,t)}s.prototype.name&&s.prototype.options||s.prototype.delete||console.log("dc");var u=new r.ErrorFactory("app","Firebase",{"no-app":"No Firebase App '{$name}' has been created - call Firebase App.initializeApp()","bad-app-name":"Illegal App name: '{$name}","duplicate-app":"Firebase App named '{$name}' already exists","app-deleted":"Firebase App named '{$name}' already deleted","duplicate-service":"Firebase service named '{$name}' already registered","sa-not-supported":"Initializing the Firebase SDK with a service account is only allowed in a Node.js environment. On client devices, you should instead initialize the SDK with an api key and auth domain","invalid-app-argument":"firebase.{$name}() takes either no argument or a Firebase App instance."}),c=function e(){var t={},n={},a={},u={__esModule:!0,initializeApp:function(e,n){if(void 0===n&&(n={}),"object"!=typeof n||null===n){var r=n;n={name:r}}var a=n;void 0===a.name&&(a.name=i);var c=a.name;"string"==typeof c&&c||l("bad-app-name",{name:c+""}),o(t,c)&&l("duplicate-app",{name:c});var d=new s(e,a,u);return t[c]=d,f(d,"create"),d},app:c,apps:null,Promise:Promise,SDK_VERSION:"5.5.0",INTERNAL:{registerService:function(e,t,o,i,f){n[e]&&l("duplicate-service",{name:e}),n[e]=t,i&&(a[e]=i,d().forEach(function(e){i("create",e)}));var p=function(t){return void 0===t&&(t=c()),"function"!=typeof t[e]&&l("invalid-app-argument",{name:e}),t[e]()};return void 0!==o&&r.deepExtend(p,o),u[e]=p,s.prototype[e]=function(){for(var t=[],n=0;n=2&&i<=4&&(a<12||a>14)?"few":o&&0==i||o&&i>=5&&i<=9||o&&a>=11&&a<=14?"many":"other"},fields:{year:{displayName:"год",relative:{0:"в этом году",1:"в следующем году","-1":"в прошлом году"},relativeTime:{future:{one:"через {0} год",few:"через {0} года",many:"через {0} лет",other:"через {0} года"},past:{one:"{0} год назад",few:"{0} года назад",many:"{0} лет назад",other:"{0} года назад"}}},month:{displayName:"месяц",relative:{0:"в этом месяце",1:"в следующем месяце","-1":"в прошлом месяце"},relativeTime:{future:{one:"через {0} месяц",few:"через {0} месяца",many:"через {0} месяцев",other:"через {0} месяца"},past:{one:"{0} месяц назад",few:"{0} месяца назад",many:"{0} месяцев назад",other:"{0} месяца назад"}}},day:{displayName:"день",relative:{0:"сегодня",1:"завтра",2:"послезавтра","-2":"позавчера","-1":"вчера"},relativeTime:{future:{one:"через {0} день",few:"через {0} дня",many:"через {0} дней",other:"через {0} дня"},past:{one:"{0} день назад",few:"{0} дня назад",many:"{0} дней назад",other:"{0} дня назад"}}},hour:{displayName:"час",relative:{0:"в этом часе"},relativeTime:{future:{one:"через {0} час",few:"через {0} часа",many:"через {0} часов",other:"через {0} часа"},past:{one:"{0} час назад",few:"{0} часа назад",many:"{0} часов назад",other:"{0} часа назад"}}},minute:{displayName:"минута",relative:{0:"в эту минуту"},relativeTime:{future:{one:"через {0} минуту",few:"через {0} минуты",many:"через {0} минут",other:"через {0} минуты"},past:{one:"{0} минуту назад",few:"{0} минуты назад",many:"{0} минут назад",other:"{0} минуты назад"}}},second:{displayName:"секунда",relative:{0:"сейчас"},relativeTime:{future:{one:"через {0} секунду",few:"через {0} секунды",many:"через {0} секунд",other:"через {0} секунды"},past:{one:"{0} секунду назад",few:"{0} секунды назад",many:"{0} секунд назад",other:"{0} секунды назад"}}}}},{locale:"ru-BY",parentLocale:"ru"},{locale:"ru-KG",parentLocale:"ru"},{locale:"ru-KZ",parentLocale:"ru"},{locale:"ru-MD",parentLocale:"ru"},{locale:"ru-UA",parentLocale:"ru"}]}()},function(e,t,n){e.exports=n(47)},function(e,t,n){"use strict"; /** @license React v16.5.2 * react.production.min.js * * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */var r=n(13),o="function"==typeof Symbol&&Symbol.for,i=o?Symbol.for("react.element"):60103,a=o?Symbol.for("react.portal"):60106,s=o?Symbol.for("react.fragment"):60107,l=o?Symbol.for("react.strict_mode"):60108,u=o?Symbol.for("react.profiler"):60114,c=o?Symbol.for("react.provider"):60109,d=o?Symbol.for("react.context"):60110,f=o?Symbol.for("react.async_mode"):60111,p=o?Symbol.for("react.forward_ref"):60112;o&&Symbol.for("react.placeholder");var h="function"==typeof Symbol&&Symbol.iterator;function m(e){for(var t=arguments.length-1,n="https://reactjs.org/docs/error-decoder.html?invariant="+e,r=0;rP.length&&P.push(e)}function M(e,t,n){return null==e?0:function e(t,n,r,o){var s=typeof t;"undefined"!==s&&"boolean"!==s||(t=null);var l=!1;if(null===t)l=!0;else switch(s){case"string":case"number":l=!0;break;case"object":switch(t.$$typeof){case i:case a:l=!0}}if(l)return r(o,t,""===n?"."+A(t,0):n),1;if(l=0,n=""===n?".":n+":",Array.isArray(t))for(var u=0;uthis.eventPool.length&&this.eventPool.push(e)}function pe(e){e.eventPool=[],e.getPooled=de,e.release=fe}o(ce.prototype,{preventDefault:function(){this.defaultPrevented=!0;var e=this.nativeEvent;e&&(e.preventDefault?e.preventDefault():"unknown"!=typeof e.returnValue&&(e.returnValue=!1),this.isDefaultPrevented=le)},stopPropagation:function(){var e=this.nativeEvent;e&&(e.stopPropagation?e.stopPropagation():"unknown"!=typeof e.cancelBubble&&(e.cancelBubble=!0),this.isPropagationStopped=le)},persist:function(){this.isPersistent=le},isPersistent:ue,destructor:function(){var e,t=this.constructor.Interface;for(e in t)this[e]=null;this.nativeEvent=this._targetInst=this.dispatchConfig=null,this.isPropagationStopped=this.isDefaultPrevented=ue,this._dispatchInstances=this._dispatchListeners=null}}),ce.Interface={type:null,target:null,currentTarget:function(){return null},eventPhase:null,bubbles:null,cancelable:null,timeStamp:function(e){return e.timeStamp||Date.now()},defaultPrevented:null,isTrusted:null},ce.extend=function(e){function t(){}function n(){return r.apply(this,arguments)}var r=this;t.prototype=r.prototype;var i=new t;return o(i,n.prototype),n.prototype=i,n.prototype.constructor=n,n.Interface=o({},r.Interface,e),n.extend=r.extend,pe(n),n},pe(ce);var he=ce.extend({data:null}),me=ce.extend({data:null}),ye=[9,13,27,32],ve=G&&"CompositionEvent"in window,ge=null;G&&"documentMode"in document&&(ge=document.documentMode);var be=G&&"TextEvent"in window&&!ge,_e=G&&(!ve||ge&&8=ge),we=String.fromCharCode(32),Ee={beforeInput:{phasedRegistrationNames:{bubbled:"onBeforeInput",captured:"onBeforeInputCapture"},dependencies:["compositionend","keypress","textInput","paste"]},compositionEnd:{phasedRegistrationNames:{bubbled:"onCompositionEnd",captured:"onCompositionEndCapture"},dependencies:"blur compositionend keydown keypress keyup mousedown".split(" ")},compositionStart:{phasedRegistrationNames:{bubbled:"onCompositionStart",captured:"onCompositionStartCapture"},dependencies:"blur compositionstart keydown keypress keyup mousedown".split(" ")},compositionUpdate:{phasedRegistrationNames:{bubbled:"onCompositionUpdate",captured:"onCompositionUpdateCapture"},dependencies:"blur compositionupdate keydown keypress keyup mousedown".split(" ")}},Se=!1;function Te(e,t){switch(e){case"keyup":return-1!==ye.indexOf(t.keyCode);case"keydown":return 229!==t.keyCode;case"keypress":case"mousedown":case"blur":return!0;default:return!1}}function ke(e){return"object"==typeof(e=e.detail)&&"data"in e?e.data:null}var Ce=!1;var Oe={eventTypes:Ee,extractEvents:function(e,t,n,r){var o=void 0,i=void 0;if(ve)e:{switch(e){case"compositionstart":o=Ee.compositionStart;break e;case"compositionend":o=Ee.compositionEnd;break e;case"compositionupdate":o=Ee.compositionUpdate;break e}o=void 0}else Ce?Te(e,n)&&(o=Ee.compositionEnd):"keydown"===e&&229===n.keyCode&&(o=Ee.compositionStart);return o?(_e&&"ko"!==n.locale&&(Ce||o!==Ee.compositionStart?o===Ee.compositionEnd&&Ce&&(i=se()):(ie="value"in(oe=r)?oe.value:oe.textContent,Ce=!0)),o=he.getPooled(o,t,n,r),i?o.data=i:null!==(i=ke(n))&&(o.data=i),z(o),i=o):i=null,(e=be?function(e,t){switch(e){case"compositionend":return ke(t);case"keypress":return 32!==t.which?null:(Se=!0,we);case"textInput":return(e=t.data)===we&&Se?null:e;default:return null}}(e,n):function(e,t){if(Ce)return"compositionend"===e||!ve&&Te(e,t)?(e=se(),ae=ie=oe=null,Ce=!1,e):null;switch(e){case"paste":return null;case"keypress":if(!(t.ctrlKey||t.altKey||t.metaKey)||t.ctrlKey&&t.altKey){if(t.char&&1