@onyx-p/imlib-web 1.0.17 → 1.0.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -34,4 +34,4 @@ return function(t){var r=e,n=r.lib,o=n.WordArray,i=n.Hasher,s=r.algo,a=o.create(
34
34
  * limitations under the License.
35
35
  *
36
36
  * SPDX-License-Identifier: Apache-2.0
37
- */var tn=null;try{tn=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function rn(e,t,r){this.low=0|e,this.high=0|t,this.unsigned=!!r}function nn(e){return!0===(e&&e.__isLong__)}function on(e){var t=Math.clz32(e&-e);return e?31-t:t}rn.prototype.__isLong__,Object.defineProperty(rn.prototype,"__isLong__",{value:!0}),rn.isLong=nn;var sn={},an={};function cn(e,t){var r,n,o;return t?(o=0<=(e>>>=0)&&e<256)&&(n=an[e])?n:(r=un(e,0,!0),o&&(an[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=sn[e])?n:(r=un(e,e<0?-1:0,!1),o&&(sn[e]=r),r)}function ln(e,t){if(isNaN(e))return t?bn:mn;if(t){if(e<0)return bn;if(e>=gn)return Sn}else{if(e<=-yn)return In;if(e+1>=yn)return _n}return e<0?ln(-e,t).neg():un(e%pn|0,e/pn|0,t)}function un(e,t,r){return new rn(e,t,r)}rn.fromInt=cn,rn.fromNumber=ln,rn.fromBits=un;var dn=Math.pow;function hn(e,t,r){if(0===e.length)throw Error("empty string");if("number"==typeof t?(r=t,t=!1):t=!!t,"NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return t?bn:mn;if((r=r||10)<2||36<r)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return hn(e.substring(1),t,r).neg();for(var o=ln(dn(r,8)),i=mn,s=0;s<e.length;s+=8){var a=Math.min(8,e.length-s),c=parseInt(e.substring(s,s+a),r);if(a<8){var l=ln(dn(r,a));i=i.mul(l).add(ln(c))}else i=(i=i.mul(o)).add(ln(c))}return i.unsigned=t,i}function fn(e,t){return"number"==typeof e?ln(e,t):"string"==typeof e?hn(e,t):un(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}rn.fromString=hn,rn.fromValue=fn;var pn=4294967296,gn=pn*pn,yn=gn/2,vn=cn(1<<24),mn=cn(0);rn.ZERO=mn;var bn=cn(0,!0);rn.UZERO=bn;var wn=cn(1);rn.ONE=wn;var On=cn(1,!0);rn.UONE=On;var Cn=cn(-1);rn.NEG_ONE=Cn;var _n=un(-1,2147483647,!1);rn.MAX_VALUE=_n;var Sn=un(-1,-1,!0);rn.MAX_UNSIGNED_VALUE=Sn;var In=un(0,-2147483648,!1);rn.MIN_VALUE=In;var En=rn.prototype;En.toInt=function(){return this.unsigned?this.low>>>0:this.low},En.toNumber=function(){return this.unsigned?(this.high>>>0)*pn+(this.low>>>0):this.high*pn+(this.low>>>0)},En.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(In)){var t=ln(e),r=this.div(t),n=r.mul(t).sub(this);return r.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var o=ln(dn(e,6),this.unsigned),i=this,s="";;){var a=i.div(o),c=(i.sub(a.mul(o)).toInt()>>>0).toString(e);if((i=a).isZero())return c+s;for(;c.length<6;)c="0"+c;s=""+c+s}},En.getHighBits=function(){return this.high},En.getHighBitsUnsigned=function(){return this.high>>>0},En.getLowBits=function(){return this.low},En.getLowBitsUnsigned=function(){return this.low>>>0},En.getNumBitsAbs=function(){if(this.isNegative())return this.eq(In)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},En.isZero=function(){return 0===this.high&&0===this.low},En.eqz=En.isZero,En.isNegative=function(){return!this.unsigned&&this.high<0},En.isPositive=function(){return this.unsigned||this.high>=0},En.isOdd=function(){return 1==(1&this.low)},En.isEven=function(){return 0==(1&this.low)},En.equals=function(e){return nn(e)||(e=fn(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},En.eq=En.equals,En.notEquals=function(e){return!this.eq(e)},En.neq=En.notEquals,En.ne=En.notEquals,En.lessThan=function(e){return this.comp(e)<0},En.lt=En.lessThan,En.lessThanOrEqual=function(e){return this.comp(e)<=0},En.lte=En.lessThanOrEqual,En.le=En.lessThanOrEqual,En.greaterThan=function(e){return this.comp(e)>0},En.gt=En.greaterThan,En.greaterThanOrEqual=function(e){return this.comp(e)>=0},En.gte=En.greaterThanOrEqual,En.ge=En.greaterThanOrEqual,En.compare=function(e){if(nn(e)||(e=fn(e)),this.eq(e))return 0;var t=this.isNegative(),r=e.isNegative();return t&&!r?-1:!t&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},En.comp=En.compare,En.negate=function(){return!this.unsigned&&this.eq(In)?In:this.not().add(wn)},En.neg=En.negate,En.add=function(e){nn(e)||(e=fn(e));var t=this.high>>>16,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,c=0,l=0,u=0,d=0;return u+=(d+=o+(65535&e.low))>>>16,l+=(u+=n+a)>>>16,c+=(l+=r+s)>>>16,c+=t+i,un((u&=65535)<<16|(d&=65535),(c&=65535)<<16|(l&=65535),this.unsigned)},En.subtract=function(e){return nn(e)||(e=fn(e)),this.add(e.neg())},En.sub=En.subtract,En.multiply=function(e){if(this.isZero())return this;if(nn(e)||(e=fn(e)),tn)return un(tn.mul(this.low,this.high,e.low,e.high),tn.get_high(),this.unsigned);if(e.isZero())return this.unsigned?bn:mn;if(this.eq(In))return e.isOdd()?In:mn;if(e.eq(In))return this.isOdd()?In:mn;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(vn)&&e.lt(vn))return ln(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,c=65535&e.low,l=0,u=0,d=0,h=0;return d+=(h+=o*c)>>>16,u+=(d+=n*c)>>>16,d&=65535,u+=(d+=o*a)>>>16,l+=(u+=r*c)>>>16,u&=65535,l+=(u+=n*a)>>>16,u&=65535,l+=(u+=o*s)>>>16,l+=t*c+r*a+n*s+o*i,un((d&=65535)<<16|(h&=65535),(l&=65535)<<16|(u&=65535),this.unsigned)},En.mul=En.multiply,En.divide=function(e){if(nn(e)||(e=fn(e)),e.isZero())throw Error("division by zero");var t,r,n;if(tn)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?un((this.unsigned?tn.div_u:tn.div_s)(this.low,this.high,e.low,e.high),tn.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?bn:mn;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return bn;if(e.gt(this.shru(1)))return On;n=bn}else{if(this.eq(In))return e.eq(wn)||e.eq(Cn)?In:e.eq(In)?wn:(t=this.shr(1).div(e).shl(1)).eq(mn)?e.isNegative()?wn:Cn:(r=this.sub(e.mul(t)),n=t.add(r.div(e)));if(e.eq(In))return this.unsigned?bn:mn;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();n=mn}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var o=Math.ceil(Math.log(t)/Math.LN2),i=o<=48?1:dn(2,o-48),s=ln(t),a=s.mul(e);a.isNegative()||a.gt(r);)a=(s=ln(t-=i,this.unsigned)).mul(e);s.isZero()&&(s=wn),n=n.add(s),r=r.sub(a)}return n},En.div=En.divide,En.modulo=function(e){return nn(e)||(e=fn(e)),tn?un((this.unsigned?tn.rem_u:tn.rem_s)(this.low,this.high,e.low,e.high),tn.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},En.mod=En.modulo,En.rem=En.modulo,En.not=function(){return un(~this.low,~this.high,this.unsigned)},En.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},En.clz=En.countLeadingZeros,En.countTrailingZeros=function(){return this.low?on(this.low):on(this.high)+32},En.ctz=En.countTrailingZeros,En.and=function(e){return nn(e)||(e=fn(e)),un(this.low&e.low,this.high&e.high,this.unsigned)},En.or=function(e){return nn(e)||(e=fn(e)),un(this.low|e.low,this.high|e.high,this.unsigned)},En.xor=function(e){return nn(e)||(e=fn(e)),un(this.low^e.low,this.high^e.high,this.unsigned)},En.shiftLeft=function(e){return nn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?un(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):un(0,this.low<<e-32,this.unsigned)},En.shl=En.shiftLeft,En.shiftRight=function(e){return nn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?un(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):un(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},En.shr=En.shiftRight,En.shiftRightUnsigned=function(e){return nn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?un(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):un(32===e?this.high:this.high>>>e-32,0,this.unsigned)},En.shru=En.shiftRightUnsigned,En.shr_u=En.shiftRightUnsigned,En.rotateLeft=function(e){var t;return nn(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?un(this.high,this.low,this.unsigned):e<32?(t=32-e,un(this.low<<e|this.high>>>t,this.high<<e|this.low>>>t,this.unsigned)):(t=32-(e-=32),un(this.high<<e|this.low>>>t,this.low<<e|this.high>>>t,this.unsigned))},En.rotl=En.rotateLeft,En.rotateRight=function(e){var t;return nn(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?un(this.high,this.low,this.unsigned):e<32?(t=32-e,un(this.high<<t|this.low>>>e,this.low<<t|this.high>>>e,this.unsigned)):(t=32-(e-=32),un(this.low<<t|this.high>>>e,this.high<<t|this.low>>>e,this.unsigned))},En.rotr=En.rotateRight,En.toSigned=function(){return this.unsigned?un(this.low,this.high,!1):this},En.toUnsigned=function(){return this.unsigned?this:un(this.low,this.high,!0)},En.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},En.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},En.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},rn.fromBytes=function(e,t,r){return r?rn.fromBytesLE(e,t):rn.fromBytesBE(e,t)},rn.fromBytesLE=function(e,t){return new rn(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},rn.fromBytesBE=function(e,t){return new rn(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};const Tn={webSocketTimeout:5e3,signalTimeout:3e4,pingInterval:15e3,pingTimeout:5e3,pingFailedTimes:2,reconnectIntervalMin:250,reconnectIntervalMax:64e3,reconnectRaisingBase:2};const Rn=t=>e[t],kn=()=>{const e="ACDeviceId";let t="";const r=ft.get(e);return r?t=r:(t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),ft.set(e,t)),t},An=e=>{const t=new Yr;return t.writeIn8(67),t.writeIn8(255),t.writeInt32(e.length+7),t.writeArr(Array.from(e)),t.writeIn8(0),new Int8Array(t.getBytesArray()).buffer},Nn=e=>{const t=new Qr(new Uint8Array(e));t.readInt8(),t.readInt8();const r=t.readInt32(),n=t.readArr(r-7);if(t.readInt8(),e.byteLength!==r)throw new Error("packet resolve failed");return n};var xn=new class{constructor(t){d(this,"url",""),d(this,"watcher",void 0),d(this,"provider",void 0),d(this,"options",void 0),d(this,"socket",void 0),d(this,"status",e.DISCONNECTED),d(this,"autoReconnect",!1),d(this,"isAuthorized",!1),d(this,"profile",void 0),d(this,"responseCallbacks",new Map),d(this,"failedCount",0),d(this,"reconnectTimer",void 0),d(this,"token",""),d(this,"connectResolve",void 0),d(this,"idCount",0),this.options=Object.assign(Tn,t)}setServerInfo(e){this.url=e}setCallback(e,t){this.watcher=e,this.provider=t}async connect(r){return this.token=r,new Promise((r=>{this.connectResolve=r,this.open().then((e=>e===t.SUCCESS?!Ze(this.provider)||this.provider.needReAuth()?this.auth():t.SUCCESS:e)).then((n=>{var o;(r(n),n===t.SUCCESS)?(this.isAuthorized=!0,this.profile=null===(o=this.provider)||void 0===o?void 0:o.profile(),this.autoReconnect=!0,this.onConnect()):this.onDisconnect(n===t.TIMEOUT?e.NETWORK_UNAVAILABLE:e.WEBSOCKET_UNAVAILABLE)}))}))}async send(e,r,n){var o;let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.options.signalTimeout;const{code:s,data:a}=await this.sendRawData(e,Ze(r)&&Ze(n.encoder)?n.encoder.encode(r).finish():new Uint8Array,i);if(0!==s)return{code:s,msg:"time out",data:null};if(!Ze(a)||!Ze(n.decoder))return{code:t.SUCCESS,msg:""};const c=null===(o=n.decoder)||void 0===o?void 0:o.decode(a);return c.errorCode?{code:en(c.errorCode),msg:c.errorMessage,data:null}:{data:c,code:t.SUCCESS,msg:""}}async sendRawData(e,r){var n,o,i;let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.options.signalTimeout;if(!this.socket)return{code:t.RC_NET_CHANNEL_INVALID};if(!this.isAuthorized&&!this.isAuthCommand(e))return{code:t.RC_NET_CHANNEL_INVALID};const a=this.generateMessageSeq(),c={cmdId:e,messageSeq:rn.fromNumber(a),deviceId:(null===(n=this.profile)||void 0===n?void 0:n.deviceId)??rn.fromInt(7),sessionId:(null===(o=this.profile)||void 0===o?void 0:o.sessionId)??rn.ZERO,uid:(null===(i=this.profile)||void 0===i?void 0:i.uid)??rn.ZERO,protocolVersion:0,destId:"",body:r,token:this.token};mt.reqInfo(`websocket send -> cmd: 0x${e.toString(16)}, messageSeq: ${a}`),this.socket.send(An(zr.encode(c).finish()));const l=await new Promise((e=>{this.responseCallbacks.set(a,e),setTimeout((()=>{this.responseCallbacks.get(a)&&this.responseCallbacks.delete(a),e(null)}),s)}));return l?{code:0,data:l}:(mt.warn(`send timeout -> cmd: 0x${e.toString(16)}, messageSeq: ${a}, timeout: ${s}`),{code:t.TIMEOUT})}close(){var r;this.autoReconnect=!1,this.doClose(),this.setStatus(e.DISCONNECTED),null===(r=this.connectResolve)||void 0===r||r.call(this,t.RC_SOCKET_DISCONNECTED)}async open(){const r=this.url;mt.info(`conenct start -> ${r}`),this.setStatus(e.CONNECTING);const n=function(e,t){const r=new WebSocket(e,t);return r.binaryType="arraybuffer",{onClose(e){r.onclose=t=>{const{code:r,reason:n}=t;null==e||e(r,n)}},onError(e){r.onerror=t=>{e(t)}},onMessage(e){r.onmessage=t=>{e(t.data)}},onOpen(e){r.onopen=e},send(e){r.send(e)},close(e,t){r.close(e,t)}}}(this.url);this.socket=n;return await new Promise((o=>{n.onMessage((e=>{"ArrayBuffer"===Je(e)?this.onReceiveMessage(e):mt.error("Socket received invalid data:",e)})),n.onClose(((r,n)=>{mt.warn("websocket closed -> code:",r,"reason:",n),this.onDisconnect(e.CONNECTION_CLOSED),o(t.RC_SOCKET_DISCONNECTED)})),n.onError((r=>{mt.error("websocket error -> ",r),this.onDisconnect(e.WEBSOCKET_ERROR),o(t.RC_SOCKET_NOT_CREATED)})),n.onOpen((()=>{mt.info("websocket open -> ",r),o(t.SUCCESS)})),setTimeout((()=>{o(t.TIMEOUT)}),this.options.webSocketTimeout)}))}async auth(){var e,r,n,o;mt.info(`start auth -> ${this.token}`);const i={token:this.token,deviceType:7,imei:kn(),brand:"",model:"",apnsToken:"",bandId:""},{code:s,msg:a,data:c}=await this.send(At.Auth,i,{encoder:Vr,decoder:Xr.AuthSignIn2TokenResp},8e3);return s===t.SUCCESS||c?(mt.info("auth success -> ",null===(e=c.user)||void 0===e||null===(r=e.uid)||void 0===r?void 0:r.toString()),null===(n=this.watcher)||void 0===n||null===(o=n.onAuth)||void 0===o||o.call(n,c),t.SUCCESS):(mt.warn("auth failed -> "+a),t.RC_CONN_NOT_AUTHRORIZED)}async checkAlive(){if(!this.socket||!this.isAuthorized)return;mt.debug("send ping ->");const r={pingId:rn.ZERO,disconnectDelay:rn.ZERO},{code:n}=await this.send(At.Heartbean,r,{encoder:Kr},this.options.pingTimeout);n===t.SUCCESS?(mt.debug("recv pong <-"),this.failedCount=0,setTimeout((()=>this.checkAlive()),this.options.pingInterval)):(this.failedCount+=1,mt.warn(`ping failed count: ${this.failedCount}, code: ${n}`),this.failedCount>=this.options.pingFailedTimes?(this.failedCount=0,mt.warn("ping timeout, close current websocket to reconnect!"),this.onDisconnect(e.NETWORK_UNAVAILABLE)):this.checkAlive())}onReceiveMessage(t){let r;try{const e=Nn(t);r=Xr.NetworkResponse.decode(e)}catch(t){return mt.error("unpack payload error -> ",t),void this.onDisconnect(e.DISCONNECT_BY_SERVER)}if(r.code)return void this.onDisconnect(e.DISCONNECT_BY_SERVER);if(r.cmdId===At.SessionKilledPush)return void this.onDisconnect(e.KICKED_OFFLINE_BY_OTHER_CLIENT);if(r.cmdId===At.SignOutPish||r.cmdId===At.SignOutPish2)return void this.onDisconnect(e.DISCONNECT_BY_SERVER);if(r.cmdId===At.UserFrozenToLogin||r.cmdId===At.UserFrozenToLogin2)return void this.onDisconnect(e.BLOCKED);const n=rn.isLong(r.messageSeq)?r.messageSeq.toNumber():0;mt.reqInfo(`websocket recv ack -> messageSeq: ${n}`);const o=this.responseCallbacks.get(n);var i;Ze(o)?(o(r.body),this.responseCallbacks.delete(n)):(mt.reqInfo(`websocket recv -> cmd: 0x${r.cmdId.toString(16)}, messageSeq: ${n}`),null===(i=this.watcher)||void 0===i||i.message(r.cmdId,r.body))}async try2Reconnect(){this.reconnectTimer=setTimeout((()=>{this.reconnectTimer=null,this.connect(this.token)}),5e3)}onConnect(){this.setStatus(e.CONNECTED),this.checkAlive(),Ze(this.reconnectTimer)&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}onDisconnect(e){Ze(this.socket)&&(this.doClose(),this.isConnectionAvailable()&&(this.setStatus(e),this.autoReconnect&&this.isConnectionAvailable()&&this.try2Reconnect()))}doClose(){if(Ze(this.socket)){const e=this.socket;this.socket=null,e.onClose(null),e.close()}Ze(this.reconnectTimer)&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.isAuthorized=!1,this.profile=null;for(const e of this.responseCallbacks.values())e(null);this.responseCallbacks.clear()}isConnectionAvailable(){return this.status!==e.DISCONNECTED&&this.status!==e.KICKED_OFFLINE_BY_OTHER_CLIENT&&this.status!==e.BLOCKED&&this.status!==e.DISCONNECT_BY_SERVER}setStatus(e){var t;e!==this.status&&(mt.info(`socketServer is changing status from ${Rn(this.status)} to ${Rn(e)}`),this.status=e,null===(t=this.watcher)||void 0===t||t.status(e))}isAuthCommand(e){return e===At.Auth}generateMessageSeq(){return++this.idCount}};var Dn=new class{constructor(){d(this,"_user",void 0),this._user=this.createDefaultUser()}get uid(){return this.user.uid.toString()}get user(){return this._user}setLogged(e,t){const r=e.user;Ze(r)&&(this._user={active:!0,uid:r.uid??rn.UZERO,deviceId:e.deviceId,sessionId:e.sessionId,token:t})}logOut(){this._user=this.createDefaultUser()}createDefaultUser(){return{active:!1,uid:rn.UZERO,deviceId:rn.UZERO,sessionId:rn.UZERO,token:""}}},Mn=Nt.exports,Ln=Mn.Reader,Bn=Mn.util,Un=Mn.roots.default||(Mn.roots.default={});Un.NewMessageNotificationResp=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.NewMessageNotificationResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.seqno=e.int64();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/NewMessageNotificationResp"},e}(),Un.SendPrivateChatMessageResp=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.localId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msgId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msgSendTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.SendPrivateChatMessageResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.localId=e.int64();break;case 4:n.msgId=e.int64();break;case 5:n.msgSendTime=e.int64();break;case 6:n.seqno=e.int64();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendPrivateChatMessageResp"},e}(),Un.GetNewMessageResp=function(){function e(e){if(this.msg={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.offset=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msg=Bn.emptyObject,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetNewMessageResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:i.offset=e.int64();break;case 4:i.seqno=e.int64();break;case 5:i.msg===Bn.emptyObject&&(i.msg={});var a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.DialogMessageList.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.msg[r]=n;break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewMessageResp"},e}(),Un.DialogMessageList=function(){function e(e){if(this.dialogMessage=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.dialogMessage=Bn.emptyArray,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.DialogMessageList;e.pos<r;){var o=e.uint32();if(o>>>3==1)n.dialogMessage&&n.dialogMessage.length||(n.dialogMessage=[]),n.dialogMessage.push(Un.DialogMessage.decode(e,e.uint32()));else e.skipType(7&o)}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DialogMessageList"},e}(),Un.DialogMessage=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.msgId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.localId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msgStatus=0,e.prototype.srcId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.destId="",e.prototype.isOut=!1,e.prototype.senderCategory=0,e.prototype.msgCategory=0,e.prototype.msgPreContent="",e.prototype.msgPostContent="",e.prototype.mediaFlag=!1,e.prototype.mediaConstructor=0,e.prototype.mediaAttribute="",e.prototype.msgSendTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.burnAfterReadingFlag=!1,e.prototype.atFlag=!1,e.prototype.replyFlag=!1,e.prototype.referenceFlag=!1,e.prototype.msgIdReferenced=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.uploadFlag=!1,e.prototype.burnAfterReadingTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.sharingGroupFlag=!1,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.extra="",e.prototype.msgContent=Bn.newBuffer([]),e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.DialogMessage;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.msgId=e.int64();break;case 2:n.localId=e.int64();break;case 3:n.msgStatus=e.int32();break;case 4:n.srcId=e.int64();break;case 5:n.destId=e.string();break;case 6:n.isOut=e.bool();break;case 7:n.senderCategory=e.int32();break;case 8:n.msgCategory=e.int32();break;case 9:n.msgPreContent=e.string();break;case 10:n.msgPostContent=e.string();break;case 11:n.mediaFlag=e.bool();break;case 12:n.mediaConstructor=e.int32();break;case 13:n.mediaAttribute=e.string();break;case 14:n.msgSendTime=e.int64();break;case 15:n.burnAfterReadingFlag=e.bool();break;case 16:n.atFlag=e.bool();break;case 17:n.replyFlag=e.bool();break;case 18:n.referenceFlag=e.bool();break;case 19:n.msgIdReferenced=e.int64();break;case 20:n.uploadFlag=e.bool();break;case 21:n.burnAfterReadingTime=e.int64();break;case 22:n.sharingGroupFlag=e.bool();break;case 23:n.seqno=e.int64();break;case 24:n.extra=e.string();break;case 25:n.msgContent=e.bytes();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DialogMessage"},e}(),Un.GetBriefDialogListResp=function(){function e(e){if(this.notExistDestId=[],this.briefDialog={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.notExistDestId=Bn.emptyArray,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.briefDialog=Bn.emptyObject,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetBriefDialogListResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:if(i.notExistDestId&&i.notExistDestId.length||(i.notExistDestId=[]),2==(7&s))for(var a=e.uint32()+e.pos;e.pos<a;)i.notExistDestId.push(e.int64());else i.notExistDestId.push(e.int64());break;case 4:i.seqno=e.int64();break;case 5:i.briefDialog===Bn.emptyObject&&(i.briefDialog={});a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.BriefDialog.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.briefDialog[r]=n;break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetBriefDialogListResp"},e}(),Un.BriefDialog=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.dialogTitle="",e.prototype.smallAvatarUrl="",e.prototype.backgroundImage="",e.prototype.stickyFlag=!1,e.prototype.muteFlag=!1,e.prototype.blockFlag=!1,e.prototype.burnAfterReadingFlag=!1,e.prototype.takeScreenshotFlag=!1,e.prototype.groupFlag=!1,e.prototype.pushNotificationLevel=0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.BriefDialog;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.destId=e.string();break;case 2:n.dialogTitle=e.string();break;case 3:n.smallAvatarUrl=e.string();break;case 4:n.backgroundImage=e.string();break;case 5:n.stickyFlag=e.bool();break;case 6:n.muteFlag=e.bool();break;case 7:n.blockFlag=e.bool();break;case 8:n.burnAfterReadingFlag=e.bool();break;case 9:n.takeScreenshotFlag=e.bool();break;case 10:n.groupFlag=e.bool();break;case 15:n.pushNotificationLevel=e.int32();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/BriefDialog"},e}(),Un.GetDialogKeyResp=function(){function e(e){if(this.retryUid=[],this.entry={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.dialogKeyVersion=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.retryUid=Bn.emptyArray,e.prototype.entry=Bn.emptyObject,e.prototype.serverSign="",e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetDialogKeyResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:i.dialogKeyVersion=e.int64();break;case 4:if(i.retryUid&&i.retryUid.length||(i.retryUid=[]),2==(7&s))for(var a=e.uint32()+e.pos;e.pos<a;)i.retryUid.push(e.int64());else i.retryUid.push(e.int64());break;case 5:i.entry===Bn.emptyObject&&(i.entry={});a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.AesKeyAndIV.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.entry[r]=n;break;case 6:i.serverSign=e.string();break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetDialogKeyResp"},e}(),Un.AesKeyAndIV=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.aesKey="",e.prototype.aesIV="",e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.AesKeyAndIV;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.aesKey=e.string();break;case 2:n.aesIV=e.string();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/AesKeyAndIV"},e}(),Un.GetHistoryMessageResp=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.msg=null,e.prototype.isEnd=!1,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.GetHistoryMessageResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.msg=Un.DialogMessageList.decode(e,e.uint32());break;case 4:n.isEnd=e.bool();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetHistoryMessageResp"},e}(),Un.GetWebDialogListResp=function(){function e(e){if(this.fullDialog=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.fullDialog=Bn.emptyArray,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.GetWebDialogListResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.fullDialog&&n.fullDialog.length||(n.fullDialog=[]),n.fullDialog.push(Un.WebFullDialog.decode(e,e.uint32()));break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetWebDialogListResp"},e}(),Un.WebFullDialog=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.dialog=null,e.prototype.msg=null,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.WebFullDialog;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.dialog=Un.BriefDialog.decode(e,e.uint32());break;case 2:n.msg=Un.DialogMessage.decode(e,e.uint32());break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/WebFullDialog"},e}(),Un.GetNewSettingDialogListResp=function(){function e(e){if(this.briefDialog={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.briefDialog=Bn.emptyObject,e.prototype.setTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetNewSettingDialogListResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:i.briefDialog===Bn.emptyObject&&(i.briefDialog={});var a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.BriefDialog.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.briefDialog[r]=n;break;case 4:i.setTime=e.int64();break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewSettingDialogListResp"},e}();var jn=Un;var Pn=new class{constructor(){d(this,"_token",""),d(this,"_uploadUrl",""),d(this,"_downloadUrl",""),d(this,"_cert","")}set imInitToken(e){this._token=e}get imInitToken(){return this._token}get fileUploadUrl(){return this._uploadUrl}get cert(){return this._cert}get fileDownloadUrl(){return this._downloadUrl}setFileServerInfo(e,t,r){this._uploadUrl=e,this._downloadUrl=t,this._cert=r}getFileAbsoluteUri(e){return ot(e)?e.startsWith("http")?e:this.fileDownloadUrl+e:e}try2ExtractFileRelativeUri(e){return ot(e)&&e.startsWith(this.fileDownloadUrl)?e.substring(this.fileDownloadUrl.length):e}};const Fn=e=>{if(!ot(e.targetId+""))return"";switch(e.conversationType){case n.PRIVATE:return"P::"+e.targetId;case n.GROUP:return"G::"+e.targetId;case n.ULTRA_GROUP:return`SG::${e.targetId}_${e.channelId??""}`;default:return""}},Gn=e=>{if(!ot(e))return null;const t=e.split("::");if(2!==t.length)return null;const r=t[0];if("G"===r)return{conversationType:n.GROUP,targetId:t[1]};if("P"===r)return{conversationType:n.PRIVATE,targetId:t[1]};if("SG"===r){const e=t[1].indexOf("_");if(e>0){const r=t[1].substring(0,e),o=t[1].substring(e+1);return{conversationType:n.ULTRA_GROUP,targetId:r,channelId:o}}return 0===e?null:{conversationType:n.ULTRA_GROUP,targetId:t[1]}}return null},qn=e=>e.startsWith("SG")||e.startsWith("G");var Hn=Nt.exports,zn=Hn.Writer,Kn=Hn.util,Vn=Hn.roots.default||(Hn.roots.default={});Vn.SendPrivateChatMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.localId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.msgPreContent="",e.prototype.msgPostContent="",e.prototype.mediaFlag=!1,e.prototype.mediaConstructor=0,e.prototype.mediaAttribute="",e.prototype.extra="",e.prototype.thumbnail="",e.prototype.msgContent=Kn.newBuffer([]),e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.localId&&Object.hasOwnProperty.call(e,"localId")&&t.uint32(16).int64(e.localId),null!=e.msgPreContent&&Object.hasOwnProperty.call(e,"msgPreContent")&&t.uint32(26).string(e.msgPreContent),null!=e.msgPostContent&&Object.hasOwnProperty.call(e,"msgPostContent")&&t.uint32(34).string(e.msgPostContent),null!=e.mediaFlag&&Object.hasOwnProperty.call(e,"mediaFlag")&&t.uint32(40).bool(e.mediaFlag),null!=e.mediaConstructor&&Object.hasOwnProperty.call(e,"mediaConstructor")&&t.uint32(48).int32(e.mediaConstructor),null!=e.mediaAttribute&&Object.hasOwnProperty.call(e,"mediaAttribute")&&t.uint32(58).string(e.mediaAttribute),null!=e.extra&&Object.hasOwnProperty.call(e,"extra")&&t.uint32(66).string(e.extra),null!=e.thumbnail&&Object.hasOwnProperty.call(e,"thumbnail")&&t.uint32(74).string(e.thumbnail),null!=e.msgContent&&Object.hasOwnProperty.call(e,"msgContent")&&t.uint32(82).bytes(e.msgContent),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendPrivateChatMessageReq"},e}(),Vn.DeletePrivateChatDialogReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeletePrivateChatDialogReq"},e}(),Vn.GetNewMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.offset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.offset&&Object.hasOwnProperty.call(e,"offset")&&t.uint32(8).int64(e.offset),null!=e.rows&&Object.hasOwnProperty.call(e,"rows")&&t.uint32(16).int32(e.rows),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewMessageReq"},e}(),Vn.UpdatePrivateChatDialogStickyConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.stickyFlag=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.stickyFlag&&Object.hasOwnProperty.call(e,"stickyFlag")&&t.uint32(16).bool(e.stickyFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdatePrivateChatDialogStickyConfigReq"},e}(),Vn.UpdatePrivateChatDialogMuteConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.muteFlag=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.muteFlag&&Object.hasOwnProperty.call(e,"muteFlag")&&t.uint32(16).bool(e.muteFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdatePrivateChatDialogMuteConfigReq"},e}(),Vn.DeleteChatMessageReq=function(){function e(e){if(this.msgIdList=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.msgId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.msgIdList=Kn.emptyArray,e.encode=function(e,t){if(t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),null!=e.msgIdList&&e.msgIdList.length){t.uint32(26).fork();for(var r=0;r<e.msgIdList.length;++r)t.int64(e.msgIdList[r]);t.ldelim()}return t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeleteChatMessageReq"},e}(),Vn.DeletePrivateChatHistoryReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.msgId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeletePrivateChatHistoryReq"},e}(),Vn.CleanHistoryMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.type=0,e.prototype.msgTime=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.type&&Object.hasOwnProperty.call(e,"type")&&t.uint32(16).int32(e.type),null!=e.msgTime&&Object.hasOwnProperty.call(e,"msgTime")&&t.uint32(24).int64(e.msgTime),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/CleanHistoryMessageReq"},e}(),Vn.GetBriefDialogListReq=function(){function e(e){if(this.destId=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId=Kn.emptyArray,e.encode=function(e,t){if(t||(t=zn.create()),null!=e.destId&&e.destId.length)for(var r=0;r<e.destId.length;++r)t.uint32(10).string(e.destId[r]);return t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetBriefDialogListReq"},e}(),Vn.GetDialogKeyReq=function(){function e(e){if(this.destId=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId=Kn.emptyArray,e.prototype.clientSign="",e.encode=function(e,t){if(t||(t=zn.create()),null!=e.destId&&e.destId.length)for(var r=0;r<e.destId.length;++r)t.uint32(10).string(e.destId[r]);return null!=e.clientSign&&Object.hasOwnProperty.call(e,"clientSign")&&t.uint32(18).string(e.clientSign),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetDialogKeyReq"},e}(),Vn.RecallPrivateChatMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.msgId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/RecallPrivateChatMessageReq"},e}(),Vn.GetHistoryMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.dialogKeys="",e.prototype.offset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.oldOffset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.dialogKeys&&Object.hasOwnProperty.call(e,"dialogKeys")&&t.uint32(10).string(e.dialogKeys),null!=e.offset&&Object.hasOwnProperty.call(e,"offset")&&t.uint32(16).int64(e.offset),null!=e.oldOffset&&Object.hasOwnProperty.call(e,"oldOffset")&&t.uint32(24).int64(e.oldOffset),null!=e.rows&&Object.hasOwnProperty.call(e,"rows")&&t.uint32(32).int32(e.rows),null!=e.newToOld&&Object.hasOwnProperty.call(e,"newToOld")&&t.uint32(40).bool(e.newToOld),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetHistoryMessageReq"},e}(),Vn.GetWebDialogListReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.type=0,e.prototype.offset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.type&&Object.hasOwnProperty.call(e,"type")&&t.uint32(8).int32(e.type),null!=e.offset&&Object.hasOwnProperty.call(e,"offset")&&t.uint32(16).int64(e.offset),null!=e.rows&&Object.hasOwnProperty.call(e,"rows")&&t.uint32(24).int32(e.rows),null!=e.newToOld&&Object.hasOwnProperty.call(e,"newToOld")&&t.uint32(32).bool(e.newToOld),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetWebDialogListReq"},e}(),Vn.GetNewSettingDialogListReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.time=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.time&&Object.hasOwnProperty.call(e,"time")&&t.uint32(8).int64(e.time),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewSettingDialogListReq"},e}();var Wn=Vn,$n=Nt.exports,Jn=$n.Writer,Zn=$n.util,Xn=$n.roots.default||($n.roots.default={});Xn.SendGroupChatMessageReq=function(){function e(e){if(this.at=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.localId=Zn.Long?Zn.Long.fromBits(0,0,!1):0,e.prototype.msgPreContent="",e.prototype.msgPostContent="",e.prototype.mediaFlag=!1,e.prototype.mediaConstructor=0,e.prototype.mediaAttribute="",e.prototype.at=Zn.emptyArray,e.prototype.extra="",e.prototype.assign="",e.prototype.atAll=!1,e.prototype.msgContent=Zn.newBuffer([]),e.encode=function(e,t){if(t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.localId&&Object.hasOwnProperty.call(e,"localId")&&t.uint32(16).int64(e.localId),null!=e.msgPreContent&&Object.hasOwnProperty.call(e,"msgPreContent")&&t.uint32(26).string(e.msgPreContent),null!=e.msgPostContent&&Object.hasOwnProperty.call(e,"msgPostContent")&&t.uint32(34).string(e.msgPostContent),null!=e.mediaFlag&&Object.hasOwnProperty.call(e,"mediaFlag")&&t.uint32(40).bool(e.mediaFlag),null!=e.mediaConstructor&&Object.hasOwnProperty.call(e,"mediaConstructor")&&t.uint32(48).int32(e.mediaConstructor),null!=e.mediaAttribute&&Object.hasOwnProperty.call(e,"mediaAttribute")&&t.uint32(58).string(e.mediaAttribute),null!=e.at&&e.at.length){t.uint32(66).fork();for(var r=0;r<e.at.length;++r)t.int64(e.at[r]);t.ldelim()}return null!=e.extra&&Object.hasOwnProperty.call(e,"extra")&&t.uint32(74).string(e.extra),null!=e.assign&&Object.hasOwnProperty.call(e,"assign")&&t.uint32(82).string(e.assign),null!=e.atAll&&Object.hasOwnProperty.call(e,"atAll")&&t.uint32(88).bool(e.atAll),null!=e.msgContent&&Object.hasOwnProperty.call(e,"msgContent")&&t.uint32(98).bytes(e.msgContent),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendGroupChatMessageReq"},e}(),Xn.DeleteGroupChatHistoryReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeleteGroupChatHistoryReq"},e}(),Xn.UpdateGroupChatDialogStickyConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.stickyFlag=!1,e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.stickyFlag&&Object.hasOwnProperty.call(e,"stickyFlag")&&t.uint32(16).bool(e.stickyFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdateGroupChatDialogStickyConfigReq"},e}(),Xn.UpdateGroupChatDialogMuteConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.muteFlag=!1,e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.muteFlag&&Object.hasOwnProperty.call(e,"muteFlag")&&t.uint32(16).bool(e.muteFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdateGroupChatDialogMuteConfigReq"},e}(),Xn.RecallGroupChatMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.msgId=Zn.Long?Zn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/RecallGroupChatMessageReq"},e}(),Xn.DeleteGroupChatDialogReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeleteGroupChatDialogReq"},e}();var Yn=Xn;const Qn=Nt.exports.Reader,eo=Nt.exports.util,to=Nt.exports.roots.default||(Nt.exports.roots.default={}),ro=to.SendGroupChatMessageResp=(()=>{function e(e){if(e)for(let t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.localId=eo.Long?eo.Long.fromBits(0,0,!1):0,e.prototype.msgId=eo.Long?eo.Long.fromBits(0,0,!1):0,e.prototype.msgSendTime=eo.Long?eo.Long.fromBits(0,0,!1):0,e.prototype.seqno=eo.Long?eo.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Qn||(e=Qn.create(e));let r=void 0===t?e.len:e.pos+t,n=new to.SendGroupChatMessageResp;for(;e.pos<r;){let t=e.uint32();switch(t>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.localId=e.int64();break;case 4:n.msgId=e.int64();break;case 5:n.msgSendTime=e.int64();break;case 6:n.seqno=e.int64();break;default:e.skipType(7&t)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendGroupChatMessageResp"},e})();let no=0;const oo=async()=>{const e=(new Date).getTime(),{code:r,data:n}=await xn.send(At.GetServerTime,null,{decoder:Xr.SystemCurrentTimeMillisResp});if(r===t.SUCCESS){const{currentTimeMillis:t}=n;no=t.toNumber()-e}},io=()=>(new Date).getTime()+no,so=new Set;var ao={addMessage(e){so.add(e)},remove(e){so.delete(e)},has:e=>so.has(e),reset(){so.clear()}};const co=new Set;var lo={addMessage(e){co.add(e)},remove(e){co.delete(e)},has:e=>co.has(e),reset(){co.clear()}};const uo=new Map;function ho(e){uo.set(e.getObjectId(),e.decode.bind(e))}class fo{constructor(e,t){let r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];d(this,"messageType",void 0),d(this,"content",void 0),d(this,"isPersited",void 0),d(this,"isCounted",void 0),d(this,"isStatusMessage",void 0),this.messageType=e,this.content=t,o?(this.isPersited=!1,this.isCounted=!1):(this.isPersited=r,this.isCounted=n),this.isStatusMessage=o}get objectId(){return this.constructor.getObjectId()}static getObjectId(){throw new Error("Method not implemented.")}static decode(e){throw new Error("Method not implemented.")}encode(){throw new Error("Method not implemented.")}}const po=0,go=268439552,yo=268439563,vo=268439562,mo=268439553,bo=268439581,wo=268439597,Oo=268439613,Co=268439629,_o=1610678301,So=268439645,Io="RC:TxtMsg",Eo="RC:HQVCMsg",To="RC:FileMsg",Ro="RC:ImgMsg",ko="RC:GIFMsg",Ao="RC:RcNtf",No="RC:CmdMsg";class xo extends fo{constructor(e){super(Io,e)}static getObjectId(){return po}static decode(e){const{user:t,extra:r,content:n}=e;return new xo({user:t,extra:r,content:n})}encode(){const{user:e,extra:t,content:r}=this.content;return{user:e,extra:t,content:r}}}class Do extends fo{constructor(e){super(Ro,e)}static getObjectId(){return go}static decode(e){const{user:t,extra:r,thumbnailObjectKey:n,originalObjectKey:o,width:i,height:s}=e;return new Do({user:t,extra:r,content:n,imageUri:Pn.getFileAbsoluteUri(o),width:i,height:s})}encode(){const{user:e,extra:t,content:r,imageUri:n,width:o,height:i}=this.content;return{user:e,extra:t,thumbnailObjectKey:r,originalObjectKey:Pn.try2ExtractFileRelativeUri(n),width:o&&Math.floor(o),height:i&&Math.floor(i)}}}class Mo extends fo{constructor(e){super(ko,e)}static getObjectId(){return yo}static decode(e){const{user:t,extra:r,size:n,originalObjectKey:o,width:i,height:s}=e;return new Mo({user:t,extra:r,gifDataSize:n,remoteUrl:Pn.getFileAbsoluteUri(o),width:i,height:s})}encode(){const{user:e,extra:t,gifDataSize:r,remoteUrl:n,width:o,height:i}=this.content;return{user:e,extra:t,size:r,originalObjectKey:Pn.try2ExtractFileRelativeUri(n),width:o&&Math.floor(o),height:i&&Math.floor(i),extension:"gif"}}}class Lo extends fo{constructor(e){super(Eo,e)}static getObjectId(){return mo}static decode(e){const{user:t,extra:r,length:n,audioObjectKey:o,extension:i}=e;return new Lo({user:t,extra:r,remoteUrl:Pn.getFileAbsoluteUri(o),duration:n,type:i})}encode(){const{user:e,extra:t,remoteUrl:r,duration:n,type:o}=this.content;return{user:e,extra:t,length:n,audioObjectKey:Pn.try2ExtractFileRelativeUri(r),extension:o}}}class Bo extends fo{constructor(e){super(To,e)}static getObjectId(){return vo}static decode(e){const{user:t,extra:r,title:n,extension:o,size:i,originalObjectKey:s}=e;return new Bo({user:t,extra:r,name:n,size:i,type:o,fileUrl:Pn.getFileAbsoluteUri(s)})}encode(){const{user:e,extra:t,name:r,size:n,type:o,fileUrl:i}=this.content;return{user:e,extra:t,title:r,originalObjectKey:Pn.try2ExtractFileRelativeUri(i),extension:o,size:n}}}class Uo extends fo{constructor(e){super(Ao,e,!0,!1,!1)}static getObjectId(){return _o}static decode(e){return new Uo(e)}encode(){return this.content}}class jo extends fo{constructor(e){super(No,e,!1,!1)}static getObjectId(){return So}static decode(e){return new jo(e)}encode(){return this.content}}class Po extends fo{static decode(e){const{messageType:t,fields:r,user:n,extra:o}=e;return new this(t,{...r,user:n,extra:o})}encode(){const{user:e,extra:t,mentionedInfo:r,...n}=this.content;return{messageType:this.messageType,fields:n,user:e,extra:t}}}class Fo extends Po{constructor(e,t){super(e,t,!1,!1)}static getObjectId(){return bo}}class Go extends Po{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return wo}}class qo extends Po{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return Oo}}class Ho extends Po{constructor(e,t){super(e,t,!1,!1,!0)}static getObjectId(){return Co}}var zo=new class{constructor(){d(this,"aesKeyRecord",new Map)}async getDialogAesKey(e){return ot(e)?this.aesKeyRecord.has(e)?this.aesKeyRecord.get(e):new Promise((t=>{this.getDialogAesKeyListFromRemote([e]).then((r=>{t(r.get(e))})),setTimeout((()=>{t(null)}),8e3)})):null}getDialogAesKeyList(e){return new Promise((t=>{const r=new Map;this.getDialogAesKeyListInBatches(e,((n,o)=>{if(o.size)for(const[e,t]of o)r.set(e,t);(r.size===e.length||n)&&t(r)}))}))}getDialogAesKeyListInBatches(e,t){const r=new Map,n=[];e.forEach((e=>{if(!ot(e))return;const t=this.getDialogAesKeyFromLocal(e);t?r.set(e,t):n.push(e)})),t(!1,r),n.length&&this.getDialogAesKeyListFromRemote(n).then((e=>{t(!0,e)}))}reset(){this.aesKeyRecord.clear()}async getDialogAesKeyListFromRemote(e){if(!e.length)return new Map;const{code:r,data:n}=await(o=e,xn.send(At.GetDialogKey,{destId:o,clientSign:""},{encoder:Wn.GetDialogKeyReq,decoder:jn.GetDialogKeyResp}));var o;if(r===t.SUCCESS){const e=new Map;for(const t in n.entry){var i,s;const r=n.entry[t];if(null!==(i=r.aesKey)&&void 0!==i&&i.length&&null!==(s=r.aesIV)&&void 0!==s&&s.length){const n={key:r.aesKey,iv:r.aesIV};e.set(t,n),this.aesKeyRecord.set(t,n)}}return e}return new Map}getDialogAesKeyFromLocal(e){return ot(e)?this.aesKeyRecord.get(e):null}};const Ko="time",Vo=(e,t)=>[e,t,Ko].join("_");class Wo{constructor(e,t){d(this,"appkey",void 0),d(this,"userId",void 0),d(this,"inBoxOffset",rn.ZERO),this.appkey=e,this.userId=t}setInboxOffset(e){if(this.inBoxOffset>e)return;this.inBoxOffset=e;const t=Vo(this.appkey,this.userId);ft.set(t,e.toString())}getInboxOffset(){if(this.inBoxOffset.isZero()){const e=Vo(this.appkey,this.userId);this.inBoxOffset=rn.fromString(ft.get(e)??"0")}return this.inBoxOffset}}const $o=e=>{const t=[];let r,n,o;for(n=0;n<e.length;++n)for(r=e[n],o=3;o>=0;--o)t.push(r>>8*o&255);return new Uint8Array(t)};const Jo=(e,t,r)=>{const n={};return e.forEach((e=>{const o=Zo(e,t.get(e),r.get(e));o.length&&(n[e]=o)})),n},Zo=(e,t,r)=>{const n=Gn(e);if(!n)return[];const o=new Set;let i=[];return t.forEach((e=>{const t=e;let c=t.mediaConstructor,l=Xo(t,r);if(!l)return;if(1610678290===c||1610743841===c){const{msgId:e,sendTime:r}=l,i={sentTime:r,messageUId:e,conversationType:n.conversationType,targetId:t.isOut?n.targetId:Dn.uid,channelId:n.channelId};c=_o,l=i,o.add(e)}const u=function(e,t){const r=uo.get(e);return r?r(t):null}(c,l);if(Ze(u)){const e={...n,senderUserId:t.srcId.toString(),messageDirection:t.isOut?s.SEND:s.RECEIVE,isCounted:u.isCounted,isMentioned:t.atFlag,content:u.content,messageType:u.messageType,isOffLineMessage:!1,isPersited:u.isPersited,messageId:rn.isLong(t.localId)?t.localId.toNumber():void 0,messageUId:t.msgId.toString(),sentTime:t.seqno.toNumber(),receivedTime:io(),isStatusMessage:u.isStatusMessage,receivedStatus:a.READ,disableNotification:!1};if(e.isStatusMessage&&io()-e.sentTime>6e3)return;i.push(e)}})),o.size&&(i=i.filter((e=>!o.has(e.messageUId)))),i},Xo=(e,t)=>{try{var r,n;let o;o=null!==(r=e.msgContent)&&void 0!==r&&r.length?((e,t)=>{const r=window.btoa(String.fromCharCode(...e));return $e.AES.decrypt(r,$e.enc.Utf8.parse(t.key),{iv:Ze(t.iv)?$e.enc.Utf8.parse(t.iv):void 0}).toString($e.enc.Utf8)})(e.msgContent,t):e.msgPreContent??"",1610678290!==e.mediaConstructor&&1610743841!==e.mediaConstructor||(o=Yo(o));let i={};return null!==(n=o)&&void 0!==n&&n.length&&(i=JSON.parse(o)),i}catch(t){return mt.error("decode message content fail -> uid:",e.msgId.toString()),null}},Yo=e=>e.replace(/("msgId")\s*:\s*(\d+)/g,((e,t,r)=>`${t}:"${r}"`));var Qo={parse:function(e,t){const r=new Map;if(Object.keys(e).forEach((t=>{var n;const o=null===(n=e[t].dialogMessage)||void 0===n?void 0:n.filter((e=>!e.sharingGroupFlag));null!=o&&o.length&&r.set(t,o)})),!r.size)return void t(!0,{});const n=new Set(r.keys());zo.getDialogAesKeyListInBatches([...r.keys()],((e,o)=>{if(o.size){const e=[...o.keys()];for(const t of e)n.delete(t);t(!n.size,Jo(e,r,o))}n.size&&e&&t(!0,{})}))},parseSingleDialogMessages:Zo};function ei(e){if(!Ze(e))return e;if(Array.isArray(e))return e.map((e=>ei(e)));if(tt(e)){const t={};return Object.keys(e).forEach((r=>{t[r]=ei(e[r])})),t}return e}const ti={unreadMessageCount:{keyName:"c",defaultVal:0},lastUnreadTime:{keyName:"lt",defaultVal:0},notificationStatus:{keyName:"nc",defaultVal:2},notificationLevel:{keyName:"nl",defaultVal:0},isTop:{keyName:"it",defaultVal:!1},mentionedUIds:{keyName:"mu",defaultVal:null}};class ri{constructor(e,t){d(this,"localStore",void 0);const r=`con-${e}-${t}`;this.localStore=new pt(r)}getStoreKey(e){return`${e.conversationType}_${e.targetId}_${e.channelId??""}`}getConOptionByKey(e){const t=(e=e||"").split("_");if(t.length>=2){const e=t.shift(),r=t.shift(),n=t.join("_");return{conversationType:Number(e),targetId:r,channelId:n}}return{conversationType:n.PRIVATE,targetId:"",channelId:""}}updateUnreadCount(e){const{conversationType:t,targetId:r,channelId:n,content:o,messageType:i,sentTime:a,isCounted:c,messageDirection:l}=e,u=l===s.SEND,d=i===Ao,h=tt(o),f={conversationType:t,targetId:r,channelId:n},p=this.get(f)||{},g=p.lastUnreadTime||0,y=p.unreadMessageCount||0;if(!(a<=g)&&!u){if(c&&(p.unreadMessageCount=y+1,g||(p.lastUnreadTime=a)),d&&h){o.sentTime>=g&&y&&(p.unreadMessageCount=y-1)}this.set(f,p)}}updateMentionedData(e){const{conversationType:t,targetId:r,channelId:o,messageUId:i,messageType:a,isMentioned:c,messageDirection:l,content:u}=e;if(l===s.SEND||!c&&a!==Ao)return;const d=this.getStoreKey({conversationType:t,targetId:r,channelId:o}),h=this.localStore.get(d)||{},f=ti.mentionedUIds.keyName,p=h[f]||[];if(c&&t===n.GROUP&&(p.includes(i)||p.push(i)),a===Ao&&t===n.GROUP){const e=u,t=p.indexOf(e.messageUId);t>=0&&p.splice(t,1)}p.length?h[f]=p:delete h[f],it(h)?this.localStore.set(d,h):this.localStore.remove(d)}set(e,t){const r=this.getStoreKey(e),n=this.localStore.get(r)||{};for(const e of at(t)){const r=ti[e],o=t[e];if(Qe(null==r?void 0:r.keyName)||Qe(o))continue;o===r.defaultVal?delete n[r.keyName]:n[r.keyName]=o,n[ti.unreadMessageCount.keyName]||(delete n[ti.lastUnreadTime.keyName],delete n[ti.mentionedUIds.keyName])}it(n)?this.localStore.set(r,n):this.localStore.remove(r)}get(e){const t=this.getStoreKey(e),r=this.localStore.get(t)||{},n={};for(const e of at(ti)){const{keyName:t,defaultVal:i}=ti[e];var o;if("mentionedUIds"===e)n.unreadMentionedCount=(null===(o=r[t])||void 0===o?void 0:o.length)??0,n.hasMentioned=!!n.unreadMentionedCount;else n[e]=r[t]||ei(i)}return n}getAll(){const e=this.localStore.getCache()||{},t=[];for(const r in e){const n=this.getConOptionByKey(r),o=e[r];for(const e of at(ti)){const{keyName:t,defaultVal:r}=ti[e];"mentionedUIds"!==e&&(n[e]=o[t]||ei(r))}t.push(n)}return t}}const ni=e=>{const t=e.destId??"",r=Gn(t);if(!r)return;return{...r,unreadMessageCount:0,notificationStatus:e.muteFlag?i.OPEN:i.CLOSE,notificationLevel:Xe(e.pushNotificationLevel)&&0!==e.pushNotificationLevel&&Ze(c[e.pushNotificationLevel])?e.pushNotificationLevel:e.muteFlag?c.AT_USER_NOTIFICATION:c.NOT_SET,isTop:!!e.stickyFlag,lastUnreadTime:0}};class oi{constructor(e,t){d(this,"storageKey",void 0),d(this,"eventEmitter",void 0),d(this,"isPulling",!1),this.storageKey=`con-s-${e}-${t}`,this.eventEmitter=new Rt}async pull(){if(this.isPulling)return;let e;this.isPulling=!0;const r=ft.get(this.storageKey);e=Xe(r)&&r>0?r:io()-1e4;let{code:n,data:o}=await(e=>xn.send(At.GetDialogChangedStatus,{time:rn.fromNumber(e)},{encoder:Wn.GetNewSettingDialogListReq,decoder:jn.GetNewSettingDialogListResp}))(e);n===t.SUCCESS&&(o.setTime.toNumber()>0&&ft.set(this.storageKey,o.setTime.toNumber()),o.briefDialog&&at(o.briefDialog).forEach((e=>{const t=o.briefDialog[e],r=ni(t);r&&this.eventEmitter.emit("STATUS_CHANGED",r)}))),this.isPulling=!1}watch(e){this.eventEmitter.on("STATUS_CHANGED",(t=>{e(t)}))}}class ii{constructor(e,t,r){d(this,"updatedConversationFunc",void 0),d(this,"store",void 0),d(this,"draftMap",new Map),d(this,"localConversationSet",new Set),d(this,"updatedConversations",[]),d(this,"notify",void 0),d(this,"statusManager",void 0),this.updatedConversationFunc=r,this.store=new ri(e,t),this.notify=lt(this.notifyConversationChanged.bind(this),0),this.statusManager=new oi(e,t),this.statusManager.watch((e=>{this.addStatus(e,!0)}))}getConversationKey(e){return`${e.conversationType}_${e.targetId}_${e.channelId??""}`}setUpdatedConversation(e){const t=this.updatedConversations.findIndex((t=>this.getConversationKey(e.conversation)===this.getConversationKey(t.conversation)));t>=0?(e={conversation:Object.assign(this.updatedConversations[t].conversation,e.conversation),updatedItems:Object.assign(this.updatedConversations[t].updatedItems,e.updatedItems)},this.updatedConversations[t]=e):this.updatedConversations.push(e),this.notify()}notifyConversationChanged(){var e;const t=this.updatedConversations.map((e=>({conversation:{...e.conversation,...this.store.get(e.conversation)},updatedItems:e.updatedItems})));this.updatedConversations=[],null===(e=this.updatedConversationFunc)||void 0===e||e.call(this,t)}syncConversationStatus(){this.statusManager.pull()}async loadConvsationsIfNotExist(e){if(null==e||!e.length)return;const r=e.filter((e=>!this.localConversationSet.has(this.getConversationKey(e))));if(!r.length)return;const n=r.map(Fn).filter(ot);if(!n.length)return;const{code:o,data:i}=await(e=>xn.send(At.GetBriefDialogList,{destId:e},{encoder:Wn.GetBriefDialogListReq,decoder:jn.GetBriefDialogListResp}))(n);o===t.SUCCESS&&at(i.briefDialog).forEach((e=>{const t=i.briefDialog[e],r=ni(t);r&&(this.localConversationSet.add(this.getConversationKey(r)),this.addStatus(r,!0))}))}addLocalConversation(e){const{conversationType:t,targetId:r,channelId:n,isTop:o,notificationStatus:i,notificationLevel:s}=e;this.localConversationSet.add(this.getConversationKey(e)),this.addStatus({conversationType:t,targetId:r,channelId:n,isTop:o,notificationStatus:i,notificationLevel:s},!1)}addStatus(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{conversationType:r,targetId:n,notificationStatus:o,notificationLevel:i,isTop:s,channelId:a}=e,c={conversationType:r,targetId:n,channelId:a},l=io(),u=this.store.get(c),d={};Ze(i)&&u.notificationLevel!==i&&(d.notificationLevel={time:l,val:i}),Ze(o)&&u.notificationStatus!==o&&(d.notificationStatus={time:l,val:o}),Ze(s)&&u.isTop!==s&&(d.isTop={time:l,val:s}),this.store.set(c,{notificationStatus:o,isTop:s,notificationLevel:i}),Object.keys(d).length&&t&&this.setUpdatedConversation({conversation:c,updatedItems:d})}setConversationCacheByMessage(e){const{conversationType:t,isPersited:r,targetId:n,channelId:o}=e,i={conversationType:t,targetId:n,channelId:o},s={conversation:i,updatedItems:{}},a=ei(this.get(i));this.store.updateUnreadCount(e),this.store.updateMentionedData(e);const c=this.get(i);a.unreadMessageCount!==c.unreadMessageCount&&(s.updatedItems.unreadMessageCount={time:e.sentTime,val:c.unreadMessageCount}),a.hasMentioned!==c.hasMentioned&&(s.updatedItems.hasMentioned={time:e.sentTime,val:c.hasMentioned}),a.unreadMentionedCount!==c.unreadMentionedCount&&(s.updatedItems.unreadMentionedCount={time:e.sentTime,val:c.unreadMentionedCount}),r&&(s.conversation.latestMessage=e,s.updatedItems.latestMessage={time:e.sentTime,val:e}),Object.keys(s.updatedItems).length&&this.setUpdatedConversation(s)}get(e){return this.store.get(e)}getAllUnreadCount(e,t){const r=this.store.getAll();let n=0;return r.forEach((r=>{let{unreadMessageCount:o,notificationStatus:s,notificationLevel:a,conversationType:c}=r;o=o||0;const l=s===i.OPEN||a>0;!t&&l||(e.length>0?e.includes(+c)&&(n+=+o):n+=+o)})),n}getUnreadCount(e){return this.store.get(e).unreadMessageCount||0}clearUnreadCount(e){const t=this.store.get(e),{unreadMessageCount:r,unreadMentionedCount:n}=t;(r||n)&&(t.unreadMessageCount=0,t.hasMentioned=!1,t.unreadMentionedCount=0),this.store.set(e,t);const o={};r&&(o.unreadMessageCount={val:0,time:io()}),n&&(o.hasMentioned={val:!1,time:io()},o.unreadMentionedCount={val:0,time:io()}),Object.keys(o).length&&this.setUpdatedConversation({conversation:e,updatedItems:o})}clearAllUnreadCount(){this.store.getAll().forEach((e=>this.clearUnreadCount(e)))}getNotificationLevel(e){return this.store.get(e).notificationLevel}getNotificationStatus(e){return this.store.get(e).notificationStatus||2}setDraft(e,t){this.draftMap.set(this.getConversationKey(e),t)}getDraft(e){return this.draftMap.get(this.getConversationKey(e))??""}clearDraft(e){this.draftMap.delete(this.getConversationKey(e))}getBlockConversationList(){return this.store.getAll().filter((e=>e.notificationStatus===i.OPEN||e.notificationLevel>0)).map((e=>({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId})))}getTopConversationList(){return(this.store.getAll()||{}).filter((e=>e.isTop)).map((e=>({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId})))}getUnreadMentionedCount(e){return this.get(e).unreadMentionedCount||0}getAllUnreadMentionedCount(){const e=this.store.getAll();let t=0;return e.forEach((e=>{let{unreadMentionedCount:r}=e;r=r||0,t+=Number(r)})),t}getAllConversationState(){return this.store.getAll().map((e=>{let{conversationType:t,targetId:r,channelId:n,unreadMessageCount:o,unreadMentionedCount:i,notificationLevel:s,notificationStatus:a,isTop:c}=e;return{conversationType:t,targetId:r,channelId:n,unreadCount:o,unreadMentionedCount:i??0,notificationLevel:s,notificationStatus:a,isTop:c}}))}destroyed(){this.updatedConversationFunc=void 0}}const si={addStatus:function(e,t){},setConversationCacheByMessage:function(e){},get:function(e){return null},getAllUnreadCount:function(e,t){return 0},getUnreadCount:function(e){return 0},clearUnreadCount:function(e){},clearAllUnreadCount(){},getNotificationLevel:function(e){return c.NOT_SET},getNotificationStatus:function(e){return i.CLOSE},setDraft:function(e,t){},getDraft:function(e){return""},clearDraft:function(e){},getBlockConversationList:function(){return[]},getTopConversationList:function(){return[]},getUnreadMentionedCount:function(e){return 0},getAllUnreadMentionedCount:function(){return 0},getAllConversationState:function(){return[]},addLocalConversation:function(e){},loadConvsationsIfNotExist:function(e){},destroyed(){},syncConversationStatus:function(){}};let ai;var ci={create(e,t,r){ai=new ii(e,t,r)},get:()=>ai??si};class li{constructor(e,t){d(this,"watcher",void 0),d(this,"pullingMsg",!1),d(this,"letterbox",void 0),d(this,"serverMsgSeqno",rn.ZERO),d(this,"pullOfflineFinished",!1),d(this,"intervalTimer",void 0),d(this,"retryTimer",void 0),d(this,"latestSyncTimestamp",0),d(this,"started",!1),this.watcher=e,this.letterbox=new Wo(t.appkey,Dn.uid)}start(){this.started=!0,this.pullOfflineFinished=!1,this.startPullInterval()}stop(){this.started=!1,this.stopPullInterval(),this.cancelRetryTask()}syncMsg(e){this.serverMsgSeqno=e,this.pullMsg()}startPullInterval(){this.stopPullInterval();this.intervalTimer=setInterval((()=>{Date.now()-this.latestSyncTimestamp>=18e4&&this.pullMsg()}),3e4),this.latestSyncTimestamp=Date.now(),this.pullMsg()}stopPullInterval(){this.intervalTimer&&(clearInterval(this.intervalTimer),this.intervalTimer=null)}try2RePullMsg(){this.retryTimer=setTimeout((()=>{this.retryTimer=null,this.pullMsg()}),1e3)}cancelRetryTask(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async pullMsg(){if(this.pullingMsg)return;if(!this.started)return;this.cancelRetryTask(),this.pullingMsg=!0;const e=this.letterbox.getInboxOffset();this.pullOfflineFinished||mt.info(`pullMsg -> time: ${e}`),this.latestSyncTimestamp=Date.now();const{code:r,data:n}=await((e,t)=>xn.send(At.GetNewMessage,{offset:e,rows:t},{encoder:Wn.GetNewMessageReq,decoder:jn.GetNewMessageResp}))(e,60);if(r!==t.SUCCESS)return this.pullOfflineFinished||mt.warn("pullMsg failed -> code:",r),this.pullingMsg=!1,void this.try2RePullMsg();const{offset:o,seqno:i,msg:a}=n,c=Object.keys(a).map(Gn).filter((e=>Ze(e)));ci.get().loadConvsationsIfNotExist(c),Qo.parse(a,((e,t)=>{const r=[],n=[],a=!this.pullOfflineFinished;var c,l;(Object.keys(t).forEach((e=>{const o=t[e],i=[];if(o.forEach((e=>{e.messageDirection===s.SEND&&e.messageId&&ao.has(e.messageId)?ao.remove(e.messageId):e.messageType===Ao&&lo.has(e.content.messageUId)?lo.remove(e.content.messageUId):(e.isOffLineMessage=a,ci.get().setConversationCacheByMessage(e),i.push(e))})),r.push(...i),this.isExistPersistedMessage(i)){const t=Gn(e);t&&n.push(t)}})),r.length)&&(null===(c=(l=this.watcher).batchMessage)||void 0===c||c.call(l,r));if(n.length&&ci.get().loadConvsationsIfNotExist(n),e){var u;i.ge(this.serverMsgSeqno)&&(this.serverMsgSeqno=i);const e=this.serverMsgSeqno.lessThanOrEqual(o);this.pullOfflineFinished||mt.info(`pullMsg success -> syncTime: ${o}, finished: ${e}`),null===(u=this.letterbox)||void 0===u||u.setInboxOffset(o),this.pullingMsg=!1,e&&!this.pullOfflineFinished&&(this.pullOfflineFinished=!0,this.watcher.pullFinished&&this.watcher.pullFinished()),e||this.pullMsg()}}))}isExistPersistedMessage(e){return e.some((e=>e.isPersited))}}class ui{static init(e){return this._loader||(this._loader=new ui(e)),this._loader}static get loader(){return this._loader}constructor(t){d(this,"options",void 0),d(this,"connectionStatus",e.DISCONNECTED),d(this,"isInternalConnected",!1),d(this,"watcher",void 0),d(this,"messageLoader",void 0),this.options=t,this.watcher={onConnecting:void 0,onConnected:void 0,onDisconnect:void 0,onSuspend:void 0,pullFinished:void 0,batchMessage:void 0,conversationState:void 0},xn.setServerInfo(this.getWebSocketUrl()),xn.setCallback({status:this.connectionStatusListener.bind(this),message:this.messageListener.bind(this),onAuth:this.authListener.bind(this)},{needReAuth:this.needReAuthProvider.bind(this),profile:this.needProfileProvider.bind(this)}),this.registerMessage()}getWebSocketUrl(){var e;const t=null===(e=this.options)||void 0===e?void 0:e.serverInfo;return ot(t)?nt(r=t)&&/wss?:\/\//.test(r)?t:"ws://"+t:"wss://tt.mimelabs.xyz:8991";var r}registerMessage(){ho(xo),ho(Do),ho(Mo),ho(Lo),ho(Fo),ho(qo),ho(Go),ho(Ho),ho(Uo),ho(jo),ho(Bo)}async connect(r){if(this.connectionStatus===e.CONNECTED)return{code:t.SUCCESS,userId:Dn.uid+""};if(this.connectionStatus===e.CONNECTING)return{code:t.BIZ_ERROR_CONNECTING};if("string"!=typeof r||0===r.length)return{code:t.RC_CONN_USER_OR_PASSWD_ERROR};Pn.imInitToken=r;const n=await xn.connect(r);var o;n===t.SUCCESS&&(this.isInternalConnected=!0,ci.get().destroyed(),ci.create(this.options.appkey,Dn.uid,this.watcher.conversationState),null===(o=this.messageLoader)||void 0===o||o.stop(),this.messageLoader=new li(this.watcher,this.options),oo(),ao.reset(),lo.reset(),zo.reset());return{code:n,userId:Dn.uid+""}}reconnect(){return this.isInternalConnected?Promise.resolve({code:t.CAN_NOT_RECONNECT}):this.connect(Pn.imInitToken)}disconnect(){return this.isInternalConnected=!1,xn.close(),Promise.resolve()}getConnectionStatus(){return this.connectionStatus}assignWatcher(e){at(this.watcher).forEach((t=>{if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this.watcher[t]=et(r)?r:void 0}}))}resetWatcher(){at(this.watcher).forEach((e=>{this.watcher[e]=void 0}))}async connectionStatusListener(t){this.connectionStatus=t,setTimeout((()=>{switch(t){case e.BLOCKED:case e.KICKED_OFFLINE_BY_OTHER_CLIENT:case e.DISCONNECT_BY_SERVER:this.handleDisconnect();break;case e.CONNECTING:this.handleConnecting();break;case e.CONNECTED:this.handleConnected();break;case e.DISCONNECTED:this.handleDisconnect()}}),0)}handleConnecting(){var e,t;null===(e=(t=this.watcher).onConnecting)||void 0===e||e.call(t)}handleConnected(){var t,r,n;null===(t=(r=this.watcher).onConnected)||void 0===t||t.call(r),null===(n=this.messageLoader)||void 0===n||n.start(),setTimeout((()=>{this.connectionStatus===e.CONNECTED&&ci.get().syncConversationStatus()}),2e3)}handleDisconnect(){var e,t,r;null===(e=(t=this.watcher).onDisconnect)||void 0===e||e.call(t),null===(r=this.messageLoader)||void 0===r||r.stop()}handleSuspend(){var e,t;null===(e=(t=this.watcher).onSuspend)||void 0===e||e.call(t)}messageListener(e,t){if(e===At.NewMessagePush){var r;const e=jn.NewMessageNotificationResp.decode(t);null===(r=this.messageLoader)||void 0===r||r.syncMsg(e.seqno)}else e===At.DialogChangedPush&&ci.get().syncConversationStatus()}authListener(e){Pn.setFileServerInfo(e.fileDomain,e.dialogFileDomain,e.cert),Dn.setLogged(e,Pn.imInitToken)}needReAuthProvider(){return!Dn.user.active||Dn.user.token!==Pn.imInitToken}needProfileProvider(){if(!this.needReAuthProvider()){const{deviceId:e,sessionId:t,uid:r}=Dn.user;return{deviceId:e,sessionId:t,uid:r}}return null}}d(ui,"_loader",void 0);var di={exports:{}},hi={exports:{}},fi={exports:{}},pi={exports:{}},gi=yi;function yi(e,t){"string"==typeof e&&(t=e,e=void 0);var r=[];function n(e){if("string"!=typeof e){var t=o();if(yi.verbose&&console.log("codegen: "+t),t="return "+t,e){for(var i=Object.keys(e),s=new Array(i.length+1),a=new Array(i.length),c=0;c<i.length;)s[c]=i[c],a[c]=e[i[c++]];return s[c]=t,Function.apply(null,s).apply(null,a)}return Function(t)()}for(var l=new Array(arguments.length-1),u=0;u<l.length;)l[u]=arguments[++u];if(u=0,e=e.replace(/%([%dfijs])/g,(function(e,t){var r=l[u++];switch(t){case"d":case"f":return String(Number(r));case"i":return String(Math.floor(r));case"j":return JSON.stringify(r);case"s":return String(r)}return"%"})),u!==l.length)throw Error("parameter count mismatch");return r.push(e),n}function o(n){return"function "+(n||t||"")+"("+(e&&e.join(",")||"")+"){\n "+r.join("\n ")+"\n}"}return n.toString=o,n}yi.verbose=!1;var vi=wi,mi=Mt,bi=zt();function wi(e,t,r){return"function"==typeof t?(r=t,t={}):t||(t={}),r?!t.xhr&&bi&&bi.readFile?bi.readFile(e,(function(n,o){return n&&"undefined"!=typeof XMLHttpRequest?wi.xhr(e,t,r):n?r(n):r(null,t.binary?o:o.toString("utf8"))})):wi.xhr(e,t,r):mi(wi,this,e,t)}wi.xhr=function(e,t,r){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState){if(0!==n.status&&200!==n.status)return r(Error("status "+n.status));if(t.binary){var e=n.response;if(!e){e=[];for(var o=0;o<n.responseText.length;++o)e.push(255&n.responseText.charCodeAt(o))}return r(null,"undefined"!=typeof Uint8Array?new Uint8Array(e):e)}return r(null,n.responseText)}},t.binary&&("overrideMimeType"in n&&n.overrideMimeType("text/plain; charset=x-user-defined"),n.responseType="arraybuffer"),n.open("GET",e),n.send()};var Oi={};!function(e){var t=e,r=t.isAbsolute=function(e){return/^(?:\/|\w+:)/.test(e)},n=t.normalize=function(e){var t=(e=e.replace(/\\/g,"/").replace(/\/{2,}/g,"/")).split("/"),n=r(e),o="";n&&(o=t.shift()+"/");for(var i=0;i<t.length;)".."===t[i]?i>0&&".."!==t[i-1]?t.splice(--i,2):n?t.splice(i,1):++i:"."===t[i]?t.splice(i,1):++i;return o+t.join("/")};t.resolve=function(e,t,o){return o||(t=n(t)),r(t)?t:(o||(e=n(e)),(e=e.replace(/(?:\/|^)[^/]+$/,"")).length?n(e+"/"+t):t)}}(Oi);var Ci,_i,Si,Ii,Ei,Ti,Ri,ki,Ai,Ni,xi,Di,Mi,Li={};function Bi(){return Ci||(Ci=1,function(e){var t=Li,r=gs(),n=["double","float","int32","uint32","sint32","fixed32","sfixed32","int64","uint64","sint64","fixed64","sfixed64","bool","string","bytes"];function o(e,t){var r=0,o={};for(t|=0;r<e.length;)o[n[r+t]]=e[r++];return o}t.basic=o([1,5,0,0,0,5,5,0,0,0,1,1,0,2,2]),t.defaults=o([0,0,0,0,0,0,0,0,0,0,0,0,!1,"",r.emptyArray,null]),t.long=o([0,0,0,1,1],7),t.mapKey=o([0,0,0,5,5,0,0,0,1,1,0,2],2),t.packed=o([1,5,0,0,0,5,5,0,0,0,1,1,0])}()),Li}function Ui(){if(Si)return _i;Si=1,_i=s;var e=ys();((s.prototype=Object.create(e.prototype)).constructor=s).className="Field";var t,r=vs(),n=Bi(),o=gs(),i=/^required|optional|repeated$/;function s(t,r,s,a,c,l,u){if(o.isObject(a)?(u=c,l=a,a=c=void 0):o.isObject(c)&&(u=l,l=c,c=void 0),e.call(this,t,l),!o.isInteger(r)||r<0)throw TypeError("id must be a non-negative integer");if(!o.isString(s))throw TypeError("type must be a string");if(void 0!==a&&!i.test(a=a.toString().toLowerCase()))throw TypeError("rule must be a string rule");if(void 0!==c&&!o.isString(c))throw TypeError("extend must be a string");"proto3_optional"===a&&(a="optional"),this.rule=a&&"optional"!==a?a:void 0,this.type=s,this.id=r,this.extend=c||void 0,this.required="required"===a,this.optional=!this.required,this.repeated="repeated"===a,this.map=!1,this.message=null,this.partOf=null,this.typeDefault=null,this.defaultValue=null,this.long=!!o.Long&&void 0!==n.long[s],this.bytes="bytes"===s,this.resolvedType=null,this.extensionField=null,this.declaringField=null,this._packed=null,this.comment=u}return s.fromJSON=function(e,t){return new s(e,t.id,t.type,t.rule,t.extend,t.options,t.comment)},Object.defineProperty(s.prototype,"packed",{get:function(){return null===this._packed&&(this._packed=!1!==this.getOption("packed")),this._packed}}),s.prototype.setOption=function(t,r,n){return"packed"===t&&(this._packed=null),e.prototype.setOption.call(this,t,r,n)},s.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return o.toObject(["rule","optional"!==this.rule&&this.rule||void 0,"type",this.type,"id",this.id,"extend",this.extend,"options",this.options,"comment",t?this.comment:void 0])},s.prototype.resolve=function(){if(this.resolved)return this;if(void 0===(this.typeDefault=n.defaults[this.type])?(this.resolvedType=(this.declaringField?this.declaringField.parent:this.parent).lookupTypeOrEnum(this.type),this.resolvedType instanceof t?this.typeDefault=null:this.typeDefault=this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]):this.options&&this.options.proto3_optional&&(this.typeDefault=null),this.options&&null!=this.options.default&&(this.typeDefault=this.options.default,this.resolvedType instanceof r&&"string"==typeof this.typeDefault&&(this.typeDefault=this.resolvedType.values[this.typeDefault])),this.options&&(!0!==this.options.packed&&(void 0===this.options.packed||!this.resolvedType||this.resolvedType instanceof r)||delete this.options.packed,Object.keys(this.options).length||(this.options=void 0)),this.long)this.typeDefault=o.Long.fromNumber(this.typeDefault,"u"===this.type.charAt(0)),Object.freeze&&Object.freeze(this.typeDefault);else if(this.bytes&&"string"==typeof this.typeDefault){var i;o.base64.test(this.typeDefault)?o.base64.decode(this.typeDefault,i=o.newBuffer(o.base64.length(this.typeDefault)),0):o.utf8.write(this.typeDefault,i=o.newBuffer(o.utf8.length(this.typeDefault)),0),this.typeDefault=i}return this.map?this.defaultValue=o.emptyObject:this.repeated?this.defaultValue=o.emptyArray:this.defaultValue=this.typeDefault,this.parent instanceof t&&(this.parent.ctor.prototype[this.name]=this.defaultValue),e.prototype.resolve.call(this)},s.d=function(e,t,r,n){return"function"==typeof t?t=o.decorateType(t).name:t&&"object"==typeof t&&(t=o.decorateEnum(t).name),function(i,a){o.decorateType(i.constructor).add(new s(a,e,t,r,{default:n}))}},s._configure=function(e){t=e},_i}function ji(){if(Ei)return Ii;Ei=1,Ii=n;var e=ys();((n.prototype=Object.create(e.prototype)).constructor=n).className="OneOf";var t=Ui(),r=gs();function n(t,r,n,o){if(Array.isArray(r)||(n=r,r=void 0),e.call(this,t,n),void 0!==r&&!Array.isArray(r))throw TypeError("fieldNames must be an Array");this.oneof=r||[],this.fieldsArray=[],this.comment=o}function o(e){if(e.parent)for(var t=0;t<e.fieldsArray.length;++t)e.fieldsArray[t].parent||e.parent.add(e.fieldsArray[t])}return n.fromJSON=function(e,t){return new n(e,t.oneof,t.options,t.comment)},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return r.toObject(["options",this.options,"oneof",this.oneof,"comment",t?this.comment:void 0])},n.prototype.add=function(e){if(!(e instanceof t))throw TypeError("field must be a Field");return e.parent&&e.parent!==this.parent&&e.parent.remove(e),this.oneof.push(e.name),this.fieldsArray.push(e),e.partOf=this,o(this),this},n.prototype.remove=function(e){if(!(e instanceof t))throw TypeError("field must be a Field");var r=this.fieldsArray.indexOf(e);if(r<0)throw Error(e+" is not a member of "+this);return this.fieldsArray.splice(r,1),(r=this.oneof.indexOf(e.name))>-1&&this.oneof.splice(r,1),e.partOf=null,this},n.prototype.onAdd=function(t){e.prototype.onAdd.call(this,t);for(var r=0;r<this.oneof.length;++r){var n=t.get(this.oneof[r]);n&&!n.partOf&&(n.partOf=this,this.fieldsArray.push(n))}o(this)},n.prototype.onRemove=function(t){for(var r,n=0;n<this.fieldsArray.length;++n)(r=this.fieldsArray[n]).parent&&r.parent.remove(r);e.prototype.onRemove.call(this,t)},n.d=function(){for(var e=new Array(arguments.length),t=0;t<arguments.length;)e[t]=arguments[t++];return function(t,o){r.decorateType(t.constructor).add(new n(o,e)),Object.defineProperty(t,o,{get:r.oneOfGetter(e),set:r.oneOfSetter(e)})}},Ii}function Pi(){if(Ri)return Ti;Ri=1,Ti=c;var e=ys();((c.prototype=Object.create(e.prototype)).constructor=c).className="Namespace";var t,r,n,o=Ui(),i=gs(),s=ji();function a(e,t){if(e&&e.length){for(var r={},n=0;n<e.length;++n)r[e[n].name]=e[n].toJSON(t);return r}}function c(t,r){e.call(this,t,r),this.nested=void 0,this._nestedArray=null}function l(e){return e._nestedArray=null,e}return c.fromJSON=function(e,t){return new c(e,t.options).addJSON(t.nested)},c.arrayToJSON=a,c.isReservedId=function(e,t){if(e)for(var r=0;r<e.length;++r)if("string"!=typeof e[r]&&e[r][0]<=t&&e[r][1]>t)return!0;return!1},c.isReservedName=function(e,t){if(e)for(var r=0;r<e.length;++r)if(e[r]===t)return!0;return!1},Object.defineProperty(c.prototype,"nestedArray",{get:function(){return this._nestedArray||(this._nestedArray=i.toArray(this.nested))}}),c.prototype.toJSON=function(e){return i.toObject(["options",this.options,"nested",a(this.nestedArray,e)])},c.prototype.addJSON=function(e){if(e)for(var i,s=Object.keys(e),a=0;a<s.length;++a)i=e[s[a]],this.add((void 0!==i.fields?t.fromJSON:void 0!==i.values?n.fromJSON:void 0!==i.methods?r.fromJSON:void 0!==i.id?o.fromJSON:c.fromJSON)(s[a],i));return this},c.prototype.get=function(e){return this.nested&&this.nested[e]||null},c.prototype.getEnum=function(e){if(this.nested&&this.nested[e]instanceof n)return this.nested[e].values;throw Error("no such enum: "+e)},c.prototype.add=function(e){if(!(e instanceof o&&void 0!==e.extend||e instanceof t||e instanceof s||e instanceof n||e instanceof r||e instanceof c))throw TypeError("object must be a valid nested object");if(this.nested){var i=this.get(e.name);if(i){if(!(i instanceof c&&e instanceof c)||i instanceof t||i instanceof r)throw Error("duplicate name '"+e.name+"' in "+this);for(var a=i.nestedArray,u=0;u<a.length;++u)e.add(a[u]);this.remove(i),this.nested||(this.nested={}),e.setOptions(i.options,!0)}}else this.nested={};return this.nested[e.name]=e,e.onAdd(this),l(this)},c.prototype.remove=function(t){if(!(t instanceof e))throw TypeError("object must be a ReflectionObject");if(t.parent!==this)throw Error(t+" is not a member of "+this);return delete this.nested[t.name],Object.keys(this.nested).length||(this.nested=void 0),t.onRemove(this),l(this)},c.prototype.define=function(e,t){if(i.isString(e))e=e.split(".");else if(!Array.isArray(e))throw TypeError("illegal path");if(e&&e.length&&""===e[0])throw Error("path must be relative");for(var r=this;e.length>0;){var n=e.shift();if(r.nested&&r.nested[n]){if(!((r=r.nested[n])instanceof c))throw Error("path conflicts with non-namespace objects")}else r.add(r=new c(n))}return t&&r.addJSON(t),r},c.prototype.resolveAll=function(){for(var e=this.nestedArray,t=0;t<e.length;)e[t]instanceof c?e[t++].resolveAll():e[t++].resolve();return this.resolve()},c.prototype.lookup=function(e,t,r){if("boolean"==typeof t?(r=t,t=void 0):t&&!Array.isArray(t)&&(t=[t]),i.isString(e)&&e.length){if("."===e)return this.root;e=e.split(".")}else if(!e.length)return this;if(""===e[0])return this.root.lookup(e.slice(1),t);var n=this.get(e[0]);if(n){if(1===e.length){if(!t||t.indexOf(n.constructor)>-1)return n}else if(n instanceof c&&(n=n.lookup(e.slice(1),t,!0)))return n}else for(var o=0;o<this.nestedArray.length;++o)if(this._nestedArray[o]instanceof c&&(n=this._nestedArray[o].lookup(e,t,!0)))return n;return null===this.parent||r?null:this.parent.lookup(e,t)},c.prototype.lookupType=function(e){var r=this.lookup(e,[t]);if(!r)throw Error("no such type: "+e);return r},c.prototype.lookupEnum=function(e){var t=this.lookup(e,[n]);if(!t)throw Error("no such Enum '"+e+"' in "+this);return t},c.prototype.lookupTypeOrEnum=function(e){var r=this.lookup(e,[t,n]);if(!r)throw Error("no such Type or Enum '"+e+"' in "+this);return r},c.prototype.lookupService=function(e){var t=this.lookup(e,[r]);if(!t)throw Error("no such Service '"+e+"' in "+this);return t},c._configure=function(e,o,i){t=e,r=o,n=i},Ti}function Fi(){if(Ai)return ki;Ai=1,ki=n;var e=Ui();((n.prototype=Object.create(e.prototype)).constructor=n).className="MapField";var t=Bi(),r=gs();function n(t,n,o,i,s,a){if(e.call(this,t,n,i,void 0,void 0,s,a),!r.isString(o))throw TypeError("keyType must be a string");this.keyType=o,this.resolvedKeyType=null,this.map=!0}return n.fromJSON=function(e,t){return new n(e,t.id,t.keyType,t.type,t.options,t.comment)},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return r.toObject(["keyType",this.keyType,"type",this.type,"id",this.id,"extend",this.extend,"options",this.options,"comment",t?this.comment:void 0])},n.prototype.resolve=function(){if(this.resolved)return this;if(void 0===t.mapKey[this.keyType])throw Error("invalid key type: "+this.keyType);return e.prototype.resolve.call(this)},n.d=function(e,t,o){return"function"==typeof o?o=r.decorateType(o).name:o&&"object"==typeof o&&(o=r.decorateEnum(o).name),function(i,s){r.decorateType(i.constructor).add(new n(s,e,t,o))}},ki}function Gi(){if(xi)return Ni;xi=1,Ni=r;var e=ys();((r.prototype=Object.create(e.prototype)).constructor=r).className="Method";var t=gs();function r(r,n,o,i,s,a,c,l,u){if(t.isObject(s)?(c=s,s=a=void 0):t.isObject(a)&&(c=a,a=void 0),void 0!==n&&!t.isString(n))throw TypeError("type must be a string");if(!t.isString(o))throw TypeError("requestType must be a string");if(!t.isString(i))throw TypeError("responseType must be a string");e.call(this,r,c),this.type=n||"rpc",this.requestType=o,this.requestStream=!!s||void 0,this.responseType=i,this.responseStream=!!a||void 0,this.resolvedRequestType=null,this.resolvedResponseType=null,this.comment=l,this.parsedOptions=u}return r.fromJSON=function(e,t){return new r(e,t.type,t.requestType,t.responseType,t.requestStream,t.responseStream,t.options,t.comment,t.parsedOptions)},r.prototype.toJSON=function(e){var r=!!e&&Boolean(e.keepComments);return t.toObject(["type","rpc"!==this.type&&this.type||void 0,"requestType",this.requestType,"requestStream",this.requestStream,"responseType",this.responseType,"responseStream",this.responseStream,"options",this.options,"comment",r?this.comment:void 0,"parsedOptions",this.parsedOptions])},r.prototype.resolve=function(){return this.resolved?this:(this.resolvedRequestType=this.parent.lookupType(this.requestType),this.resolvedResponseType=this.parent.lookupType(this.responseType),e.prototype.resolve.call(this))},Ni}function qi(){if(Mi)return Di;Mi=1,Di=o;var e=Pi();((o.prototype=Object.create(e.prototype)).constructor=o).className="Service";var t=Gi(),r=gs(),n=Br;function o(t,r){e.call(this,t,r),this.methods={},this._methodsArray=null}function i(e){return e._methodsArray=null,e}return o.fromJSON=function(e,r){var n=new o(e,r.options);if(r.methods)for(var i=Object.keys(r.methods),s=0;s<i.length;++s)n.add(t.fromJSON(i[s],r.methods[i[s]]));return r.nested&&n.addJSON(r.nested),n.comment=r.comment,n},o.prototype.toJSON=function(t){var n=e.prototype.toJSON.call(this,t),o=!!t&&Boolean(t.keepComments);return r.toObject(["options",n&&n.options||void 0,"methods",e.arrayToJSON(this.methodsArray,t)||{},"nested",n&&n.nested||void 0,"comment",o?this.comment:void 0])},Object.defineProperty(o.prototype,"methodsArray",{get:function(){return this._methodsArray||(this._methodsArray=r.toArray(this.methods))}}),o.prototype.get=function(t){return this.methods[t]||e.prototype.get.call(this,t)},o.prototype.resolveAll=function(){for(var t=this.methodsArray,r=0;r<t.length;++r)t[r].resolve();return e.prototype.resolve.call(this)},o.prototype.add=function(r){if(this.get(r.name))throw Error("duplicate name '"+r.name+"' in "+this);return r instanceof t?(this.methods[r.name]=r,r.parent=this,i(this)):e.prototype.add.call(this,r)},o.prototype.remove=function(r){if(r instanceof t){if(this.methods[r.name]!==r)throw Error(r+" is not a member of "+this);return delete this.methods[r.name],r.parent=null,i(this)}return e.prototype.remove.call(this,r)},o.prototype.create=function(e,t,o){for(var i,s=new n.Service(e,t,o),a=0;a<this.methodsArray.length;++a){var c=r.lcFirst((i=this._methodsArray[a]).resolve().name).replace(/[^$\w_]/g,"");s[c]=r.codegen(["r","c"],r.isReserved(c)?c+"_":c)("return this.rpcCall(m,q,s,r,c)")({m:i,q:i.resolvedRequestType.ctor,s:i.resolvedResponseType.ctor})}return s},Di}var Hi,zi,Ki,Vi,Wi=Ji,$i=Zt();function Ji(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)this[t[r]]=e[t[r]]}function Zi(){if(zi)return Hi;zi=1,Hi=function(o){var i=r.codegen(["r","l"],o.name+"$decode")("if(!(r instanceof Reader))")("r=Reader.create(r)")("var c=l===undefined?r.len:r.pos+l,m=new this.ctor"+(o.fieldsArray.filter((function(e){return e.map})).length?",k,value":""))("while(r.pos<c){")("var t=r.uint32()");o.group&&i("if((t&7)===4)")("break");i("switch(t>>>3){");for(var s=0;s<o.fieldsArray.length;++s){var a=o._fieldsArray[s].resolve(),c=a.resolvedType instanceof e?"int32":a.type,l="m"+r.safeProp(a.name);i("case %i: {",a.id),a.map?(i("if(%s===util.emptyObject)",l)("%s={}",l)("var c2 = r.uint32()+r.pos"),void 0!==t.defaults[a.keyType]?i("k=%j",t.defaults[a.keyType]):i("k=null"),void 0!==t.defaults[c]?i("value=%j",t.defaults[c]):i("value=null"),i("while(r.pos<c2){")("var tag2=r.uint32()")("switch(tag2>>>3){")("case 1: k=r.%s(); break",a.keyType)("case 2:"),void 0===t.basic[c]?i("value=types[%i].decode(r,r.uint32())",s):i("value=r.%s()",c),i("break")("default:")("r.skipType(tag2&7)")("break")("}")("}"),void 0!==t.long[a.keyType]?i('%s[typeof k==="object"?util.longToHash(k):k]=value',l):i("%s[k]=value",l)):a.repeated?(i("if(!(%s&&%s.length))",l,l)("%s=[]",l),void 0!==t.packed[c]&&i("if((t&7)===2){")("var c2=r.uint32()+r.pos")("while(r.pos<c2)")("%s.push(r.%s())",l,c)("}else"),void 0===t.basic[c]?i(a.resolvedType.group?"%s.push(types[%i].decode(r))":"%s.push(types[%i].decode(r,r.uint32()))",l,s):i("%s.push(r.%s())",l,c)):void 0===t.basic[c]?i(a.resolvedType.group?"%s=types[%i].decode(r)":"%s=types[%i].decode(r,r.uint32())",l,s):i("%s=r.%s()",l,c),i("break")("}")}for(i("default:")("r.skipType(t&7)")("break")("}")("}"),s=0;s<o._fieldsArray.length;++s){var u=o._fieldsArray[s];u.required&&i("if(!m.hasOwnProperty(%j))",u.name)("throw util.ProtocolError(%j,{instance:m})",n(u))}return i("return m")};var e=vs(),t=Bi(),r=gs();function n(e){return"missing required '"+e.name+"'"}return Hi}function Xi(){if(Vi)return Ki;Vi=1,Ki=function(e){var i=t.codegen(["m"],e.name+"$verify")('if(typeof m!=="object"||m===null)')("return%j","object expected"),s=e.oneofsArray,a={};s.length&&i("var p={}");for(var c=0;c<e.fieldsArray.length;++c){var l=e._fieldsArray[c].resolve(),u="m"+t.safeProp(l.name);if(l.optional&&i("if(%s!=null&&m.hasOwnProperty(%j)){",u,l.name),l.map)i("if(!util.isObject(%s))",u)("return%j",r(l,"object"))("var k=Object.keys(%s)",u)("for(var i=0;i<k.length;++i){"),o(i,l,"k[i]"),n(i,l,c,u+"[k[i]]")("}");else if(l.repeated)i("if(!Array.isArray(%s))",u)("return%j",r(l,"array"))("for(var i=0;i<%s.length;++i){",u),n(i,l,c,u+"[i]")("}");else{if(l.partOf){var d=t.safeProp(l.partOf.name);1===a[l.partOf.name]&&i("if(p%s===1)",d)("return%j",l.partOf.name+": multiple values"),a[l.partOf.name]=1,i("p%s=1",d)}n(i,l,c,u)}l.optional&&i("}")}return i("return null")};var e=vs(),t=gs();function r(e,t){return e.name+": "+t+(e.repeated&&"array"!==t?"[]":e.map&&"object"!==t?"{k:"+e.keyType+"}":"")+" expected"}function n(t,n,o,i){if(n.resolvedType)if(n.resolvedType instanceof e){t("switch(%s){",i)("default:")("return%j",r(n,"enum value"));for(var s=Object.keys(n.resolvedType.values),a=0;a<s.length;++a)t("case %i:",n.resolvedType.values[s[a]]);t("break")("}")}else t("{")("var e=types[%i].verify(%s);",o,i)("if(e)")("return%j+e",n.name+".")("}");else switch(n.type){case"int32":case"uint32":case"sint32":case"fixed32":case"sfixed32":t("if(!util.isInteger(%s))",i)("return%j",r(n,"integer"));break;case"int64":case"uint64":case"sint64":case"fixed64":case"sfixed64":t("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))",i,i,i,i)("return%j",r(n,"integer|Long"));break;case"float":case"double":t('if(typeof %s!=="number")',i)("return%j",r(n,"number"));break;case"bool":t('if(typeof %s!=="boolean")',i)("return%j",r(n,"boolean"));break;case"string":t("if(!util.isString(%s))",i)("return%j",r(n,"string"));break;case"bytes":t('if(!(%s&&typeof %s.length==="number"||util.isString(%s)))',i,i,i)("return%j",r(n,"buffer"))}return t}function o(e,t,n){switch(t.keyType){case"int32":case"uint32":case"sint32":case"fixed32":case"sfixed32":e("if(!util.key32Re.test(%s))",n)("return%j",r(t,"integer key"));break;case"int64":case"uint64":case"sint64":case"fixed64":case"sfixed64":e("if(!util.key64Re.test(%s))",n)("return%j",r(t,"integer|Long key"));break;case"bool":e("if(!util.key2Re.test(%s))",n)("return%j",r(t,"boolean key"))}return e}return Ki}Ji.create=function(e){return this.$type.create(e)},Ji.encode=function(e,t){return this.$type.encode(e,t)},Ji.encodeDelimited=function(e,t){return this.$type.encodeDelimited(e,t)},Ji.decode=function(e){return this.$type.decode(e)},Ji.decodeDelimited=function(e){return this.$type.decodeDelimited(e)},Ji.verify=function(e){return this.$type.verify(e)},Ji.fromObject=function(e){return this.$type.fromObject(e)},Ji.toObject=function(e,t){return this.$type.toObject(e,t)},Ji.prototype.toJSON=function(){return this.$type.toObject(this,$i.toJSONOptions)};var Yi,Qi={};function es(){return Yi||(Yi=1,function(e){var t=e,r=vs(),n=gs();function o(e,t,n,o){var i=!1;if(t.resolvedType)if(t.resolvedType instanceof r){e("switch(d%s){",o);for(var s=t.resolvedType.values,a=Object.keys(s),c=0;c<a.length;++c)s[a[c]]!==t.typeDefault||i||(e("default:")('if(typeof(d%s)==="number"){m%s=d%s;break}',o,o,o),t.repeated||e("break"),i=!0),e("case%j:",a[c])("case %i:",s[a[c]])("m%s=%j",o,s[a[c]])("break");e("}")}else e('if(typeof d%s!=="object")',o)("throw TypeError(%j)",t.fullName+": object expected")("m%s=types[%i].fromObject(d%s)",o,n,o);else{var l=!1;switch(t.type){case"double":case"float":e("m%s=Number(d%s)",o,o);break;case"uint32":case"fixed32":e("m%s=d%s>>>0",o,o);break;case"int32":case"sint32":case"sfixed32":e("m%s=d%s|0",o,o);break;case"uint64":l=!0;case"int64":case"sint64":case"fixed64":case"sfixed64":e("if(util.Long)")("(m%s=util.Long.fromValue(d%s)).unsigned=%j",o,o,l)('else if(typeof d%s==="string")',o)("m%s=parseInt(d%s,10)",o,o)('else if(typeof d%s==="number")',o)("m%s=d%s",o,o)('else if(typeof d%s==="object")',o)("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)",o,o,o,l?"true":"");break;case"bytes":e('if(typeof d%s==="string")',o)("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)",o,o,o)("else if(d%s.length >= 0)",o)("m%s=d%s",o,o);break;case"string":e("m%s=String(d%s)",o,o);break;case"bool":e("m%s=Boolean(d%s)",o,o)}}return e}function i(e,t,n,o){if(t.resolvedType)t.resolvedType instanceof r?e("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s",o,n,o,o,n,o,o):e("d%s=types[%i].toObject(m%s,o)",o,n,o);else{var i=!1;switch(t.type){case"double":case"float":e("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s",o,o,o,o);break;case"uint64":i=!0;case"int64":case"sint64":case"fixed64":case"sfixed64":e('if(typeof m%s==="number")',o)("d%s=o.longs===String?String(m%s):m%s",o,o,o)("else")("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s",o,o,o,o,i?"true":"",o);break;case"bytes":e("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s",o,o,o,o,o);break;default:e("d%s=m%s",o,o)}}return e}t.fromObject=function(e){var t=e.fieldsArray,i=n.codegen(["d"],e.name+"$fromObject")("if(d instanceof this.ctor)")("return d");if(!t.length)return i("return new this.ctor");i("var m=new this.ctor");for(var s=0;s<t.length;++s){var a=t[s].resolve(),c=n.safeProp(a.name);a.map?(i("if(d%s){",c)('if(typeof d%s!=="object")',c)("throw TypeError(%j)",a.fullName+": object expected")("m%s={}",c)("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){",c),o(i,a,s,c+"[ks[i]]")("}")("}")):a.repeated?(i("if(d%s){",c)("if(!Array.isArray(d%s))",c)("throw TypeError(%j)",a.fullName+": array expected")("m%s=[]",c)("for(var i=0;i<d%s.length;++i){",c),o(i,a,s,c+"[i]")("}")("}")):(a.resolvedType instanceof r||i("if(d%s!=null){",c),o(i,a,s,c),a.resolvedType instanceof r||i("}"))}return i("return m")},t.toObject=function(e){var t=e.fieldsArray.slice().sort(n.compareFieldsById);if(!t.length)return n.codegen()("return {}");for(var o=n.codegen(["m","o"],e.name+"$toObject")("if(!o)")("o={}")("var d={}"),s=[],a=[],c=[],l=0;l<t.length;++l)t[l].partOf||(t[l].resolve().repeated?s:t[l].map?a:c).push(t[l]);if(s.length){for(o("if(o.arrays||o.defaults){"),l=0;l<s.length;++l)o("d%s=[]",n.safeProp(s[l].name));o("}")}if(a.length){for(o("if(o.objects||o.defaults){"),l=0;l<a.length;++l)o("d%s={}",n.safeProp(a[l].name));o("}")}if(c.length){for(o("if(o.defaults){"),l=0;l<c.length;++l){var u=c[l],d=n.safeProp(u.name);if(u.resolvedType instanceof r)o("d%s=o.enums===String?%j:%j",d,u.resolvedType.valuesById[u.typeDefault],u.typeDefault);else if(u.long)o("if(util.Long){")("var n=new util.Long(%i,%i,%j)",u.typeDefault.low,u.typeDefault.high,u.typeDefault.unsigned)("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n",d)("}else")("d%s=o.longs===String?%j:%i",d,u.typeDefault.toString(),u.typeDefault.toNumber());else if(u.bytes){var h="["+Array.prototype.slice.call(u.typeDefault).join(",")+"]";o("if(o.bytes===String)d%s=%j",d,String.fromCharCode.apply(String,u.typeDefault))("else{")("d%s=%s",d,h)("if(o.bytes!==Array)d%s=util.newBuffer(d%s)",d,d)("}")}else o("d%s=%j",d,u.typeDefault)}o("}")}var f=!1;for(l=0;l<t.length;++l){u=t[l];var p=e._fieldsArray.indexOf(u);d=n.safeProp(u.name);u.map?(f||(f=!0,o("var ks2")),o("if(m%s&&(ks2=Object.keys(m%s)).length){",d,d)("d%s={}",d)("for(var j=0;j<ks2.length;++j){"),i(o,u,p,d+"[ks2[j]]")("}")):u.repeated?(o("if(m%s&&m%s.length){",d,d)("d%s=[]",d)("for(var j=0;j<m%s.length;++j){",d),i(o,u,p,d+"[j]")("}")):(o("if(m%s!=null&&m.hasOwnProperty(%j)){",d,u.name),i(o,u,p,d),u.partOf&&o("if(o.oneofs)")("d%s=%j",n.safeProp(u.partOf.name),u.name)),o("}")}return o("return d")}}(Qi)),Qi}var ts,rs,ns,os,is,ss,as,cs,ls,us,ds,hs={};function fs(){if(rs)return ts;rs=1,ts=g;var e=Pi();((g.prototype=Object.create(e.prototype)).constructor=g).className="Type";var t=vs(),r=ji(),n=Ui(),o=Fi(),i=qi(),s=Wi,a=br,c=Yt,l=gs(),u=ms(),d=Zi(),h=Xi(),f=es(),p=hs;function g(t,r){e.call(this,t,r),this.fields={},this.oneofs=void 0,this.extensions=void 0,this.reserved=void 0,this.group=void 0,this._fieldsById=null,this._fieldsArray=null,this._oneofsArray=null,this._ctor=null}function y(e){return e._fieldsById=e._fieldsArray=e._oneofsArray=null,delete e.encode,delete e.decode,delete e.verify,e}return Object.defineProperties(g.prototype,{fieldsById:{get:function(){if(this._fieldsById)return this._fieldsById;this._fieldsById={};for(var e=Object.keys(this.fields),t=0;t<e.length;++t){var r=this.fields[e[t]],n=r.id;if(this._fieldsById[n])throw Error("duplicate id "+n+" in "+this);this._fieldsById[n]=r}return this._fieldsById}},fieldsArray:{get:function(){return this._fieldsArray||(this._fieldsArray=l.toArray(this.fields))}},oneofsArray:{get:function(){return this._oneofsArray||(this._oneofsArray=l.toArray(this.oneofs))}},ctor:{get:function(){return this._ctor||(this.ctor=g.generateConstructor(this)())},set:function(e){var t=e.prototype;t instanceof s||((e.prototype=new s).constructor=e,l.merge(e.prototype,t)),e.$type=e.prototype.$type=this,l.merge(e,s,!0),this._ctor=e;for(var r=0;r<this.fieldsArray.length;++r)this._fieldsArray[r].resolve();var n={};for(r=0;r<this.oneofsArray.length;++r)n[this._oneofsArray[r].resolve().name]={get:l.oneOfGetter(this._oneofsArray[r].oneof),set:l.oneOfSetter(this._oneofsArray[r].oneof)};r&&Object.defineProperties(e.prototype,n)}}}),g.generateConstructor=function(e){for(var t,r=l.codegen(["p"],e.name),n=0;n<e.fieldsArray.length;++n)(t=e._fieldsArray[n]).map?r("this%s={}",l.safeProp(t.name)):t.repeated&&r("this%s=[]",l.safeProp(t.name));return r("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)")("this[ks[i]]=p[ks[i]]")},g.fromJSON=function(s,a){var c=new g(s,a.options);c.extensions=a.extensions,c.reserved=a.reserved;for(var l=Object.keys(a.fields),u=0;u<l.length;++u)c.add((void 0!==a.fields[l[u]].keyType?o.fromJSON:n.fromJSON)(l[u],a.fields[l[u]]));if(a.oneofs)for(l=Object.keys(a.oneofs),u=0;u<l.length;++u)c.add(r.fromJSON(l[u],a.oneofs[l[u]]));if(a.nested)for(l=Object.keys(a.nested),u=0;u<l.length;++u){var d=a.nested[l[u]];c.add((void 0!==d.id?n.fromJSON:void 0!==d.fields?g.fromJSON:void 0!==d.values?t.fromJSON:void 0!==d.methods?i.fromJSON:e.fromJSON)(l[u],d))}return a.extensions&&a.extensions.length&&(c.extensions=a.extensions),a.reserved&&a.reserved.length&&(c.reserved=a.reserved),a.group&&(c.group=!0),a.comment&&(c.comment=a.comment),c},g.prototype.toJSON=function(t){var r=e.prototype.toJSON.call(this,t),n=!!t&&Boolean(t.keepComments);return l.toObject(["options",r&&r.options||void 0,"oneofs",e.arrayToJSON(this.oneofsArray,t),"fields",e.arrayToJSON(this.fieldsArray.filter((function(e){return!e.declaringField})),t)||{},"extensions",this.extensions&&this.extensions.length?this.extensions:void 0,"reserved",this.reserved&&this.reserved.length?this.reserved:void 0,"group",this.group||void 0,"nested",r&&r.nested||void 0,"comment",n?this.comment:void 0])},g.prototype.resolveAll=function(){for(var t=this.fieldsArray,r=0;r<t.length;)t[r++].resolve();var n=this.oneofsArray;for(r=0;r<n.length;)n[r++].resolve();return e.prototype.resolveAll.call(this)},g.prototype.get=function(e){return this.fields[e]||this.oneofs&&this.oneofs[e]||this.nested&&this.nested[e]||null},g.prototype.add=function(t){if(this.get(t.name))throw Error("duplicate name '"+t.name+"' in "+this);if(t instanceof n&&void 0===t.extend){if(this._fieldsById?this._fieldsById[t.id]:this.fieldsById[t.id])throw Error("duplicate id "+t.id+" in "+this);if(this.isReservedId(t.id))throw Error("id "+t.id+" is reserved in "+this);if(this.isReservedName(t.name))throw Error("name '"+t.name+"' is reserved in "+this);return t.parent&&t.parent.remove(t),this.fields[t.name]=t,t.message=this,t.onAdd(this),y(this)}return t instanceof r?(this.oneofs||(this.oneofs={}),this.oneofs[t.name]=t,t.onAdd(this),y(this)):e.prototype.add.call(this,t)},g.prototype.remove=function(t){if(t instanceof n&&void 0===t.extend){if(!this.fields||this.fields[t.name]!==t)throw Error(t+" is not a member of "+this);return delete this.fields[t.name],t.parent=null,t.onRemove(this),y(this)}if(t instanceof r){if(!this.oneofs||this.oneofs[t.name]!==t)throw Error(t+" is not a member of "+this);return delete this.oneofs[t.name],t.parent=null,t.onRemove(this),y(this)}return e.prototype.remove.call(this,t)},g.prototype.isReservedId=function(t){return e.isReservedId(this.reserved,t)},g.prototype.isReservedName=function(t){return e.isReservedName(this.reserved,t)},g.prototype.create=function(e){return new this.ctor(e)},g.prototype.setup=function(){for(var e=this.fullName,t=[],r=0;r<this.fieldsArray.length;++r)t.push(this._fieldsArray[r].resolve().resolvedType);this.encode=u(this)({Writer:c,types:t,util:l}),this.decode=d(this)({Reader:a,types:t,util:l}),this.verify=h(this)({types:t,util:l}),this.fromObject=f.fromObject(this)({types:t,util:l}),this.toObject=f.toObject(this)({types:t,util:l});var n=p[e];if(n){var o=Object.create(this);o.fromObject=this.fromObject,this.fromObject=n.fromObject.bind(o),o.toObject=this.toObject,this.toObject=n.toObject.bind(o)}return this},g.prototype.encode=function(e,t){return this.setup().encode(e,t)},g.prototype.encodeDelimited=function(e,t){return this.encode(e,t&&t.len?t.fork():t).ldelim()},g.prototype.decode=function(e,t){return this.setup().decode(e,t)},g.prototype.decodeDelimited=function(e){return e instanceof a||(e=a.create(e)),this.decode(e,e.uint32())},g.prototype.verify=function(e){return this.setup().verify(e)},g.prototype.fromObject=function(e){return this.setup().fromObject(e)},g.prototype.toObject=function(e,t){return this.setup().toObject(e,t)},g.d=function(e){return function(t){l.decorateType(t,e)}},ts}function ps(){if(os)return ns;os=1,ns=c;var e=Pi();((c.prototype=Object.create(e.prototype)).constructor=c).className="Root";var t,r,n,o=Ui(),i=vs(),s=ji(),a=gs();function c(t){e.call(this,"",t),this.deferred=[],this.files=[]}function l(){}c.fromJSON=function(e,t){return t||(t=new c),e.options&&t.setOptions(e.options),t.addJSON(e.nested)},c.prototype.resolvePath=a.path.resolve,c.prototype.fetch=a.fetch,c.prototype.load=function e(t,o,i){"function"==typeof o&&(i=o,o=void 0);var s=this;if(!i)return a.asPromise(e,s,t,o);var c=i===l;function u(e,t){if(i){var r=i;if(i=null,c)throw e;r(e,t)}}function d(e){var t=e.lastIndexOf("google/protobuf/");if(t>-1){var r=e.substring(t);if(r in n)return r}return null}function h(e,t){try{if(a.isString(t)&&"{"===t.charAt(0)&&(t=JSON.parse(t)),a.isString(t)){r.filename=e;var n,i=r(t,s,o),l=0;if(i.imports)for(;l<i.imports.length;++l)(n=d(i.imports[l])||s.resolvePath(e,i.imports[l]))&&f(n);if(i.weakImports)for(l=0;l<i.weakImports.length;++l)(n=d(i.weakImports[l])||s.resolvePath(e,i.weakImports[l]))&&f(n,!0)}else s.setOptions(t.options).addJSON(t.nested)}catch(e){u(e)}c||p||u(null,s)}function f(e,t){if(e=d(e)||e,!(s.files.indexOf(e)>-1))if(s.files.push(e),e in n)c?h(e,n[e]):(++p,setTimeout((function(){--p,h(e,n[e])})));else if(c){var r;try{r=a.fs.readFileSync(e).toString("utf8")}catch(e){return void(t||u(e))}h(e,r)}else++p,s.fetch(e,(function(r,n){--p,i&&(r?t?p||u(null,s):u(r):h(e,n))}))}var p=0;a.isString(t)&&(t=[t]);for(var g,y=0;y<t.length;++y)(g=s.resolvePath("",t[y]))&&f(g);if(c)return s;p||u(null,s)},c.prototype.loadSync=function(e,t){if(!a.isNode)throw Error("not supported");return this.load(e,t,l)},c.prototype.resolveAll=function(){if(this.deferred.length)throw Error("unresolvable extensions: "+this.deferred.map((function(e){return"'extend "+e.extend+"' in "+e.parent.fullName})).join(", "));return e.prototype.resolveAll.call(this)};var u=/^[A-Z]/;function d(e,t){var r=t.parent.lookup(t.extend);if(r){var n=new o(t.fullName,t.id,t.type,t.rule,void 0,t.options);return r.get(n.name)||(n.declaringField=t,t.extensionField=n,r.add(n)),!0}return!1}return c.prototype._handleAdd=function(e){if(e instanceof o)void 0===e.extend||e.extensionField||d(0,e)||this.deferred.push(e);else if(e instanceof i)u.test(e.name)&&(e.parent[e.name]=e.values);else if(!(e instanceof s)){if(e instanceof t)for(var r=0;r<this.deferred.length;)d(0,this.deferred[r])?this.deferred.splice(r,1):++r;for(var n=0;n<e.nestedArray.length;++n)this._handleAdd(e._nestedArray[n]);u.test(e.name)&&(e.parent[e.name]=e)}},c.prototype._handleRemove=function(t){if(t instanceof o){if(void 0!==t.extend)if(t.extensionField)t.extensionField.parent.remove(t.extensionField),t.extensionField=null;else{var r=this.deferred.indexOf(t);r>-1&&this.deferred.splice(r,1)}}else if(t instanceof i)u.test(t.name)&&delete t.parent[t.name];else if(t instanceof e){for(var n=0;n<t.nestedArray.length;++n)this._handleRemove(t._nestedArray[n]);u.test(t.name)&&delete t.parent[t.name]}},c._configure=function(e,o,i){t=e,r=o,n=i},ns}function gs(){return is||(is=1,function(e){var t,r,n=pi.exports=Zt(),o=Fr;n.codegen=gi,n.fetch=vi,n.path=Oi,n.fs=n.inquire("fs"),n.toArray=function(e){if(e){for(var t=Object.keys(e),r=new Array(t.length),n=0;n<t.length;)r[n]=e[t[n++]];return r}return[]},n.toObject=function(e){for(var t={},r=0;r<e.length;){var n=e[r++],o=e[r++];void 0!==o&&(t[n]=o)}return t};var i=/\\/g,s=/"/g;n.isReserved=function(e){return/^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(e)},n.safeProp=function(e){return!/^[$\w_]+$/.test(e)||n.isReserved(e)?'["'+e.replace(i,"\\\\").replace(s,'\\"')+'"]':"."+e},n.ucFirst=function(e){return e.charAt(0).toUpperCase()+e.substring(1)};var a=/_([a-z])/g;n.camelCase=function(e){return e.substring(0,1)+e.substring(1).replace(a,(function(e,t){return t.toUpperCase()}))},n.compareFieldsById=function(e,t){return e.id-t.id},n.decorateType=function(e,r){if(e.$type)return r&&e.$type.name!==r&&(n.decorateRoot.remove(e.$type),e.$type.name=r,n.decorateRoot.add(e.$type)),e.$type;t||(t=fs());var o=new t(r||e.name);return n.decorateRoot.add(o),o.ctor=e,Object.defineProperty(e,"$type",{value:o,enumerable:!1}),Object.defineProperty(e.prototype,"$type",{value:o,enumerable:!1}),o};var c=0;n.decorateEnum=function(e){if(e.$type)return e.$type;r||(r=vs());var t=new r("Enum"+c++,e);return n.decorateRoot.add(t),Object.defineProperty(e,"$type",{value:t,enumerable:!1}),t},n.setProperty=function(e,t,r){if("object"!=typeof e)throw TypeError("dst must be an object");if(!t)throw TypeError("path must be specified");return function e(t,r,n){var o=r.shift();if("__proto__"===o)return t;if(r.length>0)t[o]=e(t[o]||{},r,n);else{var i=t[o];i&&(n=[].concat(i).concat(n)),t[o]=n}return t}(e,t=t.split("."),r)},Object.defineProperty(n,"decorateRoot",{get:function(){return o.decorated||(o.decorated=new(ps()))}})}()),pi.exports}function ys(){if(as)return ss;as=1,ss=r,r.className="ReflectionObject";var e,t=gs();function r(e,r){if(!t.isString(e))throw TypeError("name must be a string");if(r&&!t.isObject(r))throw TypeError("options must be an object");this.options=r,this.parsedOptions=null,this.name=e,this.parent=null,this.resolved=!1,this.comment=null,this.filename=null}return Object.defineProperties(r.prototype,{root:{get:function(){for(var e=this;null!==e.parent;)e=e.parent;return e}},fullName:{get:function(){for(var e=[this.name],t=this.parent;t;)e.unshift(t.name),t=t.parent;return e.join(".")}}}),r.prototype.toJSON=function(){throw Error()},r.prototype.onAdd=function(t){this.parent&&this.parent!==t&&this.parent.remove(this),this.parent=t,this.resolved=!1;var r=t.root;r instanceof e&&r._handleAdd(this)},r.prototype.onRemove=function(t){var r=t.root;r instanceof e&&r._handleRemove(this),this.parent=null,this.resolved=!1},r.prototype.resolve=function(){return this.resolved||this.root instanceof e&&(this.resolved=!0),this},r.prototype.getOption=function(e){if(this.options)return this.options[e]},r.prototype.setOption=function(e,t,r){return r&&this.options&&void 0!==this.options[e]||((this.options||(this.options={}))[e]=t),this},r.prototype.setParsedOption=function(e,r,n){this.parsedOptions||(this.parsedOptions=[]);var o=this.parsedOptions;if(n){var i=o.find((function(t){return Object.prototype.hasOwnProperty.call(t,e)}));if(i){var s=i[e];t.setProperty(s,n,r)}else(i={})[e]=t.setProperty({},n,r),o.push(i)}else{var a={};a[e]=r,o.push(a)}return this},r.prototype.setOptions=function(e,t){if(e)for(var r=Object.keys(e),n=0;n<r.length;++n)this.setOption(r[n],e[r[n]],t);return this},r.prototype.toString=function(){var e=this.constructor.className,t=this.fullName;return t.length?e+" "+t:e},r._configure=function(t){e=t},ss}function vs(){if(ls)return cs;ls=1,cs=n;var e=ys();((n.prototype=Object.create(e.prototype)).constructor=n).className="Enum";var t=Pi(),r=gs();function n(t,r,n,o,i,s){if(e.call(this,t,n),r&&"object"!=typeof r)throw TypeError("values must be an object");if(this.valuesById={},this.values=Object.create(this.valuesById),this.comment=o,this.comments=i||{},this.valuesOptions=s,this.reserved=void 0,r)for(var a=Object.keys(r),c=0;c<a.length;++c)"number"==typeof r[a[c]]&&(this.valuesById[this.values[a[c]]=r[a[c]]]=a[c])}return n.fromJSON=function(e,t){var r=new n(e,t.values,t.options,t.comment,t.comments);return r.reserved=t.reserved,r},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return r.toObject(["options",this.options,"valuesOptions",this.valuesOptions,"values",this.values,"reserved",this.reserved&&this.reserved.length?this.reserved:void 0,"comment",t?this.comment:void 0,"comments",t?this.comments:void 0])},n.prototype.add=function(e,t,n,o){if(!r.isString(e))throw TypeError("name must be a string");if(!r.isInteger(t))throw TypeError("id must be an integer");if(void 0!==this.values[e])throw Error("duplicate name '"+e+"' in "+this);if(this.isReservedId(t))throw Error("id "+t+" is reserved in "+this);if(this.isReservedName(e))throw Error("name '"+e+"' is reserved in "+this);if(void 0!==this.valuesById[t]){if(!this.options||!this.options.allow_alias)throw Error("duplicate id "+t+" in "+this);this.values[e]=t}else this.valuesById[this.values[e]=t]=e;return o&&(void 0===this.valuesOptions&&(this.valuesOptions={}),this.valuesOptions[e]=o||null),this.comments[e]=n||null,this},n.prototype.remove=function(e){if(!r.isString(e))throw TypeError("name must be a string");var t=this.values[e];if(null==t)throw Error("name '"+e+"' does not exist in "+this);return delete this.valuesById[t],delete this.values[e],delete this.comments[e],this.valuesOptions&&delete this.valuesOptions[e],this},n.prototype.isReservedId=function(e){return t.isReservedId(this.reserved,e)},n.prototype.isReservedName=function(e){return t.isReservedName(this.reserved,e)},cs}function ms(){if(ds)return us;ds=1,us=function(o){for(var i,s=r.codegen(["m","w"],o.name+"$encode")("if(!w)")("w=Writer.create()"),a=o.fieldsArray.slice().sort(r.compareFieldsById),c=0;c<a.length;++c){var l=a[c].resolve(),u=o._fieldsArray.indexOf(l),d=l.resolvedType instanceof e?"int32":l.type,h=t.basic[d];i="m"+r.safeProp(l.name),l.map?(s("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){",i,l.name)("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){",i)("w.uint32(%i).fork().uint32(%i).%s(ks[i])",(l.id<<3|2)>>>0,8|t.mapKey[l.keyType],l.keyType),void 0===h?s("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()",u,i):s(".uint32(%i).%s(%s[ks[i]]).ldelim()",16|h,d,i),s("}")("}")):l.repeated?(s("if(%s!=null&&%s.length){",i,i),l.packed&&void 0!==t.packed[d]?s("w.uint32(%i).fork()",(l.id<<3|2)>>>0)("for(var i=0;i<%s.length;++i)",i)("w.%s(%s[i])",d,i)("w.ldelim()"):(s("for(var i=0;i<%s.length;++i)",i),void 0===h?n(s,l,u,i+"[i]"):s("w.uint32(%i).%s(%s[i])",(l.id<<3|h)>>>0,d,i)),s("}")):(l.optional&&s("if(%s!=null&&Object.hasOwnProperty.call(m,%j))",i,l.name),void 0===h?n(s,l,u,i):s("w.uint32(%i).%s(%s)",(l.id<<3|h)>>>0,d,i))}return s("return w")};var e=vs(),t=Bi(),r=gs();function n(e,t,r,n){return t.resolvedType.group?e("types[%i].encode(%s,w.uint32(%i)).uint32(%i)",r,n,(t.id<<3|3)>>>0,(t.id<<3|4)>>>0):e("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()",r,n,(t.id<<3|2)>>>0)}return us}!function(e){var t=Wi;e[".google.protobuf.Any"]={fromObject:function(e){if(e&&e["@type"]){var t=e["@type"].substring(e["@type"].lastIndexOf("/")+1),r=this.lookup(t);if(r){var n="."===e["@type"].charAt(0)?e["@type"].slice(1):e["@type"];return-1===n.indexOf("/")&&(n="/"+n),this.create({type_url:n,value:r.encode(r.fromObject(e)).finish()})}}return this.fromObject(e)},toObject:function(e,r){var n="",o="";if(r&&r.json&&e.type_url&&e.value){o=e.type_url.substring(e.type_url.lastIndexOf("/")+1),n=e.type_url.substring(0,e.type_url.lastIndexOf("/")+1);var i=this.lookup(o);i&&(e=i.decode(e.value))}if(!(e instanceof this.ctor)&&e instanceof t){var s=e.$type.toObject(e,r);return""===n&&(n="type.googleapis.com/"),o=n+("."===e.$type.fullName[0]?e.$type.fullName.slice(1):e.$type.fullName),s["@type"]=o,s}return this.toObject(e,r)}}}(hs),function(e){var t=fi.exports=xt;t.build="light",t.load=function(e,r,n){return"function"==typeof r?(n=r,r=new t.Root):r||(r=new t.Root),r.load(e,n)},t.loadSync=function(e,r){return r||(r=new t.Root),r.loadSync(e)},t.encoder=ms(),t.decoder=Zi(),t.verifier=Xi(),t.converter=es(),t.ReflectionObject=ys(),t.Namespace=Pi(),t.Root=ps(),t.Enum=vs(),t.Type=fs(),t.Field=Ui(),t.OneOf=ji(),t.MapField=Fi(),t.Service=qi(),t.Method=Gi(),t.Message=Wi,t.wrappers=hs,t.types=Bi(),t.util=gs(),t.ReflectionObject._configure(t.Root),t.Namespace._configure(t.Type,t.Service,t.Enum),t.Root._configure(t.Type),t.Field._configure(t.Type)}();var bs=As,ws=/[\s{}=;:[\],'"()<>]/g,Os=/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,Cs=/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,_s=/^ *[*/]+ */,Ss=/^\s*\*?\/*/,Is=/\n/g,Es=/\s/,Ts=/\\(.?)/g,Rs={0:"\0",r:"\r",n:"\n",t:"\t"};function ks(e){return e.replace(Ts,(function(e,t){switch(t){case"\\":case"":return t;default:return Rs[t]||""}}))}function As(e,t){e=e.toString();var r=0,n=e.length,o=1,i=0,s={},a=[],c=null;function l(e){return Error("illegal "+e+" (line "+o+")")}function u(t){return e.charAt(t)}function d(r,n,a){var c,l={type:e.charAt(r++),lineEmpty:!1,leading:a},u=r-(t?2:3);do{if(--u<0||"\n"===(c=e.charAt(u))){l.lineEmpty=!0;break}}while(" "===c||"\t"===c);for(var d=e.substring(r,n).split(Is),h=0;h<d.length;++h)d[h]=d[h].replace(t?Ss:_s,"").trim();l.text=d.join("\n").trim(),s[o]=l,i=o}function h(t){var r=f(t),n=e.substring(t,r);return/^\s*\/{1,2}/.test(n)}function f(e){for(var t=e;t<n&&"\n"!==u(t);)t++;return t}function p(){if(a.length>0)return a.shift();if(c)return function(){var t="'"===c?Cs:Os;t.lastIndex=r-1;var n=t.exec(e);if(!n)throw l("string");return r=t.lastIndex,g(c),c=null,ks(n[1])}();var i,s,p,y,v,m=0===r;do{if(r===n)return null;for(i=!1;Es.test(p=u(r));)if("\n"===p&&(m=!0,++o),++r===n)return null;if("/"===u(r)){if(++r===n)throw l("comment");if("/"===u(r))if(t){if(y=r,v=!1,h(r)){v=!0;do{if((r=f(r))===n)break;if(r++,!m)break}while(h(r))}else r=Math.min(n,f(r)+1);v&&(d(y,r,m),m=!0),o++,i=!0}else{for(v="/"===u(y=r+1);"\n"!==u(++r);)if(r===n)return null;++r,v&&(d(y,r-1,m),m=!0),++o,i=!0}else{if("*"!==(p=u(r)))return"/";y=r+1,v=t||"*"===u(y);do{if("\n"===p&&++o,++r===n)throw l("comment");s=p,p=u(r)}while("*"!==s||"/"!==p);++r,v&&(d(y,r-2,m),m=!0),i=!0}}}while(i);var b=r;if(ws.lastIndex=0,!ws.test(u(b++)))for(;b<n&&!ws.test(u(b));)++b;var w=e.substring(r,r=b);return'"'!==w&&"'"!==w||(c=w),w}function g(e){a.push(e)}function y(){if(!a.length){var e=p();if(null===e)return null;g(e)}return a[0]}return Object.defineProperty({next:p,peek:y,push:g,skip:function(e,t){var r=y();if(r===e)return p(),!0;if(!t)throw l("token '"+r+"', '"+e+"' expected");return!1},cmnt:function(e){var r,n=null;return void 0===e?(r=s[o-1],delete s[o-1],r&&(t||"*"===r.type||r.lineEmpty)&&(n=r.leading?r.text:null)):(i<e&&y(),r=s[e],delete s[e],!r||r.lineEmpty||!t&&"/"!==r.type||(n=r.leading?null:r.text)),n}},"line",{get:function(){return o}})}As.unescape=ks;var Ns=Qs;Qs.filename=null,Qs.defaults={keepCase:!1};var xs=bs,Ds=ps(),Ms=fs(),Ls=Ui(),Bs=Fi(),Us=ji(),js=vs(),Ps=qi(),Fs=Gi(),Gs=Bi(),qs=gs(),Hs=/^[1-9][0-9]*$/,zs=/^-?[1-9][0-9]*$/,Ks=/^0[x][0-9a-fA-F]+$/,Vs=/^-?0[x][0-9a-fA-F]+$/,Ws=/^0[0-7]+$/,$s=/^-?0[0-7]+$/,Js=/^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,Zs=/^[a-zA-Z_][a-zA-Z_0-9]*$/,Xs=/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,Ys=/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;function Qs(e,t,r){t instanceof Ds||(r=t,t=new Ds),r||(r=Qs.defaults);var n,o,i,s,a,c=r.preferTrailingComment||!1,l=xs(e,r.alternateCommentMode||!1),u=l.next,d=l.push,h=l.peek,f=l.skip,p=l.cmnt,g=!0,y=!1,v=t,m=r.keepCase?function(e){return e}:qs.camelCase;function b(e,t,r){var n=Qs.filename;return r||(Qs.filename=null),Error("illegal "+(t||"token")+" '"+e+"' ("+(n?n+", ":"")+"line "+l.line+")")}function w(){var e,t=[];do{if('"'!==(e=u())&&"'"!==e)throw b(e);t.push(u()),f(e),e=h()}while('"'===e||"'"===e);return t.join("")}function O(e){var t=u();switch(t){case"'":case'"':return d(t),w();case"true":case"TRUE":return!0;case"false":case"FALSE":return!1}try{return function(e,t){var r=1;"-"===e.charAt(0)&&(r=-1,e=e.substring(1));switch(e){case"inf":case"INF":case"Inf":return r*(1/0);case"nan":case"NAN":case"Nan":case"NaN":return NaN;case"0":return 0}if(Hs.test(e))return r*parseInt(e,10);if(Ks.test(e))return r*parseInt(e,16);if(Ws.test(e))return r*parseInt(e,8);if(Js.test(e))return r*parseFloat(e);throw b(e,"number",t)}(t,!0)}catch(r){if(e&&Xs.test(t))return t;throw b(t,"value")}}function C(e,t){var r,n;do{!t||'"'!==(r=h())&&"'"!==r?e.push([n=_(u()),f("to",!0)?_(u()):n]):e.push(w())}while(f(",",!0));f(";")}function _(e,t){switch(e){case"max":case"MAX":case"Max":return 536870911;case"0":return 0}if(!t&&"-"===e.charAt(0))throw b(e,"id");if(zs.test(e))return parseInt(e,10);if(Vs.test(e))return parseInt(e,16);if($s.test(e))return parseInt(e,8);throw b(e,"id")}function S(){if(void 0!==n)throw b("package");if(n=u(),!Xs.test(n))throw b(n,"name");v=v.define(n),f(";")}function I(){var e,t=h();switch(t){case"weak":e=i||(i=[]),u();break;case"public":u();default:e=o||(o=[])}t=w(),f(";"),e.push(t)}function E(){if(f("="),s=w(),!(y="proto3"===s)&&"proto2"!==s)throw b(s,"syntax");f(";")}function T(e,t){switch(t){case"option":return x(e,t),f(";"),!0;case"message":return k(e,t),!0;case"enum":return N(e,t),!0;case"service":return function(e,t){if(!Zs.test(t=u()))throw b(t,"service name");var r=new Ps(t);R(r,(function(e){if(!T(r,e)){if("rpc"!==e)throw b(e);!function(e,t){var r=p(),n=t;if(!Zs.test(t=u()))throw b(t,"name");var o,i,s,a,c=t;f("("),f("stream",!0)&&(i=!0);if(!Xs.test(t=u()))throw b(t);o=t,f(")"),f("returns"),f("("),f("stream",!0)&&(a=!0);if(!Xs.test(t=u()))throw b(t);s=t,f(")");var l=new Fs(c,n,o,s,i,a);l.comment=r,R(l,(function(e){if("option"!==e)throw b(e);x(l,e),f(";")})),e.add(l)}(r,e)}})),e.add(r)}(e,t),!0;case"extend":return function(e,t){if(!Xs.test(t=u()))throw b(t,"reference");var r=t;R(null,(function(t){switch(t){case"required":case"repeated":A(e,t,r);break;case"optional":A(e,y?"proto3_optional":"optional",r);break;default:if(!y||!Xs.test(t))throw b(t);d(t),A(e,"optional",r)}}))}(e,t),!0}return!1}function R(e,t,r){var n=l.line;if(e&&("string"!=typeof e.comment&&(e.comment=p()),e.filename=Qs.filename),f("{",!0)){for(var o;"}"!==(o=u());)t(o);f(";",!0)}else r&&r(),f(";"),e&&("string"!=typeof e.comment||c)&&(e.comment=p(n)||e.comment)}function k(e,t){if(!Zs.test(t=u()))throw b(t,"type name");var r=new Ms(t);R(r,(function(e){if(!T(r,e))switch(e){case"map":!function(e){f("<");var t=u();if(void 0===Gs.mapKey[t])throw b(t,"type");f(",");var r=u();if(!Xs.test(r))throw b(r,"type");f(">");var n=u();if(!Zs.test(n))throw b(n,"name");f("=");var o=new Bs(m(n),_(u()),t,r);R(o,(function(e){if("option"!==e)throw b(e);x(o,e),f(";")}),(function(){L(o)})),e.add(o)}(r);break;case"required":case"repeated":A(r,e);break;case"optional":A(r,y?"proto3_optional":"optional");break;case"oneof":!function(e,t){if(!Zs.test(t=u()))throw b(t,"name");var r=new Us(m(t));R(r,(function(e){"option"===e?(x(r,e),f(";")):(d(e),A(r,"optional"))})),e.add(r)}(r,e);break;case"extensions":C(r.extensions||(r.extensions=[]));break;case"reserved":C(r.reserved||(r.reserved=[]),!0);break;default:if(!y||!Xs.test(e))throw b(e);d(e),A(r,"optional")}})),e.add(r)}function A(e,t,r){var n=u();if("group"!==n){if(!Xs.test(n))throw b(n,"type");var o=u();if(!Zs.test(o))throw b(o,"name");o=m(o),f("=");var i=new Ls(o,_(u()),n,t,r);if(R(i,(function(e){if("option"!==e)throw b(e);x(i,e),f(";")}),(function(){L(i)})),"proto3_optional"===t){var s=new Us("_"+o);i.setOption("proto3_optional",!0),s.add(i),e.add(s)}else e.add(i);y||!i.repeated||void 0===Gs.packed[n]&&void 0!==Gs.basic[n]||i.setOption("packed",!1,!0)}else!function(e,t){var r=u();if(!Zs.test(r))throw b(r,"name");var n=qs.lcFirst(r);r===n&&(r=qs.ucFirst(r));f("=");var o=_(u()),i=new Ms(r);i.group=!0;var s=new Ls(n,o,r,t);s.filename=Qs.filename,R(i,(function(e){switch(e){case"option":x(i,e),f(";");break;case"required":case"repeated":A(i,e);break;case"optional":A(i,y?"proto3_optional":"optional");break;case"message":k(i,e);break;case"enum":N(i,e);break;default:throw b(e)}})),e.add(i).add(s)}(e,t)}function N(e,t){if(!Zs.test(t=u()))throw b(t,"name");var r=new js(t);R(r,(function(e){switch(e){case"option":x(r,e),f(";");break;case"reserved":C(r.reserved||(r.reserved=[]),!0);break;default:!function(e,t){if(!Zs.test(t))throw b(t,"name");f("=");var r=_(u(),!0),n={options:void 0,setOption:function(e,t){void 0===this.options&&(this.options={}),this.options[e]=t}};R(n,(function(e){if("option"!==e)throw b(e);x(n,e),f(";")}),(function(){L(n)})),e.add(t,r,n.comment,n.options)}(r,e)}})),e.add(r)}function x(e,t){var r=f("(",!0);if(!Xs.test(t=u()))throw b(t,"name");var n,o=t,i=o;r&&(f(")"),i=o="("+o+")",t=h(),Ys.test(t)&&(n=t.slice(1),o+=t,u())),f("="),function(e,t,r,n){e.setParsedOption&&e.setParsedOption(t,r,n)}(e,i,D(e,o),n)}function D(e,t){if(f("{",!0)){for(var r={};!f("}",!0);){if(!Zs.test(a=u()))throw b(a,"name");var n,o=a;if(f(":",!0),"{"===h())n=D(e,t+"."+a);else if("["===h()){var i;if(n=[],f("[",!0)){do{i=O(!0),n.push(i)}while(f(",",!0));f("]"),void 0!==i&&M(e,t+"."+a,i)}}else n=O(!0),M(e,t+"."+a,n);var s=r[o];s&&(n=[].concat(s).concat(n)),r[o]=n,f(",",!0),f(";",!0)}return r}var c=O(!0);return M(e,t,c),c}function M(e,t,r){e.setOption&&e.setOption(t,r)}function L(e){if(f("[",!0)){do{x(e,"option")}while(f(",",!0));f("]")}return e}for(;null!==(a=u());)switch(a){case"package":if(!g)throw b(a);S();break;case"import":if(!g)throw b(a);I();break;case"syntax":if(!g)throw b(a);E();break;case"option":x(v,a),f(";");break;default:if(T(v,a)){g=!1;continue}throw b(a)}return Qs.filename=null,{package:n,imports:o,weakImports:i,syntax:s,root:t}}var ea,ta=na,ra=/\/|\./;function na(e,t){ra.test(e)||(e="google/protobuf/"+e+".proto",t={nested:{google:{nested:{protobuf:{nested:t}}}}}),na[e]=t}na("any",{Any:{fields:{type_url:{type:"string",id:1},value:{type:"bytes",id:2}}}}),na("duration",{Duration:ea={fields:{seconds:{type:"int64",id:1},nanos:{type:"int32",id:2}}}}),na("timestamp",{Timestamp:ea}),na("empty",{Empty:{fields:{}}}),na("struct",{Struct:{fields:{fields:{keyType:"string",type:"Value",id:1}}},Value:{oneofs:{kind:{oneof:["nullValue","numberValue","stringValue","boolValue","structValue","listValue"]}},fields:{nullValue:{type:"NullValue",id:1},numberValue:{type:"double",id:2},stringValue:{type:"string",id:3},boolValue:{type:"bool",id:4},structValue:{type:"Struct",id:5},listValue:{type:"ListValue",id:6}}},NullValue:{values:{NULL_VALUE:0}},ListValue:{fields:{values:{rule:"repeated",type:"Value",id:1}}}}),na("wrappers",{DoubleValue:{fields:{value:{type:"double",id:1}}},FloatValue:{fields:{value:{type:"float",id:1}}},Int64Value:{fields:{value:{type:"int64",id:1}}},UInt64Value:{fields:{value:{type:"uint64",id:1}}},Int32Value:{fields:{value:{type:"int32",id:1}}},UInt32Value:{fields:{value:{type:"uint32",id:1}}},BoolValue:{fields:{value:{type:"bool",id:1}}},StringValue:{fields:{value:{type:"string",id:1}}},BytesValue:{fields:{value:{type:"bytes",id:1}}}}),na("field_mask",{FieldMask:{fields:{paths:{rule:"repeated",type:"string",id:1}}}}),na.get=function(e){return na[e]||null},function(e){var t=hi.exports=fi.exports;t.build="full",t.tokenize=bs,t.parse=Ns,t.common=ta,t.Root._configure(t.Type,t.parse,t.common)}();var oa=f(di.exports=hi.exports);const ia=e=>{const t=window.URL||window.webkitURL;return t?t.createObjectURL(e):""},sa=e=>{const t=e.name;return ot(t)?t.substring(t.lastIndexOf(".")+1):e.type.indexOf("/")>0?e.type.substring(e.type.lastIndexOf("/")+1):""},aa=e=>{(window.URL||window.webkitURL).revokeObjectURL(e)},ca=e=>{const t=e.match(/data:([^;]+)/)[1],r=e.replace(/^[^,]+,/,""),n=window.atob(r);let o=n.length;const i=new Uint8Array(n.length);for(;o--;)i[o]=n.charCodeAt(o);return new Blob([i],{type:t})};class la{constructor(e){d(this,"options",void 0),d(this,"xhr",void 0),this.options=e}upload(e,t){const r=new XMLHttpRequest;r.upload.onprogress=e=>{var r;null===(r=t.onProgress)||void 0===r||r.call(t,e.loaded,e.total)},r.onreadystatechange=()=>{if(4===r.readyState){const o=r.responseText||"{}",i=JSON.parse(o);if(200===r.status&&200===i.code){var e;let r={url:i.url};this.options.transformer&&(r=this.options.transformer(r)),null===(e=t.onCompleted)||void 0===e||e.call(t,r)}else{var n;null===(n=t.onError)||void 0===n||n.call(t,"upload fail")}}},r.open("POST",this.options.uploadUrl,!0),r.setRequestHeader("device","7"),r.setRequestHeader("cert",this.options.cert??"");const n=sa(e),o=function(){let e=(new Date).getTime();return"xxxxxx4xxxyxxxxxxx".replace(/[xy]/g,(function(t){const r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?r:3&r|8).toString(16)}))}()+(n.length?`.${n}`:""),i=new FormData;i.append("file",e),i.append("name","file"),i.append("fileName",o),i.append("token",this.options.token),r.send(i),this.xhr=r}cancel(){var e;null===(e=this.xhr)||void 0===e||e.abort()}}const ua=e=>new Promise(((t,r)=>{const n=e=>{0!==e.width||0!==e.height?t(e):r()},o=new Image;if(o.addEventListener("load",(e=>n(e.target))),o.addEventListener("error",r),o.src=e,o.complete)return void n(o);const i=setInterval((()=>{o.complete&&(n(o),clearInterval(i))}),40)}));class da{constructor(e,t){d(this,"uploadInstance",void 0),d(this,"options",void 0),this.uploadInstance=e,this.options=t}async upload(e,t){try{const r=ia(e),n=await ua(r);aa(r);const{imageFile:o,compressWidth:i,compressHeight:s}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"image/jpeg";t=Math.min(1,t);const n=e.width,o=e.height;let i=n,s=o;if(t<1){const e=n<o,t=e?o/1680:n/1680;n>1680&&o>1680?e?(s=1680,i/=t):(i=1680,s/=t):n>1680&&o>160?(i=1680,s/=t,s<160&&(s=160,i=n/(o/160))):o>1680&&n>160&&(s=1680,i/=t,i<160&&(i=160,s=o/(n/160)))}i=Math.floor(i),s=Math.floor(s);const a=document.createElement("canvas");a.width=i,a.height=s;const c=a.getContext("2d");return c.fillStyle="#FFF",c.fillRect(0,0,i,s),c.drawImage(e,0,0,n,o,0,0,i,s),r&&"image/png"!=r||(r="image/jpeg"),{imageFile:ca(a.toDataURL(r,Math.min(.92,t))),compressWidth:i,compressHeight:s}}(n,.85,e.type),a=((e,t)=>{const r=document.createElement("canvas"),n=r.getContext("2d"),o=function(e,t,r){const n=e<t;let o,i,s,a=0,c=0;const l=function(){return n?(o=e/100,i=100,s=t/o,c=(s-r.maxHeight)/2):(o=t/100,s=100,i=e/o,a=(i-r.maxWidth)/2),{w:i,h:s,x:-a,y:-c}},u=function(){return n?(o=t/r.maxHeight,s=r.maxHeight,i=e/o):(o=e/r.maxWidth,i=r.maxWidth,s=t/o),{w:i,h:s,x:-a,y:-c}};return(n?t/e:e/t)>r.scale?l():u()}(e.width,e.height,t);r.width=o.w>t.maxWidth?t.maxWidth:o.w,r.height=o.h>t.maxHeight?t.maxHeight:o.h,null==n||n.drawImage(e,o.x,o.y,o.w,o.h);try{let e=r.toDataURL("image/jpeg",t.quality);const n=new RegExp("^data:image/[^;]+;base64,");return e=e.replace(n,""),e}catch(e){throw new Error(e)}})(n,{maxHeight:160,maxWidth:160,quality:.6,scale:2.4});this.uploadInstance.upload(o,{...t,onCompleted:r=>{var n;null===(n=t.onCompleted)||void 0===n||n.call(t,{url:r.url,thumbnail:a,width:i,height:s,type:e.type})}})}catch(e){var r;null===(r=t.onError)||void 0===r||r.call(t,"MEDIA_EXCEPTION")}}cancel(){this.uploadInstance.cancel()}}class ha{constructor(e){d(this,"uploadInstance",void 0),this.uploadInstance=e}async upload(e,t){if(e.size>2097152)t.onError&&t.onError("GIF_MSG_SIZE_LIMIT_EXCEED");else try{const r=ia(e),n=await ua(r);aa(r),this.uploadInstance.upload(e,{...t,onCompleted:r=>{var o;null===(o=t.onCompleted)||void 0===o||o.call(t,{url:r.url,size:e.size,width:n.width,height:n.height})}})}catch(e){var r;null===(r=t.onError)||void 0===r||r.call(t,"MEDIA_EXCEPTION")}}cancel(){this.uploadInstance.cancel()}}let fa;class pa{constructor(e){d(this,"uploadInstance",void 0),this.uploadInstance=e}upload(e,t){var r;(r=e,st(r.arrayBuffer)?r.arrayBuffer():new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(r=>{r.target?e(r.target.result):t("null")})),n.addEventListener("error",(e=>t(e))),n.readAsArrayBuffer(r)}))).then(this.getAudioInfo).then((r=>{this.uploadInstance.upload(e,{...t,onCompleted:n=>{var o;null===(o=t.onCompleted)||void 0===o||o.call(t,{url:n.url,type:sa(e),...r})}})})).catch((()=>{var e;null===(e=t.onError)||void 0===e||e.call(t,"MEDIA_EXCEPTION")}))}cancel(){this.uploadInstance.cancel()}getAudioInfo(e){const t=fa||new AudioContext;return fa=t,new Promise(((r,n)=>{t.decodeAudioData(e,(function(e){r({duration:e.duration,length:e.length})}),n)}))}}class ga{constructor(e){d(this,"uploadInstance",void 0),this.uploadInstance=e}upload(e,t){if(e.size>104857600)t.onError&&t.onError("FILE_MSG_SIZE_LIMIT_EXCEED");else try{this.uploadInstance.upload(e,{...t,onCompleted:r=>{var n;null===(n=t.onCompleted)||void 0===n||n.call(t,{url:r.url,name:e.name,type:sa(e),size:e.size})}})}catch(e){var r;null===(r=t.onError)||void 0===r||r.call(t,"MEDIA_EXCEPTION")}}cancel(){this.uploadInstance.cancel()}}var ya;!function(e){e[e.IMAGE=1]="IMAGE",e[e.GIF=2]="GIF",e[e.AUDIO=3]="AUDIO",e[e.VIDEO=4]="VIDEO",e[e.FILE=5]="FILE",e[e.SIGHT=6]="SIGHT"}(ya||(ya={}));const va=(e,t,r,n,o,i)=>({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId,senderUserId:t,messageDirection:s.SEND,isCounted:r.isCounted,isMentioned:!1,content:r.content,messageType:r.messageType,isOffLineMessage:!1,isPersited:r.isPersited,messageId:n,messageUId:o,sentTime:i,receivedTime:0,isStatusMessage:r.isStatusMessage,receivedStatus:a.UNREAD,disableNotification:!1});let ma=0;const ba=[Ro,Eo];async function wa(r,i,s){var a;if(!ui.loader||ui.loader.getConnectionStatus()!==e.CONNECTED)return{code:t.RC_NET_CHANNEL_INVALID};s=s||{};const c=JSON.stringify(ct(i.encode()));if(function(e){let t=0;if("utf-16"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf-8"))for(let r=0,n=e.length;r<n;r++)t+=e.charCodeAt(r)<=65535?2:4;else for(let r=0,n=e.length;r<n;r++){const n=e.charCodeAt(r);t+=n<127?1:n<=2047?2:n<=65535?3:4}return t}(c)>81920)return{code:t.RC_MSG_CONTENT_EXCEED_LIMIT};const l=Fn(r);let u;u=Ze(null===(a=s)||void 0===a?void 0:a.messageId)&&s.messageId>0?s.messageId:function(){ma++;const e=io();return ma<e&&(ma=e),23e13+ma}(),ao.addMessage(u);const d=va(r,Dn.uid,i,u,"",function(){Ra++;const e=io();Ra<e&&(Ra=e);return Ra}());s.onSendBefore&&s.onSendBefore(d),i.isPersited&&ci.get().loadConvsationsIfNotExist([r]);const h=await zo.getDialogAesKey(l);if(!h)return{code:t.MSG_ENCRYPT_ERROR,data:d};const f=((e,t)=>{if(!ot(e))return new Uint8Array;const r=$e.AES.encrypt(e,$e.enc.Utf8.parse(t.key),{iv:Ze(t.iv)?$e.enc.Utf8.parse(t.iv):void 0});return $o(r.ciphertext.words)})(c,h),p={localId:rn.fromNumber(u),mediaFlag:ba.includes(i.messageType),mediaConstructor:i.objectId,mediaAttribute:"",msgPreContent:"",msgPostContent:"",msgContent:f};let g;if(r.conversationType===n.GROUP){var y,v;const e={...p,groupId:l};if(null!==(y=s)&&void 0!==y&&null!==(v=y.directionalUserIdList)&&void 0!==v&&v.length&&(e.assign=s.directionalUserIdList.join(",")),Ze(i.content.mentionedInfo)){var m;const t=i.content.mentionedInfo;t.type===o.ALL?e.atAll=!0:t.type===o.SINGAL&&null!==(m=t.userIdList)&&void 0!==m&&m.length&&(e.at=t.userIdList.map((e=>rn.fromString(e))))}g=await(b=e,xn.send(At.SendGroupChatMessage,b,{encoder:Yn.SendGroupChatMessageReq,decoder:ro}))}else{const e={...p,destId:l};g=await(e=>xn.send(At.SendPrivateChatMessage,e,{encoder:Wn.SendPrivateChatMessageReq,decoder:jn.SendPrivateChatMessageResp}))(e)}var b;return g.code===t.SUCCESS&&(d.sentTime=g.data.seqno.toNumber(),d.messageUId=g.data.msgId.toString(),ci.get().setConversationCacheByMessage(d)),{code:g.code,data:d}}const Oa=Ea(ya.IMAGE,((e,t)=>new Do({content:e.thumbnail,imageUri:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),Ca=Ea(ya.GIF,((e,t)=>new Mo({gifDataSize:e.size,remoteUrl:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),_a=Ea(ya.AUDIO,((e,t)=>new Lo({remoteUrl:e.url,duration:e.duration,type:e.type,user:t.user,extra:t.extra}))),Sa=Ea(ya.FILE,((e,t)=>new Bo({fileUrl:e.url,name:e.name,type:e.type,size:e.size,user:t.user,extra:t.extra}))),Ia=async(e,r)=>{const n=Fn(e);lo.addMessage(r.messageUId);const o=await((e,t)=>{let r;return r=qn(e)?xn.send(At.RecallGroupMessage,{groupId:e,msgId:rn.fromString(t)},{encoder:Yn.RecallGroupChatMessageReq,decoder:Xr.BaseResp}):xn.send(At.RecallPrivateMessage,{destId:e,msgId:rn.fromString(t)},{encoder:Wn.RecallPrivateChatMessageReq,decoder:Xr.BaseResp}),r})(n,r.messageUId);if(o.code!==t.SUCCESS)return{code:o.code};const i=new Uo({sentTime:r.sentTime,messageUId:r.messageUId,...e}),s=va(e,Dn.uid,i,0,"",io());return ci.get().setConversationCacheByMessage(s),{code:t.SUCCESS,data:s}};function Ea(e,r){return function(n,o,i,s){return new Promise((a=>{((e,t,r,n)=>{var o;const i=new la({token:Pn.imInitToken,uploadUrl:Pn.fileUploadUrl,cert:Pn.cert,transformer:e=>({...e,url:Pn.getFileAbsoluteUri(e.url)})});let s;switch(t){case ya.IMAGE:s=new da(i,r);break;case ya.GIF:s=new ha(i);break;case ya.AUDIO:s=new pa(i);break;case ya.FILE:s=new ga(i)}null===(o=s)||void 0===o||o.upload(e,{onProgress:(e,t)=>n.onProgress(Math.floor(e/t*100)),onError:()=>n.onFail(),onCompleted:n.onSuccess})})(o.file,e,s,{onProgress:e=>{(null==i?void 0:i.onProgress)&&i.onProgress(e)},onSuccess:e=>{const t=(null==i?void 0:i.onComplete)&&i.onComplete({url:Pn.getFileAbsoluteUri(e.url)})||r(e,o);wa(n,t,s).then(a)},onFail:()=>{a({code:t.UPLOAD_FILE_FAILED})}})}))}}let Ta,Ra=1;class ka extends Rt{constructor(e){if(ka.imClient)return mt.error("Please do not perform the init method repeatedly"),ka.imClient;super(),d(this,"options",void 0),d(this,"libLoader",void 0),d(this,"getServerTime",io),d(this,"sendMessage",wa),d(this,"sendImageMessage",Oa),d(this,"sendGIFMessage",Ca),d(this,"sendHQVoiceMessage",_a),d(this,"sendFileMessage",Sa),d(this,"recallMsg",Ia),this.options=e,this.fixedProtobuf(),Ze(e.logLevel)&&mt.setLogLevel(e.logLevel),Ze(e.logStdout)&&mt.setLogStdout(e.logStdout),mt.debug("IMClient.init -> ",e.appkey),this.libLoader=ui.init(e),this.watch(),ka.imClient=this}fixedProtobuf(){oa.util.Long=rn,oa.configure()}watch(){this.libLoader.assignWatcher({onConnecting:()=>{this.emit(u.CONNECTING)},onConnected:()=>{this.emit(u.CONNECTED)},onDisconnect:()=>{this.emit(u.DISCONNECT,this.libLoader.getConnectionStatus())},onSuspend:()=>{this.emit(u.SUSPEND,this.libLoader.getConnectionStatus())},batchMessage:e=>{this.emit(u.MESSAGES,{messages:e})},pullFinished:()=>{this.emit(u.PULL_OFFLINE_MESSAGE_FINISHED)},conversationState:e=>{this.emit(u.CONVERSATION,{conversations:e})}})}connect(e){return this.libLoader.connect(e)}disconnect(){return this.libLoader.disconnect()}getConnectionStatus(){return this.libLoader.getConnectionStatus()}async getRemoteHistoryMessages(e,n){const o=Fn(e);return(e=>{const t={dialogKeys:e.dialogId,newToOld:e.newToOld,rows:e.count};return e.newToOld?t.offset=rn.fromNumber(e.offset):t.oldOffset=rn.fromNumber(e.offset),xn.send(e.dialogId.startsWith("SG")?At.GetSuperGroupRemoteMessages:At.GetRemoteMessages,t,{encoder:Wn.GetHistoryMessageReq,decoder:jn.GetHistoryMessageResp})})({dialogId:o,offset:n.timestamp??0,count:n.count??20,newToOld:0===n.order}).then((e=>{let{code:n,data:i}=e;return new Promise((e=>{n===t.SUCCESS?Qo.parse({[o]:i.msg??{}},((r,n)=>{const s=n[o]??[];s.sort(((e,t)=>e.sentTime-t.sentTime)),e({code:t.SUCCESS,data:{list:s,hasMore:!i.isEnd}})})):e({code:n,msg:r(n)})}))}))}async deleteRemoteMessage(e,t){return(r=Fn(e),n=t.map((e=>e.messageUId)),xn.send(At.DeleteChatMessages,{destId:r,msgIdList:n.map((e=>rn.fromString(e)))},{encoder:Wn.DeleteChatMessageReq,decoder:Xr.BaseResp})).then((e=>e.code));var r,n}async deleteRemoteMessageByTimestamp(e,t){return((e,t)=>xn.send(At.ClearChatHistoryMessage,{destId:e,type:qn(e)?1:0,msgTime:rn.fromNumber(t)},{encoder:Wn.CleanHistoryMessageReq,decoder:Xr.BaseResp}))(Fn(e),0===t?Number.MAX_VALUE:t).then((e=>e.code))}async getConversationList(e,r,n,o){const i={rows:e,type:r??0,offset:rn.fromNumber(n),newToOld:0===o},{code:s,data:a}=await(e=>xn.send(At.GetDialogList,e,{encoder:Wn.GetWebDialogListReq,decoder:jn.GetWebDialogListResp}))(i);if(s!==t.SUCCESS)return{code:s};const c=a.fullDialog.map((e=>{var t;return null===(t=e.dialog)||void 0===t?void 0:t.destId})).filter(ot);await zo.getDialogAesKeyList(c);const l=[];for(const e of a.fullDialog){const t=this.formatConversation(e);if(t){const e={conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId};ci.get().addLocalConversation(t);const r=ci.get().get(e);Object.assign(t,r),l.push(t)}}return{code:t.SUCCESS,data:l}}getBlockConversationList(){const e=ci.get().getBlockConversationList();return Promise.resolve({code:t.SUCCESS,data:e})}getTopConversationList(){const e=ci.get().getTopConversationList();return Promise.resolve({code:t.SUCCESS,data:e})}async getConversation(e){const r=ci.get().get(e);if(!r)return{code:t.CONVER_GET_ERROR};const{code:n,data:o}=await this.getRemoteHistoryMessages(e,{count:1,order:0});if(n!==t.SUCCESS)return{code:t.CONVER_GET_ERROR};const i=null==o?void 0:o.list[0],s={...e,...r,latestMessage:i};return{code:t.SUCCESS,data:s}}removeConversation(e){return(e=>{let t;return t=qn(e)?xn.send(At.DeleteGroupDialog,{groupId:e},{encoder:Yn.DeleteGroupChatDialogReq,decoder:Xr.BaseResp}):xn.send(At.DeletePrivateDialog,{destId:e},{encoder:Wn.DeletePrivateChatDialogReq,decoder:Xr.BaseResp}),t})(Fn(e)).then((e=>e.code))}getUnreadMentionedCount(e){return ci.get().getUnreadMentionedCount(e)}getAllUnreadMentionedCount(){return ci.get().getAllUnreadMentionedCount()}getAllConversationState(){return ci.get().getAllConversationState()}getAllConversationUnreadCount(e,t){return ci.get().getAllUnreadCount(e,t)}getConversationUnreadCount(e){return ci.get().getUnreadCount(e)}clearConversationUnreadCount(e){ci.get().clearUnreadCount(e)}clearAllConversationsUnreadCount(){ci.get().clearAllUnreadCount()}getConversationNotificationLevel(e){return ci.get().getNotificationLevel(e)}setConversationNotificationStatus(e,t){return((e,t)=>{let r;return r=qn(e)?xn.send(At.UpdateGroupChatMuteConfig,{groupId:e,muteFlag:t},{encoder:Yn.UpdateGroupChatDialogMuteConfigReq,decoder:Xr.BaseResp}):xn.send(At.UpdatePrivateChatMuteConfig,{destId:e,muteFlag:t},{encoder:Wn.UpdatePrivateChatDialogMuteConfigReq,decoder:Xr.BaseResp}),r})(Fn(e),t===i.OPEN).then((r=>(!r.code&&ci.get().addStatus({...e,notificationStatus:t,notificationLevel:t==i.OPEN?c.AT_USER_NOTIFICATION:c.NOT_SET},!0),r.code)))}getConversationNotificationStatus(e){return ci.get().getNotificationStatus(e)}setConversationToTop(e,t){return((e,t)=>{let r;return r=qn(e)?xn.send(At.UpdateGroupChatStickyConfig,{groupId:e,stickyFlag:t},{encoder:Yn.UpdateGroupChatDialogStickyConfigReq,decoder:Xr.BaseResp}):xn.send(At.UpdatePrivateChatStickyConfig,{destId:e,stickyFlag:t},{encoder:Wn.UpdatePrivateChatDialogStickyConfigReq,decoder:Xr.BaseResp}),r})(Fn(e),t).then((r=>(!r.code&&ci.get().addStatus({...e,isTop:t},!0),r.code)))}saveConversationMessageDraft(e,t){ci.get().setDraft(e,t)}getConversationMessageDraft(e){return ci.get().getDraft(e)}clearConversationMessageDraft(e){ci.get().clearDraft(e)}formatConversation(e){const{dialog:t,msg:r}=e,n=t.destId??"",o=ni(t);if(!o)return;const i=zo.getDialogAesKeyFromLocal(n);if(!i)return;const s=Qo.parseSingleDialogMessages(n,[r],i)[0];return s?(o.latestMessage=s,o):void 0}}d(ka,"imClient",void 0);const Aa=e=>{Ta=Ta||new ka(e)},Na=async e=>{Et("token",e,bt,!0);const n=await Ta.connect(e);return n.code===t.SUCCESS?{code:n.code,data:{userId:n.userId}}:{code:n.code,msg:r(n.code)}},xa=()=>Ta.disconnect(),Da=()=>Ta.getConnectionStatus(),Ma=()=>Ta.getServerTime(),La=(e,t,r)=>{Ta.on(e,t,r)};function Ba(e,t,r){Ta.once(e,t,r)}const Ua=(e,t,r)=>{Ta.off(e,t,r)},ja=async e=>{mt.debug("get conversation list ->");const{code:n,data:o}=await Ta.getConversationList((null==e?void 0:e.count)??20,null,(null==e?void 0:e.startTime)??0,(null==e?void 0:e.order)??0);return n!==t.SUCCESS&&mt.warn("get conversation list fail ->"+n+":"+r(n)),{code:n,msg:r(n),data:o}},Pa=async e=>{Et("options",e,St,!0);const n="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get conversation ->"+n);const{code:o,data:i}=await Ta.getConversation(e);return o!==t.SUCCESS?(mt.warn("get conversation fail ->"+o+":"+r(o)+","+n),{code:o,msg:r(o)}):{code:o,data:i}},Fa=async e=>{Et("options",e,St,!0);const n="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("remove conversation ->"+n);const o=await Ta.removeConversation(e);return o!==t.SUCCESS?(mt.warn("remove conversation fail ->"+o+":"+r(o)+","+n),{code:o,msg:r(o)}):{code:o}},Ga=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get draft ->"+r);const n=Ta.getConversationMessageDraft(e);return Promise.resolve({code:t.SUCCESS,data:n})},qa=(e,r)=>{Et("options",e,St,!0),Et("draft",r,bt,!0);const n="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("set draft ->"+n),Ta.saveConversationMessageDraft(e,r),Promise.resolve({code:t.SUCCESS})},Ha=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("delete draft ->"+r),Ta.clearConversationMessageDraft(e),Promise.resolve({code:t.SUCCESS})},za=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("get unreadMentionedCount ->"+r),Promise.resolve({code:t.SUCCESS,data:Ta.getUnreadMentionedCount(e)})},Ka=()=>{mt.debug("getAllUnreadMentionedCount");const e=Ta.getAllUnreadMentionedCount();return Promise.resolve({code:t.SUCCESS,data:e})},Va=()=>{mt.debug("getAllConversationState");const e=Ta.getAllConversationState();return Promise.resolve({code:t.SUCCESS,data:e})},Wa=(e,r)=>{if(mt.debug("get total unread count -> ConversationType:"+JSON.stringify(r)+" includeMuted:"+e),Et("includeMuted",e,Ot,!1),Et("conversationTypes",r,Ct,!1),r)for(const e of r)Et("conversationType",e,_t,!0);const n=Ta.getAllConversationUnreadCount(r??[],e??!1);return Promise.resolve({code:t.SUCCESS,data:n})},$a=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get unreadCount ->"+r);const n=Ta.getConversationUnreadCount(e);return Promise.resolve({code:t.SUCCESS,data:n})},Ja=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("clear unreadMsgNum ->"+r),Ta.clearConversationUnreadCount(e),Promise.resolve({code:t.SUCCESS})},Za=()=>(mt.debug("clear allMessagesUnreadStatus"),Ta.clearAllConversationsUnreadCount(),Promise.resolve({code:t.SUCCESS})),Xa=e=>{Et("options",e,St,!0),mt.info("getConversationNotificationLevel ->targetId:"+e.targetId+",conversationType:"+e.conversationType);const r=Ta.getConversationNotificationLevel(e);return Promise.resolve({code:t.SUCCESS,data:r})},Ya=async(e,n)=>{Et("options",e,St,!0),Et("notificationStatus",n,(e=>1===e||2===e),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("set conversation status ->"+o);const i=await Ta.setConversationNotificationStatus(e,n);return i!==t.SUCCESS?(mt.warn("set conversation status fail ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:i}},Qa=e=>{Et("options",e,St,!0),mt.info("getConversationNotificationStatus ->targetId:"+e.targetId+",conversationType:"+e.conversationType);const r=Ta.getConversationNotificationStatus(e);return Promise.resolve({code:t.SUCCESS,data:r})},ec=()=>Ta.getBlockConversationList(),tc=async function(e){let n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Et("options",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("set conversation status ->"+o);const i=await Ta.setConversationToTop(e,n);return i!==t.SUCCESS?(mt.warn("set conversation status fail ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:i}},rc=()=>Ta.getTopConversationList(),nc=(e,t,r,n,o)=>function(n){return o?new Ho(e,n):r?new qo(e,n):t?new Go(e,n):new Fo(e,n)},oc=async(e,r,n)=>{if(r instanceof fo==!1)return mt.warn("send message fail -> message parameter is not an instance of BaseMessage"),{code:t.PARAMETER_ERROR};Et("conversation",e,St,!0),gc(e);const o=await Ta.sendMessage(e,r,n);return yc(e,o.code),o},ic=(e,t,r)=>{const n=new xo(t);return oc(e,n,r)},sc=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.startsWith("image/")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+o),gc(e);const i=await Ta.sendImageMessage(e,t,r,n);return yc(e,i.code),i},ac=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.endsWith("image/gif")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+o),gc(e);const i=await Ta.sendGIFMessage(e,t,r,n);return yc(e,i.code),i},cc=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob),!0),gc(e);const o=await Ta.sendHQVoiceMessage(e,t,r,n);return yc(e,o.code),o},lc=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+o),gc(e);const i=await Ta.sendFileMessage(e,t,r,n);return yc(e,i.code),i},uc=async(e,n)=>{Et("options.messageUId",n.messageUId,bt,!0),Et("options.sentTime",n.sentTime,wt,!0),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId+",messageUId:"+n.messageUId;mt.debug("recall message ->"+o);const i=await Ta.recallMsg(e,n);return i.code!==t.SUCCESS&&mt.warn("recall message fail ->"+i.code+":"+r(i.code)+","+o),i},dc=async(e,n)=>{Et("options.timestamp",n.timestamp??0,wt),Et("options.count",n.count??0,wt),Et("options.order",n.order??0,(e=>0===e||1===e)),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get history message ->"+o);const i=await Ta.getRemoteHistoryMessages(e,n);return i.code!==t.SUCCESS&&mt.warn("get history message fail ->"+i.code+":"+r(i.code)+","+o),i},hc=async(e,n)=>{Et("options.timestamp",n.timestamp??0,wt),Et("options.count",n.count??0,wt),Et("options.order",n.order??0,(e=>0===e||1===e)),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get remote history message ->"+o);const i=await Ta.getRemoteHistoryMessages(e,n);return i.code!==t.SUCCESS&&mt.warn("get remote history message fail ->"+i.code+":"+r(i.code)+","+o),i},fc=async(e,n)=>{Et("messages",n,(e=>rt(e)&&!!e.length),!0),n.forEach((e=>{Et("messages.messageUId",e.messageUId,bt,!0),Et("messages.sentTime",e.sentTime,wt,!1),Et("messages.messageDirection",e.messageDirection,(e=>1===e||2===e),!1)})),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("delete messages ->"+o);const i=await Ta.deleteRemoteMessage(e,n);return i!==t.SUCCESS?(mt.warn("delete message fail ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:t.SUCCESS}},pc=async(e,n)=>{Et("timestamp",n,(e=>wt(e)&&e>=0),!0),Et("conversation",e,St);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("clear message ->"+o);const i=await Ta.deleteRemoteMessageByTimestamp(e,n);return i!==t.SUCCESS?(mt.warn("clear message ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:t.SUCCESS}},gc=e=>{const t="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+t)},yc=(e,n)=>{if(n!==t.SUCCESS){const t="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.warn("send message fail ->"+n+":"+r(n)+","+t)}};export{jo as CommandMessage,e as ConnectionStatus,n as ConversationType,t as ErrorCode,r as ErrorDesc,u as Events,Bo as FileMessage,Mo as GIFMessage,Lo as HQVoiceMessage,Do as ImageMessage,l as LogLevel,o as MentionedType,s as MessageDirection,c as NotificationLevel,i as NotificationStatus,a as ReceivedStatus,xo as TextMessage,La as addEventListener,Za as clearAllMessagesUnreadStatus,pc as clearHistoryMessages,Ja as clearMessagesUnreadStatus,Ha as clearTextMessageDraft,Na as connect,fc as deleteMessages,xa as disconnect,Va as getAllConversationState,Ka as getAllUnreadMentionedCount,ec as getBlockedConversationList,Da as getConnectionStatus,Pa as getConversation,ja as getConversationList,Xa as getConversationNotificationLevel,Qa as getConversationNotificationStatus,dc as getHistoryMessages,hc as getRemoteHistoryMessages,Ma as getServerTime,Ga as getTextMessageDraft,rc as getTopConversationList,Wa as getTotalUnreadCount,$a as getUnreadCount,za as getUnreadMentionedCount,Aa as init,Ba as onceEventListener,uc as recallMessage,nc as registerMessageType,Fa as removeConversation,Ua as removeEventListener,qa as saveTextMessageDraft,lc as sendFileMessage,ac as sendGIFMessage,cc as sendHQVoiceMessage,sc as sendImageMessage,oc as sendMessage,ic as sendTextMessage,Ya as setConversationNotificationStatus,tc as setConversationToTop};
37
+ */var tn=null;try{tn=new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0,1,13,2,96,0,1,127,96,4,127,127,127,127,1,127,3,7,6,0,1,1,1,1,1,6,6,1,127,1,65,0,11,7,50,6,3,109,117,108,0,1,5,100,105,118,95,115,0,2,5,100,105,118,95,117,0,3,5,114,101,109,95,115,0,4,5,114,101,109,95,117,0,5,8,103,101,116,95,104,105,103,104,0,0,10,191,1,6,4,0,35,0,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,126,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,127,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,128,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,129,34,4,66,32,135,167,36,0,32,4,167,11,36,1,1,126,32,0,173,32,1,173,66,32,134,132,32,2,173,32,3,173,66,32,134,132,130,34,4,66,32,135,167,36,0,32,4,167,11])),{}).exports}catch(e){}function rn(e,t,r){this.low=0|e,this.high=0|t,this.unsigned=!!r}function nn(e){return!0===(e&&e.__isLong__)}function on(e){var t=Math.clz32(e&-e);return e?31-t:t}rn.prototype.__isLong__,Object.defineProperty(rn.prototype,"__isLong__",{value:!0}),rn.isLong=nn;var sn={},an={};function cn(e,t){var r,n,o;return t?(o=0<=(e>>>=0)&&e<256)&&(n=an[e])?n:(r=un(e,0,!0),o&&(an[e]=r),r):(o=-128<=(e|=0)&&e<128)&&(n=sn[e])?n:(r=un(e,e<0?-1:0,!1),o&&(sn[e]=r),r)}function ln(e,t){if(isNaN(e))return t?bn:mn;if(t){if(e<0)return bn;if(e>=gn)return Sn}else{if(e<=-yn)return In;if(e+1>=yn)return _n}return e<0?ln(-e,t).neg():un(e%pn|0,e/pn|0,t)}function un(e,t,r){return new rn(e,t,r)}rn.fromInt=cn,rn.fromNumber=ln,rn.fromBits=un;var dn=Math.pow;function hn(e,t,r){if(0===e.length)throw Error("empty string");if("number"==typeof t?(r=t,t=!1):t=!!t,"NaN"===e||"Infinity"===e||"+Infinity"===e||"-Infinity"===e)return t?bn:mn;if((r=r||10)<2||36<r)throw RangeError("radix");var n;if((n=e.indexOf("-"))>0)throw Error("interior hyphen");if(0===n)return hn(e.substring(1),t,r).neg();for(var o=ln(dn(r,8)),i=mn,s=0;s<e.length;s+=8){var a=Math.min(8,e.length-s),c=parseInt(e.substring(s,s+a),r);if(a<8){var l=ln(dn(r,a));i=i.mul(l).add(ln(c))}else i=(i=i.mul(o)).add(ln(c))}return i.unsigned=t,i}function fn(e,t){return"number"==typeof e?ln(e,t):"string"==typeof e?hn(e,t):un(e.low,e.high,"boolean"==typeof t?t:e.unsigned)}rn.fromString=hn,rn.fromValue=fn;var pn=4294967296,gn=pn*pn,yn=gn/2,vn=cn(1<<24),mn=cn(0);rn.ZERO=mn;var bn=cn(0,!0);rn.UZERO=bn;var wn=cn(1);rn.ONE=wn;var On=cn(1,!0);rn.UONE=On;var Cn=cn(-1);rn.NEG_ONE=Cn;var _n=un(-1,2147483647,!1);rn.MAX_VALUE=_n;var Sn=un(-1,-1,!0);rn.MAX_UNSIGNED_VALUE=Sn;var In=un(0,-2147483648,!1);rn.MIN_VALUE=In;var En=rn.prototype;En.toInt=function(){return this.unsigned?this.low>>>0:this.low},En.toNumber=function(){return this.unsigned?(this.high>>>0)*pn+(this.low>>>0):this.high*pn+(this.low>>>0)},En.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(In)){var t=ln(e),r=this.div(t),n=r.mul(t).sub(this);return r.toString(e)+n.toInt().toString(e)}return"-"+this.neg().toString(e)}for(var o=ln(dn(e,6),this.unsigned),i=this,s="";;){var a=i.div(o),c=(i.sub(a.mul(o)).toInt()>>>0).toString(e);if((i=a).isZero())return c+s;for(;c.length<6;)c="0"+c;s=""+c+s}},En.getHighBits=function(){return this.high},En.getHighBitsUnsigned=function(){return this.high>>>0},En.getLowBits=function(){return this.low},En.getLowBitsUnsigned=function(){return this.low>>>0},En.getNumBitsAbs=function(){if(this.isNegative())return this.eq(In)?64:this.neg().getNumBitsAbs();for(var e=0!=this.high?this.high:this.low,t=31;t>0&&0==(e&1<<t);t--);return 0!=this.high?t+33:t+1},En.isZero=function(){return 0===this.high&&0===this.low},En.eqz=En.isZero,En.isNegative=function(){return!this.unsigned&&this.high<0},En.isPositive=function(){return this.unsigned||this.high>=0},En.isOdd=function(){return 1==(1&this.low)},En.isEven=function(){return 0==(1&this.low)},En.equals=function(e){return nn(e)||(e=fn(e)),(this.unsigned===e.unsigned||this.high>>>31!=1||e.high>>>31!=1)&&(this.high===e.high&&this.low===e.low)},En.eq=En.equals,En.notEquals=function(e){return!this.eq(e)},En.neq=En.notEquals,En.ne=En.notEquals,En.lessThan=function(e){return this.comp(e)<0},En.lt=En.lessThan,En.lessThanOrEqual=function(e){return this.comp(e)<=0},En.lte=En.lessThanOrEqual,En.le=En.lessThanOrEqual,En.greaterThan=function(e){return this.comp(e)>0},En.gt=En.greaterThan,En.greaterThanOrEqual=function(e){return this.comp(e)>=0},En.gte=En.greaterThanOrEqual,En.ge=En.greaterThanOrEqual,En.compare=function(e){if(nn(e)||(e=fn(e)),this.eq(e))return 0;var t=this.isNegative(),r=e.isNegative();return t&&!r?-1:!t&&r?1:this.unsigned?e.high>>>0>this.high>>>0||e.high===this.high&&e.low>>>0>this.low>>>0?-1:1:this.sub(e).isNegative()?-1:1},En.comp=En.compare,En.negate=function(){return!this.unsigned&&this.eq(In)?In:this.not().add(wn)},En.neg=En.negate,En.add=function(e){nn(e)||(e=fn(e));var t=this.high>>>16,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,c=0,l=0,u=0,d=0;return u+=(d+=o+(65535&e.low))>>>16,l+=(u+=n+a)>>>16,c+=(l+=r+s)>>>16,c+=t+i,un((u&=65535)<<16|(d&=65535),(c&=65535)<<16|(l&=65535),this.unsigned)},En.subtract=function(e){return nn(e)||(e=fn(e)),this.add(e.neg())},En.sub=En.subtract,En.multiply=function(e){if(this.isZero())return this;if(nn(e)||(e=fn(e)),tn)return un(tn.mul(this.low,this.high,e.low,e.high),tn.get_high(),this.unsigned);if(e.isZero())return this.unsigned?bn:mn;if(this.eq(In))return e.isOdd()?In:mn;if(e.eq(In))return this.isOdd()?In:mn;if(this.isNegative())return e.isNegative()?this.neg().mul(e.neg()):this.neg().mul(e).neg();if(e.isNegative())return this.mul(e.neg()).neg();if(this.lt(vn)&&e.lt(vn))return ln(this.toNumber()*e.toNumber(),this.unsigned);var t=this.high>>>16,r=65535&this.high,n=this.low>>>16,o=65535&this.low,i=e.high>>>16,s=65535&e.high,a=e.low>>>16,c=65535&e.low,l=0,u=0,d=0,h=0;return d+=(h+=o*c)>>>16,u+=(d+=n*c)>>>16,d&=65535,u+=(d+=o*a)>>>16,l+=(u+=r*c)>>>16,u&=65535,l+=(u+=n*a)>>>16,u&=65535,l+=(u+=o*s)>>>16,l+=t*c+r*a+n*s+o*i,un((d&=65535)<<16|(h&=65535),(l&=65535)<<16|(u&=65535),this.unsigned)},En.mul=En.multiply,En.divide=function(e){if(nn(e)||(e=fn(e)),e.isZero())throw Error("division by zero");var t,r,n;if(tn)return this.unsigned||-2147483648!==this.high||-1!==e.low||-1!==e.high?un((this.unsigned?tn.div_u:tn.div_s)(this.low,this.high,e.low,e.high),tn.get_high(),this.unsigned):this;if(this.isZero())return this.unsigned?bn:mn;if(this.unsigned){if(e.unsigned||(e=e.toUnsigned()),e.gt(this))return bn;if(e.gt(this.shru(1)))return On;n=bn}else{if(this.eq(In))return e.eq(wn)||e.eq(Cn)?In:e.eq(In)?wn:(t=this.shr(1).div(e).shl(1)).eq(mn)?e.isNegative()?wn:Cn:(r=this.sub(e.mul(t)),n=t.add(r.div(e)));if(e.eq(In))return this.unsigned?bn:mn;if(this.isNegative())return e.isNegative()?this.neg().div(e.neg()):this.neg().div(e).neg();if(e.isNegative())return this.div(e.neg()).neg();n=mn}for(r=this;r.gte(e);){t=Math.max(1,Math.floor(r.toNumber()/e.toNumber()));for(var o=Math.ceil(Math.log(t)/Math.LN2),i=o<=48?1:dn(2,o-48),s=ln(t),a=s.mul(e);a.isNegative()||a.gt(r);)a=(s=ln(t-=i,this.unsigned)).mul(e);s.isZero()&&(s=wn),n=n.add(s),r=r.sub(a)}return n},En.div=En.divide,En.modulo=function(e){return nn(e)||(e=fn(e)),tn?un((this.unsigned?tn.rem_u:tn.rem_s)(this.low,this.high,e.low,e.high),tn.get_high(),this.unsigned):this.sub(this.div(e).mul(e))},En.mod=En.modulo,En.rem=En.modulo,En.not=function(){return un(~this.low,~this.high,this.unsigned)},En.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},En.clz=En.countLeadingZeros,En.countTrailingZeros=function(){return this.low?on(this.low):on(this.high)+32},En.ctz=En.countTrailingZeros,En.and=function(e){return nn(e)||(e=fn(e)),un(this.low&e.low,this.high&e.high,this.unsigned)},En.or=function(e){return nn(e)||(e=fn(e)),un(this.low|e.low,this.high|e.high,this.unsigned)},En.xor=function(e){return nn(e)||(e=fn(e)),un(this.low^e.low,this.high^e.high,this.unsigned)},En.shiftLeft=function(e){return nn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?un(this.low<<e,this.high<<e|this.low>>>32-e,this.unsigned):un(0,this.low<<e-32,this.unsigned)},En.shl=En.shiftLeft,En.shiftRight=function(e){return nn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?un(this.low>>>e|this.high<<32-e,this.high>>e,this.unsigned):un(this.high>>e-32,this.high>=0?0:-1,this.unsigned)},En.shr=En.shiftRight,En.shiftRightUnsigned=function(e){return nn(e)&&(e=e.toInt()),0==(e&=63)?this:e<32?un(this.low>>>e|this.high<<32-e,this.high>>>e,this.unsigned):un(32===e?this.high:this.high>>>e-32,0,this.unsigned)},En.shru=En.shiftRightUnsigned,En.shr_u=En.shiftRightUnsigned,En.rotateLeft=function(e){var t;return nn(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?un(this.high,this.low,this.unsigned):e<32?(t=32-e,un(this.low<<e|this.high>>>t,this.high<<e|this.low>>>t,this.unsigned)):(t=32-(e-=32),un(this.high<<e|this.low>>>t,this.low<<e|this.high>>>t,this.unsigned))},En.rotl=En.rotateLeft,En.rotateRight=function(e){var t;return nn(e)&&(e=e.toInt()),0==(e&=63)?this:32===e?un(this.high,this.low,this.unsigned):e<32?(t=32-e,un(this.high<<t|this.low>>>e,this.low<<t|this.high>>>e,this.unsigned)):(t=32-(e-=32),un(this.low<<t|this.high>>>e,this.high<<t|this.low>>>e,this.unsigned))},En.rotr=En.rotateRight,En.toSigned=function(){return this.unsigned?un(this.low,this.high,!1):this},En.toUnsigned=function(){return this.unsigned?this:un(this.low,this.high,!0)},En.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},En.toBytesLE=function(){var e=this.high,t=this.low;return[255&t,t>>>8&255,t>>>16&255,t>>>24,255&e,e>>>8&255,e>>>16&255,e>>>24]},En.toBytesBE=function(){var e=this.high,t=this.low;return[e>>>24,e>>>16&255,e>>>8&255,255&e,t>>>24,t>>>16&255,t>>>8&255,255&t]},rn.fromBytes=function(e,t,r){return r?rn.fromBytesLE(e,t):rn.fromBytesBE(e,t)},rn.fromBytesLE=function(e,t){return new rn(e[0]|e[1]<<8|e[2]<<16|e[3]<<24,e[4]|e[5]<<8|e[6]<<16|e[7]<<24,t)},rn.fromBytesBE=function(e,t){return new rn(e[4]<<24|e[5]<<16|e[6]<<8|e[7],e[0]<<24|e[1]<<16|e[2]<<8|e[3],t)};const Tn={webSocketTimeout:5e3,signalTimeout:3e4,pingInterval:15e3,pingTimeout:5e3,pingFailedTimes:2,reconnectIntervalMin:250,reconnectIntervalMax:64e3,reconnectRaisingBase:2};const Rn=t=>e[t],kn=()=>{const e="ACDeviceId";let t="";const r=ft.get(e);return r?t=r:(t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})),ft.set(e,t)),t},An=e=>{const t=new Yr;return t.writeIn8(67),t.writeIn8(255),t.writeInt32(e.length+7),t.writeArr(Array.from(e)),t.writeIn8(0),new Int8Array(t.getBytesArray()).buffer},Nn=e=>{const t=new Qr(new Uint8Array(e));t.readInt8(),t.readInt8();const r=t.readInt32(),n=t.readArr(r-7);if(t.readInt8(),e.byteLength!==r)throw new Error("packet resolve failed");return n};var xn=new class{constructor(t){d(this,"url",""),d(this,"watcher",void 0),d(this,"provider",void 0),d(this,"options",void 0),d(this,"socket",void 0),d(this,"status",e.DISCONNECTED),d(this,"autoReconnect",!1),d(this,"isAuthorized",!1),d(this,"profile",void 0),d(this,"responseCallbacks",new Map),d(this,"failedCount",0),d(this,"reconnectTimer",void 0),d(this,"token",""),d(this,"connectResolve",void 0),d(this,"idCount",0),this.options=Object.assign(Tn,t)}setServerInfo(e){this.url=e}setCallback(e,t){this.watcher=e,this.provider=t}async connect(r){return this.token=r,new Promise((r=>{this.connectResolve=r,this.open().then((e=>e===t.SUCCESS?!Ze(this.provider)||this.provider.needReAuth()?this.auth():t.SUCCESS:e)).then((n=>{var o;(r(n),n===t.SUCCESS)?(this.isAuthorized=!0,this.profile=null===(o=this.provider)||void 0===o?void 0:o.profile(),this.autoReconnect=!0,this.onConnect()):this.onDisconnect(n===t.TIMEOUT?e.NETWORK_UNAVAILABLE:e.WEBSOCKET_UNAVAILABLE)}))}))}async send(e,r,n){var o;let i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:this.options.signalTimeout;const{code:s,data:a}=await this.sendRawData(e,Ze(r)&&Ze(n.encoder)?n.encoder.encode(r).finish():new Uint8Array,i);if(0!==s)return{code:s,msg:"time out",data:null};if(!Ze(a)||!Ze(n.decoder))return{code:t.SUCCESS,msg:""};const c=null===(o=n.decoder)||void 0===o?void 0:o.decode(a);return c.errorCode?{code:en(c.errorCode),msg:c.errorMessage,data:null}:{data:c,code:t.SUCCESS,msg:""}}async sendRawData(e,r){var n,o,i;let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.options.signalTimeout;if(!this.socket)return{code:t.RC_NET_CHANNEL_INVALID};if(!this.isAuthorized&&!this.isAuthCommand(e))return{code:t.RC_NET_CHANNEL_INVALID};const a=this.generateMessageSeq(),c={cmdId:e,messageSeq:rn.fromNumber(a),deviceId:(null===(n=this.profile)||void 0===n?void 0:n.deviceId)??rn.fromInt(7),sessionId:(null===(o=this.profile)||void 0===o?void 0:o.sessionId)??rn.ZERO,uid:(null===(i=this.profile)||void 0===i?void 0:i.uid)??rn.ZERO,protocolVersion:0,destId:"",body:r,token:this.token};mt.reqInfo(`websocket send -> cmd: 0x${e.toString(16)}, messageSeq: ${a}`),this.socket.send(An(zr.encode(c).finish()));const l=await new Promise((e=>{this.responseCallbacks.set(a,e),setTimeout((()=>{this.responseCallbacks.get(a)&&this.responseCallbacks.delete(a),e(null)}),s)}));return l?{code:0,data:l}:(mt.warn(`send timeout -> cmd: 0x${e.toString(16)}, messageSeq: ${a}, timeout: ${s}`),{code:t.TIMEOUT})}close(){var r;this.autoReconnect=!1,this.doClose(),this.setStatus(e.DISCONNECTED),null===(r=this.connectResolve)||void 0===r||r.call(this,t.RC_SOCKET_DISCONNECTED)}async open(){const r=this.url;mt.info(`conenct start -> ${r}`),this.setStatus(e.CONNECTING);const n=function(e,t){const r=new WebSocket(e,t);return r.binaryType="arraybuffer",{onClose(e){r.onclose=t=>{const{code:r,reason:n}=t;null==e||e(r,n)}},onError(e){r.onerror=t=>{e(t)}},onMessage(e){r.onmessage=t=>{e(t.data)}},onOpen(e){r.onopen=e},send(e){r.send(e)},close(e,t){r.close(e,t)}}}(this.url);this.socket=n;return await new Promise((o=>{n.onMessage((e=>{"ArrayBuffer"===Je(e)?this.onReceiveMessage(e):mt.error("Socket received invalid data:",e)})),n.onClose(((r,n)=>{mt.warn("websocket closed -> code:",r,"reason:",n),this.onDisconnect(e.CONNECTION_CLOSED),o(t.RC_SOCKET_DISCONNECTED)})),n.onError((r=>{mt.error("websocket error -> ",r),this.onDisconnect(e.WEBSOCKET_ERROR),o(t.RC_SOCKET_NOT_CREATED)})),n.onOpen((()=>{mt.info("websocket open -> ",r),o(t.SUCCESS)})),setTimeout((()=>{o(t.TIMEOUT)}),this.options.webSocketTimeout)}))}async auth(){var e,r,n,o;mt.info(`start auth -> ${this.token}`);const i={token:this.token,deviceType:7,imei:kn(),brand:"",model:"",apnsToken:"",bandId:""},{code:s,msg:a,data:c}=await this.send(At.Auth,i,{encoder:Vr,decoder:Xr.AuthSignIn2TokenResp},8e3);return s===t.SUCCESS||c?(mt.info("auth success -> ",null===(e=c.user)||void 0===e||null===(r=e.uid)||void 0===r?void 0:r.toString()),null===(n=this.watcher)||void 0===n||null===(o=n.onAuth)||void 0===o||o.call(n,c),t.SUCCESS):(mt.warn("auth failed -> "+a),t.RC_CONN_NOT_AUTHRORIZED)}async checkAlive(){if(!this.socket||!this.isAuthorized)return;mt.debug("send ping ->");const r={pingId:rn.ZERO,disconnectDelay:rn.ZERO},{code:n}=await this.send(At.Heartbean,r,{encoder:Kr},this.options.pingTimeout);n===t.SUCCESS?(mt.debug("recv pong <-"),this.failedCount=0,setTimeout((()=>this.checkAlive()),this.options.pingInterval)):(this.failedCount+=1,mt.warn(`ping failed count: ${this.failedCount}, code: ${n}`),this.failedCount>=this.options.pingFailedTimes?(this.failedCount=0,mt.warn("ping timeout, close current websocket to reconnect!"),this.onDisconnect(e.NETWORK_UNAVAILABLE)):this.checkAlive())}onReceiveMessage(t){let r;try{const e=Nn(t);r=Xr.NetworkResponse.decode(e)}catch(t){return mt.error("unpack payload error -> ",t),void this.onDisconnect(e.DISCONNECT_BY_SERVER)}if(r.code)return void this.onDisconnect(e.DISCONNECT_BY_SERVER);if(r.cmdId===At.SessionKilledPush)return void this.onDisconnect(e.KICKED_OFFLINE_BY_OTHER_CLIENT);if(r.cmdId===At.SignOutPish||r.cmdId===At.SignOutPish2)return void this.onDisconnect(e.DISCONNECT_BY_SERVER);if(r.cmdId===At.UserFrozenToLogin||r.cmdId===At.UserFrozenToLogin2)return void this.onDisconnect(e.BLOCKED);const n=rn.isLong(r.messageSeq)?r.messageSeq.toNumber():0;mt.reqInfo(`websocket recv ack -> messageSeq: ${n}`);const o=this.responseCallbacks.get(n);var i;Ze(o)?(o(r.body),this.responseCallbacks.delete(n)):(mt.reqInfo(`websocket recv -> cmd: 0x${r.cmdId.toString(16)}, messageSeq: ${n}`),null===(i=this.watcher)||void 0===i||i.message(r.cmdId,r.body))}async try2Reconnect(){this.reconnectTimer=setTimeout((()=>{this.reconnectTimer=null,this.connect(this.token)}),5e3)}onConnect(){this.setStatus(e.CONNECTED),this.checkAlive(),Ze(this.reconnectTimer)&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}onDisconnect(e){Ze(this.socket)&&(this.doClose(),this.isConnectionAvailable()&&(this.setStatus(e),this.autoReconnect&&this.isConnectionAvailable()&&this.try2Reconnect()))}doClose(){if(Ze(this.socket)){const e=this.socket;this.socket=null,e.onClose(null),e.close()}Ze(this.reconnectTimer)&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null),this.isAuthorized=!1,this.profile=null;for(const e of this.responseCallbacks.values())e(null);this.responseCallbacks.clear()}isConnectionAvailable(){return this.status!==e.DISCONNECTED&&this.status!==e.KICKED_OFFLINE_BY_OTHER_CLIENT&&this.status!==e.BLOCKED&&this.status!==e.DISCONNECT_BY_SERVER}setStatus(e){var t;e!==this.status&&(mt.info(`socketServer is changing status from ${Rn(this.status)} to ${Rn(e)}`),this.status=e,null===(t=this.watcher)||void 0===t||t.status(e))}isAuthCommand(e){return e===At.Auth}generateMessageSeq(){return++this.idCount}};var Dn=new class{constructor(){d(this,"_user",void 0),this._user=this.createDefaultUser()}get uid(){return this.user.uid.toString()}get user(){return this._user}setLogged(e,t){const r=e.user;Ze(r)&&(this._user={active:!0,uid:r.uid??rn.UZERO,deviceId:e.deviceId,sessionId:e.sessionId,token:t})}logOut(){this._user=this.createDefaultUser()}createDefaultUser(){return{active:!1,uid:rn.UZERO,deviceId:rn.UZERO,sessionId:rn.UZERO,token:""}}},Mn=Nt.exports,Ln=Mn.Reader,Bn=Mn.util,Un=Mn.roots.default||(Mn.roots.default={});Un.NewMessageNotificationResp=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.NewMessageNotificationResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.seqno=e.int64();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/NewMessageNotificationResp"},e}(),Un.SendPrivateChatMessageResp=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.localId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msgId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msgSendTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.SendPrivateChatMessageResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.localId=e.int64();break;case 4:n.msgId=e.int64();break;case 5:n.msgSendTime=e.int64();break;case 6:n.seqno=e.int64();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendPrivateChatMessageResp"},e}(),Un.GetNewMessageResp=function(){function e(e){if(this.msg={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.offset=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msg=Bn.emptyObject,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetNewMessageResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:i.offset=e.int64();break;case 4:i.seqno=e.int64();break;case 5:i.msg===Bn.emptyObject&&(i.msg={});var a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.DialogMessageList.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.msg[r]=n;break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewMessageResp"},e}(),Un.DialogMessageList=function(){function e(e){if(this.dialogMessage=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.dialogMessage=Bn.emptyArray,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.DialogMessageList;e.pos<r;){var o=e.uint32();if(o>>>3==1)n.dialogMessage&&n.dialogMessage.length||(n.dialogMessage=[]),n.dialogMessage.push(Un.DialogMessage.decode(e,e.uint32()));else e.skipType(7&o)}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DialogMessageList"},e}(),Un.DialogMessage=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.msgId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.localId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.msgStatus=0,e.prototype.srcId=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.destId="",e.prototype.isOut=!1,e.prototype.senderCategory=0,e.prototype.msgCategory=0,e.prototype.msgPreContent="",e.prototype.msgPostContent="",e.prototype.mediaFlag=!1,e.prototype.mediaConstructor=0,e.prototype.mediaAttribute="",e.prototype.msgSendTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.burnAfterReadingFlag=!1,e.prototype.atFlag=!1,e.prototype.replyFlag=!1,e.prototype.referenceFlag=!1,e.prototype.msgIdReferenced=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.uploadFlag=!1,e.prototype.burnAfterReadingTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.sharingGroupFlag=!1,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.extra="",e.prototype.msgContent=Bn.newBuffer([]),e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.DialogMessage;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.msgId=e.int64();break;case 2:n.localId=e.int64();break;case 3:n.msgStatus=e.int32();break;case 4:n.srcId=e.int64();break;case 5:n.destId=e.string();break;case 6:n.isOut=e.bool();break;case 7:n.senderCategory=e.int32();break;case 8:n.msgCategory=e.int32();break;case 9:n.msgPreContent=e.string();break;case 10:n.msgPostContent=e.string();break;case 11:n.mediaFlag=e.bool();break;case 12:n.mediaConstructor=e.int32();break;case 13:n.mediaAttribute=e.string();break;case 14:n.msgSendTime=e.int64();break;case 15:n.burnAfterReadingFlag=e.bool();break;case 16:n.atFlag=e.bool();break;case 17:n.replyFlag=e.bool();break;case 18:n.referenceFlag=e.bool();break;case 19:n.msgIdReferenced=e.int64();break;case 20:n.uploadFlag=e.bool();break;case 21:n.burnAfterReadingTime=e.int64();break;case 22:n.sharingGroupFlag=e.bool();break;case 23:n.seqno=e.int64();break;case 24:n.extra=e.string();break;case 25:n.msgContent=e.bytes();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DialogMessage"},e}(),Un.GetBriefDialogListResp=function(){function e(e){if(this.notExistDestId=[],this.briefDialog={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.notExistDestId=Bn.emptyArray,e.prototype.seqno=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.briefDialog=Bn.emptyObject,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetBriefDialogListResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:if(i.notExistDestId&&i.notExistDestId.length||(i.notExistDestId=[]),2==(7&s))for(var a=e.uint32()+e.pos;e.pos<a;)i.notExistDestId.push(e.int64());else i.notExistDestId.push(e.int64());break;case 4:i.seqno=e.int64();break;case 5:i.briefDialog===Bn.emptyObject&&(i.briefDialog={});a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.BriefDialog.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.briefDialog[r]=n;break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetBriefDialogListResp"},e}(),Un.BriefDialog=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.dialogTitle="",e.prototype.smallAvatarUrl="",e.prototype.backgroundImage="",e.prototype.stickyFlag=!1,e.prototype.muteFlag=!1,e.prototype.blockFlag=!1,e.prototype.burnAfterReadingFlag=!1,e.prototype.takeScreenshotFlag=!1,e.prototype.groupFlag=!1,e.prototype.pushNotificationLevel=0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.BriefDialog;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.destId=e.string();break;case 2:n.dialogTitle=e.string();break;case 3:n.smallAvatarUrl=e.string();break;case 4:n.backgroundImage=e.string();break;case 5:n.stickyFlag=e.bool();break;case 6:n.muteFlag=e.bool();break;case 7:n.blockFlag=e.bool();break;case 8:n.burnAfterReadingFlag=e.bool();break;case 9:n.takeScreenshotFlag=e.bool();break;case 10:n.groupFlag=e.bool();break;case 15:n.pushNotificationLevel=e.int32();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/BriefDialog"},e}(),Un.GetDialogKeyResp=function(){function e(e){if(this.retryUid=[],this.entry={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.dialogKeyVersion=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.prototype.retryUid=Bn.emptyArray,e.prototype.entry=Bn.emptyObject,e.prototype.serverSign="",e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetDialogKeyResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:i.dialogKeyVersion=e.int64();break;case 4:if(i.retryUid&&i.retryUid.length||(i.retryUid=[]),2==(7&s))for(var a=e.uint32()+e.pos;e.pos<a;)i.retryUid.push(e.int64());else i.retryUid.push(e.int64());break;case 5:i.entry===Bn.emptyObject&&(i.entry={});a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.AesKeyAndIV.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.entry[r]=n;break;case 6:i.serverSign=e.string();break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetDialogKeyResp"},e}(),Un.AesKeyAndIV=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.aesKey="",e.prototype.aesIV="",e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.AesKeyAndIV;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.aesKey=e.string();break;case 2:n.aesIV=e.string();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/AesKeyAndIV"},e}(),Un.GetHistoryMessageResp=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.msg=null,e.prototype.isEnd=!1,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.GetHistoryMessageResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.msg=Un.DialogMessageList.decode(e,e.uint32());break;case 4:n.isEnd=e.bool();break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetHistoryMessageResp"},e}(),Un.GetWebDialogListResp=function(){function e(e){if(this.fullDialog=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.fullDialog=Bn.emptyArray,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.GetWebDialogListResp;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.fullDialog&&n.fullDialog.length||(n.fullDialog=[]),n.fullDialog.push(Un.WebFullDialog.decode(e,e.uint32()));break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetWebDialogListResp"},e}(),Un.WebFullDialog=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.dialog=null,e.prototype.msg=null,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r=void 0===t?e.len:e.pos+t,n=new Un.WebFullDialog;e.pos<r;){var o=e.uint32();switch(o>>>3){case 1:n.dialog=Un.BriefDialog.decode(e,e.uint32());break;case 2:n.msg=Un.DialogMessage.decode(e,e.uint32());break;default:e.skipType(7&o)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/WebFullDialog"},e}(),Un.GetNewSettingDialogListResp=function(){function e(e){if(this.briefDialog={},e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.briefDialog=Bn.emptyObject,e.prototype.setTime=Bn.Long?Bn.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Ln||(e=Ln.create(e));for(var r,n,o=void 0===t?e.len:e.pos+t,i=new Un.GetNewSettingDialogListResp;e.pos<o;){var s=e.uint32();switch(s>>>3){case 1:i.errorCode=e.int32();break;case 2:i.errorMessage=e.string();break;case 3:i.briefDialog===Bn.emptyObject&&(i.briefDialog={});var a=e.uint32()+e.pos;for(r="",n=null;e.pos<a;){var c=e.uint32();switch(c>>>3){case 1:r=e.string();break;case 2:n=Un.BriefDialog.decode(e,e.uint32());break;default:e.skipType(7&c)}}i.briefDialog[r]=n;break;case 4:i.setTime=e.int64();break;default:e.skipType(7&s)}}return i},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewSettingDialogListResp"},e}();var jn=Un;var Pn=new class{constructor(){d(this,"_token",""),d(this,"_uploadUrl",""),d(this,"_downloadUrl",""),d(this,"_cert","")}set imInitToken(e){this._token=e}get imInitToken(){return this._token}get fileUploadUrl(){return this._uploadUrl}get cert(){return this._cert}get fileDownloadUrl(){return this._downloadUrl}setFileServerInfo(e,t,r){this._uploadUrl=e,this._downloadUrl=t,this._cert=r}getFileAbsoluteUri(e){return ot(e)?e.startsWith("http")?e:this.fileDownloadUrl+e:e}try2ExtractFileRelativeUri(e){return ot(e)&&e.startsWith(this.fileDownloadUrl)?e.substring(this.fileDownloadUrl.length):e}};const Fn=e=>{if(!ot(e.targetId+""))return"";switch(e.conversationType){case n.PRIVATE:return"P::"+e.targetId;case n.GROUP:return"G::"+e.targetId;case n.ULTRA_GROUP:return`SG::${e.targetId}_${e.channelId??""}`;default:return""}},Gn=e=>{if(!ot(e))return null;const t=e.split("::");if(2!==t.length)return null;const r=t[0];if("G"===r)return{conversationType:n.GROUP,targetId:t[1]};if("P"===r)return{conversationType:n.PRIVATE,targetId:t[1]};if("SG"===r){const e=t[1].indexOf("_");if(e>0){const r=t[1].substring(0,e),o=t[1].substring(e+1);return{conversationType:n.ULTRA_GROUP,targetId:r,channelId:o}}return 0===e?null:{conversationType:n.ULTRA_GROUP,targetId:t[1]}}return null},qn=e=>e.startsWith("SG")||e.startsWith("G");var Hn=Nt.exports,zn=Hn.Writer,Kn=Hn.util,Vn=Hn.roots.default||(Hn.roots.default={});Vn.SendPrivateChatMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.localId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.msgPreContent="",e.prototype.msgPostContent="",e.prototype.mediaFlag=!1,e.prototype.mediaConstructor=0,e.prototype.mediaAttribute="",e.prototype.extra="",e.prototype.thumbnail="",e.prototype.msgContent=Kn.newBuffer([]),e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.localId&&Object.hasOwnProperty.call(e,"localId")&&t.uint32(16).int64(e.localId),null!=e.msgPreContent&&Object.hasOwnProperty.call(e,"msgPreContent")&&t.uint32(26).string(e.msgPreContent),null!=e.msgPostContent&&Object.hasOwnProperty.call(e,"msgPostContent")&&t.uint32(34).string(e.msgPostContent),null!=e.mediaFlag&&Object.hasOwnProperty.call(e,"mediaFlag")&&t.uint32(40).bool(e.mediaFlag),null!=e.mediaConstructor&&Object.hasOwnProperty.call(e,"mediaConstructor")&&t.uint32(48).int32(e.mediaConstructor),null!=e.mediaAttribute&&Object.hasOwnProperty.call(e,"mediaAttribute")&&t.uint32(58).string(e.mediaAttribute),null!=e.extra&&Object.hasOwnProperty.call(e,"extra")&&t.uint32(66).string(e.extra),null!=e.thumbnail&&Object.hasOwnProperty.call(e,"thumbnail")&&t.uint32(74).string(e.thumbnail),null!=e.msgContent&&Object.hasOwnProperty.call(e,"msgContent")&&t.uint32(82).bytes(e.msgContent),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendPrivateChatMessageReq"},e}(),Vn.DeletePrivateChatDialogReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeletePrivateChatDialogReq"},e}(),Vn.GetNewMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.offset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.offset&&Object.hasOwnProperty.call(e,"offset")&&t.uint32(8).int64(e.offset),null!=e.rows&&Object.hasOwnProperty.call(e,"rows")&&t.uint32(16).int32(e.rows),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewMessageReq"},e}(),Vn.UpdatePrivateChatDialogStickyConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.stickyFlag=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.stickyFlag&&Object.hasOwnProperty.call(e,"stickyFlag")&&t.uint32(16).bool(e.stickyFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdatePrivateChatDialogStickyConfigReq"},e}(),Vn.UpdatePrivateChatDialogMuteConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.muteFlag=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.muteFlag&&Object.hasOwnProperty.call(e,"muteFlag")&&t.uint32(16).bool(e.muteFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdatePrivateChatDialogMuteConfigReq"},e}(),Vn.DeleteChatMessageReq=function(){function e(e){if(this.msgIdList=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.msgId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.msgIdList=Kn.emptyArray,e.encode=function(e,t){if(t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),null!=e.msgIdList&&e.msgIdList.length){t.uint32(26).fork();for(var r=0;r<e.msgIdList.length;++r)t.int64(e.msgIdList[r]);t.ldelim()}return t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeleteChatMessageReq"},e}(),Vn.DeletePrivateChatHistoryReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.msgId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeletePrivateChatHistoryReq"},e}(),Vn.CleanHistoryMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.type=0,e.prototype.msgTime=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.type&&Object.hasOwnProperty.call(e,"type")&&t.uint32(16).int32(e.type),null!=e.msgTime&&Object.hasOwnProperty.call(e,"msgTime")&&t.uint32(24).int64(e.msgTime),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/CleanHistoryMessageReq"},e}(),Vn.GetBriefDialogListReq=function(){function e(e){if(this.destId=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId=Kn.emptyArray,e.encode=function(e,t){if(t||(t=zn.create()),null!=e.destId&&e.destId.length)for(var r=0;r<e.destId.length;++r)t.uint32(10).string(e.destId[r]);return t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetBriefDialogListReq"},e}(),Vn.GetDialogKeyReq=function(){function e(e){if(this.destId=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId=Kn.emptyArray,e.prototype.clientSign="",e.encode=function(e,t){if(t||(t=zn.create()),null!=e.destId&&e.destId.length)for(var r=0;r<e.destId.length;++r)t.uint32(10).string(e.destId[r]);return null!=e.clientSign&&Object.hasOwnProperty.call(e,"clientSign")&&t.uint32(18).string(e.clientSign),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetDialogKeyReq"},e}(),Vn.RecallPrivateChatMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.destId="",e.prototype.msgId=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.destId&&Object.hasOwnProperty.call(e,"destId")&&t.uint32(10).string(e.destId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/RecallPrivateChatMessageReq"},e}(),Vn.GetHistoryMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.dialogKeys="",e.prototype.offset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.oldOffset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.dialogKeys&&Object.hasOwnProperty.call(e,"dialogKeys")&&t.uint32(10).string(e.dialogKeys),null!=e.offset&&Object.hasOwnProperty.call(e,"offset")&&t.uint32(16).int64(e.offset),null!=e.oldOffset&&Object.hasOwnProperty.call(e,"oldOffset")&&t.uint32(24).int64(e.oldOffset),null!=e.rows&&Object.hasOwnProperty.call(e,"rows")&&t.uint32(32).int32(e.rows),null!=e.newToOld&&Object.hasOwnProperty.call(e,"newToOld")&&t.uint32(40).bool(e.newToOld),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetHistoryMessageReq"},e}(),Vn.GetWebDialogListReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.type=0,e.prototype.offset=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=zn.create()),null!=e.type&&Object.hasOwnProperty.call(e,"type")&&t.uint32(8).int32(e.type),null!=e.offset&&Object.hasOwnProperty.call(e,"offset")&&t.uint32(16).int64(e.offset),null!=e.rows&&Object.hasOwnProperty.call(e,"rows")&&t.uint32(24).int32(e.rows),null!=e.newToOld&&Object.hasOwnProperty.call(e,"newToOld")&&t.uint32(32).bool(e.newToOld),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetWebDialogListReq"},e}(),Vn.GetNewSettingDialogListReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.time=Kn.Long?Kn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=zn.create()),null!=e.time&&Object.hasOwnProperty.call(e,"time")&&t.uint32(8).int64(e.time),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/GetNewSettingDialogListReq"},e}();var Wn=Vn,$n=Nt.exports,Jn=$n.Writer,Zn=$n.util,Xn=$n.roots.default||($n.roots.default={});Xn.SendGroupChatMessageReq=function(){function e(e){if(this.at=[],e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.localId=Zn.Long?Zn.Long.fromBits(0,0,!1):0,e.prototype.msgPreContent="",e.prototype.msgPostContent="",e.prototype.mediaFlag=!1,e.prototype.mediaConstructor=0,e.prototype.mediaAttribute="",e.prototype.at=Zn.emptyArray,e.prototype.extra="",e.prototype.assign="",e.prototype.atAll=!1,e.prototype.msgContent=Zn.newBuffer([]),e.encode=function(e,t){if(t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.localId&&Object.hasOwnProperty.call(e,"localId")&&t.uint32(16).int64(e.localId),null!=e.msgPreContent&&Object.hasOwnProperty.call(e,"msgPreContent")&&t.uint32(26).string(e.msgPreContent),null!=e.msgPostContent&&Object.hasOwnProperty.call(e,"msgPostContent")&&t.uint32(34).string(e.msgPostContent),null!=e.mediaFlag&&Object.hasOwnProperty.call(e,"mediaFlag")&&t.uint32(40).bool(e.mediaFlag),null!=e.mediaConstructor&&Object.hasOwnProperty.call(e,"mediaConstructor")&&t.uint32(48).int32(e.mediaConstructor),null!=e.mediaAttribute&&Object.hasOwnProperty.call(e,"mediaAttribute")&&t.uint32(58).string(e.mediaAttribute),null!=e.at&&e.at.length){t.uint32(66).fork();for(var r=0;r<e.at.length;++r)t.int64(e.at[r]);t.ldelim()}return null!=e.extra&&Object.hasOwnProperty.call(e,"extra")&&t.uint32(74).string(e.extra),null!=e.assign&&Object.hasOwnProperty.call(e,"assign")&&t.uint32(82).string(e.assign),null!=e.atAll&&Object.hasOwnProperty.call(e,"atAll")&&t.uint32(88).bool(e.atAll),null!=e.msgContent&&Object.hasOwnProperty.call(e,"msgContent")&&t.uint32(98).bytes(e.msgContent),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendGroupChatMessageReq"},e}(),Xn.DeleteGroupChatHistoryReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeleteGroupChatHistoryReq"},e}(),Xn.UpdateGroupChatDialogStickyConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.stickyFlag=!1,e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.stickyFlag&&Object.hasOwnProperty.call(e,"stickyFlag")&&t.uint32(16).bool(e.stickyFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdateGroupChatDialogStickyConfigReq"},e}(),Xn.UpdateGroupChatDialogMuteConfigReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.muteFlag=!1,e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.muteFlag&&Object.hasOwnProperty.call(e,"muteFlag")&&t.uint32(16).bool(e.muteFlag),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/UpdateGroupChatDialogMuteConfigReq"},e}(),Xn.RecallGroupChatMessageReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.prototype.msgId=Zn.Long?Zn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),null!=e.msgId&&Object.hasOwnProperty.call(e,"msgId")&&t.uint32(16).int64(e.msgId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/RecallGroupChatMessageReq"},e}(),Xn.DeleteGroupChatDialogReq=function(){function e(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.groupId="",e.encode=function(e,t){return t||(t=Jn.create()),null!=e.groupId&&Object.hasOwnProperty.call(e,"groupId")&&t.uint32(10).string(e.groupId),t},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/DeleteGroupChatDialogReq"},e}();var Yn=Xn;const Qn=Nt.exports.Reader,eo=Nt.exports.util,to=Nt.exports.roots.default||(Nt.exports.roots.default={}),ro=to.SendGroupChatMessageResp=(()=>{function e(e){if(e)for(let t=Object.keys(e),r=0;r<t.length;++r)null!=e[t[r]]&&(this[t[r]]=e[t[r]])}return e.prototype.errorCode=0,e.prototype.errorMessage="",e.prototype.localId=eo.Long?eo.Long.fromBits(0,0,!1):0,e.prototype.msgId=eo.Long?eo.Long.fromBits(0,0,!1):0,e.prototype.msgSendTime=eo.Long?eo.Long.fromBits(0,0,!1):0,e.prototype.seqno=eo.Long?eo.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof Qn||(e=Qn.create(e));let r=void 0===t?e.len:e.pos+t,n=new to.SendGroupChatMessageResp;for(;e.pos<r;){let t=e.uint32();switch(t>>>3){case 1:n.errorCode=e.int32();break;case 2:n.errorMessage=e.string();break;case 3:n.localId=e.int64();break;case 4:n.msgId=e.int64();break;case 5:n.msgSendTime=e.int64();break;case 6:n.seqno=e.int64();break;default:e.skipType(7&t)}}return n},e.getTypeUrl=function(e){return void 0===e&&(e="type.googleapis.com"),e+"/SendGroupChatMessageResp"},e})();let no=0;const oo=async()=>{const e=(new Date).getTime(),{code:r,data:n}=await xn.send(At.GetServerTime,null,{decoder:Xr.SystemCurrentTimeMillisResp});if(r===t.SUCCESS){const{currentTimeMillis:t}=n;no=t.toNumber()-e}},io=()=>(new Date).getTime()+no,so=new Set;var ao={addMessage(e){so.add(e)},remove(e){so.delete(e)},has:e=>so.has(e),reset(){so.clear()}};const co=new Set;var lo={addMessage(e){co.add(e)},remove(e){co.delete(e)},has:e=>co.has(e),reset(){co.clear()}};const uo=new Map;function ho(e){uo.set(e.getObjectId(),e.decode.bind(e))}class fo{constructor(e,t){let r=!(arguments.length>2&&void 0!==arguments[2])||arguments[2],n=!(arguments.length>3&&void 0!==arguments[3])||arguments[3],o=arguments.length>4&&void 0!==arguments[4]&&arguments[4];d(this,"messageType",void 0),d(this,"content",void 0),d(this,"isPersited",void 0),d(this,"isCounted",void 0),d(this,"isStatusMessage",void 0),this.messageType=e,this.content=t,o?(this.isPersited=!1,this.isCounted=!1):(this.isPersited=r,this.isCounted=n),this.isStatusMessage=o}get objectId(){return this.constructor.getObjectId()}static getObjectId(){throw new Error("Method not implemented.")}static decode(e){throw new Error("Method not implemented.")}encode(){throw new Error("Method not implemented.")}}const po=0,go=268439552,yo=268439563,vo=268439562,mo=268439553,bo=268439581,wo=268439597,Oo=268439613,Co=268439629,_o=1610678301,So=268439645,Io="RC:TxtMsg",Eo="RC:HQVCMsg",To="RC:FileMsg",Ro="RC:ImgMsg",ko="RC:GIFMsg",Ao="RC:RcNtf",No="RC:CmdMsg";class xo extends fo{constructor(e){super(Io,e)}static getObjectId(){return po}static decode(e){const{user:t,extra:r,content:n}=e;return new xo({user:t,extra:r,content:n})}encode(){const{user:e,extra:t,content:r}=this.content;return{user:e,extra:t,content:r}}}class Do extends fo{constructor(e){super(Ro,e)}static getObjectId(){return go}static decode(e){const{user:t,extra:r,thumbnailObjectKey:n,originalObjectKey:o,width:i,height:s}=e;return new Do({user:t,extra:r,content:n,imageUri:Pn.getFileAbsoluteUri(o),width:i,height:s})}encode(){const{user:e,extra:t,content:r,imageUri:n,width:o,height:i}=this.content;return{user:e,extra:t,thumbnailObjectKey:r,originalObjectKey:Pn.try2ExtractFileRelativeUri(n),width:o&&Math.floor(o),height:i&&Math.floor(i)}}}class Mo extends fo{constructor(e){super(ko,e)}static getObjectId(){return yo}static decode(e){const{user:t,extra:r,size:n,originalObjectKey:o,width:i,height:s}=e;return new Mo({user:t,extra:r,gifDataSize:n,remoteUrl:Pn.getFileAbsoluteUri(o),width:i,height:s})}encode(){const{user:e,extra:t,gifDataSize:r,remoteUrl:n,width:o,height:i}=this.content;return{user:e,extra:t,size:r,originalObjectKey:Pn.try2ExtractFileRelativeUri(n),width:o&&Math.floor(o),height:i&&Math.floor(i),extension:"gif"}}}class Lo extends fo{constructor(e){super(Eo,e)}static getObjectId(){return mo}static decode(e){const{user:t,extra:r,length:n,audioObjectKey:o,extension:i}=e;return new Lo({user:t,extra:r,remoteUrl:Pn.getFileAbsoluteUri(o),duration:n,type:i})}encode(){const{user:e,extra:t,remoteUrl:r,duration:n,type:o}=this.content;return{user:e,extra:t,length:n,audioObjectKey:Pn.try2ExtractFileRelativeUri(r),extension:o}}}class Bo extends fo{constructor(e){super(To,e)}static getObjectId(){return vo}static decode(e){const{user:t,extra:r,title:n,extension:o,size:i,originalObjectKey:s}=e;return new Bo({user:t,extra:r,name:n,size:i,type:o,fileUrl:Pn.getFileAbsoluteUri(s)})}encode(){const{user:e,extra:t,name:r,size:n,type:o,fileUrl:i}=this.content;return{user:e,extra:t,title:r,originalObjectKey:Pn.try2ExtractFileRelativeUri(i),extension:o,size:n}}}class Uo extends fo{constructor(e){super(Ao,e,!0,!1,!1)}static getObjectId(){return _o}static decode(e){return new Uo(e)}encode(){return this.content}}class jo extends fo{constructor(e){super(No,e,!1,!1)}static getObjectId(){return So}static decode(e){return new jo(e)}encode(){return this.content}}class Po extends fo{static decode(e){const{messageType:t,fields:r,user:n,extra:o}=e;return new this(t,{...r,user:n,extra:o})}encode(){const{user:e,extra:t,mentionedInfo:r,...n}=this.content;return{messageType:this.messageType,fields:n,user:e,extra:t}}}class Fo extends Po{constructor(e,t){super(e,t,!1,!1)}static getObjectId(){return bo}}class Go extends Po{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return wo}}class qo extends Po{constructor(e,t){super(e,t,!0,!0)}static getObjectId(){return Oo}}class Ho extends Po{constructor(e,t){super(e,t,!1,!1,!0)}static getObjectId(){return Co}}var zo=new class{constructor(){d(this,"aesKeyRecord",new Map)}async getDialogAesKey(e){return ot(e)?this.aesKeyRecord.has(e)?this.aesKeyRecord.get(e):new Promise((t=>{this.getDialogAesKeyListFromRemote([e]).then((r=>{t(r.get(e))})),setTimeout((()=>{t(null)}),8e3)})):null}getDialogAesKeyList(e){return new Promise((t=>{const r=new Map;this.getDialogAesKeyListInBatches(e,((n,o)=>{if(o.size)for(const[e,t]of o)r.set(e,t);(r.size===e.length||n)&&t(r)}))}))}getDialogAesKeyListInBatches(e,t){const r=new Map,n=[];e.forEach((e=>{if(!ot(e))return;const t=this.getDialogAesKeyFromLocal(e);t?r.set(e,t):n.push(e)})),t(!1,r),n.length&&this.getDialogAesKeyListFromRemote(n).then((e=>{t(!0,e)}))}reset(){this.aesKeyRecord.clear()}async getDialogAesKeyListFromRemote(e){if(!e.length)return new Map;const{code:r,data:n}=await(o=e,xn.send(At.GetDialogKey,{destId:o,clientSign:""},{encoder:Wn.GetDialogKeyReq,decoder:jn.GetDialogKeyResp}));var o;if(r===t.SUCCESS){const e=new Map;for(const t in n.entry){var i,s;const r=n.entry[t];if(null!==(i=r.aesKey)&&void 0!==i&&i.length&&null!==(s=r.aesIV)&&void 0!==s&&s.length){const n={key:r.aesKey,iv:r.aesIV};e.set(t,n),this.aesKeyRecord.set(t,n)}}return e}return new Map}getDialogAesKeyFromLocal(e){return ot(e)?this.aesKeyRecord.get(e):null}};const Ko="time",Vo=(e,t)=>[e,t,Ko].join("_");class Wo{constructor(e,t){d(this,"appkey",void 0),d(this,"userId",void 0),d(this,"inBoxOffset",rn.ZERO),this.appkey=e,this.userId=t}setInboxOffset(e){if(this.inBoxOffset>e)return;this.inBoxOffset=e;const t=Vo(this.appkey,this.userId);ft.set(t,e.toString())}getInboxOffset(){if(this.inBoxOffset.isZero()){const e=Vo(this.appkey,this.userId);this.inBoxOffset=rn.fromString(ft.get(e)??"0")}return this.inBoxOffset}}const $o=e=>{const t=[];let r,n,o;for(n=0;n<e.length;++n)for(r=e[n],o=3;o>=0;--o)t.push(r>>8*o&255);return new Uint8Array(t)};const Jo=(e,t,r)=>{const n={};return e.forEach((e=>{const o=Zo(e,t.get(e),r.get(e));o.length&&(n[e]=o)})),n},Zo=(e,t,r)=>{const n=Gn(e);if(!n)return[];const o=new Set;let i=[];return t.forEach((e=>{const t=e;let c=t.mediaConstructor,l=Xo(t,r);if(!l)return;if(1610678290===c||1610743841===c){const{msgId:e,sendTime:r}=l,i={sentTime:r,messageUId:e,conversationType:n.conversationType,targetId:t.isOut?n.targetId:Dn.uid,channelId:n.channelId};c=_o,l=i,o.add(e)}const u=function(e,t){const r=uo.get(e);return r?r(t):null}(c,l);if(Ze(u)){const e={...n,senderUserId:t.srcId.toString(),messageDirection:t.isOut?s.SEND:s.RECEIVE,isCounted:u.isCounted,isMentioned:t.atFlag,content:u.content,messageType:u.messageType,isOffLineMessage:!1,isPersited:u.isPersited,messageId:rn.isLong(t.localId)?t.localId.toNumber():void 0,messageUId:t.msgId.toString(),sentTime:t.seqno.toNumber(),receivedTime:io(),isStatusMessage:u.isStatusMessage,receivedStatus:a.READ,disableNotification:!1};if(e.isStatusMessage&&io()-e.sentTime>6e3)return;i.push(e)}})),o.size&&(i=i.filter((e=>!o.has(e.messageUId)))),i},Xo=(e,t)=>{try{var r,n;let o;o=null!==(r=e.msgContent)&&void 0!==r&&r.length?((e,t)=>{const r=window.btoa(String.fromCharCode(...e));return $e.AES.decrypt(r,$e.enc.Utf8.parse(t.key),{iv:Ze(t.iv)?$e.enc.Utf8.parse(t.iv):void 0}).toString($e.enc.Utf8)})(e.msgContent,t):e.msgPreContent??"",1610678290!==e.mediaConstructor&&1610743841!==e.mediaConstructor||(o=Yo(o));let i={};return null!==(n=o)&&void 0!==n&&n.length&&(i=JSON.parse(o)),i}catch(t){return mt.error("decode message content fail -> uid:",e.msgId.toString()),null}},Yo=e=>e.replace(/("msgId")\s*:\s*(\d+)/g,((e,t,r)=>`${t}:"${r}"`));var Qo={parse:function(e,t){const r=new Map;if(Object.keys(e).forEach((t=>{var n;const o=null===(n=e[t].dialogMessage)||void 0===n?void 0:n.filter((e=>!e.sharingGroupFlag));null!=o&&o.length&&r.set(t,o)})),!r.size)return void t(!0,{});const n=new Set(r.keys());zo.getDialogAesKeyListInBatches([...r.keys()],((e,o)=>{if(o.size){const e=[...o.keys()];for(const t of e)n.delete(t);t(!n.size,Jo(e,r,o))}n.size&&e&&t(!0,{})}))},parseSingleDialogMessages:Zo};function ei(e){if(!Ze(e))return e;if(Array.isArray(e))return e.map((e=>ei(e)));if(tt(e)){const t={};return Object.keys(e).forEach((r=>{t[r]=ei(e[r])})),t}return e}const ti={unreadMessageCount:{keyName:"c",defaultVal:0},lastUnreadTime:{keyName:"lt",defaultVal:0},notificationStatus:{keyName:"nc",defaultVal:2},notificationLevel:{keyName:"nl",defaultVal:0},isTop:{keyName:"it",defaultVal:!1},mentionedUIds:{keyName:"mu",defaultVal:null}};class ri{constructor(e,t){d(this,"localStore",void 0);const r=`con-${e}-${t}`;this.localStore=new pt(r)}getStoreKey(e){return`${e.conversationType}_${e.targetId}_${e.channelId??""}`}getConOptionByKey(e){const t=(e=e||"").split("_");if(t.length>=2){const e=t.shift(),r=t.shift(),n=t.join("_");return{conversationType:Number(e),targetId:r,channelId:n}}return{conversationType:n.PRIVATE,targetId:"",channelId:""}}updateUnreadCount(e){const{conversationType:t,targetId:r,channelId:n,content:o,messageType:i,sentTime:a,isCounted:c,messageDirection:l}=e,u=l===s.SEND,d=i===Ao,h=tt(o),f={conversationType:t,targetId:r,channelId:n},p=this.get(f)||{},g=p.lastUnreadTime||0,y=p.unreadMessageCount||0;if(!(a<=g)&&!u){if(c&&(p.unreadMessageCount=y+1,g||(p.lastUnreadTime=a)),d&&h){o.sentTime>=g&&y&&(p.unreadMessageCount=y-1)}this.set(f,p)}}updateMentionedData(e){const{conversationType:t,targetId:r,channelId:o,messageUId:i,messageType:a,isMentioned:c,messageDirection:l,content:u}=e;if(l===s.SEND||!c&&a!==Ao)return;const d=this.getStoreKey({conversationType:t,targetId:r,channelId:o}),h=this.localStore.get(d)||{},f=ti.mentionedUIds.keyName,p=h[f]||[];if(c&&t===n.GROUP&&(p.includes(i)||p.push(i)),a===Ao&&t===n.GROUP){const e=u,t=p.indexOf(e.messageUId);t>=0&&p.splice(t,1)}p.length?h[f]=p:delete h[f],it(h)?this.localStore.set(d,h):this.localStore.remove(d)}set(e,t){const r=this.getStoreKey(e),n=this.localStore.get(r)||{};for(const e of at(t)){const r=ti[e],o=t[e];if(Qe(null==r?void 0:r.keyName)||Qe(o))continue;o===r.defaultVal?delete n[r.keyName]:n[r.keyName]=o,n[ti.unreadMessageCount.keyName]||(delete n[ti.lastUnreadTime.keyName],delete n[ti.mentionedUIds.keyName])}it(n)?this.localStore.set(r,n):this.localStore.remove(r)}get(e){const t=this.getStoreKey(e),r=this.localStore.get(t)||{},n={};for(const e of at(ti)){const{keyName:t,defaultVal:i}=ti[e];var o;if("mentionedUIds"===e)n.unreadMentionedCount=(null===(o=r[t])||void 0===o?void 0:o.length)??0,n.hasMentioned=!!n.unreadMentionedCount;else n[e]=r[t]||ei(i)}return n}getAll(){const e=this.localStore.getCache()||{},t=[];for(const r in e){const n=this.getConOptionByKey(r),o=e[r];for(const e of at(ti)){const{keyName:t,defaultVal:r}=ti[e];"mentionedUIds"!==e&&(n[e]=o[t]||ei(r))}t.push(n)}return t}}const ni=e=>{const t=e.destId??"",r=Gn(t);if(!r)return;return{...r,unreadMessageCount:0,notificationStatus:e.muteFlag?i.OPEN:i.CLOSE,notificationLevel:Xe(e.pushNotificationLevel)&&0!==e.pushNotificationLevel&&Ze(c[e.pushNotificationLevel])?e.pushNotificationLevel:e.muteFlag?c.AT_USER_NOTIFICATION:c.NOT_SET,isTop:!!e.stickyFlag,lastUnreadTime:0}};class oi{constructor(e,t){d(this,"storageKey",void 0),d(this,"eventEmitter",void 0),d(this,"isPulling",!1),this.storageKey=`con-s-${e}-${t}`,this.eventEmitter=new Rt}async pull(){if(this.isPulling)return;let e;this.isPulling=!0;const r=ft.get(this.storageKey);e=Xe(r)&&r>0?r:io()-1e4;let{code:n,data:o}=await(e=>xn.send(At.GetDialogChangedStatus,{time:rn.fromNumber(e)},{encoder:Wn.GetNewSettingDialogListReq,decoder:jn.GetNewSettingDialogListResp}))(e);n===t.SUCCESS&&(o.setTime.toNumber()>0&&ft.set(this.storageKey,o.setTime.toNumber()),o.briefDialog&&at(o.briefDialog).forEach((e=>{const t=o.briefDialog[e],r=ni(t);r&&this.eventEmitter.emit("STATUS_CHANGED",r)}))),this.isPulling=!1}watch(e){this.eventEmitter.on("STATUS_CHANGED",(t=>{e(t)}))}}class ii{constructor(e,t,r){d(this,"updatedConversationFunc",void 0),d(this,"store",void 0),d(this,"draftMap",new Map),d(this,"localConversationSet",new Set),d(this,"updatedConversations",[]),d(this,"notify",void 0),d(this,"statusManager",void 0),this.updatedConversationFunc=r,this.store=new ri(e,t),this.notify=lt(this.notifyConversationChanged.bind(this),0),this.statusManager=new oi(e,t),this.statusManager.watch((e=>{this.addStatus(e,!0)}))}getConversationKey(e){return`${e.conversationType}_${e.targetId}_${e.channelId??""}`}setUpdatedConversation(e){const t=this.updatedConversations.findIndex((t=>this.getConversationKey(e.conversation)===this.getConversationKey(t.conversation)));t>=0?(e={conversation:Object.assign(this.updatedConversations[t].conversation,e.conversation),updatedItems:Object.assign(this.updatedConversations[t].updatedItems,e.updatedItems)},this.updatedConversations[t]=e):this.updatedConversations.push(e),this.notify()}notifyConversationChanged(){var e;const t=this.updatedConversations.map((e=>({conversation:{...e.conversation,...this.store.get(e.conversation)},updatedItems:e.updatedItems})));this.updatedConversations=[],null===(e=this.updatedConversationFunc)||void 0===e||e.call(this,t)}syncConversationStatus(){this.statusManager.pull()}async loadConvsationsIfNotExist(e){if(null==e||!e.length)return;const r=e.filter((e=>!this.localConversationSet.has(this.getConversationKey(e))));if(!r.length)return;const n=r.map(Fn).filter(ot);if(!n.length)return;const{code:o,data:i}=await(e=>xn.send(At.GetBriefDialogList,{destId:e},{encoder:Wn.GetBriefDialogListReq,decoder:jn.GetBriefDialogListResp}))(n);o===t.SUCCESS&&at(i.briefDialog).forEach((e=>{const t=i.briefDialog[e],r=ni(t);r&&(this.localConversationSet.add(this.getConversationKey(r)),this.addStatus(r,!0))}))}addLocalConversation(e){const{conversationType:t,targetId:r,channelId:n,isTop:o,notificationStatus:i,notificationLevel:s}=e;this.localConversationSet.add(this.getConversationKey(e)),this.addStatus({conversationType:t,targetId:r,channelId:n,isTop:o,notificationStatus:i,notificationLevel:s},!1)}addStatus(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];const{conversationType:r,targetId:n,notificationStatus:o,notificationLevel:i,isTop:s,channelId:a}=e,c={conversationType:r,targetId:n,channelId:a},l=io(),u=this.store.get(c),d={};Ze(i)&&u.notificationLevel!==i&&(d.notificationLevel={time:l,val:i}),Ze(o)&&u.notificationStatus!==o&&(d.notificationStatus={time:l,val:o}),Ze(s)&&u.isTop!==s&&(d.isTop={time:l,val:s}),this.store.set(c,{notificationStatus:o,isTop:s,notificationLevel:i}),Object.keys(d).length&&t&&this.setUpdatedConversation({conversation:c,updatedItems:d})}setConversationCacheByMessage(e){const{conversationType:t,isPersited:r,targetId:n,channelId:o}=e,i={conversationType:t,targetId:n,channelId:o},s={conversation:i,updatedItems:{}},a=ei(this.get(i));this.store.updateUnreadCount(e),this.store.updateMentionedData(e);const c=this.get(i);a.unreadMessageCount!==c.unreadMessageCount&&(s.updatedItems.unreadMessageCount={time:e.sentTime,val:c.unreadMessageCount}),a.hasMentioned!==c.hasMentioned&&(s.updatedItems.hasMentioned={time:e.sentTime,val:c.hasMentioned}),a.unreadMentionedCount!==c.unreadMentionedCount&&(s.updatedItems.unreadMentionedCount={time:e.sentTime,val:c.unreadMentionedCount}),r&&(s.conversation.latestMessage=e,s.updatedItems.latestMessage={time:e.sentTime,val:e}),Object.keys(s.updatedItems).length&&this.setUpdatedConversation(s)}get(e){return this.store.get(e)}getAllUnreadCount(e,t){const r=this.store.getAll();let n=0;return r.forEach((r=>{let{unreadMessageCount:o,notificationStatus:s,notificationLevel:a,conversationType:c}=r;o=o||0;const l=s===i.OPEN||a>0;!t&&l||(e.length>0?e.includes(+c)&&(n+=+o):n+=+o)})),n}getUnreadCount(e){return this.store.get(e).unreadMessageCount||0}clearUnreadCount(e){const t=this.store.get(e),{unreadMessageCount:r,unreadMentionedCount:n}=t;(r||n)&&(t.unreadMessageCount=0,t.hasMentioned=!1,t.unreadMentionedCount=0),this.store.set(e,t);const o={};r&&(o.unreadMessageCount={val:0,time:io()}),n&&(o.hasMentioned={val:!1,time:io()},o.unreadMentionedCount={val:0,time:io()}),Object.keys(o).length&&this.setUpdatedConversation({conversation:e,updatedItems:o})}clearAllUnreadCount(){this.store.getAll().forEach((e=>this.clearUnreadCount(e)))}getNotificationLevel(e){return this.store.get(e).notificationLevel}getNotificationStatus(e){return this.store.get(e).notificationStatus||2}setDraft(e,t){this.draftMap.set(this.getConversationKey(e),t)}getDraft(e){return this.draftMap.get(this.getConversationKey(e))??""}clearDraft(e){this.draftMap.delete(this.getConversationKey(e))}getBlockConversationList(){return this.store.getAll().filter((e=>e.notificationStatus===i.OPEN||e.notificationLevel>0)).map((e=>({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId})))}getTopConversationList(){return(this.store.getAll()||{}).filter((e=>e.isTop)).map((e=>({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId})))}getUnreadMentionedCount(e){return this.get(e).unreadMentionedCount||0}getAllUnreadMentionedCount(){const e=this.store.getAll();let t=0;return e.forEach((e=>{let{unreadMentionedCount:r}=e;r=r||0,t+=Number(r)})),t}getAllConversationState(){return this.store.getAll().map((e=>{let{conversationType:t,targetId:r,channelId:n,unreadMessageCount:o,unreadMentionedCount:i,notificationLevel:s,notificationStatus:a,isTop:c}=e;return{conversationType:t,targetId:r,channelId:n,unreadCount:o,unreadMentionedCount:i??0,notificationLevel:s,notificationStatus:a,isTop:c}}))}destroyed(){this.updatedConversationFunc=void 0}}const si={addStatus:function(e,t){},setConversationCacheByMessage:function(e){},get:function(e){return null},getAllUnreadCount:function(e,t){return 0},getUnreadCount:function(e){return 0},clearUnreadCount:function(e){},clearAllUnreadCount(){},getNotificationLevel:function(e){return c.NOT_SET},getNotificationStatus:function(e){return i.CLOSE},setDraft:function(e,t){},getDraft:function(e){return""},clearDraft:function(e){},getBlockConversationList:function(){return[]},getTopConversationList:function(){return[]},getUnreadMentionedCount:function(e){return 0},getAllUnreadMentionedCount:function(){return 0},getAllConversationState:function(){return[]},addLocalConversation:function(e){},loadConvsationsIfNotExist:function(e){},destroyed(){},syncConversationStatus:function(){}};let ai;var ci={create(e,t,r){ai=new ii(e,t,r)},get:()=>ai??si};class li{constructor(e,t){d(this,"watcher",void 0),d(this,"pullingMsg",!1),d(this,"letterbox",void 0),d(this,"serverMsgSeqno",rn.ZERO),d(this,"pullOfflineFinished",!1),d(this,"intervalTimer",void 0),d(this,"retryTimer",void 0),d(this,"latestSyncTimestamp",0),d(this,"started",!1),this.watcher=e,this.letterbox=new Wo(t.appkey,Dn.uid)}start(){this.started=!0,this.pullOfflineFinished=!1,this.startPullInterval()}stop(){this.started=!1,this.stopPullInterval(),this.cancelRetryTask()}syncMsg(e){this.serverMsgSeqno=e,this.pullMsg()}startPullInterval(){this.stopPullInterval();this.intervalTimer=setInterval((()=>{Date.now()-this.latestSyncTimestamp>=18e4&&this.pullMsg()}),3e4),this.latestSyncTimestamp=Date.now(),this.pullMsg()}stopPullInterval(){this.intervalTimer&&(clearInterval(this.intervalTimer),this.intervalTimer=null)}try2RePullMsg(){this.retryTimer=setTimeout((()=>{this.retryTimer=null,this.pullMsg()}),1e3)}cancelRetryTask(){this.retryTimer&&(clearTimeout(this.retryTimer),this.retryTimer=null)}async pullMsg(){if(this.pullingMsg)return;if(!this.started)return;this.cancelRetryTask(),this.pullingMsg=!0;const e=this.letterbox.getInboxOffset();this.pullOfflineFinished||mt.info(`pullMsg -> time: ${e}`),this.latestSyncTimestamp=Date.now();const{code:r,data:n}=await((e,t)=>xn.send(At.GetNewMessage,{offset:e,rows:t},{encoder:Wn.GetNewMessageReq,decoder:jn.GetNewMessageResp}))(e,60);if(r!==t.SUCCESS)return this.pullOfflineFinished||mt.warn("pullMsg failed -> code:",r),this.pullingMsg=!1,void this.try2RePullMsg();const{offset:o,seqno:i,msg:a}=n,c=Object.keys(a).map(Gn).filter((e=>Ze(e)));ci.get().loadConvsationsIfNotExist(c),Qo.parse(a,((e,t)=>{const r=[],n=[],a=!this.pullOfflineFinished;var c,l;(Object.keys(t).forEach((e=>{const o=t[e],i=[];if(o.forEach((e=>{e.messageDirection===s.SEND&&e.messageId&&ao.has(e.messageId)?ao.remove(e.messageId):e.messageType===Ao&&lo.has(e.content.messageUId)?lo.remove(e.content.messageUId):(e.isOffLineMessage=a,ci.get().setConversationCacheByMessage(e),i.push(e))})),r.push(...i),this.isExistPersistedMessage(i)){const t=Gn(e);t&&n.push(t)}})),r.length)&&(null===(c=(l=this.watcher).batchMessage)||void 0===c||c.call(l,r));if(n.length&&ci.get().loadConvsationsIfNotExist(n),e){var u;i.ge(this.serverMsgSeqno)&&(this.serverMsgSeqno=i);const e=this.serverMsgSeqno.lessThanOrEqual(o);this.pullOfflineFinished||mt.info(`pullMsg success -> syncTime: ${o}, finished: ${e}`),null===(u=this.letterbox)||void 0===u||u.setInboxOffset(o),this.pullingMsg=!1,e&&!this.pullOfflineFinished&&(this.pullOfflineFinished=!0,this.watcher.pullFinished&&this.watcher.pullFinished()),e||this.pullMsg()}}))}isExistPersistedMessage(e){return e.some((e=>e.isPersited))}}class ui{static init(e){return this._loader||(this._loader=new ui(e)),this._loader}static get loader(){return this._loader}constructor(t){d(this,"options",void 0),d(this,"connectionStatus",e.DISCONNECTED),d(this,"isInternalConnected",!1),d(this,"watcher",void 0),d(this,"messageLoader",void 0),this.options=t,this.watcher={onConnecting:void 0,onConnected:void 0,onDisconnect:void 0,onSuspend:void 0,pullFinished:void 0,batchMessage:void 0,conversationState:void 0},xn.setServerInfo(this.getWebSocketUrl()),xn.setCallback({status:this.connectionStatusListener.bind(this),message:this.messageListener.bind(this),onAuth:this.authListener.bind(this)},{needReAuth:this.needReAuthProvider.bind(this),profile:this.needProfileProvider.bind(this)}),this.registerMessage()}getWebSocketUrl(){var e;const t=null===(e=this.options)||void 0===e?void 0:e.serverInfo;return ot(t)?nt(r=t)&&/wss?:\/\//.test(r)?t:"ws://"+t:"wss://tt.mimelabs.xyz:8991";var r}registerMessage(){ho(xo),ho(Do),ho(Mo),ho(Lo),ho(Fo),ho(qo),ho(Go),ho(Ho),ho(Uo),ho(jo),ho(Bo)}async connect(r){if(this.connectionStatus===e.CONNECTED)return{code:t.SUCCESS,userId:Dn.uid+""};if(this.connectionStatus===e.CONNECTING)return{code:t.BIZ_ERROR_CONNECTING};if("string"!=typeof r||0===r.length)return{code:t.RC_CONN_USER_OR_PASSWD_ERROR};Pn.imInitToken=r;const n=await xn.connect(r);var o;n===t.SUCCESS&&(this.isInternalConnected=!0,ci.get().destroyed(),ci.create(this.options.appkey,Dn.uid,this.watcher.conversationState),null===(o=this.messageLoader)||void 0===o||o.stop(),this.messageLoader=new li(this.watcher,this.options),oo(),ao.reset(),lo.reset(),zo.reset());return{code:n,userId:Dn.uid+""}}reconnect(){return this.isInternalConnected?Promise.resolve({code:t.CAN_NOT_RECONNECT}):this.connect(Pn.imInitToken)}disconnect(){return this.isInternalConnected=!1,xn.close(),Promise.resolve()}getConnectionStatus(){return this.connectionStatus}assignWatcher(e){at(this.watcher).forEach((t=>{if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this.watcher[t]=et(r)?r:void 0}}))}resetWatcher(){at(this.watcher).forEach((e=>{this.watcher[e]=void 0}))}async connectionStatusListener(t){this.connectionStatus=t,setTimeout((()=>{switch(t){case e.BLOCKED:case e.KICKED_OFFLINE_BY_OTHER_CLIENT:case e.DISCONNECT_BY_SERVER:this.handleDisconnect();break;case e.CONNECTING:this.handleConnecting();break;case e.CONNECTED:this.handleConnected();break;case e.DISCONNECTED:this.handleDisconnect()}}),0)}handleConnecting(){var e,t;null===(e=(t=this.watcher).onConnecting)||void 0===e||e.call(t)}handleConnected(){var t,r,n;null===(t=(r=this.watcher).onConnected)||void 0===t||t.call(r),null===(n=this.messageLoader)||void 0===n||n.start(),setTimeout((()=>{this.connectionStatus===e.CONNECTED&&ci.get().syncConversationStatus()}),2e3)}handleDisconnect(){var e,t,r;null===(e=(t=this.watcher).onDisconnect)||void 0===e||e.call(t),null===(r=this.messageLoader)||void 0===r||r.stop()}handleSuspend(){var e,t;null===(e=(t=this.watcher).onSuspend)||void 0===e||e.call(t)}messageListener(e,t){if(e===At.NewMessagePush){var r;const e=jn.NewMessageNotificationResp.decode(t);null===(r=this.messageLoader)||void 0===r||r.syncMsg(e.seqno)}else e===At.DialogChangedPush&&ci.get().syncConversationStatus()}authListener(e){Pn.setFileServerInfo(e.fileDomain,e.dialogFileDomain,e.cert),Dn.setLogged(e,Pn.imInitToken)}needReAuthProvider(){return!Dn.user.active||Dn.user.token!==Pn.imInitToken}needProfileProvider(){if(!this.needReAuthProvider()){const{deviceId:e,sessionId:t,uid:r}=Dn.user;return{deviceId:e,sessionId:t,uid:r}}return null}}d(ui,"_loader",void 0);var di,hi,fi,pi,gi={exports:{}},yi={exports:{}},vi={exports:{}},mi={exports:{}};var bi,wi={};var Oi,Ci,_i,Si,Ii,Ei,Ti,Ri,ki,Ai,Ni,xi,Di,Mi={};function Li(){return Oi||(Oi=1,function(e){var t=Mi,r=ps(),n=["double","float","int32","uint32","sint32","fixed32","sfixed32","int64","uint64","sint64","fixed64","sfixed64","bool","string","bytes"];function o(e,t){var r=0,o={};for(t|=0;r<e.length;)o[n[r+t]]=e[r++];return o}t.basic=o([1,5,0,0,0,5,5,0,0,0,1,1,0,2,2]),t.defaults=o([0,0,0,0,0,0,0,0,0,0,0,0,!1,"",r.emptyArray,null]),t.long=o([0,0,0,1,1],7),t.mapKey=o([0,0,0,5,5,0,0,0,1,1,0,2],2),t.packed=o([1,5,0,0,0,5,5,0,0,0,1,1,0])}()),Mi}function Bi(){if(_i)return Ci;_i=1,Ci=s;var e=gs();((s.prototype=Object.create(e.prototype)).constructor=s).className="Field";var t,r=ys(),n=Li(),o=ps(),i=/^required|optional|repeated$/;function s(t,r,s,a,c,l,u){if(o.isObject(a)?(u=c,l=a,a=c=void 0):o.isObject(c)&&(u=l,l=c,c=void 0),e.call(this,t,l),!o.isInteger(r)||r<0)throw TypeError("id must be a non-negative integer");if(!o.isString(s))throw TypeError("type must be a string");if(void 0!==a&&!i.test(a=a.toString().toLowerCase()))throw TypeError("rule must be a string rule");if(void 0!==c&&!o.isString(c))throw TypeError("extend must be a string");"proto3_optional"===a&&(a="optional"),this.rule=a&&"optional"!==a?a:void 0,this.type=s,this.id=r,this.extend=c||void 0,this.required="required"===a,this.optional=!this.required,this.repeated="repeated"===a,this.map=!1,this.message=null,this.partOf=null,this.typeDefault=null,this.defaultValue=null,this.long=!!o.Long&&void 0!==n.long[s],this.bytes="bytes"===s,this.resolvedType=null,this.extensionField=null,this.declaringField=null,this._packed=null,this.comment=u}return s.fromJSON=function(e,t){return new s(e,t.id,t.type,t.rule,t.extend,t.options,t.comment)},Object.defineProperty(s.prototype,"packed",{get:function(){return null===this._packed&&(this._packed=!1!==this.getOption("packed")),this._packed}}),s.prototype.setOption=function(t,r,n){return"packed"===t&&(this._packed=null),e.prototype.setOption.call(this,t,r,n)},s.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return o.toObject(["rule","optional"!==this.rule&&this.rule||void 0,"type",this.type,"id",this.id,"extend",this.extend,"options",this.options,"comment",t?this.comment:void 0])},s.prototype.resolve=function(){if(this.resolved)return this;if(void 0===(this.typeDefault=n.defaults[this.type])?(this.resolvedType=(this.declaringField?this.declaringField.parent:this.parent).lookupTypeOrEnum(this.type),this.resolvedType instanceof t?this.typeDefault=null:this.typeDefault=this.resolvedType.values[Object.keys(this.resolvedType.values)[0]]):this.options&&this.options.proto3_optional&&(this.typeDefault=null),this.options&&null!=this.options.default&&(this.typeDefault=this.options.default,this.resolvedType instanceof r&&"string"==typeof this.typeDefault&&(this.typeDefault=this.resolvedType.values[this.typeDefault])),this.options&&(!0!==this.options.packed&&(void 0===this.options.packed||!this.resolvedType||this.resolvedType instanceof r)||delete this.options.packed,Object.keys(this.options).length||(this.options=void 0)),this.long)this.typeDefault=o.Long.fromNumber(this.typeDefault,"u"===this.type.charAt(0)),Object.freeze&&Object.freeze(this.typeDefault);else if(this.bytes&&"string"==typeof this.typeDefault){var i;o.base64.test(this.typeDefault)?o.base64.decode(this.typeDefault,i=o.newBuffer(o.base64.length(this.typeDefault)),0):o.utf8.write(this.typeDefault,i=o.newBuffer(o.utf8.length(this.typeDefault)),0),this.typeDefault=i}return this.map?this.defaultValue=o.emptyObject:this.repeated?this.defaultValue=o.emptyArray:this.defaultValue=this.typeDefault,this.parent instanceof t&&(this.parent.ctor.prototype[this.name]=this.defaultValue),e.prototype.resolve.call(this)},s.d=function(e,t,r,n){return"function"==typeof t?t=o.decorateType(t).name:t&&"object"==typeof t&&(t=o.decorateEnum(t).name),function(i,a){o.decorateType(i.constructor).add(new s(a,e,t,r,{default:n}))}},s._configure=function(e){t=e},Ci}function Ui(){if(Ii)return Si;Ii=1,Si=n;var e=gs();((n.prototype=Object.create(e.prototype)).constructor=n).className="OneOf";var t=Bi(),r=ps();function n(t,r,n,o){if(Array.isArray(r)||(n=r,r=void 0),e.call(this,t,n),void 0!==r&&!Array.isArray(r))throw TypeError("fieldNames must be an Array");this.oneof=r||[],this.fieldsArray=[],this.comment=o}function o(e){if(e.parent)for(var t=0;t<e.fieldsArray.length;++t)e.fieldsArray[t].parent||e.parent.add(e.fieldsArray[t])}return n.fromJSON=function(e,t){return new n(e,t.oneof,t.options,t.comment)},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return r.toObject(["options",this.options,"oneof",this.oneof,"comment",t?this.comment:void 0])},n.prototype.add=function(e){if(!(e instanceof t))throw TypeError("field must be a Field");return e.parent&&e.parent!==this.parent&&e.parent.remove(e),this.oneof.push(e.name),this.fieldsArray.push(e),e.partOf=this,o(this),this},n.prototype.remove=function(e){if(!(e instanceof t))throw TypeError("field must be a Field");var r=this.fieldsArray.indexOf(e);if(r<0)throw Error(e+" is not a member of "+this);return this.fieldsArray.splice(r,1),(r=this.oneof.indexOf(e.name))>-1&&this.oneof.splice(r,1),e.partOf=null,this},n.prototype.onAdd=function(t){e.prototype.onAdd.call(this,t);for(var r=0;r<this.oneof.length;++r){var n=t.get(this.oneof[r]);n&&!n.partOf&&(n.partOf=this,this.fieldsArray.push(n))}o(this)},n.prototype.onRemove=function(t){for(var r,n=0;n<this.fieldsArray.length;++n)(r=this.fieldsArray[n]).parent&&r.parent.remove(r);e.prototype.onRemove.call(this,t)},n.d=function(){for(var e=new Array(arguments.length),t=0;t<arguments.length;)e[t]=arguments[t++];return function(t,o){r.decorateType(t.constructor).add(new n(o,e)),Object.defineProperty(t,o,{get:r.oneOfGetter(e),set:r.oneOfSetter(e)})}},Si}function ji(){if(Ti)return Ei;Ti=1,Ei=c;var e=gs();((c.prototype=Object.create(e.prototype)).constructor=c).className="Namespace";var t,r,n,o=Bi(),i=ps(),s=Ui();function a(e,t){if(e&&e.length){for(var r={},n=0;n<e.length;++n)r[e[n].name]=e[n].toJSON(t);return r}}function c(t,r){e.call(this,t,r),this.nested=void 0,this._nestedArray=null}function l(e){return e._nestedArray=null,e}return c.fromJSON=function(e,t){return new c(e,t.options).addJSON(t.nested)},c.arrayToJSON=a,c.isReservedId=function(e,t){if(e)for(var r=0;r<e.length;++r)if("string"!=typeof e[r]&&e[r][0]<=t&&e[r][1]>t)return!0;return!1},c.isReservedName=function(e,t){if(e)for(var r=0;r<e.length;++r)if(e[r]===t)return!0;return!1},Object.defineProperty(c.prototype,"nestedArray",{get:function(){return this._nestedArray||(this._nestedArray=i.toArray(this.nested))}}),c.prototype.toJSON=function(e){return i.toObject(["options",this.options,"nested",a(this.nestedArray,e)])},c.prototype.addJSON=function(e){if(e)for(var i,s=Object.keys(e),a=0;a<s.length;++a)i=e[s[a]],this.add((void 0!==i.fields?t.fromJSON:void 0!==i.values?n.fromJSON:void 0!==i.methods?r.fromJSON:void 0!==i.id?o.fromJSON:c.fromJSON)(s[a],i));return this},c.prototype.get=function(e){return this.nested&&this.nested[e]||null},c.prototype.getEnum=function(e){if(this.nested&&this.nested[e]instanceof n)return this.nested[e].values;throw Error("no such enum: "+e)},c.prototype.add=function(e){if(!(e instanceof o&&void 0!==e.extend||e instanceof t||e instanceof s||e instanceof n||e instanceof r||e instanceof c))throw TypeError("object must be a valid nested object");if(this.nested){var i=this.get(e.name);if(i){if(!(i instanceof c&&e instanceof c)||i instanceof t||i instanceof r)throw Error("duplicate name '"+e.name+"' in "+this);for(var a=i.nestedArray,u=0;u<a.length;++u)e.add(a[u]);this.remove(i),this.nested||(this.nested={}),e.setOptions(i.options,!0)}}else this.nested={};return this.nested[e.name]=e,e.onAdd(this),l(this)},c.prototype.remove=function(t){if(!(t instanceof e))throw TypeError("object must be a ReflectionObject");if(t.parent!==this)throw Error(t+" is not a member of "+this);return delete this.nested[t.name],Object.keys(this.nested).length||(this.nested=void 0),t.onRemove(this),l(this)},c.prototype.define=function(e,t){if(i.isString(e))e=e.split(".");else if(!Array.isArray(e))throw TypeError("illegal path");if(e&&e.length&&""===e[0])throw Error("path must be relative");for(var r=this;e.length>0;){var n=e.shift();if(r.nested&&r.nested[n]){if(!((r=r.nested[n])instanceof c))throw Error("path conflicts with non-namespace objects")}else r.add(r=new c(n))}return t&&r.addJSON(t),r},c.prototype.resolveAll=function(){for(var e=this.nestedArray,t=0;t<e.length;)e[t]instanceof c?e[t++].resolveAll():e[t++].resolve();return this.resolve()},c.prototype.lookup=function(e,t,r){if("boolean"==typeof t?(r=t,t=void 0):t&&!Array.isArray(t)&&(t=[t]),i.isString(e)&&e.length){if("."===e)return this.root;e=e.split(".")}else if(!e.length)return this;if(""===e[0])return this.root.lookup(e.slice(1),t);var n=this.get(e[0]);if(n){if(1===e.length){if(!t||t.indexOf(n.constructor)>-1)return n}else if(n instanceof c&&(n=n.lookup(e.slice(1),t,!0)))return n}else for(var o=0;o<this.nestedArray.length;++o)if(this._nestedArray[o]instanceof c&&(n=this._nestedArray[o].lookup(e,t,!0)))return n;return null===this.parent||r?null:this.parent.lookup(e,t)},c.prototype.lookupType=function(e){var r=this.lookup(e,[t]);if(!r)throw Error("no such type: "+e);return r},c.prototype.lookupEnum=function(e){var t=this.lookup(e,[n]);if(!t)throw Error("no such Enum '"+e+"' in "+this);return t},c.prototype.lookupTypeOrEnum=function(e){var r=this.lookup(e,[t,n]);if(!r)throw Error("no such Type or Enum '"+e+"' in "+this);return r},c.prototype.lookupService=function(e){var t=this.lookup(e,[r]);if(!t)throw Error("no such Service '"+e+"' in "+this);return t},c._configure=function(e,o,i){t=e,r=o,n=i},Ei}function Pi(){if(ki)return Ri;ki=1,Ri=n;var e=Bi();((n.prototype=Object.create(e.prototype)).constructor=n).className="MapField";var t=Li(),r=ps();function n(t,n,o,i,s,a){if(e.call(this,t,n,i,void 0,void 0,s,a),!r.isString(o))throw TypeError("keyType must be a string");this.keyType=o,this.resolvedKeyType=null,this.map=!0}return n.fromJSON=function(e,t){return new n(e,t.id,t.keyType,t.type,t.options,t.comment)},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return r.toObject(["keyType",this.keyType,"type",this.type,"id",this.id,"extend",this.extend,"options",this.options,"comment",t?this.comment:void 0])},n.prototype.resolve=function(){if(this.resolved)return this;if(void 0===t.mapKey[this.keyType])throw Error("invalid key type: "+this.keyType);return e.prototype.resolve.call(this)},n.d=function(e,t,o){return"function"==typeof o?o=r.decorateType(o).name:o&&"object"==typeof o&&(o=r.decorateEnum(o).name),function(i,s){r.decorateType(i.constructor).add(new n(s,e,t,o))}},Ri}function Fi(){if(Ni)return Ai;Ni=1,Ai=r;var e=gs();((r.prototype=Object.create(e.prototype)).constructor=r).className="Method";var t=ps();function r(r,n,o,i,s,a,c,l,u){if(t.isObject(s)?(c=s,s=a=void 0):t.isObject(a)&&(c=a,a=void 0),void 0!==n&&!t.isString(n))throw TypeError("type must be a string");if(!t.isString(o))throw TypeError("requestType must be a string");if(!t.isString(i))throw TypeError("responseType must be a string");e.call(this,r,c),this.type=n||"rpc",this.requestType=o,this.requestStream=!!s||void 0,this.responseType=i,this.responseStream=!!a||void 0,this.resolvedRequestType=null,this.resolvedResponseType=null,this.comment=l,this.parsedOptions=u}return r.fromJSON=function(e,t){return new r(e,t.type,t.requestType,t.responseType,t.requestStream,t.responseStream,t.options,t.comment,t.parsedOptions)},r.prototype.toJSON=function(e){var r=!!e&&Boolean(e.keepComments);return t.toObject(["type","rpc"!==this.type&&this.type||void 0,"requestType",this.requestType,"requestStream",this.requestStream,"responseType",this.responseType,"responseStream",this.responseStream,"options",this.options,"comment",r?this.comment:void 0,"parsedOptions",this.parsedOptions])},r.prototype.resolve=function(){return this.resolved?this:(this.resolvedRequestType=this.parent.lookupType(this.requestType),this.resolvedResponseType=this.parent.lookupType(this.responseType),e.prototype.resolve.call(this))},Ai}function Gi(){if(Di)return xi;Di=1,xi=o;var e=ji();((o.prototype=Object.create(e.prototype)).constructor=o).className="Service";var t=Fi(),r=ps(),n=Br;function o(t,r){e.call(this,t,r),this.methods={},this._methodsArray=null}function i(e){return e._methodsArray=null,e}return o.fromJSON=function(e,r){var n=new o(e,r.options);if(r.methods)for(var i=Object.keys(r.methods),s=0;s<i.length;++s)n.add(t.fromJSON(i[s],r.methods[i[s]]));return r.nested&&n.addJSON(r.nested),n.comment=r.comment,n},o.prototype.toJSON=function(t){var n=e.prototype.toJSON.call(this,t),o=!!t&&Boolean(t.keepComments);return r.toObject(["options",n&&n.options||void 0,"methods",e.arrayToJSON(this.methodsArray,t)||{},"nested",n&&n.nested||void 0,"comment",o?this.comment:void 0])},Object.defineProperty(o.prototype,"methodsArray",{get:function(){return this._methodsArray||(this._methodsArray=r.toArray(this.methods))}}),o.prototype.get=function(t){return this.methods[t]||e.prototype.get.call(this,t)},o.prototype.resolveAll=function(){for(var t=this.methodsArray,r=0;r<t.length;++r)t[r].resolve();return e.prototype.resolve.call(this)},o.prototype.add=function(r){if(this.get(r.name))throw Error("duplicate name '"+r.name+"' in "+this);return r instanceof t?(this.methods[r.name]=r,r.parent=this,i(this)):e.prototype.add.call(this,r)},o.prototype.remove=function(r){if(r instanceof t){if(this.methods[r.name]!==r)throw Error(r+" is not a member of "+this);return delete this.methods[r.name],r.parent=null,i(this)}return e.prototype.remove.call(this,r)},o.prototype.create=function(e,t,o){for(var i,s=new n.Service(e,t,o),a=0;a<this.methodsArray.length;++a){var c=r.lcFirst((i=this._methodsArray[a]).resolve().name).replace(/[^$\w_]/g,"");s[c]=r.codegen(["r","c"],r.isReserved(c)?c+"_":c)("return this.rpcCall(m,q,s,r,c)")({m:i,q:i.resolvedRequestType.ctor,s:i.resolvedResponseType.ctor})}return s},xi}var qi,Hi,zi,Ki,Vi=$i,Wi=Zt();function $i(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)this[t[r]]=e[t[r]]}function Ji(){if(Hi)return qi;Hi=1,qi=function(o){var i=r.codegen(["r","l"],o.name+"$decode")("if(!(r instanceof Reader))")("r=Reader.create(r)")("var c=l===undefined?r.len:r.pos+l,m=new this.ctor"+(o.fieldsArray.filter((function(e){return e.map})).length?",k,value":""))("while(r.pos<c){")("var t=r.uint32()");o.group&&i("if((t&7)===4)")("break");i("switch(t>>>3){");for(var s=0;s<o.fieldsArray.length;++s){var a=o._fieldsArray[s].resolve(),c=a.resolvedType instanceof e?"int32":a.type,l="m"+r.safeProp(a.name);i("case %i: {",a.id),a.map?(i("if(%s===util.emptyObject)",l)("%s={}",l)("var c2 = r.uint32()+r.pos"),void 0!==t.defaults[a.keyType]?i("k=%j",t.defaults[a.keyType]):i("k=null"),void 0!==t.defaults[c]?i("value=%j",t.defaults[c]):i("value=null"),i("while(r.pos<c2){")("var tag2=r.uint32()")("switch(tag2>>>3){")("case 1: k=r.%s(); break",a.keyType)("case 2:"),void 0===t.basic[c]?i("value=types[%i].decode(r,r.uint32())",s):i("value=r.%s()",c),i("break")("default:")("r.skipType(tag2&7)")("break")("}")("}"),void 0!==t.long[a.keyType]?i('%s[typeof k==="object"?util.longToHash(k):k]=value',l):i("%s[k]=value",l)):a.repeated?(i("if(!(%s&&%s.length))",l,l)("%s=[]",l),void 0!==t.packed[c]&&i("if((t&7)===2){")("var c2=r.uint32()+r.pos")("while(r.pos<c2)")("%s.push(r.%s())",l,c)("}else"),void 0===t.basic[c]?i(a.resolvedType.group?"%s.push(types[%i].decode(r))":"%s.push(types[%i].decode(r,r.uint32()))",l,s):i("%s.push(r.%s())",l,c)):void 0===t.basic[c]?i(a.resolvedType.group?"%s=types[%i].decode(r)":"%s=types[%i].decode(r,r.uint32())",l,s):i("%s=r.%s()",l,c),i("break")("}")}for(i("default:")("r.skipType(t&7)")("break")("}")("}"),s=0;s<o._fieldsArray.length;++s){var u=o._fieldsArray[s];u.required&&i("if(!m.hasOwnProperty(%j))",u.name)("throw util.ProtocolError(%j,{instance:m})",n(u))}return i("return m")};var e=ys(),t=Li(),r=ps();function n(e){return"missing required '"+e.name+"'"}return qi}function Zi(){if(Ki)return zi;Ki=1,zi=function(e){var i=t.codegen(["m"],e.name+"$verify")('if(typeof m!=="object"||m===null)')("return%j","object expected"),s=e.oneofsArray,a={};s.length&&i("var p={}");for(var c=0;c<e.fieldsArray.length;++c){var l=e._fieldsArray[c].resolve(),u="m"+t.safeProp(l.name);if(l.optional&&i("if(%s!=null&&m.hasOwnProperty(%j)){",u,l.name),l.map)i("if(!util.isObject(%s))",u)("return%j",r(l,"object"))("var k=Object.keys(%s)",u)("for(var i=0;i<k.length;++i){"),o(i,l,"k[i]"),n(i,l,c,u+"[k[i]]")("}");else if(l.repeated)i("if(!Array.isArray(%s))",u)("return%j",r(l,"array"))("for(var i=0;i<%s.length;++i){",u),n(i,l,c,u+"[i]")("}");else{if(l.partOf){var d=t.safeProp(l.partOf.name);1===a[l.partOf.name]&&i("if(p%s===1)",d)("return%j",l.partOf.name+": multiple values"),a[l.partOf.name]=1,i("p%s=1",d)}n(i,l,c,u)}l.optional&&i("}")}return i("return null")};var e=ys(),t=ps();function r(e,t){return e.name+": "+t+(e.repeated&&"array"!==t?"[]":e.map&&"object"!==t?"{k:"+e.keyType+"}":"")+" expected"}function n(t,n,o,i){if(n.resolvedType)if(n.resolvedType instanceof e){t("switch(%s){",i)("default:")("return%j",r(n,"enum value"));for(var s=Object.keys(n.resolvedType.values),a=0;a<s.length;++a)t("case %i:",n.resolvedType.values[s[a]]);t("break")("}")}else t("{")("var e=types[%i].verify(%s);",o,i)("if(e)")("return%j+e",n.name+".")("}");else switch(n.type){case"int32":case"uint32":case"sint32":case"fixed32":case"sfixed32":t("if(!util.isInteger(%s))",i)("return%j",r(n,"integer"));break;case"int64":case"uint64":case"sint64":case"fixed64":case"sfixed64":t("if(!util.isInteger(%s)&&!(%s&&util.isInteger(%s.low)&&util.isInteger(%s.high)))",i,i,i,i)("return%j",r(n,"integer|Long"));break;case"float":case"double":t('if(typeof %s!=="number")',i)("return%j",r(n,"number"));break;case"bool":t('if(typeof %s!=="boolean")',i)("return%j",r(n,"boolean"));break;case"string":t("if(!util.isString(%s))",i)("return%j",r(n,"string"));break;case"bytes":t('if(!(%s&&typeof %s.length==="number"||util.isString(%s)))',i,i,i)("return%j",r(n,"buffer"))}return t}function o(e,t,n){switch(t.keyType){case"int32":case"uint32":case"sint32":case"fixed32":case"sfixed32":e("if(!util.key32Re.test(%s))",n)("return%j",r(t,"integer key"));break;case"int64":case"uint64":case"sint64":case"fixed64":case"sfixed64":e("if(!util.key64Re.test(%s))",n)("return%j",r(t,"integer|Long key"));break;case"bool":e("if(!util.key2Re.test(%s))",n)("return%j",r(t,"boolean key"))}return e}return zi}$i.create=function(e){return this.$type.create(e)},$i.encode=function(e,t){return this.$type.encode(e,t)},$i.encodeDelimited=function(e,t){return this.$type.encodeDelimited(e,t)},$i.decode=function(e){return this.$type.decode(e)},$i.decodeDelimited=function(e){return this.$type.decodeDelimited(e)},$i.verify=function(e){return this.$type.verify(e)},$i.fromObject=function(e){return this.$type.fromObject(e)},$i.toObject=function(e,t){return this.$type.toObject(e,t)},$i.prototype.toJSON=function(){return this.$type.toObject(this,Wi.toJSONOptions)};var Xi,Yi={};function Qi(){return Xi||(Xi=1,function(e){var t=e,r=ys(),n=ps();function o(e,t,n,o){var i=!1;if(t.resolvedType)if(t.resolvedType instanceof r){e("switch(d%s){",o);for(var s=t.resolvedType.values,a=Object.keys(s),c=0;c<a.length;++c)s[a[c]]!==t.typeDefault||i||(e("default:")('if(typeof(d%s)==="number"){m%s=d%s;break}',o,o,o),t.repeated||e("break"),i=!0),e("case%j:",a[c])("case %i:",s[a[c]])("m%s=%j",o,s[a[c]])("break");e("}")}else e('if(typeof d%s!=="object")',o)("throw TypeError(%j)",t.fullName+": object expected")("m%s=types[%i].fromObject(d%s)",o,n,o);else{var l=!1;switch(t.type){case"double":case"float":e("m%s=Number(d%s)",o,o);break;case"uint32":case"fixed32":e("m%s=d%s>>>0",o,o);break;case"int32":case"sint32":case"sfixed32":e("m%s=d%s|0",o,o);break;case"uint64":l=!0;case"int64":case"sint64":case"fixed64":case"sfixed64":e("if(util.Long)")("(m%s=util.Long.fromValue(d%s)).unsigned=%j",o,o,l)('else if(typeof d%s==="string")',o)("m%s=parseInt(d%s,10)",o,o)('else if(typeof d%s==="number")',o)("m%s=d%s",o,o)('else if(typeof d%s==="object")',o)("m%s=new util.LongBits(d%s.low>>>0,d%s.high>>>0).toNumber(%s)",o,o,o,l?"true":"");break;case"bytes":e('if(typeof d%s==="string")',o)("util.base64.decode(d%s,m%s=util.newBuffer(util.base64.length(d%s)),0)",o,o,o)("else if(d%s.length >= 0)",o)("m%s=d%s",o,o);break;case"string":e("m%s=String(d%s)",o,o);break;case"bool":e("m%s=Boolean(d%s)",o,o)}}return e}function i(e,t,n,o){if(t.resolvedType)t.resolvedType instanceof r?e("d%s=o.enums===String?(types[%i].values[m%s]===undefined?m%s:types[%i].values[m%s]):m%s",o,n,o,o,n,o,o):e("d%s=types[%i].toObject(m%s,o)",o,n,o);else{var i=!1;switch(t.type){case"double":case"float":e("d%s=o.json&&!isFinite(m%s)?String(m%s):m%s",o,o,o,o);break;case"uint64":i=!0;case"int64":case"sint64":case"fixed64":case"sfixed64":e('if(typeof m%s==="number")',o)("d%s=o.longs===String?String(m%s):m%s",o,o,o)("else")("d%s=o.longs===String?util.Long.prototype.toString.call(m%s):o.longs===Number?new util.LongBits(m%s.low>>>0,m%s.high>>>0).toNumber(%s):m%s",o,o,o,o,i?"true":"",o);break;case"bytes":e("d%s=o.bytes===String?util.base64.encode(m%s,0,m%s.length):o.bytes===Array?Array.prototype.slice.call(m%s):m%s",o,o,o,o,o);break;default:e("d%s=m%s",o,o)}}return e}t.fromObject=function(e){var t=e.fieldsArray,i=n.codegen(["d"],e.name+"$fromObject")("if(d instanceof this.ctor)")("return d");if(!t.length)return i("return new this.ctor");i("var m=new this.ctor");for(var s=0;s<t.length;++s){var a=t[s].resolve(),c=n.safeProp(a.name);a.map?(i("if(d%s){",c)('if(typeof d%s!=="object")',c)("throw TypeError(%j)",a.fullName+": object expected")("m%s={}",c)("for(var ks=Object.keys(d%s),i=0;i<ks.length;++i){",c),o(i,a,s,c+"[ks[i]]")("}")("}")):a.repeated?(i("if(d%s){",c)("if(!Array.isArray(d%s))",c)("throw TypeError(%j)",a.fullName+": array expected")("m%s=[]",c)("for(var i=0;i<d%s.length;++i){",c),o(i,a,s,c+"[i]")("}")("}")):(a.resolvedType instanceof r||i("if(d%s!=null){",c),o(i,a,s,c),a.resolvedType instanceof r||i("}"))}return i("return m")},t.toObject=function(e){var t=e.fieldsArray.slice().sort(n.compareFieldsById);if(!t.length)return n.codegen()("return {}");for(var o=n.codegen(["m","o"],e.name+"$toObject")("if(!o)")("o={}")("var d={}"),s=[],a=[],c=[],l=0;l<t.length;++l)t[l].partOf||(t[l].resolve().repeated?s:t[l].map?a:c).push(t[l]);if(s.length){for(o("if(o.arrays||o.defaults){"),l=0;l<s.length;++l)o("d%s=[]",n.safeProp(s[l].name));o("}")}if(a.length){for(o("if(o.objects||o.defaults){"),l=0;l<a.length;++l)o("d%s={}",n.safeProp(a[l].name));o("}")}if(c.length){for(o("if(o.defaults){"),l=0;l<c.length;++l){var u=c[l],d=n.safeProp(u.name);if(u.resolvedType instanceof r)o("d%s=o.enums===String?%j:%j",d,u.resolvedType.valuesById[u.typeDefault],u.typeDefault);else if(u.long)o("if(util.Long){")("var n=new util.Long(%i,%i,%j)",u.typeDefault.low,u.typeDefault.high,u.typeDefault.unsigned)("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n",d)("}else")("d%s=o.longs===String?%j:%i",d,u.typeDefault.toString(),u.typeDefault.toNumber());else if(u.bytes){var h="["+Array.prototype.slice.call(u.typeDefault).join(",")+"]";o("if(o.bytes===String)d%s=%j",d,String.fromCharCode.apply(String,u.typeDefault))("else{")("d%s=%s",d,h)("if(o.bytes!==Array)d%s=util.newBuffer(d%s)",d,d)("}")}else o("d%s=%j",d,u.typeDefault)}o("}")}var f=!1;for(l=0;l<t.length;++l){u=t[l];var p=e._fieldsArray.indexOf(u);d=n.safeProp(u.name);u.map?(f||(f=!0,o("var ks2")),o("if(m%s&&(ks2=Object.keys(m%s)).length){",d,d)("d%s={}",d)("for(var j=0;j<ks2.length;++j){"),i(o,u,p,d+"[ks2[j]]")("}")):u.repeated?(o("if(m%s&&m%s.length){",d,d)("d%s=[]",d)("for(var j=0;j<m%s.length;++j){",d),i(o,u,p,d+"[j]")("}")):(o("if(m%s!=null&&m.hasOwnProperty(%j)){",d,u.name),i(o,u,p,d),u.partOf&&o("if(o.oneofs)")("d%s=%j",n.safeProp(u.partOf.name),u.name)),o("}")}return o("return d")}}(Yi)),Yi}var es,ts,rs,ns,os,is,ss,as,cs,ls,us,ds={};function hs(){if(ts)return es;ts=1,es=g;var e=ji();((g.prototype=Object.create(e.prototype)).constructor=g).className="Type";var t=ys(),r=Ui(),n=Bi(),o=Pi(),i=Gi(),s=Vi,a=br,c=Yt,l=ps(),u=vs(),d=Ji(),h=Zi(),f=Qi(),p=ds;function g(t,r){e.call(this,t,r),this.fields={},this.oneofs=void 0,this.extensions=void 0,this.reserved=void 0,this.group=void 0,this._fieldsById=null,this._fieldsArray=null,this._oneofsArray=null,this._ctor=null}function y(e){return e._fieldsById=e._fieldsArray=e._oneofsArray=null,delete e.encode,delete e.decode,delete e.verify,e}return Object.defineProperties(g.prototype,{fieldsById:{get:function(){if(this._fieldsById)return this._fieldsById;this._fieldsById={};for(var e=Object.keys(this.fields),t=0;t<e.length;++t){var r=this.fields[e[t]],n=r.id;if(this._fieldsById[n])throw Error("duplicate id "+n+" in "+this);this._fieldsById[n]=r}return this._fieldsById}},fieldsArray:{get:function(){return this._fieldsArray||(this._fieldsArray=l.toArray(this.fields))}},oneofsArray:{get:function(){return this._oneofsArray||(this._oneofsArray=l.toArray(this.oneofs))}},ctor:{get:function(){return this._ctor||(this.ctor=g.generateConstructor(this)())},set:function(e){var t=e.prototype;t instanceof s||((e.prototype=new s).constructor=e,l.merge(e.prototype,t)),e.$type=e.prototype.$type=this,l.merge(e,s,!0),this._ctor=e;for(var r=0;r<this.fieldsArray.length;++r)this._fieldsArray[r].resolve();var n={};for(r=0;r<this.oneofsArray.length;++r)n[this._oneofsArray[r].resolve().name]={get:l.oneOfGetter(this._oneofsArray[r].oneof),set:l.oneOfSetter(this._oneofsArray[r].oneof)};r&&Object.defineProperties(e.prototype,n)}}}),g.generateConstructor=function(e){for(var t,r=l.codegen(["p"],e.name),n=0;n<e.fieldsArray.length;++n)(t=e._fieldsArray[n]).map?r("this%s={}",l.safeProp(t.name)):t.repeated&&r("this%s=[]",l.safeProp(t.name));return r("if(p)for(var ks=Object.keys(p),i=0;i<ks.length;++i)if(p[ks[i]]!=null)")("this[ks[i]]=p[ks[i]]")},g.fromJSON=function(s,a){var c=new g(s,a.options);c.extensions=a.extensions,c.reserved=a.reserved;for(var l=Object.keys(a.fields),u=0;u<l.length;++u)c.add((void 0!==a.fields[l[u]].keyType?o.fromJSON:n.fromJSON)(l[u],a.fields[l[u]]));if(a.oneofs)for(l=Object.keys(a.oneofs),u=0;u<l.length;++u)c.add(r.fromJSON(l[u],a.oneofs[l[u]]));if(a.nested)for(l=Object.keys(a.nested),u=0;u<l.length;++u){var d=a.nested[l[u]];c.add((void 0!==d.id?n.fromJSON:void 0!==d.fields?g.fromJSON:void 0!==d.values?t.fromJSON:void 0!==d.methods?i.fromJSON:e.fromJSON)(l[u],d))}return a.extensions&&a.extensions.length&&(c.extensions=a.extensions),a.reserved&&a.reserved.length&&(c.reserved=a.reserved),a.group&&(c.group=!0),a.comment&&(c.comment=a.comment),c},g.prototype.toJSON=function(t){var r=e.prototype.toJSON.call(this,t),n=!!t&&Boolean(t.keepComments);return l.toObject(["options",r&&r.options||void 0,"oneofs",e.arrayToJSON(this.oneofsArray,t),"fields",e.arrayToJSON(this.fieldsArray.filter((function(e){return!e.declaringField})),t)||{},"extensions",this.extensions&&this.extensions.length?this.extensions:void 0,"reserved",this.reserved&&this.reserved.length?this.reserved:void 0,"group",this.group||void 0,"nested",r&&r.nested||void 0,"comment",n?this.comment:void 0])},g.prototype.resolveAll=function(){for(var t=this.fieldsArray,r=0;r<t.length;)t[r++].resolve();var n=this.oneofsArray;for(r=0;r<n.length;)n[r++].resolve();return e.prototype.resolveAll.call(this)},g.prototype.get=function(e){return this.fields[e]||this.oneofs&&this.oneofs[e]||this.nested&&this.nested[e]||null},g.prototype.add=function(t){if(this.get(t.name))throw Error("duplicate name '"+t.name+"' in "+this);if(t instanceof n&&void 0===t.extend){if(this._fieldsById?this._fieldsById[t.id]:this.fieldsById[t.id])throw Error("duplicate id "+t.id+" in "+this);if(this.isReservedId(t.id))throw Error("id "+t.id+" is reserved in "+this);if(this.isReservedName(t.name))throw Error("name '"+t.name+"' is reserved in "+this);return t.parent&&t.parent.remove(t),this.fields[t.name]=t,t.message=this,t.onAdd(this),y(this)}return t instanceof r?(this.oneofs||(this.oneofs={}),this.oneofs[t.name]=t,t.onAdd(this),y(this)):e.prototype.add.call(this,t)},g.prototype.remove=function(t){if(t instanceof n&&void 0===t.extend){if(!this.fields||this.fields[t.name]!==t)throw Error(t+" is not a member of "+this);return delete this.fields[t.name],t.parent=null,t.onRemove(this),y(this)}if(t instanceof r){if(!this.oneofs||this.oneofs[t.name]!==t)throw Error(t+" is not a member of "+this);return delete this.oneofs[t.name],t.parent=null,t.onRemove(this),y(this)}return e.prototype.remove.call(this,t)},g.prototype.isReservedId=function(t){return e.isReservedId(this.reserved,t)},g.prototype.isReservedName=function(t){return e.isReservedName(this.reserved,t)},g.prototype.create=function(e){return new this.ctor(e)},g.prototype.setup=function(){for(var e=this.fullName,t=[],r=0;r<this.fieldsArray.length;++r)t.push(this._fieldsArray[r].resolve().resolvedType);this.encode=u(this)({Writer:c,types:t,util:l}),this.decode=d(this)({Reader:a,types:t,util:l}),this.verify=h(this)({types:t,util:l}),this.fromObject=f.fromObject(this)({types:t,util:l}),this.toObject=f.toObject(this)({types:t,util:l});var n=p[e];if(n){var o=Object.create(this);o.fromObject=this.fromObject,this.fromObject=n.fromObject.bind(o),o.toObject=this.toObject,this.toObject=n.toObject.bind(o)}return this},g.prototype.encode=function(e,t){return this.setup().encode(e,t)},g.prototype.encodeDelimited=function(e,t){return this.encode(e,t&&t.len?t.fork():t).ldelim()},g.prototype.decode=function(e,t){return this.setup().decode(e,t)},g.prototype.decodeDelimited=function(e){return e instanceof a||(e=a.create(e)),this.decode(e,e.uint32())},g.prototype.verify=function(e){return this.setup().verify(e)},g.prototype.fromObject=function(e){return this.setup().fromObject(e)},g.prototype.toObject=function(e,t){return this.setup().toObject(e,t)},g.d=function(e){return function(t){l.decorateType(t,e)}},es}function fs(){if(ns)return rs;ns=1,rs=c;var e=ji();((c.prototype=Object.create(e.prototype)).constructor=c).className="Root";var t,r,n,o=Bi(),i=ys(),s=Ui(),a=ps();function c(t){e.call(this,"",t),this.deferred=[],this.files=[]}function l(){}c.fromJSON=function(e,t){return t||(t=new c),e.options&&t.setOptions(e.options),t.addJSON(e.nested)},c.prototype.resolvePath=a.path.resolve,c.prototype.fetch=a.fetch,c.prototype.load=function e(t,o,i){"function"==typeof o&&(i=o,o=void 0);var s=this;if(!i)return a.asPromise(e,s,t,o);var c=i===l;function u(e,t){if(i){var r=i;if(i=null,c)throw e;r(e,t)}}function d(e){var t=e.lastIndexOf("google/protobuf/");if(t>-1){var r=e.substring(t);if(r in n)return r}return null}function h(e,t){try{if(a.isString(t)&&"{"===t.charAt(0)&&(t=JSON.parse(t)),a.isString(t)){r.filename=e;var n,i=r(t,s,o),l=0;if(i.imports)for(;l<i.imports.length;++l)(n=d(i.imports[l])||s.resolvePath(e,i.imports[l]))&&f(n);if(i.weakImports)for(l=0;l<i.weakImports.length;++l)(n=d(i.weakImports[l])||s.resolvePath(e,i.weakImports[l]))&&f(n,!0)}else s.setOptions(t.options).addJSON(t.nested)}catch(e){u(e)}c||p||u(null,s)}function f(e,t){if(e=d(e)||e,!(s.files.indexOf(e)>-1))if(s.files.push(e),e in n)c?h(e,n[e]):(++p,setTimeout((function(){--p,h(e,n[e])})));else if(c){var r;try{r=a.fs.readFileSync(e).toString("utf8")}catch(e){return void(t||u(e))}h(e,r)}else++p,s.fetch(e,(function(r,n){--p,i&&(r?t?p||u(null,s):u(r):h(e,n))}))}var p=0;a.isString(t)&&(t=[t]);for(var g,y=0;y<t.length;++y)(g=s.resolvePath("",t[y]))&&f(g);if(c)return s;p||u(null,s)},c.prototype.loadSync=function(e,t){if(!a.isNode)throw Error("not supported");return this.load(e,t,l)},c.prototype.resolveAll=function(){if(this.deferred.length)throw Error("unresolvable extensions: "+this.deferred.map((function(e){return"'extend "+e.extend+"' in "+e.parent.fullName})).join(", "));return e.prototype.resolveAll.call(this)};var u=/^[A-Z]/;function d(e,t){var r=t.parent.lookup(t.extend);if(r){var n=new o(t.fullName,t.id,t.type,t.rule,void 0,t.options);return r.get(n.name)||(n.declaringField=t,t.extensionField=n,r.add(n)),!0}return!1}return c.prototype._handleAdd=function(e){if(e instanceof o)void 0===e.extend||e.extensionField||d(0,e)||this.deferred.push(e);else if(e instanceof i)u.test(e.name)&&(e.parent[e.name]=e.values);else if(!(e instanceof s)){if(e instanceof t)for(var r=0;r<this.deferred.length;)d(0,this.deferred[r])?this.deferred.splice(r,1):++r;for(var n=0;n<e.nestedArray.length;++n)this._handleAdd(e._nestedArray[n]);u.test(e.name)&&(e.parent[e.name]=e)}},c.prototype._handleRemove=function(t){if(t instanceof o){if(void 0!==t.extend)if(t.extensionField)t.extensionField.parent.remove(t.extensionField),t.extensionField=null;else{var r=this.deferred.indexOf(t);r>-1&&this.deferred.splice(r,1)}}else if(t instanceof i)u.test(t.name)&&delete t.parent[t.name];else if(t instanceof e){for(var n=0;n<t.nestedArray.length;++n)this._handleRemove(t._nestedArray[n]);u.test(t.name)&&delete t.parent[t.name]}},c._configure=function(e,o,i){t=e,r=o,n=i},rs}function ps(){return os||(os=1,function(e){var t,r,n=mi.exports=Zt(),o=Fr;n.codegen=function(){if(hi)return di;function e(t,r){"string"==typeof t&&(r=t,t=void 0);var n=[];function o(t){if("string"!=typeof t){var r=i();if(e.verbose&&console.log("codegen: "+r),r="return "+r,t){for(var s=Object.keys(t),a=new Array(s.length+1),c=new Array(s.length),l=0;l<s.length;)a[l]=s[l],c[l]=t[s[l++]];return a[l]=r,Function.apply(null,a).apply(null,c)}return Function(r)()}for(var u=new Array(arguments.length-1),d=0;d<u.length;)u[d]=arguments[++d];if(d=0,t=t.replace(/%([%dfijs])/g,(function(e,t){var r=u[d++];switch(t){case"d":case"f":return String(Number(r));case"i":return String(Math.floor(r));case"j":return JSON.stringify(r);case"s":return String(r)}return"%"})),d!==u.length)throw Error("parameter count mismatch");return n.push(t),o}function i(e){return"function "+(e||r||"")+"("+(t&&t.join(",")||"")+"){\n "+n.join("\n ")+"\n}"}return o.toString=i,o}return hi=1,di=e,e.verbose=!1,di}(),n.fetch=function(){if(pi)return fi;pi=1,fi=r;var e=Mt,t=zt();function r(n,o,i){return"function"==typeof o?(i=o,o={}):o||(o={}),i?!o.xhr&&t&&t.readFile?t.readFile(n,(function(e,t){return e&&"undefined"!=typeof XMLHttpRequest?r.xhr(n,o,i):e?i(e):i(null,o.binary?t:t.toString("utf8"))})):r.xhr(n,o,i):e(r,this,n,o)}return r.xhr=function(e,t,r){var n=new XMLHttpRequest;n.onreadystatechange=function(){if(4===n.readyState){if(0!==n.status&&200!==n.status)return r(Error("status "+n.status));if(t.binary){var e=n.response;if(!e){e=[];for(var o=0;o<n.responseText.length;++o)e.push(255&n.responseText.charCodeAt(o))}return r(null,"undefined"!=typeof Uint8Array?new Uint8Array(e):e)}return r(null,n.responseText)}},t.binary&&("overrideMimeType"in n&&n.overrideMimeType("text/plain; charset=x-user-defined"),n.responseType="arraybuffer"),n.open("GET",e),n.send()},fi}(),n.path=(bi||(bi=1,function(e){var t=e,r=t.isAbsolute=function(e){return/^(?:\/|\w+:)/.test(e)},n=t.normalize=function(e){var t=(e=e.replace(/\\/g,"/").replace(/\/{2,}/g,"/")).split("/"),n=r(e),o="";n&&(o=t.shift()+"/");for(var i=0;i<t.length;)".."===t[i]?i>0&&".."!==t[i-1]?t.splice(--i,2):n?t.splice(i,1):++i:"."===t[i]?t.splice(i,1):++i;return o+t.join("/")};t.resolve=function(e,t,o){return o||(t=n(t)),r(t)?t:(o||(e=n(e)),(e=e.replace(/(?:\/|^)[^/]+$/,"")).length?n(e+"/"+t):t)}}(wi)),wi),n.fs=n.inquire("fs"),n.toArray=function(e){if(e){for(var t=Object.keys(e),r=new Array(t.length),n=0;n<t.length;)r[n]=e[t[n++]];return r}return[]},n.toObject=function(e){for(var t={},r=0;r<e.length;){var n=e[r++],o=e[r++];void 0!==o&&(t[n]=o)}return t};var i=/\\/g,s=/"/g;n.isReserved=function(e){return/^(?:do|if|in|for|let|new|try|var|case|else|enum|eval|false|null|this|true|void|with|break|catch|class|const|super|throw|while|yield|delete|export|import|public|return|static|switch|typeof|default|extends|finally|package|private|continue|debugger|function|arguments|interface|protected|implements|instanceof)$/.test(e)},n.safeProp=function(e){return!/^[$\w_]+$/.test(e)||n.isReserved(e)?'["'+e.replace(i,"\\\\").replace(s,'\\"')+'"]':"."+e},n.ucFirst=function(e){return e.charAt(0).toUpperCase()+e.substring(1)};var a=/_([a-z])/g;n.camelCase=function(e){return e.substring(0,1)+e.substring(1).replace(a,(function(e,t){return t.toUpperCase()}))},n.compareFieldsById=function(e,t){return e.id-t.id},n.decorateType=function(e,r){if(e.$type)return r&&e.$type.name!==r&&(n.decorateRoot.remove(e.$type),e.$type.name=r,n.decorateRoot.add(e.$type)),e.$type;t||(t=hs());var o=new t(r||e.name);return n.decorateRoot.add(o),o.ctor=e,Object.defineProperty(e,"$type",{value:o,enumerable:!1}),Object.defineProperty(e.prototype,"$type",{value:o,enumerable:!1}),o};var c=0;n.decorateEnum=function(e){if(e.$type)return e.$type;r||(r=ys());var t=new r("Enum"+c++,e);return n.decorateRoot.add(t),Object.defineProperty(e,"$type",{value:t,enumerable:!1}),t},n.setProperty=function(e,t,r){if("object"!=typeof e)throw TypeError("dst must be an object");if(!t)throw TypeError("path must be specified");return function e(t,r,n){var o=r.shift();if("__proto__"===o)return t;if(r.length>0)t[o]=e(t[o]||{},r,n);else{var i=t[o];i&&(n=[].concat(i).concat(n)),t[o]=n}return t}(e,t=t.split("."),r)},Object.defineProperty(n,"decorateRoot",{get:function(){return o.decorated||(o.decorated=new(fs()))}})}()),mi.exports}function gs(){if(ss)return is;ss=1,is=r,r.className="ReflectionObject";var e,t=ps();function r(e,r){if(!t.isString(e))throw TypeError("name must be a string");if(r&&!t.isObject(r))throw TypeError("options must be an object");this.options=r,this.parsedOptions=null,this.name=e,this.parent=null,this.resolved=!1,this.comment=null,this.filename=null}return Object.defineProperties(r.prototype,{root:{get:function(){for(var e=this;null!==e.parent;)e=e.parent;return e}},fullName:{get:function(){for(var e=[this.name],t=this.parent;t;)e.unshift(t.name),t=t.parent;return e.join(".")}}}),r.prototype.toJSON=function(){throw Error()},r.prototype.onAdd=function(t){this.parent&&this.parent!==t&&this.parent.remove(this),this.parent=t,this.resolved=!1;var r=t.root;r instanceof e&&r._handleAdd(this)},r.prototype.onRemove=function(t){var r=t.root;r instanceof e&&r._handleRemove(this),this.parent=null,this.resolved=!1},r.prototype.resolve=function(){return this.resolved||this.root instanceof e&&(this.resolved=!0),this},r.prototype.getOption=function(e){if(this.options)return this.options[e]},r.prototype.setOption=function(e,t,r){return r&&this.options&&void 0!==this.options[e]||((this.options||(this.options={}))[e]=t),this},r.prototype.setParsedOption=function(e,r,n){this.parsedOptions||(this.parsedOptions=[]);var o=this.parsedOptions;if(n){var i=o.find((function(t){return Object.prototype.hasOwnProperty.call(t,e)}));if(i){var s=i[e];t.setProperty(s,n,r)}else(i={})[e]=t.setProperty({},n,r),o.push(i)}else{var a={};a[e]=r,o.push(a)}return this},r.prototype.setOptions=function(e,t){if(e)for(var r=Object.keys(e),n=0;n<r.length;++n)this.setOption(r[n],e[r[n]],t);return this},r.prototype.toString=function(){var e=this.constructor.className,t=this.fullName;return t.length?e+" "+t:e},r._configure=function(t){e=t},is}function ys(){if(cs)return as;cs=1,as=n;var e=gs();((n.prototype=Object.create(e.prototype)).constructor=n).className="Enum";var t=ji(),r=ps();function n(t,r,n,o,i,s){if(e.call(this,t,n),r&&"object"!=typeof r)throw TypeError("values must be an object");if(this.valuesById={},this.values=Object.create(this.valuesById),this.comment=o,this.comments=i||{},this.valuesOptions=s,this.reserved=void 0,r)for(var a=Object.keys(r),c=0;c<a.length;++c)"number"==typeof r[a[c]]&&(this.valuesById[this.values[a[c]]=r[a[c]]]=a[c])}return n.fromJSON=function(e,t){var r=new n(e,t.values,t.options,t.comment,t.comments);return r.reserved=t.reserved,r},n.prototype.toJSON=function(e){var t=!!e&&Boolean(e.keepComments);return r.toObject(["options",this.options,"valuesOptions",this.valuesOptions,"values",this.values,"reserved",this.reserved&&this.reserved.length?this.reserved:void 0,"comment",t?this.comment:void 0,"comments",t?this.comments:void 0])},n.prototype.add=function(e,t,n,o){if(!r.isString(e))throw TypeError("name must be a string");if(!r.isInteger(t))throw TypeError("id must be an integer");if(void 0!==this.values[e])throw Error("duplicate name '"+e+"' in "+this);if(this.isReservedId(t))throw Error("id "+t+" is reserved in "+this);if(this.isReservedName(e))throw Error("name '"+e+"' is reserved in "+this);if(void 0!==this.valuesById[t]){if(!this.options||!this.options.allow_alias)throw Error("duplicate id "+t+" in "+this);this.values[e]=t}else this.valuesById[this.values[e]=t]=e;return o&&(void 0===this.valuesOptions&&(this.valuesOptions={}),this.valuesOptions[e]=o||null),this.comments[e]=n||null,this},n.prototype.remove=function(e){if(!r.isString(e))throw TypeError("name must be a string");var t=this.values[e];if(null==t)throw Error("name '"+e+"' does not exist in "+this);return delete this.valuesById[t],delete this.values[e],delete this.comments[e],this.valuesOptions&&delete this.valuesOptions[e],this},n.prototype.isReservedId=function(e){return t.isReservedId(this.reserved,e)},n.prototype.isReservedName=function(e){return t.isReservedName(this.reserved,e)},as}function vs(){if(us)return ls;us=1,ls=function(o){for(var i,s=r.codegen(["m","w"],o.name+"$encode")("if(!w)")("w=Writer.create()"),a=o.fieldsArray.slice().sort(r.compareFieldsById),c=0;c<a.length;++c){var l=a[c].resolve(),u=o._fieldsArray.indexOf(l),d=l.resolvedType instanceof e?"int32":l.type,h=t.basic[d];i="m"+r.safeProp(l.name),l.map?(s("if(%s!=null&&Object.hasOwnProperty.call(m,%j)){",i,l.name)("for(var ks=Object.keys(%s),i=0;i<ks.length;++i){",i)("w.uint32(%i).fork().uint32(%i).%s(ks[i])",(l.id<<3|2)>>>0,8|t.mapKey[l.keyType],l.keyType),void 0===h?s("types[%i].encode(%s[ks[i]],w.uint32(18).fork()).ldelim().ldelim()",u,i):s(".uint32(%i).%s(%s[ks[i]]).ldelim()",16|h,d,i),s("}")("}")):l.repeated?(s("if(%s!=null&&%s.length){",i,i),l.packed&&void 0!==t.packed[d]?s("w.uint32(%i).fork()",(l.id<<3|2)>>>0)("for(var i=0;i<%s.length;++i)",i)("w.%s(%s[i])",d,i)("w.ldelim()"):(s("for(var i=0;i<%s.length;++i)",i),void 0===h?n(s,l,u,i+"[i]"):s("w.uint32(%i).%s(%s[i])",(l.id<<3|h)>>>0,d,i)),s("}")):(l.optional&&s("if(%s!=null&&Object.hasOwnProperty.call(m,%j))",i,l.name),void 0===h?n(s,l,u,i):s("w.uint32(%i).%s(%s)",(l.id<<3|h)>>>0,d,i))}return s("return w")};var e=ys(),t=Li(),r=ps();function n(e,t,r,n){return t.resolvedType.group?e("types[%i].encode(%s,w.uint32(%i)).uint32(%i)",r,n,(t.id<<3|3)>>>0,(t.id<<3|4)>>>0):e("types[%i].encode(%s,w.uint32(%i).fork()).ldelim()",r,n,(t.id<<3|2)>>>0)}return ls}!function(e){var t=Vi;e[".google.protobuf.Any"]={fromObject:function(e){if(e&&e["@type"]){var t=e["@type"].substring(e["@type"].lastIndexOf("/")+1),r=this.lookup(t);if(r){var n="."===e["@type"].charAt(0)?e["@type"].slice(1):e["@type"];return-1===n.indexOf("/")&&(n="/"+n),this.create({type_url:n,value:r.encode(r.fromObject(e)).finish()})}}return this.fromObject(e)},toObject:function(e,r){var n="",o="";if(r&&r.json&&e.type_url&&e.value){o=e.type_url.substring(e.type_url.lastIndexOf("/")+1),n=e.type_url.substring(0,e.type_url.lastIndexOf("/")+1);var i=this.lookup(o);i&&(e=i.decode(e.value))}if(!(e instanceof this.ctor)&&e instanceof t){var s=e.$type.toObject(e,r);return""===n&&(n="type.googleapis.com/"),o=n+("."===e.$type.fullName[0]?e.$type.fullName.slice(1):e.$type.fullName),s["@type"]=o,s}return this.toObject(e,r)}}}(ds),function(e){var t=vi.exports=xt;t.build="light",t.load=function(e,r,n){return"function"==typeof r?(n=r,r=new t.Root):r||(r=new t.Root),r.load(e,n)},t.loadSync=function(e,r){return r||(r=new t.Root),r.loadSync(e)},t.encoder=vs(),t.decoder=Ji(),t.verifier=Zi(),t.converter=Qi(),t.ReflectionObject=gs(),t.Namespace=ji(),t.Root=fs(),t.Enum=ys(),t.Type=hs(),t.Field=Bi(),t.OneOf=Ui(),t.MapField=Pi(),t.Service=Gi(),t.Method=Fi(),t.Message=Vi,t.wrappers=ds,t.types=Li(),t.util=ps(),t.ReflectionObject._configure(t.Root),t.Namespace._configure(t.Type,t.Service,t.Enum),t.Root._configure(t.Type),t.Field._configure(t.Type)}();var ms=ks,bs=/[\s{}=;:[\],'"()<>]/g,ws=/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,Os=/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,Cs=/^ *[*/]+ */,_s=/^\s*\*?\/*/,Ss=/\n/g,Is=/\s/,Es=/\\(.?)/g,Ts={0:"\0",r:"\r",n:"\n",t:"\t"};function Rs(e){return e.replace(Es,(function(e,t){switch(t){case"\\":case"":return t;default:return Ts[t]||""}}))}function ks(e,t){e=e.toString();var r=0,n=e.length,o=1,i=0,s={},a=[],c=null;function l(e){return Error("illegal "+e+" (line "+o+")")}function u(t){return e.charAt(t)}function d(r,n,a){var c,l={type:e.charAt(r++),lineEmpty:!1,leading:a},u=r-(t?2:3);do{if(--u<0||"\n"===(c=e.charAt(u))){l.lineEmpty=!0;break}}while(" "===c||"\t"===c);for(var d=e.substring(r,n).split(Ss),h=0;h<d.length;++h)d[h]=d[h].replace(t?_s:Cs,"").trim();l.text=d.join("\n").trim(),s[o]=l,i=o}function h(t){var r=f(t),n=e.substring(t,r);return/^\s*\/{1,2}/.test(n)}function f(e){for(var t=e;t<n&&"\n"!==u(t);)t++;return t}function p(){if(a.length>0)return a.shift();if(c)return function(){var t="'"===c?Os:ws;t.lastIndex=r-1;var n=t.exec(e);if(!n)throw l("string");return r=t.lastIndex,g(c),c=null,Rs(n[1])}();var i,s,p,y,v,m=0===r;do{if(r===n)return null;for(i=!1;Is.test(p=u(r));)if("\n"===p&&(m=!0,++o),++r===n)return null;if("/"===u(r)){if(++r===n)throw l("comment");if("/"===u(r))if(t){if(y=r,v=!1,h(r)){v=!0;do{if((r=f(r))===n)break;if(r++,!m)break}while(h(r))}else r=Math.min(n,f(r)+1);v&&(d(y,r,m),m=!0),o++,i=!0}else{for(v="/"===u(y=r+1);"\n"!==u(++r);)if(r===n)return null;++r,v&&(d(y,r-1,m),m=!0),++o,i=!0}else{if("*"!==(p=u(r)))return"/";y=r+1,v=t||"*"===u(y);do{if("\n"===p&&++o,++r===n)throw l("comment");s=p,p=u(r)}while("*"!==s||"/"!==p);++r,v&&(d(y,r-2,m),m=!0),i=!0}}}while(i);var b=r;if(bs.lastIndex=0,!bs.test(u(b++)))for(;b<n&&!bs.test(u(b));)++b;var w=e.substring(r,r=b);return'"'!==w&&"'"!==w||(c=w),w}function g(e){a.push(e)}function y(){if(!a.length){var e=p();if(null===e)return null;g(e)}return a[0]}return Object.defineProperty({next:p,peek:y,push:g,skip:function(e,t){var r=y();if(r===e)return p(),!0;if(!t)throw l("token '"+r+"', '"+e+"' expected");return!1},cmnt:function(e){var r,n=null;return void 0===e?(r=s[o-1],delete s[o-1],r&&(t||"*"===r.type||r.lineEmpty)&&(n=r.leading?r.text:null)):(i<e&&y(),r=s[e],delete s[e],!r||r.lineEmpty||!t&&"/"!==r.type||(n=r.leading?null:r.text)),n}},"line",{get:function(){return o}})}ks.unescape=Rs;var As=Ys;Ys.filename=null,Ys.defaults={keepCase:!1};var Ns=ms,xs=fs(),Ds=hs(),Ms=Bi(),Ls=Pi(),Bs=Ui(),Us=ys(),js=Gi(),Ps=Fi(),Fs=Li(),Gs=ps(),qs=/^[1-9][0-9]*$/,Hs=/^-?[1-9][0-9]*$/,zs=/^0[x][0-9a-fA-F]+$/,Ks=/^-?0[x][0-9a-fA-F]+$/,Vs=/^0[0-7]+$/,Ws=/^-?0[0-7]+$/,$s=/^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,Js=/^[a-zA-Z_][a-zA-Z_0-9]*$/,Zs=/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,Xs=/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;function Ys(e,t,r){t instanceof xs||(r=t,t=new xs),r||(r=Ys.defaults);var n,o,i,s,a,c=r.preferTrailingComment||!1,l=Ns(e,r.alternateCommentMode||!1),u=l.next,d=l.push,h=l.peek,f=l.skip,p=l.cmnt,g=!0,y=!1,v=t,m=r.keepCase?function(e){return e}:Gs.camelCase;function b(e,t,r){var n=Ys.filename;return r||(Ys.filename=null),Error("illegal "+(t||"token")+" '"+e+"' ("+(n?n+", ":"")+"line "+l.line+")")}function w(){var e,t=[];do{if('"'!==(e=u())&&"'"!==e)throw b(e);t.push(u()),f(e),e=h()}while('"'===e||"'"===e);return t.join("")}function O(e){var t=u();switch(t){case"'":case'"':return d(t),w();case"true":case"TRUE":return!0;case"false":case"FALSE":return!1}try{return function(e,t){var r=1;"-"===e.charAt(0)&&(r=-1,e=e.substring(1));switch(e){case"inf":case"INF":case"Inf":return r*(1/0);case"nan":case"NAN":case"Nan":case"NaN":return NaN;case"0":return 0}if(qs.test(e))return r*parseInt(e,10);if(zs.test(e))return r*parseInt(e,16);if(Vs.test(e))return r*parseInt(e,8);if($s.test(e))return r*parseFloat(e);throw b(e,"number",t)}(t,!0)}catch(r){if(e&&Zs.test(t))return t;throw b(t,"value")}}function C(e,t){var r,n;do{!t||'"'!==(r=h())&&"'"!==r?e.push([n=_(u()),f("to",!0)?_(u()):n]):e.push(w())}while(f(",",!0));f(";")}function _(e,t){switch(e){case"max":case"MAX":case"Max":return 536870911;case"0":return 0}if(!t&&"-"===e.charAt(0))throw b(e,"id");if(Hs.test(e))return parseInt(e,10);if(Ks.test(e))return parseInt(e,16);if(Ws.test(e))return parseInt(e,8);throw b(e,"id")}function S(){if(void 0!==n)throw b("package");if(n=u(),!Zs.test(n))throw b(n,"name");v=v.define(n),f(";")}function I(){var e,t=h();switch(t){case"weak":e=i||(i=[]),u();break;case"public":u();default:e=o||(o=[])}t=w(),f(";"),e.push(t)}function E(){if(f("="),s=w(),!(y="proto3"===s)&&"proto2"!==s)throw b(s,"syntax");f(";")}function T(e,t){switch(t){case"option":return x(e,t),f(";"),!0;case"message":return k(e,t),!0;case"enum":return N(e,t),!0;case"service":return function(e,t){if(!Js.test(t=u()))throw b(t,"service name");var r=new js(t);R(r,(function(e){if(!T(r,e)){if("rpc"!==e)throw b(e);!function(e,t){var r=p(),n=t;if(!Js.test(t=u()))throw b(t,"name");var o,i,s,a,c=t;f("("),f("stream",!0)&&(i=!0);if(!Zs.test(t=u()))throw b(t);o=t,f(")"),f("returns"),f("("),f("stream",!0)&&(a=!0);if(!Zs.test(t=u()))throw b(t);s=t,f(")");var l=new Ps(c,n,o,s,i,a);l.comment=r,R(l,(function(e){if("option"!==e)throw b(e);x(l,e),f(";")})),e.add(l)}(r,e)}})),e.add(r)}(e,t),!0;case"extend":return function(e,t){if(!Zs.test(t=u()))throw b(t,"reference");var r=t;R(null,(function(t){switch(t){case"required":case"repeated":A(e,t,r);break;case"optional":A(e,y?"proto3_optional":"optional",r);break;default:if(!y||!Zs.test(t))throw b(t);d(t),A(e,"optional",r)}}))}(e,t),!0}return!1}function R(e,t,r){var n=l.line;if(e&&("string"!=typeof e.comment&&(e.comment=p()),e.filename=Ys.filename),f("{",!0)){for(var o;"}"!==(o=u());)t(o);f(";",!0)}else r&&r(),f(";"),e&&("string"!=typeof e.comment||c)&&(e.comment=p(n)||e.comment)}function k(e,t){if(!Js.test(t=u()))throw b(t,"type name");var r=new Ds(t);R(r,(function(e){if(!T(r,e))switch(e){case"map":!function(e){f("<");var t=u();if(void 0===Fs.mapKey[t])throw b(t,"type");f(",");var r=u();if(!Zs.test(r))throw b(r,"type");f(">");var n=u();if(!Js.test(n))throw b(n,"name");f("=");var o=new Ls(m(n),_(u()),t,r);R(o,(function(e){if("option"!==e)throw b(e);x(o,e),f(";")}),(function(){L(o)})),e.add(o)}(r);break;case"required":case"repeated":A(r,e);break;case"optional":A(r,y?"proto3_optional":"optional");break;case"oneof":!function(e,t){if(!Js.test(t=u()))throw b(t,"name");var r=new Bs(m(t));R(r,(function(e){"option"===e?(x(r,e),f(";")):(d(e),A(r,"optional"))})),e.add(r)}(r,e);break;case"extensions":C(r.extensions||(r.extensions=[]));break;case"reserved":C(r.reserved||(r.reserved=[]),!0);break;default:if(!y||!Zs.test(e))throw b(e);d(e),A(r,"optional")}})),e.add(r)}function A(e,t,r){var n=u();if("group"!==n){if(!Zs.test(n))throw b(n,"type");var o=u();if(!Js.test(o))throw b(o,"name");o=m(o),f("=");var i=new Ms(o,_(u()),n,t,r);if(R(i,(function(e){if("option"!==e)throw b(e);x(i,e),f(";")}),(function(){L(i)})),"proto3_optional"===t){var s=new Bs("_"+o);i.setOption("proto3_optional",!0),s.add(i),e.add(s)}else e.add(i);y||!i.repeated||void 0===Fs.packed[n]&&void 0!==Fs.basic[n]||i.setOption("packed",!1,!0)}else!function(e,t){var r=u();if(!Js.test(r))throw b(r,"name");var n=Gs.lcFirst(r);r===n&&(r=Gs.ucFirst(r));f("=");var o=_(u()),i=new Ds(r);i.group=!0;var s=new Ms(n,o,r,t);s.filename=Ys.filename,R(i,(function(e){switch(e){case"option":x(i,e),f(";");break;case"required":case"repeated":A(i,e);break;case"optional":A(i,y?"proto3_optional":"optional");break;case"message":k(i,e);break;case"enum":N(i,e);break;default:throw b(e)}})),e.add(i).add(s)}(e,t)}function N(e,t){if(!Js.test(t=u()))throw b(t,"name");var r=new Us(t);R(r,(function(e){switch(e){case"option":x(r,e),f(";");break;case"reserved":C(r.reserved||(r.reserved=[]),!0);break;default:!function(e,t){if(!Js.test(t))throw b(t,"name");f("=");var r=_(u(),!0),n={options:void 0,setOption:function(e,t){void 0===this.options&&(this.options={}),this.options[e]=t}};R(n,(function(e){if("option"!==e)throw b(e);x(n,e),f(";")}),(function(){L(n)})),e.add(t,r,n.comment,n.options)}(r,e)}})),e.add(r)}function x(e,t){var r=f("(",!0);if(!Zs.test(t=u()))throw b(t,"name");var n,o=t,i=o;r&&(f(")"),i=o="("+o+")",t=h(),Xs.test(t)&&(n=t.slice(1),o+=t,u())),f("="),function(e,t,r,n){e.setParsedOption&&e.setParsedOption(t,r,n)}(e,i,D(e,o),n)}function D(e,t){if(f("{",!0)){for(var r={};!f("}",!0);){if(!Js.test(a=u()))throw b(a,"name");var n,o=a;if(f(":",!0),"{"===h())n=D(e,t+"."+a);else if("["===h()){var i;if(n=[],f("[",!0)){do{i=O(!0),n.push(i)}while(f(",",!0));f("]"),void 0!==i&&M(e,t+"."+a,i)}}else n=O(!0),M(e,t+"."+a,n);var s=r[o];s&&(n=[].concat(s).concat(n)),r[o]=n,f(",",!0),f(";",!0)}return r}var c=O(!0);return M(e,t,c),c}function M(e,t,r){e.setOption&&e.setOption(t,r)}function L(e){if(f("[",!0)){do{x(e,"option")}while(f(",",!0));f("]")}return e}for(;null!==(a=u());)switch(a){case"package":if(!g)throw b(a);S();break;case"import":if(!g)throw b(a);I();break;case"syntax":if(!g)throw b(a);E();break;case"option":x(v,a),f(";");break;default:if(T(v,a)){g=!1;continue}throw b(a)}return Ys.filename=null,{package:n,imports:o,weakImports:i,syntax:s,root:t}}var Qs,ea=ra,ta=/\/|\./;function ra(e,t){ta.test(e)||(e="google/protobuf/"+e+".proto",t={nested:{google:{nested:{protobuf:{nested:t}}}}}),ra[e]=t}ra("any",{Any:{fields:{type_url:{type:"string",id:1},value:{type:"bytes",id:2}}}}),ra("duration",{Duration:Qs={fields:{seconds:{type:"int64",id:1},nanos:{type:"int32",id:2}}}}),ra("timestamp",{Timestamp:Qs}),ra("empty",{Empty:{fields:{}}}),ra("struct",{Struct:{fields:{fields:{keyType:"string",type:"Value",id:1}}},Value:{oneofs:{kind:{oneof:["nullValue","numberValue","stringValue","boolValue","structValue","listValue"]}},fields:{nullValue:{type:"NullValue",id:1},numberValue:{type:"double",id:2},stringValue:{type:"string",id:3},boolValue:{type:"bool",id:4},structValue:{type:"Struct",id:5},listValue:{type:"ListValue",id:6}}},NullValue:{values:{NULL_VALUE:0}},ListValue:{fields:{values:{rule:"repeated",type:"Value",id:1}}}}),ra("wrappers",{DoubleValue:{fields:{value:{type:"double",id:1}}},FloatValue:{fields:{value:{type:"float",id:1}}},Int64Value:{fields:{value:{type:"int64",id:1}}},UInt64Value:{fields:{value:{type:"uint64",id:1}}},Int32Value:{fields:{value:{type:"int32",id:1}}},UInt32Value:{fields:{value:{type:"uint32",id:1}}},BoolValue:{fields:{value:{type:"bool",id:1}}},StringValue:{fields:{value:{type:"string",id:1}}},BytesValue:{fields:{value:{type:"bytes",id:1}}}}),ra("field_mask",{FieldMask:{fields:{paths:{rule:"repeated",type:"string",id:1}}}}),ra.get=function(e){return ra[e]||null},function(e){var t=yi.exports=vi.exports;t.build="full",t.tokenize=ms,t.parse=As,t.common=ea,t.Root._configure(t.Type,t.parse,t.common)}();var na=f(gi.exports=yi.exports);const oa=e=>{const t=window.URL||window.webkitURL;return t?t.createObjectURL(e):""},ia=e=>{const t=e.name;return ot(t)?t.substring(t.lastIndexOf(".")+1):e.type.indexOf("/")>0?e.type.substring(e.type.lastIndexOf("/")+1):""},sa=e=>{(window.URL||window.webkitURL).revokeObjectURL(e)},aa=e=>{const t=e.match(/data:([^;]+)/)[1],r=e.replace(/^[^,]+,/,""),n=window.atob(r);let o=n.length;const i=new Uint8Array(n.length);for(;o--;)i[o]=n.charCodeAt(o);return new Blob([i],{type:t})};class ca{constructor(e){d(this,"options",void 0),d(this,"xhr",void 0),this.options=e}upload(e,t){const r=new XMLHttpRequest;r.upload.onprogress=e=>{var r;null===(r=t.onProgress)||void 0===r||r.call(t,e.loaded,e.total)},r.onreadystatechange=()=>{if(4===r.readyState){const o=r.responseText||"{}",i=JSON.parse(o);if(200===r.status&&200===i.code){var e;let r={url:i.url};this.options.transformer&&(r=this.options.transformer(r)),null===(e=t.onCompleted)||void 0===e||e.call(t,r)}else{var n;null===(n=t.onError)||void 0===n||n.call(t,"upload fail")}}},r.open("POST",this.options.uploadUrl,!0),r.setRequestHeader("device","7"),r.setRequestHeader("cert",this.options.cert??"");const n=ia(e),o=function(){let e=(new Date).getTime();return"xxxxxx4xxxyxxxxxxx".replace(/[xy]/g,(function(t){const r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?r:3&r|8).toString(16)}))}()+(n.length?`.${n}`:""),i=new FormData;i.append("file",e),i.append("name","file"),i.append("fileName",o),i.append("token",this.options.token),r.send(i),this.xhr=r}cancel(){var e;null===(e=this.xhr)||void 0===e||e.abort()}}const la=e=>new Promise(((t,r)=>{const n=e=>{0!==e.width||0!==e.height?t(e):r()},o=new Image;if(o.addEventListener("load",(e=>n(e.target))),o.addEventListener("error",r),o.src=e,o.complete)return void n(o);const i=setInterval((()=>{o.complete&&(n(o),clearInterval(i))}),40)}));class ua{constructor(e,t){d(this,"uploadInstance",void 0),d(this,"options",void 0),this.uploadInstance=e,this.options=t}async upload(e,t){try{const r=oa(e),n=await la(r);sa(r);const{imageFile:o,compressWidth:i,compressHeight:s}=function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"image/jpeg";t=Math.min(1,t);const n=e.width,o=e.height;let i=n,s=o;if(t<1){const e=n<o,t=e?o/1680:n/1680;n>1680&&o>1680?e?(s=1680,i/=t):(i=1680,s/=t):n>1680&&o>160?(i=1680,s/=t,s<160&&(s=160,i=n/(o/160))):o>1680&&n>160&&(s=1680,i/=t,i<160&&(i=160,s=o/(n/160)))}i=Math.floor(i),s=Math.floor(s);const a=document.createElement("canvas");a.width=i,a.height=s;const c=a.getContext("2d");return c.fillStyle="#FFF",c.fillRect(0,0,i,s),c.drawImage(e,0,0,n,o,0,0,i,s),r&&"image/png"!=r||(r="image/jpeg"),{imageFile:aa(a.toDataURL(r,Math.min(.92,t))),compressWidth:i,compressHeight:s}}(n,.85,e.type),a=((e,t)=>{const r=document.createElement("canvas"),n=r.getContext("2d"),o=function(e,t,r){const n=e<t;let o,i,s,a=0,c=0;const l=function(){return n?(o=e/100,i=100,s=t/o,c=(s-r.maxHeight)/2):(o=t/100,s=100,i=e/o,a=(i-r.maxWidth)/2),{w:i,h:s,x:-a,y:-c}},u=function(){return n?(o=t/r.maxHeight,s=r.maxHeight,i=e/o):(o=e/r.maxWidth,i=r.maxWidth,s=t/o),{w:i,h:s,x:-a,y:-c}};return(n?t/e:e/t)>r.scale?l():u()}(e.width,e.height,t);r.width=o.w>t.maxWidth?t.maxWidth:o.w,r.height=o.h>t.maxHeight?t.maxHeight:o.h,null==n||n.drawImage(e,o.x,o.y,o.w,o.h);try{let e=r.toDataURL("image/jpeg",t.quality);const n=new RegExp("^data:image/[^;]+;base64,");return e=e.replace(n,""),e}catch(e){throw new Error(e)}})(n,{maxHeight:160,maxWidth:160,quality:.6,scale:2.4});this.uploadInstance.upload(o,{...t,onCompleted:r=>{var n;null===(n=t.onCompleted)||void 0===n||n.call(t,{url:r.url,thumbnail:a,width:i,height:s,type:e.type})}})}catch(e){var r;null===(r=t.onError)||void 0===r||r.call(t,"MEDIA_EXCEPTION")}}cancel(){this.uploadInstance.cancel()}}class da{constructor(e){d(this,"uploadInstance",void 0),this.uploadInstance=e}async upload(e,t){if(e.size>2097152)t.onError&&t.onError("GIF_MSG_SIZE_LIMIT_EXCEED");else try{const r=oa(e),n=await la(r);sa(r),this.uploadInstance.upload(e,{...t,onCompleted:r=>{var o;null===(o=t.onCompleted)||void 0===o||o.call(t,{url:r.url,size:e.size,width:n.width,height:n.height})}})}catch(e){var r;null===(r=t.onError)||void 0===r||r.call(t,"MEDIA_EXCEPTION")}}cancel(){this.uploadInstance.cancel()}}let ha;class fa{constructor(e){d(this,"uploadInstance",void 0),this.uploadInstance=e}upload(e,t){var r;(r=e,st(r.arrayBuffer)?r.arrayBuffer():new Promise(((e,t)=>{const n=new FileReader;n.addEventListener("load",(r=>{r.target?e(r.target.result):t("null")})),n.addEventListener("error",(e=>t(e))),n.readAsArrayBuffer(r)}))).then(this.getAudioInfo).then((r=>{this.uploadInstance.upload(e,{...t,onCompleted:n=>{var o;null===(o=t.onCompleted)||void 0===o||o.call(t,{url:n.url,type:ia(e),...r})}})})).catch((()=>{var e;null===(e=t.onError)||void 0===e||e.call(t,"MEDIA_EXCEPTION")}))}cancel(){this.uploadInstance.cancel()}getAudioInfo(e){const t=ha||new AudioContext;return ha=t,new Promise(((r,n)=>{t.decodeAudioData(e,(function(e){r({duration:e.duration,length:e.length})}),n)}))}}class pa{constructor(e){d(this,"uploadInstance",void 0),this.uploadInstance=e}upload(e,t){if(e.size>104857600)t.onError&&t.onError("FILE_MSG_SIZE_LIMIT_EXCEED");else try{this.uploadInstance.upload(e,{...t,onCompleted:r=>{var n;null===(n=t.onCompleted)||void 0===n||n.call(t,{url:r.url,name:e.name,type:ia(e),size:e.size})}})}catch(e){var r;null===(r=t.onError)||void 0===r||r.call(t,"MEDIA_EXCEPTION")}}cancel(){this.uploadInstance.cancel()}}var ga;!function(e){e[e.IMAGE=1]="IMAGE",e[e.GIF=2]="GIF",e[e.AUDIO=3]="AUDIO",e[e.VIDEO=4]="VIDEO",e[e.FILE=5]="FILE",e[e.SIGHT=6]="SIGHT"}(ga||(ga={}));const ya=(e,t,r,n,o,i)=>({conversationType:e.conversationType,targetId:e.targetId,channelId:e.channelId,senderUserId:t,messageDirection:s.SEND,isCounted:r.isCounted,isMentioned:!1,content:r.content,messageType:r.messageType,isOffLineMessage:!1,isPersited:r.isPersited,messageId:n,messageUId:o,sentTime:i,receivedTime:0,isStatusMessage:r.isStatusMessage,receivedStatus:a.UNREAD,disableNotification:!1});let va=0;const ma=[Ro,Eo];async function ba(r,i,s){var a;if(!ui.loader||ui.loader.getConnectionStatus()!==e.CONNECTED)return{code:t.RC_NET_CHANNEL_INVALID};s=s||{};const c=JSON.stringify(ct(i.encode()));if(function(e){let t=0;if("utf-16"===(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"utf-8"))for(let r=0,n=e.length;r<n;r++)t+=e.charCodeAt(r)<=65535?2:4;else for(let r=0,n=e.length;r<n;r++){const n=e.charCodeAt(r);t+=n<127?1:n<=2047?2:n<=65535?3:4}return t}(c)>81920)return{code:t.RC_MSG_CONTENT_EXCEED_LIMIT};const l=Fn(r);let u;u=Ze(null===(a=s)||void 0===a?void 0:a.messageId)&&s.messageId>0?s.messageId:function(){va++;const e=io();return va<e&&(va=e),23e13+va}(),ao.addMessage(u);const d=ya(r,Dn.uid,i,u,"",function(){Ta++;const e=io();Ta<e&&(Ta=e);return Ta}());s.onSendBefore&&s.onSendBefore(d),i.isPersited&&ci.get().loadConvsationsIfNotExist([r]);const h=await zo.getDialogAesKey(l);if(!h)return{code:t.MSG_ENCRYPT_ERROR,data:d};const f=((e,t)=>{if(!ot(e))return new Uint8Array;const r=$e.AES.encrypt(e,$e.enc.Utf8.parse(t.key),{iv:Ze(t.iv)?$e.enc.Utf8.parse(t.iv):void 0});return $o(r.ciphertext.words)})(c,h),p={localId:rn.fromNumber(u),mediaFlag:ma.includes(i.messageType),mediaConstructor:i.objectId,mediaAttribute:"",msgPreContent:"",msgPostContent:"",msgContent:f};let g;if(r.conversationType===n.GROUP){var y,v;const e={...p,groupId:l};if(null!==(y=s)&&void 0!==y&&null!==(v=y.directionalUserIdList)&&void 0!==v&&v.length&&(e.assign=s.directionalUserIdList.join(",")),Ze(i.content.mentionedInfo)){var m;const t=i.content.mentionedInfo;t.type===o.ALL?e.atAll=!0:t.type===o.SINGAL&&null!==(m=t.userIdList)&&void 0!==m&&m.length&&(e.at=t.userIdList.map((e=>rn.fromString(e))))}g=await(b=e,xn.send(At.SendGroupChatMessage,b,{encoder:Yn.SendGroupChatMessageReq,decoder:ro}))}else{const e={...p,destId:l};g=await(e=>xn.send(At.SendPrivateChatMessage,e,{encoder:Wn.SendPrivateChatMessageReq,decoder:jn.SendPrivateChatMessageResp}))(e)}var b;return g.code===t.SUCCESS&&(d.sentTime=g.data.seqno.toNumber(),d.messageUId=g.data.msgId.toString(),ci.get().setConversationCacheByMessage(d)),{code:g.code,data:d}}const wa=Ia(ga.IMAGE,((e,t)=>new Do({content:e.thumbnail,imageUri:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),Oa=Ia(ga.GIF,((e,t)=>new Mo({gifDataSize:e.size,remoteUrl:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),Ca=Ia(ga.AUDIO,((e,t)=>new Lo({remoteUrl:e.url,duration:e.duration,type:e.type,user:t.user,extra:t.extra}))),_a=Ia(ga.FILE,((e,t)=>new Bo({fileUrl:e.url,name:e.name,type:e.type,size:e.size,user:t.user,extra:t.extra}))),Sa=async(e,r)=>{const n=Fn(e);lo.addMessage(r.messageUId);const o=await((e,t)=>{let r;return r=qn(e)?xn.send(At.RecallGroupMessage,{groupId:e,msgId:rn.fromString(t)},{encoder:Yn.RecallGroupChatMessageReq,decoder:Xr.BaseResp}):xn.send(At.RecallPrivateMessage,{destId:e,msgId:rn.fromString(t)},{encoder:Wn.RecallPrivateChatMessageReq,decoder:Xr.BaseResp}),r})(n,r.messageUId);if(o.code!==t.SUCCESS)return{code:o.code};const i=new Uo({sentTime:r.sentTime,messageUId:r.messageUId,...e}),s=ya(e,Dn.uid,i,0,"",io());return ci.get().setConversationCacheByMessage(s),{code:t.SUCCESS,data:s}};function Ia(e,r){return function(n,o,i,s){return new Promise((a=>{((e,t,r,n)=>{var o;const i=new ca({token:Pn.imInitToken,uploadUrl:Pn.fileUploadUrl,cert:Pn.cert,transformer:e=>({...e,url:Pn.getFileAbsoluteUri(e.url)})});let s;switch(t){case ga.IMAGE:s=new ua(i,r);break;case ga.GIF:s=new da(i);break;case ga.AUDIO:s=new fa(i);break;case ga.FILE:s=new pa(i)}null===(o=s)||void 0===o||o.upload(e,{onProgress:(e,t)=>n.onProgress(Math.floor(e/t*100)),onError:()=>n.onFail(),onCompleted:n.onSuccess})})(o.file,e,s,{onProgress:e=>{(null==i?void 0:i.onProgress)&&i.onProgress(e)},onSuccess:e=>{const t=(null==i?void 0:i.onComplete)&&i.onComplete({url:Pn.getFileAbsoluteUri(e.url)})||r(e,o);ba(n,t,s).then(a)},onFail:()=>{a({code:t.UPLOAD_FILE_FAILED})}})}))}}let Ea,Ta=1;class Ra extends Rt{constructor(e){if(Ra.imClient)return mt.error("Please do not perform the init method repeatedly"),Ra.imClient;super(),d(this,"options",void 0),d(this,"libLoader",void 0),d(this,"getServerTime",io),d(this,"sendMessage",ba),d(this,"sendImageMessage",wa),d(this,"sendGIFMessage",Oa),d(this,"sendHQVoiceMessage",Ca),d(this,"sendFileMessage",_a),d(this,"recallMsg",Sa),this.options=e,this.fixedProtobuf(),Ze(e.logLevel)&&mt.setLogLevel(e.logLevel),Ze(e.logStdout)&&mt.setLogStdout(e.logStdout),mt.debug("IMClient.init -> ",e.appkey),this.libLoader=ui.init(e),this.watch(),Ra.imClient=this}fixedProtobuf(){na.util.Long=rn,na.configure()}watch(){this.libLoader.assignWatcher({onConnecting:()=>{this.emit(u.CONNECTING)},onConnected:()=>{this.emit(u.CONNECTED)},onDisconnect:()=>{this.emit(u.DISCONNECT,this.libLoader.getConnectionStatus())},onSuspend:()=>{this.emit(u.SUSPEND,this.libLoader.getConnectionStatus())},batchMessage:e=>{this.emit(u.MESSAGES,{messages:e})},pullFinished:()=>{this.emit(u.PULL_OFFLINE_MESSAGE_FINISHED)},conversationState:e=>{this.emit(u.CONVERSATION,{conversations:e})}})}connect(e){return this.libLoader.connect(e)}disconnect(){return this.libLoader.disconnect()}getConnectionStatus(){return this.libLoader.getConnectionStatus()}async getRemoteHistoryMessages(e,n){const o=Fn(e);return(e=>{const t={dialogKeys:e.dialogId,newToOld:e.newToOld,rows:e.count};return e.newToOld?t.offset=rn.fromNumber(e.offset):t.oldOffset=rn.fromNumber(e.offset),xn.send(e.dialogId.startsWith("SG")?At.GetSuperGroupRemoteMessages:At.GetRemoteMessages,t,{encoder:Wn.GetHistoryMessageReq,decoder:jn.GetHistoryMessageResp})})({dialogId:o,offset:n.timestamp??0,count:n.count??20,newToOld:0===n.order}).then((e=>{let{code:n,data:i}=e;return new Promise((e=>{n===t.SUCCESS?Qo.parse({[o]:i.msg??{}},((r,n)=>{const s=n[o]??[];s.sort(((e,t)=>e.sentTime-t.sentTime)),e({code:t.SUCCESS,data:{list:s,hasMore:!i.isEnd}})})):e({code:n,msg:r(n)})}))}))}async deleteRemoteMessage(e,t){return(r=Fn(e),n=t.map((e=>e.messageUId)),xn.send(At.DeleteChatMessages,{destId:r,msgIdList:n.map((e=>rn.fromString(e)))},{encoder:Wn.DeleteChatMessageReq,decoder:Xr.BaseResp})).then((e=>e.code));var r,n}async deleteRemoteMessageByTimestamp(e,t){return((e,t)=>xn.send(At.ClearChatHistoryMessage,{destId:e,type:qn(e)?1:0,msgTime:rn.fromNumber(t)},{encoder:Wn.CleanHistoryMessageReq,decoder:Xr.BaseResp}))(Fn(e),0===t?Number.MAX_VALUE:t).then((e=>e.code))}async getConversationList(e,r,n,o){const i={rows:e,type:r??0,offset:rn.fromNumber(n),newToOld:0===o},{code:s,data:a}=await(e=>xn.send(At.GetDialogList,e,{encoder:Wn.GetWebDialogListReq,decoder:jn.GetWebDialogListResp}))(i);if(s!==t.SUCCESS)return{code:s};const c=a.fullDialog.map((e=>{var t;return null===(t=e.dialog)||void 0===t?void 0:t.destId})).filter(ot);await zo.getDialogAesKeyList(c);const l=[];for(const e of a.fullDialog){const t=this.formatConversation(e);if(t){const e={conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId};ci.get().addLocalConversation(t);const r=ci.get().get(e);Object.assign(t,r),l.push(t)}}return{code:t.SUCCESS,data:l}}getBlockConversationList(){const e=ci.get().getBlockConversationList();return Promise.resolve({code:t.SUCCESS,data:e})}getTopConversationList(){const e=ci.get().getTopConversationList();return Promise.resolve({code:t.SUCCESS,data:e})}async getConversation(e){const r=ci.get().get(e);if(!r)return{code:t.CONVER_GET_ERROR};const{code:n,data:o}=await this.getRemoteHistoryMessages(e,{count:1,order:0});if(n!==t.SUCCESS)return{code:t.CONVER_GET_ERROR};const i=null==o?void 0:o.list[0],s={...e,...r,latestMessage:i};return{code:t.SUCCESS,data:s}}removeConversation(e){return(e=>{let t;return t=qn(e)?xn.send(At.DeleteGroupDialog,{groupId:e},{encoder:Yn.DeleteGroupChatDialogReq,decoder:Xr.BaseResp}):xn.send(At.DeletePrivateDialog,{destId:e},{encoder:Wn.DeletePrivateChatDialogReq,decoder:Xr.BaseResp}),t})(Fn(e)).then((e=>e.code))}getUnreadMentionedCount(e){return ci.get().getUnreadMentionedCount(e)}getAllUnreadMentionedCount(){return ci.get().getAllUnreadMentionedCount()}getAllConversationState(){return ci.get().getAllConversationState()}getAllConversationUnreadCount(e,t){return ci.get().getAllUnreadCount(e,t)}getConversationUnreadCount(e){return ci.get().getUnreadCount(e)}clearConversationUnreadCount(e){ci.get().clearUnreadCount(e)}clearAllConversationsUnreadCount(){ci.get().clearAllUnreadCount()}getConversationNotificationLevel(e){return ci.get().getNotificationLevel(e)}setConversationNotificationStatus(e,t){return((e,t)=>{let r;return r=qn(e)?xn.send(At.UpdateGroupChatMuteConfig,{groupId:e,muteFlag:t},{encoder:Yn.UpdateGroupChatDialogMuteConfigReq,decoder:Xr.BaseResp}):xn.send(At.UpdatePrivateChatMuteConfig,{destId:e,muteFlag:t},{encoder:Wn.UpdatePrivateChatDialogMuteConfigReq,decoder:Xr.BaseResp}),r})(Fn(e),t===i.OPEN).then((r=>(!r.code&&ci.get().addStatus({...e,notificationStatus:t,notificationLevel:t==i.OPEN?c.AT_USER_NOTIFICATION:c.NOT_SET},!0),r.code)))}getConversationNotificationStatus(e){return ci.get().getNotificationStatus(e)}setConversationToTop(e,t){return((e,t)=>{let r;return r=qn(e)?xn.send(At.UpdateGroupChatStickyConfig,{groupId:e,stickyFlag:t},{encoder:Yn.UpdateGroupChatDialogStickyConfigReq,decoder:Xr.BaseResp}):xn.send(At.UpdatePrivateChatStickyConfig,{destId:e,stickyFlag:t},{encoder:Wn.UpdatePrivateChatDialogStickyConfigReq,decoder:Xr.BaseResp}),r})(Fn(e),t).then((r=>(!r.code&&ci.get().addStatus({...e,isTop:t},!0),r.code)))}saveConversationMessageDraft(e,t){ci.get().setDraft(e,t)}getConversationMessageDraft(e){return ci.get().getDraft(e)}clearConversationMessageDraft(e){ci.get().clearDraft(e)}formatConversation(e){const{dialog:t,msg:r}=e,n=t.destId??"",o=ni(t);if(!o)return;const i=zo.getDialogAesKeyFromLocal(n);if(!i)return;const s=Qo.parseSingleDialogMessages(n,[r],i)[0];return s?(o.latestMessage=s,o):void 0}}d(Ra,"imClient",void 0);const ka=e=>{Ea=Ea||new Ra(e)},Aa=async e=>{Et("token",e,bt,!0);const n=await Ea.connect(e);return n.code===t.SUCCESS?{code:n.code,data:{userId:n.userId}}:{code:n.code,msg:r(n.code)}},Na=()=>Ea.disconnect(),xa=()=>Ea.getConnectionStatus(),Da=()=>Ea.getServerTime(),Ma=(e,t,r)=>{Ea.on(e,t,r)};function La(e,t,r){Ea.once(e,t,r)}const Ba=(e,t,r)=>{Ea.off(e,t,r)},Ua=async e=>{mt.debug("get conversation list ->");const{code:n,data:o}=await Ea.getConversationList((null==e?void 0:e.count)??20,null,(null==e?void 0:e.startTime)??0,(null==e?void 0:e.order)??0);return n!==t.SUCCESS&&mt.warn("get conversation list fail ->"+n+":"+r(n)),{code:n,msg:r(n),data:o}},ja=async e=>{Et("options",e,St,!0);const n="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get conversation ->"+n);const{code:o,data:i}=await Ea.getConversation(e);return o!==t.SUCCESS?(mt.warn("get conversation fail ->"+o+":"+r(o)+","+n),{code:o,msg:r(o)}):{code:o,data:i}},Pa=async e=>{Et("options",e,St,!0);const n="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("remove conversation ->"+n);const o=await Ea.removeConversation(e);return o!==t.SUCCESS?(mt.warn("remove conversation fail ->"+o+":"+r(o)+","+n),{code:o,msg:r(o)}):{code:o}},Fa=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get draft ->"+r);const n=Ea.getConversationMessageDraft(e);return Promise.resolve({code:t.SUCCESS,data:n})},Ga=(e,r)=>{Et("options",e,St,!0),Et("draft",r,bt,!0);const n="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("set draft ->"+n),Ea.saveConversationMessageDraft(e,r),Promise.resolve({code:t.SUCCESS})},qa=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("delete draft ->"+r),Ea.clearConversationMessageDraft(e),Promise.resolve({code:t.SUCCESS})},Ha=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("get unreadMentionedCount ->"+r),Promise.resolve({code:t.SUCCESS,data:Ea.getUnreadMentionedCount(e)})},za=()=>{mt.debug("getAllUnreadMentionedCount");const e=Ea.getAllUnreadMentionedCount();return Promise.resolve({code:t.SUCCESS,data:e})},Ka=()=>{mt.debug("getAllConversationState");const e=Ea.getAllConversationState();return Promise.resolve({code:t.SUCCESS,data:e})},Va=(e,r)=>{if(mt.debug("get total unread count -> ConversationType:"+JSON.stringify(r)+" includeMuted:"+e),Et("includeMuted",e,Ot,!1),Et("conversationTypes",r,Ct,!1),r)for(const e of r)Et("conversationType",e,_t,!0);const n=Ea.getAllConversationUnreadCount(r??[],e??!1);return Promise.resolve({code:t.SUCCESS,data:n})},Wa=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get unreadCount ->"+r);const n=Ea.getConversationUnreadCount(e);return Promise.resolve({code:t.SUCCESS,data:n})},$a=e=>{Et("options",e,St,!0);const r="conversationType:"+e.conversationType+",targetId:"+e.targetId;return mt.debug("clear unreadMsgNum ->"+r),Ea.clearConversationUnreadCount(e),Promise.resolve({code:t.SUCCESS})},Ja=()=>(mt.debug("clear allMessagesUnreadStatus"),Ea.clearAllConversationsUnreadCount(),Promise.resolve({code:t.SUCCESS})),Za=e=>{Et("options",e,St,!0),mt.info("getConversationNotificationLevel ->targetId:"+e.targetId+",conversationType:"+e.conversationType);const r=Ea.getConversationNotificationLevel(e);return Promise.resolve({code:t.SUCCESS,data:r})},Xa=async(e,n)=>{Et("options",e,St,!0),Et("notificationStatus",n,(e=>1===e||2===e),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("set conversation status ->"+o);const i=await Ea.setConversationNotificationStatus(e,n);return i!==t.SUCCESS?(mt.warn("set conversation status fail ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:i}},Ya=e=>{Et("options",e,St,!0),mt.info("getConversationNotificationStatus ->targetId:"+e.targetId+",conversationType:"+e.conversationType);const r=Ea.getConversationNotificationStatus(e);return Promise.resolve({code:t.SUCCESS,data:r})},Qa=()=>Ea.getBlockConversationList(),ec=async function(e){let n=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];Et("options",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("set conversation status ->"+o);const i=await Ea.setConversationToTop(e,n);return i!==t.SUCCESS?(mt.warn("set conversation status fail ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:i}},tc=()=>Ea.getTopConversationList(),rc=(e,t,r,n,o)=>function(n){return o?new Ho(e,n):r?new qo(e,n):t?new Go(e,n):new Fo(e,n)},nc=async(e,r,n)=>{if(r instanceof fo==!1)return mt.warn("send message fail -> message parameter is not an instance of BaseMessage"),{code:t.PARAMETER_ERROR};Et("conversation",e,St,!0),pc(e);const o=await Ea.sendMessage(e,r,n);return gc(e,o.code),o},oc=(e,t,r)=>{const n=new xo(t);return nc(e,n,r)},ic=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.startsWith("image/")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+o),pc(e);const i=await Ea.sendImageMessage(e,t,r,n);return gc(e,i.code),i},sc=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.endsWith("image/gif")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+o),pc(e);const i=await Ea.sendGIFMessage(e,t,r,n);return gc(e,i.code),i},ac=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob),!0),pc(e);const o=await Ea.sendHQVoiceMessage(e,t,r,n);return gc(e,o.code),o},cc=async(e,t,r,n)=>{Et("conversation",e,St,!0),Et("msgBody.file",t.file,(e=>e instanceof Blob),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+o),pc(e);const i=await Ea.sendFileMessage(e,t,r,n);return gc(e,i.code),i},lc=async(e,n)=>{Et("options.messageUId",n.messageUId,bt,!0),Et("options.sentTime",n.sentTime,wt,!0),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId+",messageUId:"+n.messageUId;mt.debug("recall message ->"+o);const i=await Ea.recallMsg(e,n);return i.code!==t.SUCCESS&&mt.warn("recall message fail ->"+i.code+":"+r(i.code)+","+o),i},uc=async(e,n)=>{Et("options.timestamp",n.timestamp??0,wt),Et("options.count",n.count??0,wt),Et("options.order",n.order??0,(e=>0===e||1===e)),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get history message ->"+o);const i=await Ea.getRemoteHistoryMessages(e,n);return i.code!==t.SUCCESS&&mt.warn("get history message fail ->"+i.code+":"+r(i.code)+","+o),i},dc=async(e,n)=>{Et("options.timestamp",n.timestamp??0,wt),Et("options.count",n.count??0,wt),Et("options.order",n.order??0,(e=>0===e||1===e)),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("get remote history message ->"+o);const i=await Ea.getRemoteHistoryMessages(e,n);return i.code!==t.SUCCESS&&mt.warn("get remote history message fail ->"+i.code+":"+r(i.code)+","+o),i},hc=async(e,n)=>{Et("messages",n,(e=>rt(e)&&!!e.length),!0),n.forEach((e=>{Et("messages.messageUId",e.messageUId,bt,!0),Et("messages.sentTime",e.sentTime,wt,!1),Et("messages.messageDirection",e.messageDirection,(e=>1===e||2===e),!1)})),Et("conversation",e,St,!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("delete messages ->"+o);const i=await Ea.deleteRemoteMessage(e,n);return i!==t.SUCCESS?(mt.warn("delete message fail ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:t.SUCCESS}},fc=async(e,n)=>{Et("timestamp",n,(e=>wt(e)&&e>=0),!0),Et("conversation",e,St);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("clear message ->"+o);const i=await Ea.deleteRemoteMessageByTimestamp(e,n);return i!==t.SUCCESS?(mt.warn("clear message ->"+i+":"+r(i)+","+o),{code:i,msg:r(i)}):{code:t.SUCCESS}},pc=e=>{const t="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.debug("send message ->"+t)},gc=(e,n)=>{if(n!==t.SUCCESS){const t="conversationType:"+e.conversationType+",targetId:"+e.targetId;mt.warn("send message fail ->"+n+":"+r(n)+","+t)}};export{jo as CommandMessage,e as ConnectionStatus,n as ConversationType,t as ErrorCode,r as ErrorDesc,u as Events,Bo as FileMessage,Mo as GIFMessage,Lo as HQVoiceMessage,Do as ImageMessage,l as LogLevel,o as MentionedType,s as MessageDirection,c as NotificationLevel,i as NotificationStatus,a as ReceivedStatus,xo as TextMessage,Ma as addEventListener,Ja as clearAllMessagesUnreadStatus,fc as clearHistoryMessages,$a as clearMessagesUnreadStatus,qa as clearTextMessageDraft,Aa as connect,hc as deleteMessages,Na as disconnect,Ka as getAllConversationState,za as getAllUnreadMentionedCount,Qa as getBlockedConversationList,xa as getConnectionStatus,ja as getConversation,Ua as getConversationList,Za as getConversationNotificationLevel,Ya as getConversationNotificationStatus,uc as getHistoryMessages,dc as getRemoteHistoryMessages,Da as getServerTime,Fa as getTextMessageDraft,tc as getTopConversationList,Va as getTotalUnreadCount,Wa as getUnreadCount,Ha as getUnreadMentionedCount,ka as init,La as onceEventListener,lc as recallMessage,rc as registerMessageType,Pa as removeConversation,Ba as removeEventListener,Ga as saveTextMessageDraft,cc as sendFileMessage,sc as sendGIFMessage,ac as sendHQVoiceMessage,ic as sendImageMessage,nc as sendMessage,oc as sendTextMessage,Xa as setConversationNotificationStatus,ec as setConversationToTop};