@onyx-p/imlib-web 1.0.15 → 1.0.16

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.umd.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 On}else{if(e<=-yn)return _n;if(e+1>=yn)return Sn}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 Cn=cn(1);rn.ONE=Cn;var wn=cn(1,!0);rn.UONE=wn;var En=cn(-1);rn.NEG_ONE=En;var Sn=un(-1,2147483647,!1);rn.MAX_VALUE=Sn;var On=un(-1,-1,!0);rn.MAX_UNSIGNED_VALUE=On;var _n=un(0,-2147483648,!1);rn.MIN_VALUE=_n;var In=rn.prototype;In.toInt=function(){return this.unsigned?this.low>>>0:this.low},In.toNumber=function(){return this.unsigned?(this.high>>>0)*pn+(this.low>>>0):this.high*pn+(this.low>>>0)},In.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(_n)){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}},In.getHighBits=function(){return this.high},In.getHighBitsUnsigned=function(){return this.high>>>0},In.getLowBits=function(){return this.low},In.getLowBitsUnsigned=function(){return this.low>>>0},In.getNumBitsAbs=function(){if(this.isNegative())return this.eq(_n)?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},In.isZero=function(){return 0===this.high&&0===this.low},In.eqz=In.isZero,In.isNegative=function(){return!this.unsigned&&this.high<0},In.isPositive=function(){return this.unsigned||this.high>=0},In.isOdd=function(){return 1==(1&this.low)},In.isEven=function(){return 0==(1&this.low)},In.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)},In.eq=In.equals,In.notEquals=function(e){return!this.eq(e)},In.neq=In.notEquals,In.ne=In.notEquals,In.lessThan=function(e){return this.comp(e)<0},In.lt=In.lessThan,In.lessThanOrEqual=function(e){return this.comp(e)<=0},In.lte=In.lessThanOrEqual,In.le=In.lessThanOrEqual,In.greaterThan=function(e){return this.comp(e)>0},In.gt=In.greaterThan,In.greaterThanOrEqual=function(e){return this.comp(e)>=0},In.gte=In.greaterThanOrEqual,In.ge=In.greaterThanOrEqual,In.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},In.comp=In.compare,In.negate=function(){return!this.unsigned&&this.eq(_n)?_n:this.not().add(Cn)},In.neg=In.negate,In.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)},In.subtract=function(e){return nn(e)||(e=fn(e)),this.add(e.neg())},In.sub=In.subtract,In.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(_n))return e.isOdd()?_n:mn;if(e.eq(_n))return this.isOdd()?_n: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)},In.mul=In.multiply,In.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 wn;n=bn}else{if(this.eq(_n))return e.eq(Cn)||e.eq(En)?_n:e.eq(_n)?Cn:(t=this.shr(1).div(e).shl(1)).eq(mn)?e.isNegative()?Cn:En:(r=this.sub(e.mul(t)),n=t.add(r.div(e)));if(e.eq(_n))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=Cn),n=n.add(s),r=r.sub(a)}return n},In.div=In.divide,In.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))},In.mod=In.modulo,In.rem=In.modulo,In.not=function(){return un(~this.low,~this.high,this.unsigned)},In.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},In.clz=In.countLeadingZeros,In.countTrailingZeros=function(){return this.low?on(this.low):on(this.high)+32},In.ctz=In.countTrailingZeros,In.and=function(e){return nn(e)||(e=fn(e)),un(this.low&e.low,this.high&e.high,this.unsigned)},In.or=function(e){return nn(e)||(e=fn(e)),un(this.low|e.low,this.high|e.high,this.unsigned)},In.xor=function(e){return nn(e)||(e=fn(e)),un(this.low^e.low,this.high^e.high,this.unsigned)},In.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)},In.shl=In.shiftLeft,In.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)},In.shr=In.shiftRight,In.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)},In.shru=In.shiftRightUnsigned,In.shr_u=In.shiftRightUnsigned,In.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))},In.rotl=In.rotateLeft,In.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))},In.rotr=In.rotateRight,In.toSigned=function(){return this.unsigned?un(this.low,this.high,!1):this},In.toUnsigned=function(){return this.unsigned?this:un(this.low,this.high,!0)},In.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},In.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]},In.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.ConnectionStatus[t],kn=()=>{const e="ACDeviceId";let t="";const r=kt.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)})),kt.set(e,t)),t},Nn=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},An=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 Ln=new class{constructor(t){h(this,"url",""),h(this,"watcher",void 0),h(this,"provider",void 0),h(this,"options",void 0),h(this,"socket",void 0),h(this,"status",e.ConnectionStatus.DISCONNECTED),h(this,"autoReconnect",!1),h(this,"isAuthorized",!1),h(this,"profile",void 0),h(this,"responseCallbacks",new Map),h(this,"failedCount",0),h(this,"reconnectTimer",void 0),h(this,"token",""),h(this,"connectResolve",void 0),h(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(t){return this.token=t,new Promise((t=>{this.connectResolve=t,this.open().then((t=>t===e.ErrorCode.SUCCESS?!p(this.provider)||this.provider.needReAuth()?this.auth():e.ErrorCode.SUCCESS:t)).then((r=>{var n;(t(r),r===e.ErrorCode.SUCCESS)?(this.isAuthorized=!0,this.profile=null===(n=this.provider)||void 0===n?void 0:n.profile(),this.autoReconnect=!0,this.onConnect()):this.onDisconnect(r===e.ErrorCode.TIMEOUT?e.ConnectionStatus.NETWORK_UNAVAILABLE:e.ConnectionStatus.WEBSOCKET_UNAVAILABLE)}))}))}async send(t,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(t,p(r)&&p(n.encoder)?n.encoder.encode(r).finish():new Uint8Array,i);if(0!==s)return{code:s,msg:"time out",data:null};if(!p(a)||!p(n.decoder))return{code:e.ErrorCode.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:e.ErrorCode.SUCCESS,msg:""}}async sendRawData(t,r){var n,o,i;let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.options.signalTimeout;if(!this.socket)return{code:e.ErrorCode.RC_NET_CHANNEL_INVALID};if(!this.isAuthorized&&!this.isAuthCommand(t))return{code:e.ErrorCode.RC_NET_CHANNEL_INVALID};const a=this.generateMessageSeq(),c={cmdId:t,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};T.reqInfo(`websocket send -> cmd: 0x${t.toString(16)}, messageSeq: ${a}`),this.socket.send(Nn(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}:(T.warn(`send timeout -> cmd: 0x${t.toString(16)}, messageSeq: ${a}, timeout: ${s}`),{code:e.ErrorCode.TIMEOUT})}close(){var t;this.autoReconnect=!1,this.doClose(),this.setStatus(e.ConnectionStatus.DISCONNECTED),null===(t=this.connectResolve)||void 0===t||t.call(this,e.ErrorCode.RC_SOCKET_DISCONNECTED)}async open(){const t=this.url;T.info(`conenct start -> ${t}`),this.setStatus(e.ConnectionStatus.CONNECTING);const r=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=r;return await new Promise((n=>{r.onMessage((e=>{"ArrayBuffer"===f(e)?this.onReceiveMessage(e):T.error("Socket received invalid data:",e)})),r.onClose(((t,r)=>{T.warn("websocket closed -> code:",t,"reason:",r),this.onDisconnect(e.ConnectionStatus.CONNECTION_CLOSED),n(e.ErrorCode.RC_SOCKET_DISCONNECTED)})),r.onError((t=>{T.error("websocket error -> ",t),this.onDisconnect(e.ConnectionStatus.WEBSOCKET_ERROR),n(e.ErrorCode.RC_SOCKET_NOT_CREATED)})),r.onOpen((()=>{T.info("websocket open -> ",t),n(e.ErrorCode.SUCCESS)})),setTimeout((()=>{n(e.ErrorCode.TIMEOUT)}),this.options.webSocketTimeout)}))}async auth(){var t,r,n,o;T.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(P.Auth,i,{encoder:Vr,decoder:Xr.AuthSignIn2TokenResp},8e3);return s===e.ErrorCode.SUCCESS||c?(T.info("auth success -> ",null===(t=c.user)||void 0===t||null===(r=t.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),e.ErrorCode.SUCCESS):(T.warn("auth failed -> "+a),e.ErrorCode.RC_CONN_NOT_AUTHRORIZED)}async checkAlive(){if(!this.socket||!this.isAuthorized)return;T.debug("send ping ->");const t={pingId:rn.ZERO,disconnectDelay:rn.ZERO},{code:r}=await this.send(P.Heartbean,t,{encoder:Kr},this.options.pingTimeout);r===e.ErrorCode.SUCCESS?(T.debug("recv pong <-"),this.failedCount=0,setTimeout((()=>this.checkAlive()),this.options.pingInterval)):(this.failedCount+=1,T.warn(`ping failed count: ${this.failedCount}, code: ${r}`),this.failedCount>=this.options.pingFailedTimes?(this.failedCount=0,T.warn("ping timeout, close current websocket to reconnect!"),this.onDisconnect(e.ConnectionStatus.NETWORK_UNAVAILABLE)):this.checkAlive())}onReceiveMessage(t){let r;try{const e=An(t);r=Xr.NetworkResponse.decode(e)}catch(t){return T.error("unpack payload error -> ",t),void this.onDisconnect(e.ConnectionStatus.DISCONNECT_BY_SERVER)}if(r.code)return void this.onDisconnect(e.ConnectionStatus.DISCONNECT_BY_SERVER);if(r.cmdId===P.SessionKilledPush)return void this.onDisconnect(e.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT);if(r.cmdId===P.SignOutPish||r.cmdId===P.SignOutPish2)return void this.onDisconnect(e.ConnectionStatus.DISCONNECT_BY_SERVER);if(r.cmdId===P.UserFrozenToLogin||r.cmdId===P.UserFrozenToLogin2)return void this.onDisconnect(e.ConnectionStatus.BLOCKED);const n=rn.isLong(r.messageSeq)?r.messageSeq.toNumber():0;T.reqInfo(`websocket recv ack -> messageSeq: ${n}`);const o=this.responseCallbacks.get(n);var i;p(o)?(o(r.body),this.responseCallbacks.delete(n)):(T.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.ConnectionStatus.CONNECTED),this.checkAlive(),p(this.reconnectTimer)&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}onDisconnect(e){p(this.socket)&&(this.doClose(),this.isConnectionAvailable()&&(this.setStatus(e),this.autoReconnect&&this.isConnectionAvailable()&&this.try2Reconnect()))}doClose(){if(p(this.socket)){const e=this.socket;this.socket=null,e.onClose(null),e.close()}p(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.ConnectionStatus.DISCONNECTED&&this.status!==e.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT&&this.status!==e.ConnectionStatus.BLOCKED&&this.status!==e.ConnectionStatus.DISCONNECT_BY_SERVER}setStatus(e){var t;e!==this.status&&(T.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===P.Auth}generateMessageSeq(){return++this.idCount}};var Mn=new class{constructor(){h(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;p(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:""}}},xn=Lt.exports,Dn=xn.Reader,Bn=xn.util,Un=xn.roots.default||(xn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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(){h(this,"_token",""),h(this,"_uploadUrl",""),h(this,"_downloadUrl",""),h(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 E(e)?e.startsWith("http")?e:this.fileDownloadUrl+e:e}try2ExtractFileRelativeUri(e){return E(e)&&e.startsWith(this.fileDownloadUrl)?e.substring(this.fileDownloadUrl.length):e}};const Fn="SG",Gn="::",qn=t=>{if(!E(t.targetId+""))return"";switch(t.conversationType){case e.ConversationType.PRIVATE:return"P::"+t.targetId;case e.ConversationType.GROUP:return"G::"+t.targetId;case e.ConversationType.ULTRA_GROUP:return`SG::${t.targetId}_${t.channelId??""}`;default:return""}},Hn=t=>{if(!E(t))return null;const r=t.split(Gn);if(2!==r.length)return null;const n=r[0];if("G"===n)return{conversationType:e.ConversationType.GROUP,targetId:r[1]};if("P"===n)return{conversationType:e.ConversationType.PRIVATE,targetId:r[1]};if(n===Fn){const t=r[1].indexOf("_");if(t>0){const n=r[1].substring(0,t),o=r[1].substring(t+1);return{conversationType:e.ConversationType.ULTRA_GROUP,targetId:n,channelId:o}}return 0===t?null:{conversationType:e.ConversationType.ULTRA_GROUP,targetId:r[1]}}return null},zn=e=>e.startsWith(Fn)||e.startsWith("G");var Kn=Lt.exports,Vn=Kn.Writer,Wn=Kn.util,$n=Kn.roots.default||(Kn.roots.default={});$n.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=Wn.Long?Wn.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=Wn.newBuffer([]),e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Vn.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}(),$n.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=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.msgIdList=Wn.emptyArray,e.encode=function(e,t){if(t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.emptyArray,e.encode=function(e,t){if(t||(t=Vn.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}(),$n.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=Wn.emptyArray,e.prototype.clientSign="",e.encode=function(e,t){if(t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.oldOffset=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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 Jn=$n,Zn=Lt.exports,Xn=Zn.Writer,Yn=Zn.util,Qn=Zn.roots.default||(Zn.roots.default={});Qn.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=Yn.Long?Yn.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=Yn.emptyArray,e.prototype.extra="",e.prototype.assign="",e.prototype.atAll=!1,e.prototype.msgContent=Yn.newBuffer([]),e.encode=function(e,t){if(t||(t=Xn.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}(),Qn.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=Xn.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}(),Qn.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=Xn.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}(),Qn.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=Xn.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}(),Qn.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=Yn.Long?Yn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Xn.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}(),Qn.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=Xn.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 eo=Qn;const to=Lt.exports.Reader,ro=Lt.exports.util,no=Lt.exports.roots.default||(Lt.exports.roots.default={}),oo=no.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=ro.Long?ro.Long.fromBits(0,0,!1):0,e.prototype.msgId=ro.Long?ro.Long.fromBits(0,0,!1):0,e.prototype.msgSendTime=ro.Long?ro.Long.fromBits(0,0,!1):0,e.prototype.seqno=ro.Long?ro.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof to||(e=to.create(e));let r=void 0===t?e.len:e.pos+t,n=new no.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})(),io=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),Ln.send(e.dialogId.startsWith(Fn)?P.GetSuperGroupRemoteMessages:P.GetRemoteMessages,t,{encoder:Jn.GetHistoryMessageReq,decoder:jn.GetHistoryMessageResp})};let so=0;const ao=async()=>{const t=(new Date).getTime(),{code:r,data:n}=await Ln.send(P.GetServerTime,null,{decoder:Xr.SystemCurrentTimeMillisResp});if(r===e.ErrorCode.SUCCESS){const{currentTimeMillis:e}=n;so=e.toNumber()-t}},co=()=>(new Date).getTime()+so,lo=new Set;var uo={addMessage(e){lo.add(e)},remove(e){lo.delete(e)},has:e=>lo.has(e),reset(){lo.clear()}};const ho=new Set;var fo={addMessage(e){ho.add(e)},remove(e){ho.delete(e)},has:e=>ho.has(e),reset(){ho.clear()}};const po=new Map;function go(e){po.set(e.getObjectId(),e.decode.bind(e))}class yo{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];h(this,"messageType",void 0),h(this,"content",void 0),h(this,"isPersited",void 0),h(this,"isCounted",void 0),h(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 vo=0,mo=268439552,bo=268439563,Co=268439562,wo=268439553,Eo=268439581,So=268439597,Oo=268439613,_o=268439629,Io=1610678301,To=268439645,Ro="RC:TxtMsg",ko="RC:HQVCMsg",No="RC:FileMsg",Ao="RC:ImgMsg",Lo="RC:GIFMsg",Mo="RC:RcNtf",xo="RC:CmdMsg";class Do extends yo{constructor(e){super(Ro,e)}static getObjectId(){return vo}static decode(e){const{user:t,extra:r,content:n}=e;return new Do({user:t,extra:r,content:n})}encode(){const{user:e,extra:t,content:r}=this.content;return{user:e,extra:t,content:r}}}class Bo extends yo{constructor(e){super(Ao,e)}static getObjectId(){return mo}static decode(e){const{user:t,extra:r,thumbnailObjectKey:n,originalObjectKey:o,width:i,height:s}=e;return new Bo({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 Uo extends yo{constructor(e){super(Lo,e)}static getObjectId(){return bo}static decode(e){const{user:t,extra:r,size:n,originalObjectKey:o,width:i,height:s}=e;return new Uo({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 jo extends yo{constructor(e){super(ko,e)}static getObjectId(){return wo}static decode(e){const{user:t,extra:r,length:n,audioObjectKey:o,extension:i}=e;return new jo({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 Po extends yo{constructor(e){super(No,e)}static getObjectId(){return Co}static decode(e){const{user:t,extra:r,title:n,extension:o,size:i,originalObjectKey:s}=e;return new Po({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 Fo extends yo{constructor(e){super(Mo,e,!0,!1,!1)}static getObjectId(){return Io}static decode(e){return new Fo(e)}encode(){return this.content}}class Go extends yo{constructor(e){super(xo,e,!1,!1)}static getObjectId(){return To}static decode(e){return new Go(e)}encode(){return this.content}}class qo extends yo{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 Ho extends qo{constructor(e,t){super(e,t,!1,!1)}static getObjectId(){return Eo}}class zo extends qo{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return So}}class Ko extends qo{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return Oo}}class Vo extends qo{constructor(e,t){super(e,t,!1,!1,!0)}static getObjectId(){return _o}}var Wo=new class{constructor(){h(this,"aesKeyRecord",new Map)}async getDialogAesKey(e){return E(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(!E(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(t){if(!t.length)return new Map;const{code:r,data:n}=await(o=t,Ln.send(P.GetDialogKey,{destId:o,clientSign:""},{encoder:Jn.GetDialogKeyReq,decoder:jn.GetDialogKeyResp}));var o;if(r===e.ErrorCode.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 E(e)?this.aesKeyRecord.get(e):null}};const $o="time",Jo=(e,t)=>[e,t,$o].join("_");class Zo{constructor(e,t){h(this,"appkey",void 0),h(this,"userId",void 0),h(this,"inBoxOffset",rn.ZERO),this.appkey=e,this.userId=t}setInboxOffset(e){if(this.inBoxOffset>e)return;this.inBoxOffset=e;const t=Jo(this.appkey,this.userId);kt.set(t,e.toString())}getInboxOffset(){if(this.inBoxOffset.isZero()){const e=Jo(this.appkey,this.userId);this.inBoxOffset=rn.fromString(kt.get(e)??"0")}return this.inBoxOffset}}const Xo=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 Yo=(e,t,r)=>{const n={};return e.forEach((e=>{const o=Qo(e,t.get(e),r.get(e));o.length&&(n[e]=o)})),n},Qo=(t,r,n)=>{const o=Hn(t);if(!o)return[];const i=new Set;let s=[];return r.forEach((t=>{const r=t;let a=r.mediaConstructor,c=ei(r,n);if(!c)return;if(1610678290===a||1610743841===a){const{msgId:e,sendTime:t}=c,n={sentTime:t,messageUId:e,conversationType:o.conversationType,targetId:r.isOut?o.targetId:Mn.uid,channelId:o.channelId};a=Io,c=n,i.add(e)}const l=function(e,t){const r=po.get(e);return r?r(t):null}(a,c);if(p(l)){const t={...o,senderUserId:r.srcId.toString(),messageDirection:r.isOut?e.MessageDirection.SEND:e.MessageDirection.RECEIVE,isCounted:l.isCounted,isMentioned:r.atFlag,content:l.content,messageType:l.messageType,isOffLineMessage:!1,isPersited:l.isPersited,messageId:rn.isLong(r.localId)?r.localId.toNumber():void 0,messageUId:r.msgId.toString(),sentTime:r.seqno.toNumber(),receivedTime:co(),isStatusMessage:l.isStatusMessage,receivedStatus:e.ReceivedStatus.READ,disableNotification:!1};if(t.isStatusMessage&&co()-t.sentTime>6e3)return;s.push(t)}})),i.size&&(s=s.filter((e=>!i.has(e.messageUId)))),s},ei=(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 Et.AES.decrypt(r,Et.enc.Utf8.parse(t.key),{iv:p(t.iv)?Et.enc.Utf8.parse(t.iv):void 0}).toString(Et.enc.Utf8)})(e.msgContent,t):e.msgPreContent??"",1610678290!==e.mediaConstructor&&1610743841!==e.mediaConstructor||(o=ti(o));let i={};return null!==(n=o)&&void 0!==n&&n.length&&(i=JSON.parse(o)),i}catch(t){return T.error("decode message content fail -> uid:",e.msgId.toString()),null}},ti=e=>e.replace(/("msgId")\s*:\s*(\d+)/g,((e,t,r)=>`${t}:"${r}"`));var ri={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());Wo.getDialogAesKeyListInBatches([...r.keys()],((e,o)=>{if(o.size){const e=[...o.keys()];for(const t of e)n.delete(t);t(!n.size,Yo(e,r,o))}n.size&&e&&t(!0,{})}))},parseSingleDialogMessages:Qo};function ni(e){if(!p(e))return e;if(Array.isArray(e))return e.map((e=>ni(e)));if(b(e)){const t={};return Object.keys(e).forEach((r=>{t[r]=ni(e[r])})),t}return e}const oi={unreadMessageCount:{keyName:"c",defaultVal:0},lastUnreadTime:{keyName:"t",defaultVal:0},notificationStatus:{keyName:"nc",defaultVal:2},notificationLevel:{keyName:"nl",defaultVal:0},isTop:{keyName:"it",defaultVal:!1},mentionedUIds:{keyName:"mu",defaultVal:null}};class ii{constructor(e,t){h(this,"localStore",void 0);const r=`con-${e}-${t}`;this.localStore=new At(r)}getStoreKey(e){return`${e.conversationType}_${e.targetId}_${e.channelId??""}`}getConOptionByKey(t){const r=(t=t||"").split("_");if(r.length>=2){const e=r.shift(),t=r.shift(),n=r.join("_");return{conversationType:Number(e),targetId:t,channelId:n}}return{conversationType:e.ConversationType.PRIVATE,targetId:"",channelId:""}}updateUnreadCount(t){const{conversationType:r,targetId:n,channelId:o,content:i,messageType:s,sentTime:a,isCounted:c,messageDirection:l}=t,u=l===e.MessageDirection.SEND,d=s===Mo,h=b(i),f={conversationType:r,targetId:n,channelId:o},p=this.get(f)||{},g=p.lastUnreadTime||0,y=p.unreadMessageCount||0;if(!(g>a)&&!u){if(c&&(p.unreadMessageCount=y+1,p.lastUnreadTime=a),d&&h){g>=i.sentTime&&y&&(p.unreadMessageCount=y-1)}this.set(f,p)}}updateMentionedData(t){const{conversationType:r,targetId:n,channelId:o,messageUId:i,messageType:s,isMentioned:a,messageDirection:c,content:l}=t;if(c===e.MessageDirection.SEND||!a&&s!==Mo)return;const u=this.getStoreKey({conversationType:r,targetId:n,channelId:o}),d=this.localStore.get(u)||{},h=oi.mentionedUIds.keyName,f=d[h]||[];if(a&&r===e.ConversationType.GROUP&&(f.includes(i)||f.push(i)),s===Mo&&r===e.ConversationType.GROUP){const e=l,t=f.indexOf(e.messageUId);t>=0&&f.splice(t,1)}f.length?d[h]=f:delete d[h],S(d)?this.localStore.set(u,d):this.localStore.remove(u)}set(e,t){const r=this.getStoreKey(e),n=this.localStore.get(r)||{};for(const e of St(t)){const r=oi[e],o=t[e];if(v(null==r?void 0:r.keyName)||v(o))continue;o===r.defaultVal?delete n[r.keyName]:n[r.keyName]=o,n[oi.unreadMessageCount.keyName]||(delete n[oi.lastUnreadTime.keyName],delete n[oi.mentionedUIds.keyName])}S(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 St(oi)){const{keyName:t,defaultVal:i}=oi[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]||ni(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 St(oi)){const{keyName:t,defaultVal:r}=oi[e];"mentionedUIds"!==e&&(n[e]=o[t]||ni(r))}t.push(n)}return t}}const si=t=>{const r=t.destId??"",n=Hn(r);if(!n)return;return{...n,unreadMessageCount:0,notificationStatus:t.muteFlag?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,notificationLevel:g(t.pushNotificationLevel)&&0!==t.pushNotificationLevel&&p(e.NotificationLevel[t.pushNotificationLevel])?t.pushNotificationLevel:t.muteFlag?e.NotificationLevel.AT_USER_NOTIFICATION:e.NotificationLevel.NOT_SET,isTop:!!t.stickyFlag,lastUnreadTime:0}},ai="STATUS_CHANGED";class ci{constructor(e,t){h(this,"storageKey",void 0),h(this,"eventEmitter",void 0),h(this,"isPulling",!1),this.storageKey=`con-s-${e}-${t}`,this.eventEmitter=new U}async pull(){if(this.isPulling)return;let t;this.isPulling=!0;const r=kt.get(this.storageKey);t=g(r)&&r>0?r:co()-1e4;let{code:n,data:o}=await(e=>Ln.send(P.GetDialogChangedStatus,{time:rn.fromNumber(e)},{encoder:Jn.GetNewSettingDialogListReq,decoder:jn.GetNewSettingDialogListResp}))(t);n===e.ErrorCode.SUCCESS&&(o.setTime.toNumber()>0&&kt.set(this.storageKey,o.setTime.toNumber()),o.briefDialog&&St(o.briefDialog).forEach((e=>{const t=o.briefDialog[e],r=si(t);r&&this.eventEmitter.emit(ai,r)}))),this.isPulling=!1}watch(e){this.eventEmitter.on(ai,(t=>{e(t)}))}}class li{constructor(e,t,r){h(this,"updatedConversationFunc",void 0),h(this,"store",void 0),h(this,"draftMap",new Map),h(this,"localConversationSet",new Set),h(this,"updatedConversations",[]),h(this,"notify",void 0),h(this,"statusManager",void 0),this.updatedConversationFunc=r,this.store=new ii(e,t),this.notify=_t(this.notifyConversationChanged.bind(this),0),this.statusManager=new ci(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(t){if(null==t||!t.length)return;const r=t.filter((e=>!this.localConversationSet.has(this.getConversationKey(e))));if(!r.length)return;const n=r.map(qn).filter(E);if(!n.length)return;const{code:o,data:i}=await(e=>Ln.send(P.GetBriefDialogList,{destId:e},{encoder:Jn.GetBriefDialogListReq,decoder:jn.GetBriefDialogListResp}))(n);o===e.ErrorCode.SUCCESS&&St(i.briefDialog).forEach((e=>{const t=i.briefDialog[e],r=si(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=co(),u=this.store.get(c),d={};p(i)&&u.notificationLevel!==i&&(d.notificationLevel={time:l,val:i}),p(o)&&u.notificationStatus!==o&&(d.notificationStatus={time:l,val:o}),p(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=ni(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(t,r){const n=this.store.getAll();let o=0;return n.forEach((n=>{let{unreadMessageCount:i,notificationStatus:s,notificationLevel:a,conversationType:c}=n;i=i||0;const l=s===e.NotificationStatus.OPEN||a>0;!r&&l||(t.length>0?t.includes(+c)&&(o+=+i):o+=+i)})),o}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:co()}),n&&(o.hasMentioned={val:!1,time:co()},o.unreadMentionedCount={val:0,time:co()}),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((t=>t.notificationStatus===e.NotificationStatus.OPEN||t.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 ui={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(t){return e.NotificationLevel.NOT_SET},getNotificationStatus:function(t){return e.NotificationStatus.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 di;var hi={create(e,t,r){di=new li(e,t,r)},get:()=>di??ui};class fi{constructor(e,t){h(this,"watcher",void 0),h(this,"pullingMsg",!1),h(this,"letterbox",void 0),h(this,"serverMsgSeqno",rn.ZERO),h(this,"pullOfflineFinished",!1),h(this,"intervalTimer",void 0),h(this,"retryTimer",void 0),h(this,"latestSyncTimestamp",0),h(this,"started",!1),this.watcher=e,this.letterbox=new Zo(t.appkey,Mn.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 t=this.letterbox.getInboxOffset();this.pullOfflineFinished||T.info(`pullMsg -> time: ${t}`),this.latestSyncTimestamp=Date.now();const{code:r,data:n}=await((e,t)=>Ln.send(P.GetNewMessage,{offset:e,rows:t},{encoder:Jn.GetNewMessageReq,decoder:jn.GetNewMessageResp}))(t,60);if(r!==e.ErrorCode.SUCCESS)return this.pullOfflineFinished||T.warn("pullMsg failed -> code:",r),this.pullingMsg=!1,void this.try2RePullMsg();const{offset:o,seqno:i,msg:s}=n,a=Object.keys(s).map(Hn).filter((e=>p(e)));hi.get().loadConvsationsIfNotExist(a),ri.parse(s,((t,r)=>{const n=[],s=[],a=!this.pullOfflineFinished;var c,l;(Object.keys(r).forEach((t=>{const o=r[t],i=[];if(o.forEach((t=>{t.messageDirection===e.MessageDirection.SEND&&t.messageId&&uo.has(t.messageId)?uo.remove(t.messageId):t.messageType===Mo&&fo.has(t.content.messageUId)?fo.remove(t.content.messageUId):(t.isOffLineMessage=a,hi.get().setConversationCacheByMessage(t),i.push(t))})),n.push(...i),this.isExistPersistedMessage(i)){const e=Hn(t);e&&s.push(e)}})),n.length)&&(null===(c=(l=this.watcher).batchMessage)||void 0===c||c.call(l,n));if(s.length&&hi.get().loadConvsationsIfNotExist(s),t){var u;i.ge(this.serverMsgSeqno)&&(this.serverMsgSeqno=i);const e=this.serverMsgSeqno.lessThanOrEqual(o);this.pullOfflineFinished||T.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 pi{static init(e){return this._loader||(this._loader=new pi(e)),this._loader}static get loader(){return this._loader}constructor(t){h(this,"options",void 0),h(this,"connectionStatus",e.ConnectionStatus.DISCONNECTED),h(this,"isInternalConnected",!1),h(this,"watcher",void 0),h(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},Ln.setServerInfo(this.getWebSocketUrl()),Ln.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 E(t)?w(r=t)&&/wss?:\/\//.test(r)?t:"ws://"+t:"wss://tt.mimelabs.xyz:8991";var r}registerMessage(){go(Do),go(Bo),go(Uo),go(jo),go(Ho),go(Ko),go(zo),go(Vo),go(Fo),go(Go),go(Po)}async connect(t){if(this.connectionStatus===e.ConnectionStatus.CONNECTED)return{code:e.ErrorCode.SUCCESS,userId:Mn.uid+""};if(this.connectionStatus===e.ConnectionStatus.CONNECTING)return{code:e.ErrorCode.BIZ_ERROR_CONNECTING};if("string"!=typeof t||0===t.length)return{code:e.ErrorCode.RC_CONN_USER_OR_PASSWD_ERROR};Pn.imInitToken=t;const r=await Ln.connect(t);var n;r===e.ErrorCode.SUCCESS&&(this.isInternalConnected=!0,hi.get().destroyed(),hi.create(this.options.appkey,Mn.uid,this.watcher.conversationState),null===(n=this.messageLoader)||void 0===n||n.stop(),this.messageLoader=new fi(this.watcher,this.options),ao(),uo.reset(),fo.reset(),Wo.reset());return{code:r,userId:Mn.uid+""}}reconnect(){return this.isInternalConnected?Promise.resolve({code:e.ErrorCode.CAN_NOT_RECONNECT}):this.connect(Pn.imInitToken)}disconnect(){return this.isInternalConnected=!1,Ln.close(),Promise.resolve()}getConnectionStatus(){return this.connectionStatus}assignWatcher(e){St(this.watcher).forEach((t=>{if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this.watcher[t]=m(r)?r:void 0}}))}resetWatcher(){St(this.watcher).forEach((e=>{this.watcher[e]=void 0}))}async connectionStatusListener(t){this.connectionStatus=t,setTimeout((()=>{switch(t){case e.ConnectionStatus.BLOCKED:case e.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT:case e.ConnectionStatus.DISCONNECT_BY_SERVER:this.handleDisconnect();break;case e.ConnectionStatus.CONNECTING:this.handleConnecting();break;case e.ConnectionStatus.CONNECTED:this.handleConnected();break;case e.ConnectionStatus.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.ConnectionStatus.CONNECTED&&hi.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===P.NewMessagePush){var r;const e=jn.NewMessageNotificationResp.decode(t);null===(r=this.messageLoader)||void 0===r||r.syncMsg(e.seqno)}else e===P.DialogChangedPush&&hi.get().syncConversationStatus()}authListener(e){Pn.setFileServerInfo(e.fileDomain,e.dialogFileDomain,e.cert),Mn.setLogged(e,Pn.imInitToken)}needReAuthProvider(){return!Mn.user.active||Mn.user.token!==Pn.imInitToken}needProfileProvider(){if(!this.needReAuthProvider()){const{deviceId:e,sessionId:t,uid:r}=Mn.user;return{deviceId:e,sessionId:t,uid:r}}return null}}h(pi,"_loader",void 0);var gi,yi,vi,mi,bi={exports:{}},Ci={exports:{}},wi={exports:{}},Ei={exports:{}};var Si,Oi={};var _i,Ii,Ti,Ri,ki,Ni,Ai,Li,Mi,xi,Di,Bi,Ui,ji={};function Pi(){return _i||(_i=1,function(e){var t=e,r=ms(),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])}(ji)),ji}function Fi(){if(Ti)return Ii;Ti=1,Ii=s;var e=bs();((s.prototype=Object.create(e.prototype)).constructor=s).className="Field";var t,r=Cs(),n=Pi(),o=ms(),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},Ii}function Gi(){if(ki)return Ri;ki=1,Ri=n;var e=bs();((n.prototype=Object.create(e.prototype)).constructor=n).className="OneOf";var t=Fi(),r=ms();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)})}},Ri}function qi(){if(Ai)return Ni;Ai=1,Ni=c;var e=bs();((c.prototype=Object.create(e.prototype)).constructor=c).className="Namespace";var t,r,n,o=Fi(),i=ms(),s=Gi();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},Ni}function Hi(){if(Mi)return Li;Mi=1,Li=n;var e=Fi();((n.prototype=Object.create(e.prototype)).constructor=n).className="MapField";var t=Pi(),r=ms();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))}},Li}function zi(){if(Di)return xi;Di=1,xi=r;var e=bs();((r.prototype=Object.create(e.prototype)).constructor=r).className="Method";var t=ms();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))},xi}function Ki(){if(Ui)return Bi;Ui=1,Bi=o;var e=qi();((o.prototype=Object.create(e.prototype)).constructor=o).className="Service";var t=zi(),r=ms(),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},Bi}var Vi,Wi,$i,Ji,Zi=Yi,Xi=Xt();function Yi(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)this[t[r]]=e[t[r]]}function Qi(){if(Wi)return Vi;Wi=1,Vi=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=Cs(),t=Pi(),r=ms();function n(e){return"missing required '"+e.name+"'"}return Vi}function es(){if(Ji)return $i;Ji=1,$i=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=Cs(),t=ms();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 $i}Yi.create=function(e){return this.$type.create(e)},Yi.encode=function(e,t){return this.$type.encode(e,t)},Yi.encodeDelimited=function(e,t){return this.$type.encodeDelimited(e,t)},Yi.decode=function(e){return this.$type.decode(e)},Yi.decodeDelimited=function(e){return this.$type.decodeDelimited(e)},Yi.verify=function(e){return this.$type.verify(e)},Yi.fromObject=function(e){return this.$type.fromObject(e)},Yi.toObject=function(e,t){return this.$type.toObject(e,t)},Yi.prototype.toJSON=function(){return this.$type.toObject(this,Xi.toJSONOptions)};var ts,rs={};function ns(){return ts||(ts=1,function(e){var t=e,r=Cs(),n=ms();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")}}(rs)),rs}var os,is,ss,as,cs,ls,us,ds,hs,fs,ps,gs={};function ys(){if(is)return os;is=1,os=g;var e=qi();((g.prototype=Object.create(e.prototype)).constructor=g).className="Type";var t=Cs(),r=Gi(),n=Fi(),o=Hi(),i=Ki(),s=Zi,a=Cr,c=Qt,l=ms(),u=ws(),d=Qi(),h=es(),f=ns(),p=gs;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)}},os}function vs(){if(as)return ss;as=1,ss=c;var e=qi();((c.prototype=Object.create(e.prototype)).constructor=c).className="Root";var t,r,n,o=Fi(),i=Cs(),s=Gi(),a=ms();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},ss}function ms(){return cs||(cs=1,function(e){var t,r,n=e.exports=Xt(),o=Fr;n.codegen=function(){if(yi)return gi;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 yi=1,gi=e,e.verbose=!1,gi}(),n.fetch=function(){if(mi)return vi;mi=1,vi=r;var e=Dt,t=Kt();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()},vi}(),n.path=(Si||(Si=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)}}(Oi)),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=ys());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=Cs());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(vs()))}})}(Ei)),Ei.exports}function bs(){if(us)return ls;us=1,ls=r,r.className="ReflectionObject";var e,t=ms();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},ls}function Cs(){if(hs)return ds;hs=1,ds=n;var e=bs();((n.prototype=Object.create(e.prototype)).constructor=n).className="Enum";var t=qi(),r=ms();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)},ds}function ws(){if(ps)return fs;ps=1,fs=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=Cs(),t=Pi(),r=ms();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 fs}!function(e){var t=Zi;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)}}}(gs),function(e){var t=e.exports=Mt;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=ws(),t.decoder=Qi(),t.verifier=es(),t.converter=ns(),t.ReflectionObject=bs(),t.Namespace=qi(),t.Root=vs(),t.Enum=Cs(),t.Type=ys(),t.Field=Fi(),t.OneOf=Gi(),t.MapField=Hi(),t.Service=Ki(),t.Method=zi(),t.Message=Zi,t.wrappers=gs,t.types=Pi(),t.util=ms(),t.ReflectionObject._configure(t.Root),t.Namespace._configure(t.Type,t.Service,t.Enum),t.Root._configure(t.Type),t.Field._configure(t.Type)}(wi);var Es=Ms,Ss=/[\s{}=;:[\],'"()<>]/g,Os=/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,_s=/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,Is=/^ *[*/]+ */,Ts=/^\s*\*?\/*/,Rs=/\n/g,ks=/\s/,Ns=/\\(.?)/g,As={0:"\0",r:"\r",n:"\n",t:"\t"};function Ls(e){return e.replace(Ns,(function(e,t){switch(t){case"\\":case"":return t;default:return As[t]||""}}))}function Ms(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(Rs),h=0;h<d.length;++h)d[h]=d[h].replace(t?Ts:Is,"").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?_s:Os;t.lastIndex=r-1;var n=t.exec(e);if(!n)throw l("string");return r=t.lastIndex,g(c),c=null,Ls(n[1])}();var i,s,p,y,v,m=0===r;do{if(r===n)return null;for(i=!1;ks.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(Ss.lastIndex=0,!Ss.test(u(b++)))for(;b<n&&!Ss.test(u(b));)++b;var C=e.substring(r,r=b);return'"'!==C&&"'"!==C||(c=C),C}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}})}Ms.unescape=Ls;var xs=ra;ra.filename=null,ra.defaults={keepCase:!1};var Ds=Es,Bs=vs(),Us=ys(),js=Fi(),Ps=Hi(),Fs=Gi(),Gs=Cs(),qs=Ki(),Hs=zi(),zs=Pi(),Ks=ms(),Vs=/^[1-9][0-9]*$/,Ws=/^-?[1-9][0-9]*$/,$s=/^0[x][0-9a-fA-F]+$/,Js=/^-?0[x][0-9a-fA-F]+$/,Zs=/^0[0-7]+$/,Xs=/^-?0[0-7]+$/,Ys=/^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,Qs=/^[a-zA-Z_][a-zA-Z_0-9]*$/,ea=/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,ta=/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;function ra(e,t,r){t instanceof Bs||(r=t,t=new Bs),r||(r=ra.defaults);var n,o,i,s,a,c=r.preferTrailingComment||!1,l=Ds(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}:Ks.camelCase;function b(e,t,r){var n=ra.filename;return r||(ra.filename=null),Error("illegal "+(t||"token")+" '"+e+"' ("+(n?n+", ":"")+"line "+l.line+")")}function C(){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 w(e){var t=u();switch(t){case"'":case'"':return d(t),C();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(Vs.test(e))return r*parseInt(e,10);if($s.test(e))return r*parseInt(e,16);if(Zs.test(e))return r*parseInt(e,8);if(Ys.test(e))return r*parseFloat(e);throw b(e,"number",t)}(t,!0)}catch(r){if(e&&ea.test(t))return t;throw b(t,"value")}}function E(e,t){var r,n;do{!t||'"'!==(r=h())&&"'"!==r?e.push([n=S(u()),f("to",!0)?S(u()):n]):e.push(C())}while(f(",",!0));f(";")}function S(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(Ws.test(e))return parseInt(e,10);if(Js.test(e))return parseInt(e,16);if(Xs.test(e))return parseInt(e,8);throw b(e,"id")}function O(){if(void 0!==n)throw b("package");if(n=u(),!ea.test(n))throw b(n,"name");v=v.define(n),f(";")}function _(){var e,t=h();switch(t){case"weak":e=i||(i=[]),u();break;case"public":u();default:e=o||(o=[])}t=C(),f(";"),e.push(t)}function I(){if(f("="),s=C(),!(y="proto3"===s)&&"proto2"!==s)throw b(s,"syntax");f(";")}function T(e,t){switch(t){case"option":return L(e,t),f(";"),!0;case"message":return k(e,t),!0;case"enum":return A(e,t),!0;case"service":return function(e,t){if(!Qs.test(t=u()))throw b(t,"service name");var r=new qs(t);R(r,(function(e){if(!T(r,e)){if("rpc"!==e)throw b(e);!function(e,t){var r=p(),n=t;if(!Qs.test(t=u()))throw b(t,"name");var o,i,s,a,c=t;f("("),f("stream",!0)&&(i=!0);if(!ea.test(t=u()))throw b(t);o=t,f(")"),f("returns"),f("("),f("stream",!0)&&(a=!0);if(!ea.test(t=u()))throw b(t);s=t,f(")");var l=new Hs(c,n,o,s,i,a);l.comment=r,R(l,(function(e){if("option"!==e)throw b(e);L(l,e),f(";")})),e.add(l)}(r,e)}})),e.add(r)}(e,t),!0;case"extend":return function(e,t){if(!ea.test(t=u()))throw b(t,"reference");var r=t;R(null,(function(t){switch(t){case"required":case"repeated":N(e,t,r);break;case"optional":N(e,y?"proto3_optional":"optional",r);break;default:if(!y||!ea.test(t))throw b(t);d(t),N(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=ra.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(!Qs.test(t=u()))throw b(t,"type name");var r=new Us(t);R(r,(function(e){if(!T(r,e))switch(e){case"map":!function(e){f("<");var t=u();if(void 0===zs.mapKey[t])throw b(t,"type");f(",");var r=u();if(!ea.test(r))throw b(r,"type");f(">");var n=u();if(!Qs.test(n))throw b(n,"name");f("=");var o=new Ps(m(n),S(u()),t,r);R(o,(function(e){if("option"!==e)throw b(e);L(o,e),f(";")}),(function(){D(o)})),e.add(o)}(r);break;case"required":case"repeated":N(r,e);break;case"optional":N(r,y?"proto3_optional":"optional");break;case"oneof":!function(e,t){if(!Qs.test(t=u()))throw b(t,"name");var r=new Fs(m(t));R(r,(function(e){"option"===e?(L(r,e),f(";")):(d(e),N(r,"optional"))})),e.add(r)}(r,e);break;case"extensions":E(r.extensions||(r.extensions=[]));break;case"reserved":E(r.reserved||(r.reserved=[]),!0);break;default:if(!y||!ea.test(e))throw b(e);d(e),N(r,"optional")}})),e.add(r)}function N(e,t,r){var n=u();if("group"!==n){if(!ea.test(n))throw b(n,"type");var o=u();if(!Qs.test(o))throw b(o,"name");o=m(o),f("=");var i=new js(o,S(u()),n,t,r);if(R(i,(function(e){if("option"!==e)throw b(e);L(i,e),f(";")}),(function(){D(i)})),"proto3_optional"===t){var s=new Fs("_"+o);i.setOption("proto3_optional",!0),s.add(i),e.add(s)}else e.add(i);y||!i.repeated||void 0===zs.packed[n]&&void 0!==zs.basic[n]||i.setOption("packed",!1,!0)}else!function(e,t){var r=u();if(!Qs.test(r))throw b(r,"name");var n=Ks.lcFirst(r);r===n&&(r=Ks.ucFirst(r));f("=");var o=S(u()),i=new Us(r);i.group=!0;var s=new js(n,o,r,t);s.filename=ra.filename,R(i,(function(e){switch(e){case"option":L(i,e),f(";");break;case"required":case"repeated":N(i,e);break;case"optional":N(i,y?"proto3_optional":"optional");break;case"message":k(i,e);break;case"enum":A(i,e);break;default:throw b(e)}})),e.add(i).add(s)}(e,t)}function A(e,t){if(!Qs.test(t=u()))throw b(t,"name");var r=new Gs(t);R(r,(function(e){switch(e){case"option":L(r,e),f(";");break;case"reserved":E(r.reserved||(r.reserved=[]),!0);break;default:!function(e,t){if(!Qs.test(t))throw b(t,"name");f("=");var r=S(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);L(n,e),f(";")}),(function(){D(n)})),e.add(t,r,n.comment,n.options)}(r,e)}})),e.add(r)}function L(e,t){var r=f("(",!0);if(!ea.test(t=u()))throw b(t,"name");var n,o=t,i=o;r&&(f(")"),i=o="("+o+")",t=h(),ta.test(t)&&(n=t.slice(1),o+=t,u())),f("="),function(e,t,r,n){e.setParsedOption&&e.setParsedOption(t,r,n)}(e,i,M(e,o),n)}function M(e,t){if(f("{",!0)){for(var r={};!f("}",!0);){if(!Qs.test(a=u()))throw b(a,"name");var n,o=a;if(f(":",!0),"{"===h())n=M(e,t+"."+a);else if("["===h()){var i;if(n=[],f("[",!0)){do{i=w(!0),n.push(i)}while(f(",",!0));f("]"),void 0!==i&&x(e,t+"."+a,i)}}else n=w(!0),x(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=w(!0);return x(e,t,c),c}function x(e,t,r){e.setOption&&e.setOption(t,r)}function D(e){if(f("[",!0)){do{L(e,"option")}while(f(",",!0));f("]")}return e}for(;null!==(a=u());)switch(a){case"package":if(!g)throw b(a);O();break;case"import":if(!g)throw b(a);_();break;case"syntax":if(!g)throw b(a);I();break;case"option":L(v,a),f(";");break;default:if(T(v,a)){g=!1;continue}throw b(a)}return ra.filename=null,{package:n,imports:o,weakImports:i,syntax:s,root:t}}var na,oa=sa,ia=/\/|\./;function sa(e,t){ia.test(e)||(e="google/protobuf/"+e+".proto",t={nested:{google:{nested:{protobuf:{nested:t}}}}}),sa[e]=t}sa("any",{Any:{fields:{type_url:{type:"string",id:1},value:{type:"bytes",id:2}}}}),sa("duration",{Duration:na={fields:{seconds:{type:"int64",id:1},nanos:{type:"int32",id:2}}}}),sa("timestamp",{Timestamp:na}),sa("empty",{Empty:{fields:{}}}),sa("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}}}}),sa("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}}}}),sa("field_mask",{FieldMask:{fields:{paths:{rule:"repeated",type:"string",id:1}}}}),sa.get=function(e){return sa[e]||null},function(e){var t=e.exports=wi.exports;t.build="full",t.tokenize=Es,t.parse=xs,t.common=oa,t.Root._configure(t.Type,t.parse,t.common)}(Ci),function(e){e.exports=Ci.exports}(bi);var aa=G(bi.exports);const ca=e=>{const t=window.URL||window.webkitURL;return t?t.createObjectURL(e):""},la=e=>{const t=e.name;return E(t)?t.substring(t.lastIndexOf(".")+1):e.type.indexOf("/")>0?e.type.substring(e.type.lastIndexOf("/")+1):""},ua=e=>{(window.URL||window.webkitURL).revokeObjectURL(e)},da=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 ha{constructor(e){h(this,"options",void 0),h(this,"xhr",void 0),this.options=e}upload(e,t){const r=new XMLHttpRequest;r.open("POST",this.options.uploadUrl,!0),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.setRequestHeader("device","7"),r.setRequestHeader("cert",this.options.cert??"");const n=la(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 fa=1680,pa=160,ga=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 ya{constructor(e,t){h(this,"uploadInstance",void 0),h(this,"options",void 0),this.uploadInstance=e,this.options=t}async upload(e,t){try{const r=ca(e),n=await ga(r);ua(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/fa:n/fa;n>fa&&o>fa?e?(s=fa,i/=t):(i=fa,s/=t):n>fa&&o>pa?(i=fa,s/=t,s<pa&&(s=pa,i=n/(o/pa))):o>fa&&n>pa&&(s=fa,i/=t,i<pa&&(i=pa,s=o/(n/pa)))}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:da(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 va{constructor(e){h(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=ca(e),n=await ga(r);ua(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 ma;class ba{constructor(e){h(this,"uploadInstance",void 0),this.uploadInstance=e}upload(e,t){var r;(r=e,O(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:la(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=ma||new AudioContext;return ma=t,new Promise(((r,n)=>{t.decodeAudioData(e,(function(e){r({duration:e.duration,length:e.length})}),n)}))}}class Ca{constructor(e){h(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:la(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 wa;!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"}(wa||(wa={}));const Ea=(t,r,n,o,i,s)=>({conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId,senderUserId:r,messageDirection:e.MessageDirection.SEND,isCounted:n.isCounted,isMentioned:!1,content:n.content,messageType:n.messageType,isOffLineMessage:!1,isPersited:n.isPersited,messageId:o,messageUId:i,sentTime:s,receivedTime:0,isStatusMessage:n.isStatusMessage,receivedStatus:e.ReceivedStatus.UNREAD,disableNotification:!1});let Sa=0;const Oa=[Ao,ko];async function _a(t,r,n){var o;if(!pi.loader||pi.loader.getConnectionStatus()!==e.ConnectionStatus.CONNECTED)return{code:e.ErrorCode.RC_NET_CHANNEL_INVALID};n=n||{};const i=JSON.stringify(Ot(r.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}(i)>81920)return{code:e.ErrorCode.RC_MSG_CONTENT_EXCEED_LIMIT};const s=qn(t);let a;a=p(null===(o=n)||void 0===o?void 0:o.messageId)&&n.messageId>0?n.messageId:function(){Sa++;const e=co();return Sa<e&&(Sa=e),23e13+Sa}(),uo.addMessage(a);const c=Ea(t,Mn.uid,r,a,"",function(){Ma++;const e=co();Ma<e&&(Ma=e);return Ma}());n.onSendBefore&&n.onSendBefore(c),r.isPersited&&hi.get().loadConvsationsIfNotExist([t]);const l=await Wo.getDialogAesKey(s);if(!l)return{code:e.ErrorCode.MSG_ENCRYPT_ERROR,data:c};const u=((e,t)=>{if(!E(e))return new Uint8Array;const r=Et.AES.encrypt(e,Et.enc.Utf8.parse(t.key),{iv:p(t.iv)?Et.enc.Utf8.parse(t.iv):void 0});return Xo(r.ciphertext.words)})(i,l),d={localId:rn.fromNumber(a),mediaFlag:Oa.includes(r.messageType),mediaConstructor:r.objectId,mediaAttribute:"",msgPreContent:"",msgPostContent:"",msgContent:u};let h;if(t.conversationType===e.ConversationType.GROUP){var f,g;const t={...d,groupId:s};if(null!==(f=n)&&void 0!==f&&null!==(g=f.directionalUserIdList)&&void 0!==g&&g.length&&(t.assign=n.directionalUserIdList.join(",")),p(r.content.mentionedInfo)){var y;const n=r.content.mentionedInfo;n.type===e.MentionedType.ALL?t.atAll=!0:n.type===e.MentionedType.SINGAL&&null!==(y=n.userIdList)&&void 0!==y&&y.length&&(t.at=n.userIdList.map((e=>rn.fromString(e))))}h=await(v=t,Ln.send(P.SendGroupChatMessage,v,{encoder:eo.SendGroupChatMessageReq,decoder:oo}))}else{const e={...d,destId:s};h=await(e=>Ln.send(P.SendPrivateChatMessage,e,{encoder:Jn.SendPrivateChatMessageReq,decoder:jn.SendPrivateChatMessageResp}))(e)}var v;return h.code===e.ErrorCode.SUCCESS&&(c.sentTime=h.data.seqno.toNumber(),c.messageUId=h.data.msgId.toString(),hi.get().setConversationCacheByMessage(c)),{code:h.code,data:c}}const Ia=Aa(wa.IMAGE,((e,t)=>new Bo({content:e.thumbnail,imageUri:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),Ta=Aa(wa.GIF,((e,t)=>new Uo({gifDataSize:e.size,remoteUrl:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),Ra=Aa(wa.AUDIO,((e,t)=>new jo({remoteUrl:e.url,duration:e.duration,type:e.type,user:t.user,extra:t.extra}))),ka=Aa(wa.FILE,((e,t)=>new Po({fileUrl:e.url,name:e.name,type:e.type,size:e.size,user:t.user,extra:t.extra}))),Na=async(t,r)=>{const n=qn(t);fo.addMessage(r.messageUId);const o=await((e,t)=>{let r;return r=zn(e)?Ln.send(P.RecallGroupMessage,{groupId:e,msgId:rn.fromString(t)},{encoder:eo.RecallGroupChatMessageReq,decoder:Xr.BaseResp}):Ln.send(P.RecallPrivateMessage,{destId:e,msgId:rn.fromString(t)},{encoder:Jn.RecallPrivateChatMessageReq,decoder:Xr.BaseResp}),r})(n,r.messageUId);if(o.code!==e.ErrorCode.SUCCESS)return{code:o.code};const i=new Fo({sentTime:r.sentTime,messageUId:r.messageUId,...t}),s=Ea(t,Mn.uid,i,0,"",co());return hi.get().setConversationCacheByMessage(s),{code:e.ErrorCode.SUCCESS,data:s}};function Aa(t,r){return function(n,o,i,s){return new Promise((a=>{((e,t,r,n)=>{var o;const i=new ha({token:Pn.imInitToken,uploadUrl:Pn.fileUploadUrl,cert:Pn.cert,transformer:e=>({...e,url:Pn.getFileAbsoluteUri(e.url)})});let s;switch(t){case wa.IMAGE:s=new ya(i,r);break;case wa.GIF:s=new va(i);break;case wa.AUDIO:s=new ba(i);break;case wa.FILE:s=new Ca(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,t,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);_a(n,t,s).then(a)},onFail:()=>{a({code:e.ErrorCode.UPLOAD_FILE_FAILED})}})}))}}let La,Ma=1;class xa extends U{constructor(e){if(xa.imClient)return T.error("Please do not perform the init method repeatedly"),xa.imClient;super(),h(this,"options",void 0),h(this,"libLoader",void 0),h(this,"getServerTime",co),h(this,"sendMessage",_a),h(this,"sendImageMessage",Ia),h(this,"sendGIFMessage",Ta),h(this,"sendHQVoiceMessage",Ra),h(this,"sendFileMessage",ka),h(this,"recallMsg",Na),this.options=e,this.fixedProtobuf(),p(e.logLevel)&&T.setLogLevel(e.logLevel),p(e.logStdout)&&T.setLogStdout(e.logStdout),T.debug("IMClient.init -> ",e.appkey),this.libLoader=pi.init(e),this.watch(),xa.imClient=this}fixedProtobuf(){aa.util.Long=rn,aa.configure()}watch(){this.libLoader.assignWatcher({onConnecting:()=>{this.emit(e.Events.CONNECTING)},onConnected:()=>{this.emit(e.Events.CONNECTED)},onDisconnect:()=>{this.emit(e.Events.DISCONNECT,this.libLoader.getConnectionStatus())},onSuspend:()=>{this.emit(e.Events.SUSPEND,this.libLoader.getConnectionStatus())},batchMessage:t=>{this.emit(e.Events.MESSAGES,{messages:t})},pullFinished:()=>{this.emit(e.Events.PULL_OFFLINE_MESSAGE_FINISHED)},conversationState:t=>{this.emit(e.Events.CONVERSATION,{conversations:t})}})}connect(e){return this.libLoader.connect(e)}disconnect(){return this.libLoader.disconnect()}getConnectionStatus(){return this.libLoader.getConnectionStatus()}async getRemoteHistoryMessages(t,r){const o=qn(t);return io({dialogId:o,offset:r.timestamp??0,count:r.count??20,newToOld:0===r.order}).then((t=>{let{code:r,data:i}=t;return new Promise((t=>{r===e.ErrorCode.SUCCESS?ri.parse({[o]:i.msg??{}},((r,n)=>{const s=n[o]??[];s.sort(((e,t)=>e.sentTime-t.sentTime)),t({code:e.ErrorCode.SUCCESS,data:{list:s,hasMore:!i.isEnd}})})):t({code:r,msg:n(r)})}))}))}async deleteRemoteMessage(e,t){return(r=qn(e),n=t.map((e=>e.messageUId)),Ln.send(P.DeleteChatMessages,{destId:r,msgIdList:n.map((e=>rn.fromString(e)))},{encoder:Jn.DeleteChatMessageReq,decoder:Xr.BaseResp})).then((e=>e.code));var r,n}async deleteRemoteMessageByTimestamp(e,t){return((e,t)=>Ln.send(P.ClearChatHistoryMessage,{destId:e,type:zn(e)?1:0,msgTime:rn.fromNumber(t)},{encoder:Jn.CleanHistoryMessageReq,decoder:Xr.BaseResp}))(qn(e),0===t?Number.MAX_VALUE:t).then((e=>e.code))}async getConversationList(t,r,n,o){const i={rows:t,type:r??0,offset:rn.fromNumber(n),newToOld:0===o},{code:s,data:a}=await(e=>Ln.send(P.GetDialogList,e,{encoder:Jn.GetWebDialogListReq,decoder:jn.GetWebDialogListResp}))(i);if(s!==e.ErrorCode.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(E);await Wo.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};hi.get().addLocalConversation(t);const r=hi.get().get(e);Object.assign(t,r),l.push(t)}}return{code:e.ErrorCode.SUCCESS,data:l}}getBlockConversationList(){const t=hi.get().getBlockConversationList();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})}getTopConversationList(){const t=hi.get().getTopConversationList();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})}async getConversation(t){const r=hi.get().get(t);if(!r)return{code:e.ErrorCode.CONVER_GET_ERROR};const{code:n,data:o}=await this.getRemoteHistoryMessages(t,{count:1,order:0});if(n!==e.ErrorCode.SUCCESS)return{code:e.ErrorCode.CONVER_GET_ERROR};const i=null==o?void 0:o.list[0],s={...t,...r,latestMessage:i};return{code:e.ErrorCode.SUCCESS,data:s}}removeConversation(e){return(e=>{let t;return t=zn(e)?Ln.send(P.DeleteGroupDialog,{groupId:e},{encoder:eo.DeleteGroupChatDialogReq,decoder:Xr.BaseResp}):Ln.send(P.DeletePrivateDialog,{destId:e},{encoder:Jn.DeletePrivateChatDialogReq,decoder:Xr.BaseResp}),t})(qn(e)).then((e=>e.code))}getUnreadMentionedCount(e){return hi.get().getUnreadMentionedCount(e)}getAllUnreadMentionedCount(){return hi.get().getAllUnreadMentionedCount()}getAllConversationState(){return hi.get().getAllConversationState()}getAllConversationUnreadCount(e,t){return hi.get().getAllUnreadCount(e,t)}getConversationUnreadCount(e){return hi.get().getUnreadCount(e)}clearConversationUnreadCount(e){hi.get().clearUnreadCount(e)}clearAllConversationsUnreadCount(){hi.get().clearAllUnreadCount()}getConversationNotificationLevel(e){return hi.get().getNotificationLevel(e)}setConversationNotificationStatus(t,r){return((e,t)=>{let r;return r=zn(e)?Ln.send(P.UpdateGroupChatMuteConfig,{groupId:e,muteFlag:t},{encoder:eo.UpdateGroupChatDialogMuteConfigReq,decoder:Xr.BaseResp}):Ln.send(P.UpdatePrivateChatMuteConfig,{destId:e,muteFlag:t},{encoder:Jn.UpdatePrivateChatDialogMuteConfigReq,decoder:Xr.BaseResp}),r})(qn(t),r===e.NotificationStatus.OPEN).then((n=>(!n.code&&hi.get().addStatus({...t,notificationStatus:r,notificationLevel:r==e.NotificationStatus.OPEN?e.NotificationLevel.AT_USER_NOTIFICATION:e.NotificationLevel.NOT_SET},!0),n.code)))}getConversationNotificationStatus(e){return hi.get().getNotificationStatus(e)}setConversationToTop(e,t){return((e,t)=>{let r;return r=zn(e)?Ln.send(P.UpdateGroupChatStickyConfig,{groupId:e,stickyFlag:t},{encoder:eo.UpdateGroupChatDialogStickyConfigReq,decoder:Xr.BaseResp}):Ln.send(P.UpdatePrivateChatStickyConfig,{destId:e,stickyFlag:t},{encoder:Jn.UpdatePrivateChatDialogStickyConfigReq,decoder:Xr.BaseResp}),r})(qn(e),t).then((r=>(!r.code&&hi.get().addStatus({...e,isTop:t},!0),r.code)))}saveConversationMessageDraft(e,t){hi.get().setDraft(e,t)}getConversationMessageDraft(e){return hi.get().getDraft(e)}clearConversationMessageDraft(e){hi.get().clearDraft(e)}formatConversation(e){const{dialog:t,msg:r}=e,n=t.destId??"",o=si(t);if(!o)return;const i=Wo.getDialogAesKeyFromLocal(n);if(!i)return;const s=ri.parseSingleDialogMessages(n,[r],i)[0];return s?(o.latestMessage=s,o):void 0}}h(xa,"imClient",void 0);const Da=async(t,r,n)=>{if(r instanceof yo==!1)return T.warn("send message fail -> message parameter is not an instance of BaseMessage"),{code:e.ErrorCode.PARAMETER_ERROR};D("conversation",t,M,!0),Ba(t);const o=await La.sendMessage(t,r,n);return Ua(t,o.code),o},Ba=e=>{const t="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+t)},Ua=(t,r)=>{if(r!==e.ErrorCode.SUCCESS){const e="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.warn("send message fail ->"+r+":"+n(r)+","+e)}};e.CommandMessage=Go,e.ErrorDesc=n,e.FileMessage=Po,e.GIFMessage=Uo,e.HQVoiceMessage=jo,e.ImageMessage=Bo,e.TextMessage=Do,e.addEventListener=(e,t,r)=>{La.on(e,t,r)},e.clearAllMessagesUnreadStatus=()=>(T.debug("clear allMessagesUnreadStatus"),La.clearAllConversationsUnreadCount(),Promise.resolve({code:e.ErrorCode.SUCCESS})),e.clearHistoryMessages=async(t,r)=>{D("timestamp",r,(e=>k(e)&&e>=0),!0),D("conversation",t,M);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("clear message ->"+o);const i=await La.deleteRemoteMessageByTimestamp(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("clear message ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:e.ErrorCode.SUCCESS}},e.clearMessagesUnreadStatus=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("clear unreadMsgNum ->"+r),La.clearConversationUnreadCount(t),Promise.resolve({code:e.ErrorCode.SUCCESS})},e.clearTextMessageDraft=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("delete draft ->"+r),La.clearConversationMessageDraft(t),Promise.resolve({code:e.ErrorCode.SUCCESS})},e.connect=async t=>{D("token",t,R,!0);const r=await La.connect(t);return r.code===e.ErrorCode.SUCCESS?{code:r.code,data:{userId:r.userId}}:{code:r.code,msg:n(r.code)}},e.deleteMessages=async(t,r)=>{D("messages",r,(e=>C(e)&&!!e.length),!0),r.forEach((e=>{D("messages.messageUId",e.messageUId,R,!0),D("messages.sentTime",e.sentTime,k,!1),D("messages.messageDirection",e.messageDirection,(e=>1===e||2===e),!1)})),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("delete messages ->"+o);const i=await La.deleteRemoteMessage(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("delete message fail ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:e.ErrorCode.SUCCESS}},e.disconnect=()=>La.disconnect(),e.getAllConversationState=()=>{T.debug("getAllConversationState");const t=La.getAllConversationState();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},e.getAllUnreadMentionedCount=()=>{T.debug("getAllUnreadMentionedCount");const t=La.getAllUnreadMentionedCount();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},e.getBlockedConversationList=()=>La.getBlockConversationList(),e.getConnectionStatus=()=>La.getConnectionStatus(),e.getConversation=async t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get conversation ->"+r);const{code:o,data:i}=await La.getConversation(t);return o!==e.ErrorCode.SUCCESS?(T.warn("get conversation fail ->"+o+":"+n(o)+","+r),{code:o,msg:n(o)}):{code:o,data:i}},e.getConversationList=async t=>{T.debug("get conversation list ->");const{code:r,data:o}=await La.getConversationList((null==t?void 0:t.count)??20,null,(null==t?void 0:t.startTime)??0,(null==t?void 0:t.order)??0);return r!==e.ErrorCode.SUCCESS&&T.warn("get conversation list fail ->"+r+":"+n(r)),{code:r,msg:n(r),data:o}},e.getConversationNotificationLevel=t=>{D("options",t,M,!0),T.info("getConversationNotificationLevel ->targetId:"+t.targetId+",conversationType:"+t.conversationType);const r=La.getConversationNotificationLevel(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},e.getConversationNotificationStatus=t=>{D("options",t,M,!0),T.info("getConversationNotificationStatus ->targetId:"+t.targetId+",conversationType:"+t.conversationType);const r=La.getConversationNotificationStatus(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},e.getHistoryMessages=async(t,r)=>{D("options.timestamp",r.timestamp??0,k),D("options.count",r.count??0,k),D("options.order",r.order??0,(e=>0===e||1===e)),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get history message ->"+o);const i=await La.getRemoteHistoryMessages(t,r);return i.code!==e.ErrorCode.SUCCESS&&T.warn("get history message fail ->"+i.code+":"+n(i.code)+","+o),i},e.getRemoteHistoryMessages=async(t,r)=>{D("options.timestamp",r.timestamp??0,k),D("options.count",r.count??0,k),D("options.order",r.order??0,(e=>0===e||1===e)),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get remote history message ->"+o);const i=await La.getRemoteHistoryMessages(t,r);return i.code!==e.ErrorCode.SUCCESS&&T.warn("get remote history message fail ->"+i.code+":"+n(i.code)+","+o),i},e.getServerTime=()=>La.getServerTime(),e.getTextMessageDraft=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get draft ->"+r);const n=La.getConversationMessageDraft(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},e.getTopConversationList=()=>La.getTopConversationList(),e.getTotalUnreadCount=(t,r)=>{if(T.debug("get total unread count -> ConversationType:"+JSON.stringify(r)+" includeMuted:"+t),D("includeMuted",t,N,!1),D("conversationTypes",r,A,!1),r)for(const e of r)D("conversationType",e,L,!0);const n=La.getAllConversationUnreadCount(r??[],t??!1);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},e.getUnreadCount=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get unreadCount ->"+r);const n=La.getConversationUnreadCount(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},e.getUnreadMentionedCount=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("get unreadMentionedCount ->"+r),Promise.resolve({code:e.ErrorCode.SUCCESS,data:La.getUnreadMentionedCount(t)})},e.init=e=>{La=La||new xa(e)},e.onceEventListener=function(e,t,r){La.once(e,t,r)},e.recallMessage=async(t,r)=>{D("options.messageUId",r.messageUId,R,!0),D("options.sentTime",r.sentTime,k,!0),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId+",messageUId:"+r.messageUId;T.debug("recall message ->"+o);const i=await La.recallMsg(t,r);return i.code!==e.ErrorCode.SUCCESS&&T.warn("recall message fail ->"+i.code+":"+n(i.code)+","+o),i},e.registerMessageType=(e,t,r,n,o)=>function(n){return o?new Vo(e,n):r?new Ko(e,n):t?new zo(e,n):new Ho(e,n)},e.removeConversation=async t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("remove conversation ->"+r);const o=await La.removeConversation(t);return o!==e.ErrorCode.SUCCESS?(T.warn("remove conversation fail ->"+o+":"+n(o)+","+r),{code:o,msg:n(o)}):{code:o}},e.removeEventListener=(e,t,r)=>{La.off(e,t,r)},e.saveTextMessageDraft=(t,r)=>{D("options",t,M,!0),D("draft",r,R,!0);const n="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("set draft ->"+n),La.saveConversationMessageDraft(t,r),Promise.resolve({code:e.ErrorCode.SUCCESS})},e.sendFileMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+o),Ba(e);const i=await La.sendFileMessage(e,t,r,n);return Ua(e,i.code),i},e.sendGIFMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.endsWith("image/gif")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+o),Ba(e);const i=await La.sendGIFMessage(e,t,r,n);return Ua(e,i.code),i},e.sendHQVoiceMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob),!0),Ba(e);const o=await La.sendHQVoiceMessage(e,t,r,n);return Ua(e,o.code),o},e.sendImageMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.startsWith("image/")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+o),Ba(e);const i=await La.sendImageMessage(e,t,r,n);return Ua(e,i.code),i},e.sendMessage=Da,e.sendTextMessage=(e,t,r)=>{const n=new Do(t);return Da(e,n,r)},e.setConversationNotificationStatus=async(t,r)=>{D("options",t,M,!0),D("notificationStatus",r,(e=>1===e||2===e),!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("set conversation status ->"+o);const i=await La.setConversationNotificationStatus(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("set conversation status fail ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:i}},e.setConversationToTop=async function(t){let r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];D("options",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("set conversation status ->"+o);const i=await La.setConversationToTop(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("set conversation status fail ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:i}}}));
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 On}else{if(e<=-yn)return _n;if(e+1>=yn)return Sn}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 Cn=cn(1);rn.ONE=Cn;var wn=cn(1,!0);rn.UONE=wn;var En=cn(-1);rn.NEG_ONE=En;var Sn=un(-1,2147483647,!1);rn.MAX_VALUE=Sn;var On=un(-1,-1,!0);rn.MAX_UNSIGNED_VALUE=On;var _n=un(0,-2147483648,!1);rn.MIN_VALUE=_n;var In=rn.prototype;In.toInt=function(){return this.unsigned?this.low>>>0:this.low},In.toNumber=function(){return this.unsigned?(this.high>>>0)*pn+(this.low>>>0):this.high*pn+(this.low>>>0)},In.toString=function(e){if((e=e||10)<2||36<e)throw RangeError("radix");if(this.isZero())return"0";if(this.isNegative()){if(this.eq(_n)){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}},In.getHighBits=function(){return this.high},In.getHighBitsUnsigned=function(){return this.high>>>0},In.getLowBits=function(){return this.low},In.getLowBitsUnsigned=function(){return this.low>>>0},In.getNumBitsAbs=function(){if(this.isNegative())return this.eq(_n)?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},In.isZero=function(){return 0===this.high&&0===this.low},In.eqz=In.isZero,In.isNegative=function(){return!this.unsigned&&this.high<0},In.isPositive=function(){return this.unsigned||this.high>=0},In.isOdd=function(){return 1==(1&this.low)},In.isEven=function(){return 0==(1&this.low)},In.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)},In.eq=In.equals,In.notEquals=function(e){return!this.eq(e)},In.neq=In.notEquals,In.ne=In.notEquals,In.lessThan=function(e){return this.comp(e)<0},In.lt=In.lessThan,In.lessThanOrEqual=function(e){return this.comp(e)<=0},In.lte=In.lessThanOrEqual,In.le=In.lessThanOrEqual,In.greaterThan=function(e){return this.comp(e)>0},In.gt=In.greaterThan,In.greaterThanOrEqual=function(e){return this.comp(e)>=0},In.gte=In.greaterThanOrEqual,In.ge=In.greaterThanOrEqual,In.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},In.comp=In.compare,In.negate=function(){return!this.unsigned&&this.eq(_n)?_n:this.not().add(Cn)},In.neg=In.negate,In.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)},In.subtract=function(e){return nn(e)||(e=fn(e)),this.add(e.neg())},In.sub=In.subtract,In.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(_n))return e.isOdd()?_n:mn;if(e.eq(_n))return this.isOdd()?_n: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)},In.mul=In.multiply,In.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 wn;n=bn}else{if(this.eq(_n))return e.eq(Cn)||e.eq(En)?_n:e.eq(_n)?Cn:(t=this.shr(1).div(e).shl(1)).eq(mn)?e.isNegative()?Cn:En:(r=this.sub(e.mul(t)),n=t.add(r.div(e)));if(e.eq(_n))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=Cn),n=n.add(s),r=r.sub(a)}return n},In.div=In.divide,In.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))},In.mod=In.modulo,In.rem=In.modulo,In.not=function(){return un(~this.low,~this.high,this.unsigned)},In.countLeadingZeros=function(){return this.high?Math.clz32(this.high):Math.clz32(this.low)+32},In.clz=In.countLeadingZeros,In.countTrailingZeros=function(){return this.low?on(this.low):on(this.high)+32},In.ctz=In.countTrailingZeros,In.and=function(e){return nn(e)||(e=fn(e)),un(this.low&e.low,this.high&e.high,this.unsigned)},In.or=function(e){return nn(e)||(e=fn(e)),un(this.low|e.low,this.high|e.high,this.unsigned)},In.xor=function(e){return nn(e)||(e=fn(e)),un(this.low^e.low,this.high^e.high,this.unsigned)},In.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)},In.shl=In.shiftLeft,In.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)},In.shr=In.shiftRight,In.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)},In.shru=In.shiftRightUnsigned,In.shr_u=In.shiftRightUnsigned,In.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))},In.rotl=In.rotateLeft,In.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))},In.rotr=In.rotateRight,In.toSigned=function(){return this.unsigned?un(this.low,this.high,!1):this},In.toUnsigned=function(){return this.unsigned?this:un(this.low,this.high,!0)},In.toBytes=function(e){return e?this.toBytesLE():this.toBytesBE()},In.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]},In.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.ConnectionStatus[t],kn=()=>{const e="ACDeviceId";let t="";const r=kt.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)})),kt.set(e,t)),t},Nn=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},An=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 Ln=new class{constructor(t){h(this,"url",""),h(this,"watcher",void 0),h(this,"provider",void 0),h(this,"options",void 0),h(this,"socket",void 0),h(this,"status",e.ConnectionStatus.DISCONNECTED),h(this,"autoReconnect",!1),h(this,"isAuthorized",!1),h(this,"profile",void 0),h(this,"responseCallbacks",new Map),h(this,"failedCount",0),h(this,"reconnectTimer",void 0),h(this,"token",""),h(this,"connectResolve",void 0),h(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(t){return this.token=t,new Promise((t=>{this.connectResolve=t,this.open().then((t=>t===e.ErrorCode.SUCCESS?!p(this.provider)||this.provider.needReAuth()?this.auth():e.ErrorCode.SUCCESS:t)).then((r=>{var n;(t(r),r===e.ErrorCode.SUCCESS)?(this.isAuthorized=!0,this.profile=null===(n=this.provider)||void 0===n?void 0:n.profile(),this.autoReconnect=!0,this.onConnect()):this.onDisconnect(r===e.ErrorCode.TIMEOUT?e.ConnectionStatus.NETWORK_UNAVAILABLE:e.ConnectionStatus.WEBSOCKET_UNAVAILABLE)}))}))}async send(t,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(t,p(r)&&p(n.encoder)?n.encoder.encode(r).finish():new Uint8Array,i);if(0!==s)return{code:s,msg:"time out",data:null};if(!p(a)||!p(n.decoder))return{code:e.ErrorCode.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:e.ErrorCode.SUCCESS,msg:""}}async sendRawData(t,r){var n,o,i;let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:this.options.signalTimeout;if(!this.socket)return{code:e.ErrorCode.RC_NET_CHANNEL_INVALID};if(!this.isAuthorized&&!this.isAuthCommand(t))return{code:e.ErrorCode.RC_NET_CHANNEL_INVALID};const a=this.generateMessageSeq(),c={cmdId:t,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};T.reqInfo(`websocket send -> cmd: 0x${t.toString(16)}, messageSeq: ${a}`),this.socket.send(Nn(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}:(T.warn(`send timeout -> cmd: 0x${t.toString(16)}, messageSeq: ${a}, timeout: ${s}`),{code:e.ErrorCode.TIMEOUT})}close(){var t;this.autoReconnect=!1,this.doClose(),this.setStatus(e.ConnectionStatus.DISCONNECTED),null===(t=this.connectResolve)||void 0===t||t.call(this,e.ErrorCode.RC_SOCKET_DISCONNECTED)}async open(){const t=this.url;T.info(`conenct start -> ${t}`),this.setStatus(e.ConnectionStatus.CONNECTING);const r=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=r;return await new Promise((n=>{r.onMessage((e=>{"ArrayBuffer"===f(e)?this.onReceiveMessage(e):T.error("Socket received invalid data:",e)})),r.onClose(((t,r)=>{T.warn("websocket closed -> code:",t,"reason:",r),this.onDisconnect(e.ConnectionStatus.CONNECTION_CLOSED),n(e.ErrorCode.RC_SOCKET_DISCONNECTED)})),r.onError((t=>{T.error("websocket error -> ",t),this.onDisconnect(e.ConnectionStatus.WEBSOCKET_ERROR),n(e.ErrorCode.RC_SOCKET_NOT_CREATED)})),r.onOpen((()=>{T.info("websocket open -> ",t),n(e.ErrorCode.SUCCESS)})),setTimeout((()=>{n(e.ErrorCode.TIMEOUT)}),this.options.webSocketTimeout)}))}async auth(){var t,r,n,o;T.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(P.Auth,i,{encoder:Vr,decoder:Xr.AuthSignIn2TokenResp},8e3);return s===e.ErrorCode.SUCCESS||c?(T.info("auth success -> ",null===(t=c.user)||void 0===t||null===(r=t.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),e.ErrorCode.SUCCESS):(T.warn("auth failed -> "+a),e.ErrorCode.RC_CONN_NOT_AUTHRORIZED)}async checkAlive(){if(!this.socket||!this.isAuthorized)return;T.debug("send ping ->");const t={pingId:rn.ZERO,disconnectDelay:rn.ZERO},{code:r}=await this.send(P.Heartbean,t,{encoder:Kr},this.options.pingTimeout);r===e.ErrorCode.SUCCESS?(T.debug("recv pong <-"),this.failedCount=0,setTimeout((()=>this.checkAlive()),this.options.pingInterval)):(this.failedCount+=1,T.warn(`ping failed count: ${this.failedCount}, code: ${r}`),this.failedCount>=this.options.pingFailedTimes?(this.failedCount=0,T.warn("ping timeout, close current websocket to reconnect!"),this.onDisconnect(e.ConnectionStatus.NETWORK_UNAVAILABLE)):this.checkAlive())}onReceiveMessage(t){let r;try{const e=An(t);r=Xr.NetworkResponse.decode(e)}catch(t){return T.error("unpack payload error -> ",t),void this.onDisconnect(e.ConnectionStatus.DISCONNECT_BY_SERVER)}if(r.code)return void this.onDisconnect(e.ConnectionStatus.DISCONNECT_BY_SERVER);if(r.cmdId===P.SessionKilledPush)return void this.onDisconnect(e.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT);if(r.cmdId===P.SignOutPish||r.cmdId===P.SignOutPish2)return void this.onDisconnect(e.ConnectionStatus.DISCONNECT_BY_SERVER);if(r.cmdId===P.UserFrozenToLogin||r.cmdId===P.UserFrozenToLogin2)return void this.onDisconnect(e.ConnectionStatus.BLOCKED);const n=rn.isLong(r.messageSeq)?r.messageSeq.toNumber():0;T.reqInfo(`websocket recv ack -> messageSeq: ${n}`);const o=this.responseCallbacks.get(n);var i;p(o)?(o(r.body),this.responseCallbacks.delete(n)):(T.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.ConnectionStatus.CONNECTED),this.checkAlive(),p(this.reconnectTimer)&&(clearTimeout(this.reconnectTimer),this.reconnectTimer=null)}onDisconnect(e){p(this.socket)&&(this.doClose(),this.isConnectionAvailable()&&(this.setStatus(e),this.autoReconnect&&this.isConnectionAvailable()&&this.try2Reconnect()))}doClose(){if(p(this.socket)){const e=this.socket;this.socket=null,e.onClose(null),e.close()}p(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.ConnectionStatus.DISCONNECTED&&this.status!==e.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT&&this.status!==e.ConnectionStatus.BLOCKED&&this.status!==e.ConnectionStatus.DISCONNECT_BY_SERVER}setStatus(e){var t;e!==this.status&&(T.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===P.Auth}generateMessageSeq(){return++this.idCount}};var Mn=new class{constructor(){h(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;p(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:""}}},xn=Lt.exports,Dn=xn.Reader,Bn=xn.util,Un=xn.roots.default||(xn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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 Dn||(e=Dn.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(){h(this,"_token",""),h(this,"_uploadUrl",""),h(this,"_downloadUrl",""),h(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 E(e)?e.startsWith("http")?e:this.fileDownloadUrl+e:e}try2ExtractFileRelativeUri(e){return E(e)&&e.startsWith(this.fileDownloadUrl)?e.substring(this.fileDownloadUrl.length):e}};const Fn="SG",Gn="::",qn=t=>{if(!E(t.targetId+""))return"";switch(t.conversationType){case e.ConversationType.PRIVATE:return"P::"+t.targetId;case e.ConversationType.GROUP:return"G::"+t.targetId;case e.ConversationType.ULTRA_GROUP:return`SG::${t.targetId}_${t.channelId??""}`;default:return""}},Hn=t=>{if(!E(t))return null;const r=t.split(Gn);if(2!==r.length)return null;const n=r[0];if("G"===n)return{conversationType:e.ConversationType.GROUP,targetId:r[1]};if("P"===n)return{conversationType:e.ConversationType.PRIVATE,targetId:r[1]};if(n===Fn){const t=r[1].indexOf("_");if(t>0){const n=r[1].substring(0,t),o=r[1].substring(t+1);return{conversationType:e.ConversationType.ULTRA_GROUP,targetId:n,channelId:o}}return 0===t?null:{conversationType:e.ConversationType.ULTRA_GROUP,targetId:r[1]}}return null},zn=e=>e.startsWith(Fn)||e.startsWith("G");var Kn=Lt.exports,Vn=Kn.Writer,Wn=Kn.util,$n=Kn.roots.default||(Kn.roots.default={});$n.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=Wn.Long?Wn.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=Wn.newBuffer([]),e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Vn.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}(),$n.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=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.msgIdList=Wn.emptyArray,e.encode=function(e,t){if(t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.emptyArray,e.encode=function(e,t){if(t||(t=Vn.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}(),$n.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=Wn.emptyArray,e.prototype.clientSign="",e.encode=function(e,t){if(t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.oldOffset=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.prototype.rows=0,e.prototype.newToOld=!1,e.encode=function(e,t){return t||(t=Vn.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}(),$n.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=Wn.Long?Wn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Vn.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 Jn=$n,Zn=Lt.exports,Xn=Zn.Writer,Yn=Zn.util,Qn=Zn.roots.default||(Zn.roots.default={});Qn.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=Yn.Long?Yn.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=Yn.emptyArray,e.prototype.extra="",e.prototype.assign="",e.prototype.atAll=!1,e.prototype.msgContent=Yn.newBuffer([]),e.encode=function(e,t){if(t||(t=Xn.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}(),Qn.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=Xn.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}(),Qn.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=Xn.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}(),Qn.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=Xn.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}(),Qn.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=Yn.Long?Yn.Long.fromBits(0,0,!1):0,e.encode=function(e,t){return t||(t=Xn.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}(),Qn.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=Xn.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 eo=Qn;const to=Lt.exports.Reader,ro=Lt.exports.util,no=Lt.exports.roots.default||(Lt.exports.roots.default={}),oo=no.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=ro.Long?ro.Long.fromBits(0,0,!1):0,e.prototype.msgId=ro.Long?ro.Long.fromBits(0,0,!1):0,e.prototype.msgSendTime=ro.Long?ro.Long.fromBits(0,0,!1):0,e.prototype.seqno=ro.Long?ro.Long.fromBits(0,0,!1):0,e.decode=function(e,t){e instanceof to||(e=to.create(e));let r=void 0===t?e.len:e.pos+t,n=new no.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})(),io=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),Ln.send(e.dialogId.startsWith(Fn)?P.GetSuperGroupRemoteMessages:P.GetRemoteMessages,t,{encoder:Jn.GetHistoryMessageReq,decoder:jn.GetHistoryMessageResp})};let so=0;const ao=async()=>{const t=(new Date).getTime(),{code:r,data:n}=await Ln.send(P.GetServerTime,null,{decoder:Xr.SystemCurrentTimeMillisResp});if(r===e.ErrorCode.SUCCESS){const{currentTimeMillis:e}=n;so=e.toNumber()-t}},co=()=>(new Date).getTime()+so,lo=new Set;var uo={addMessage(e){lo.add(e)},remove(e){lo.delete(e)},has:e=>lo.has(e),reset(){lo.clear()}};const ho=new Set;var fo={addMessage(e){ho.add(e)},remove(e){ho.delete(e)},has:e=>ho.has(e),reset(){ho.clear()}};const po=new Map;function go(e){po.set(e.getObjectId(),e.decode.bind(e))}class yo{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];h(this,"messageType",void 0),h(this,"content",void 0),h(this,"isPersited",void 0),h(this,"isCounted",void 0),h(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 vo=0,mo=268439552,bo=268439563,Co=268439562,wo=268439553,Eo=268439581,So=268439597,Oo=268439613,_o=268439629,Io=1610678301,To=268439645,Ro="RC:TxtMsg",ko="RC:HQVCMsg",No="RC:FileMsg",Ao="RC:ImgMsg",Lo="RC:GIFMsg",Mo="RC:RcNtf",xo="RC:CmdMsg";class Do extends yo{constructor(e){super(Ro,e)}static getObjectId(){return vo}static decode(e){const{user:t,extra:r,content:n}=e;return new Do({user:t,extra:r,content:n})}encode(){const{user:e,extra:t,content:r}=this.content;return{user:e,extra:t,content:r}}}class Bo extends yo{constructor(e){super(Ao,e)}static getObjectId(){return mo}static decode(e){const{user:t,extra:r,thumbnailObjectKey:n,originalObjectKey:o,width:i,height:s}=e;return new Bo({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 Uo extends yo{constructor(e){super(Lo,e)}static getObjectId(){return bo}static decode(e){const{user:t,extra:r,size:n,originalObjectKey:o,width:i,height:s}=e;return new Uo({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 jo extends yo{constructor(e){super(ko,e)}static getObjectId(){return wo}static decode(e){const{user:t,extra:r,length:n,audioObjectKey:o,extension:i}=e;return new jo({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 Po extends yo{constructor(e){super(No,e)}static getObjectId(){return Co}static decode(e){const{user:t,extra:r,title:n,extension:o,size:i,originalObjectKey:s}=e;return new Po({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 Fo extends yo{constructor(e){super(Mo,e,!0,!1,!1)}static getObjectId(){return Io}static decode(e){return new Fo(e)}encode(){return this.content}}class Go extends yo{constructor(e){super(xo,e,!1,!1)}static getObjectId(){return To}static decode(e){return new Go(e)}encode(){return this.content}}class qo extends yo{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 Ho extends qo{constructor(e,t){super(e,t,!1,!1)}static getObjectId(){return Eo}}class zo extends qo{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return So}}class Ko extends qo{constructor(e,t){super(e,t,!0,!1)}static getObjectId(){return Oo}}class Vo extends qo{constructor(e,t){super(e,t,!1,!1,!0)}static getObjectId(){return _o}}var Wo=new class{constructor(){h(this,"aesKeyRecord",new Map)}async getDialogAesKey(e){return E(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(!E(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(t){if(!t.length)return new Map;const{code:r,data:n}=await(o=t,Ln.send(P.GetDialogKey,{destId:o,clientSign:""},{encoder:Jn.GetDialogKeyReq,decoder:jn.GetDialogKeyResp}));var o;if(r===e.ErrorCode.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 E(e)?this.aesKeyRecord.get(e):null}};const $o="time",Jo=(e,t)=>[e,t,$o].join("_");class Zo{constructor(e,t){h(this,"appkey",void 0),h(this,"userId",void 0),h(this,"inBoxOffset",rn.ZERO),this.appkey=e,this.userId=t}setInboxOffset(e){if(this.inBoxOffset>e)return;this.inBoxOffset=e;const t=Jo(this.appkey,this.userId);kt.set(t,e.toString())}getInboxOffset(){if(this.inBoxOffset.isZero()){const e=Jo(this.appkey,this.userId);this.inBoxOffset=rn.fromString(kt.get(e)??"0")}return this.inBoxOffset}}const Xo=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 Yo=(e,t,r)=>{const n={};return e.forEach((e=>{const o=Qo(e,t.get(e),r.get(e));o.length&&(n[e]=o)})),n},Qo=(t,r,n)=>{const o=Hn(t);if(!o)return[];const i=new Set;let s=[];return r.forEach((t=>{const r=t;let a=r.mediaConstructor,c=ei(r,n);if(!c)return;if(1610678290===a||1610743841===a){const{msgId:e,sendTime:t}=c,n={sentTime:t,messageUId:e,conversationType:o.conversationType,targetId:r.isOut?o.targetId:Mn.uid,channelId:o.channelId};a=Io,c=n,i.add(e)}const l=function(e,t){const r=po.get(e);return r?r(t):null}(a,c);if(p(l)){const t={...o,senderUserId:r.srcId.toString(),messageDirection:r.isOut?e.MessageDirection.SEND:e.MessageDirection.RECEIVE,isCounted:l.isCounted,isMentioned:r.atFlag,content:l.content,messageType:l.messageType,isOffLineMessage:!1,isPersited:l.isPersited,messageId:rn.isLong(r.localId)?r.localId.toNumber():void 0,messageUId:r.msgId.toString(),sentTime:r.seqno.toNumber(),receivedTime:co(),isStatusMessage:l.isStatusMessage,receivedStatus:e.ReceivedStatus.READ,disableNotification:!1};if(t.isStatusMessage&&co()-t.sentTime>6e3)return;s.push(t)}})),i.size&&(s=s.filter((e=>!i.has(e.messageUId)))),s},ei=(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 Et.AES.decrypt(r,Et.enc.Utf8.parse(t.key),{iv:p(t.iv)?Et.enc.Utf8.parse(t.iv):void 0}).toString(Et.enc.Utf8)})(e.msgContent,t):e.msgPreContent??"",1610678290!==e.mediaConstructor&&1610743841!==e.mediaConstructor||(o=ti(o));let i={};return null!==(n=o)&&void 0!==n&&n.length&&(i=JSON.parse(o)),i}catch(t){return T.error("decode message content fail -> uid:",e.msgId.toString()),null}},ti=e=>e.replace(/("msgId")\s*:\s*(\d+)/g,((e,t,r)=>`${t}:"${r}"`));var ri={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());Wo.getDialogAesKeyListInBatches([...r.keys()],((e,o)=>{if(o.size){const e=[...o.keys()];for(const t of e)n.delete(t);t(!n.size,Yo(e,r,o))}n.size&&e&&t(!0,{})}))},parseSingleDialogMessages:Qo};function ni(e){if(!p(e))return e;if(Array.isArray(e))return e.map((e=>ni(e)));if(b(e)){const t={};return Object.keys(e).forEach((r=>{t[r]=ni(e[r])})),t}return e}const oi={unreadMessageCount:{keyName:"c",defaultVal:0},lastUnreadTime:{keyName:"t",defaultVal:0},notificationStatus:{keyName:"nc",defaultVal:2},notificationLevel:{keyName:"nl",defaultVal:0},isTop:{keyName:"it",defaultVal:!1},mentionedUIds:{keyName:"mu",defaultVal:null}};class ii{constructor(e,t){h(this,"localStore",void 0);const r=`con-${e}-${t}`;this.localStore=new At(r)}getStoreKey(e){return`${e.conversationType}_${e.targetId}_${e.channelId??""}`}getConOptionByKey(t){const r=(t=t||"").split("_");if(r.length>=2){const e=r.shift(),t=r.shift(),n=r.join("_");return{conversationType:Number(e),targetId:t,channelId:n}}return{conversationType:e.ConversationType.PRIVATE,targetId:"",channelId:""}}updateUnreadCount(t){const{conversationType:r,targetId:n,channelId:o,content:i,messageType:s,sentTime:a,isCounted:c,messageDirection:l}=t,u=l===e.MessageDirection.SEND,d=s===Mo,h=b(i),f={conversationType:r,targetId:n,channelId:o},p=this.get(f)||{},g=p.lastUnreadTime||0,y=p.unreadMessageCount||0;if(!(g>a)&&!u){if(c&&(p.unreadMessageCount=y+1,p.lastUnreadTime=a),d&&h){g>=i.sentTime&&y&&(p.unreadMessageCount=y-1)}this.set(f,p)}}updateMentionedData(t){const{conversationType:r,targetId:n,channelId:o,messageUId:i,messageType:s,isMentioned:a,messageDirection:c,content:l}=t;if(c===e.MessageDirection.SEND||!a&&s!==Mo)return;const u=this.getStoreKey({conversationType:r,targetId:n,channelId:o}),d=this.localStore.get(u)||{},h=oi.mentionedUIds.keyName,f=d[h]||[];if(a&&r===e.ConversationType.GROUP&&(f.includes(i)||f.push(i)),s===Mo&&r===e.ConversationType.GROUP){const e=l,t=f.indexOf(e.messageUId);t>=0&&f.splice(t,1)}f.length?d[h]=f:delete d[h],S(d)?this.localStore.set(u,d):this.localStore.remove(u)}set(e,t){const r=this.getStoreKey(e),n=this.localStore.get(r)||{};for(const e of St(t)){const r=oi[e],o=t[e];if(v(null==r?void 0:r.keyName)||v(o))continue;o===r.defaultVal?delete n[r.keyName]:n[r.keyName]=o,n[oi.unreadMessageCount.keyName]||(delete n[oi.lastUnreadTime.keyName],delete n[oi.mentionedUIds.keyName])}S(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 St(oi)){const{keyName:t,defaultVal:i}=oi[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]||ni(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 St(oi)){const{keyName:t,defaultVal:r}=oi[e];"mentionedUIds"!==e&&(n[e]=o[t]||ni(r))}t.push(n)}return t}}const si=t=>{const r=t.destId??"",n=Hn(r);if(!n)return;return{...n,unreadMessageCount:0,notificationStatus:t.muteFlag?e.NotificationStatus.OPEN:e.NotificationStatus.CLOSE,notificationLevel:g(t.pushNotificationLevel)&&0!==t.pushNotificationLevel&&p(e.NotificationLevel[t.pushNotificationLevel])?t.pushNotificationLevel:t.muteFlag?e.NotificationLevel.AT_USER_NOTIFICATION:e.NotificationLevel.NOT_SET,isTop:!!t.stickyFlag,lastUnreadTime:0}},ai="STATUS_CHANGED";class ci{constructor(e,t){h(this,"storageKey",void 0),h(this,"eventEmitter",void 0),h(this,"isPulling",!1),this.storageKey=`con-s-${e}-${t}`,this.eventEmitter=new U}async pull(){if(this.isPulling)return;let t;this.isPulling=!0;const r=kt.get(this.storageKey);t=g(r)&&r>0?r:co()-1e4;let{code:n,data:o}=await(e=>Ln.send(P.GetDialogChangedStatus,{time:rn.fromNumber(e)},{encoder:Jn.GetNewSettingDialogListReq,decoder:jn.GetNewSettingDialogListResp}))(t);n===e.ErrorCode.SUCCESS&&(o.setTime.toNumber()>0&&kt.set(this.storageKey,o.setTime.toNumber()),o.briefDialog&&St(o.briefDialog).forEach((e=>{const t=o.briefDialog[e],r=si(t);r&&this.eventEmitter.emit(ai,r)}))),this.isPulling=!1}watch(e){this.eventEmitter.on(ai,(t=>{e(t)}))}}class li{constructor(e,t,r){h(this,"updatedConversationFunc",void 0),h(this,"store",void 0),h(this,"draftMap",new Map),h(this,"localConversationSet",new Set),h(this,"updatedConversations",[]),h(this,"notify",void 0),h(this,"statusManager",void 0),this.updatedConversationFunc=r,this.store=new ii(e,t),this.notify=_t(this.notifyConversationChanged.bind(this),0),this.statusManager=new ci(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(t){if(null==t||!t.length)return;const r=t.filter((e=>!this.localConversationSet.has(this.getConversationKey(e))));if(!r.length)return;const n=r.map(qn).filter(E);if(!n.length)return;const{code:o,data:i}=await(e=>Ln.send(P.GetBriefDialogList,{destId:e},{encoder:Jn.GetBriefDialogListReq,decoder:jn.GetBriefDialogListResp}))(n);o===e.ErrorCode.SUCCESS&&St(i.briefDialog).forEach((e=>{const t=i.briefDialog[e],r=si(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=co(),u=this.store.get(c),d={};p(i)&&u.notificationLevel!==i&&(d.notificationLevel={time:l,val:i}),p(o)&&u.notificationStatus!==o&&(d.notificationStatus={time:l,val:o}),p(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=ni(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(t,r){const n=this.store.getAll();let o=0;return n.forEach((n=>{let{unreadMessageCount:i,notificationStatus:s,notificationLevel:a,conversationType:c}=n;i=i||0;const l=s===e.NotificationStatus.OPEN||a>0;!r&&l||(t.length>0?t.includes(+c)&&(o+=+i):o+=+i)})),o}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:co()}),n&&(o.hasMentioned={val:!1,time:co()},o.unreadMentionedCount={val:0,time:co()}),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((t=>t.notificationStatus===e.NotificationStatus.OPEN||t.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 ui={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(t){return e.NotificationLevel.NOT_SET},getNotificationStatus:function(t){return e.NotificationStatus.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 di;var hi={create(e,t,r){di=new li(e,t,r)},get:()=>di??ui};class fi{constructor(e,t){h(this,"watcher",void 0),h(this,"pullingMsg",!1),h(this,"letterbox",void 0),h(this,"serverMsgSeqno",rn.ZERO),h(this,"pullOfflineFinished",!1),h(this,"intervalTimer",void 0),h(this,"retryTimer",void 0),h(this,"latestSyncTimestamp",0),h(this,"started",!1),this.watcher=e,this.letterbox=new Zo(t.appkey,Mn.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 t=this.letterbox.getInboxOffset();this.pullOfflineFinished||T.info(`pullMsg -> time: ${t}`),this.latestSyncTimestamp=Date.now();const{code:r,data:n}=await((e,t)=>Ln.send(P.GetNewMessage,{offset:e,rows:t},{encoder:Jn.GetNewMessageReq,decoder:jn.GetNewMessageResp}))(t,60);if(r!==e.ErrorCode.SUCCESS)return this.pullOfflineFinished||T.warn("pullMsg failed -> code:",r),this.pullingMsg=!1,void this.try2RePullMsg();const{offset:o,seqno:i,msg:s}=n,a=Object.keys(s).map(Hn).filter((e=>p(e)));hi.get().loadConvsationsIfNotExist(a),ri.parse(s,((t,r)=>{const n=[],s=[],a=!this.pullOfflineFinished;var c,l;(Object.keys(r).forEach((t=>{const o=r[t],i=[];if(o.forEach((t=>{t.messageDirection===e.MessageDirection.SEND&&t.messageId&&uo.has(t.messageId)?uo.remove(t.messageId):t.messageType===Mo&&fo.has(t.content.messageUId)?fo.remove(t.content.messageUId):(t.isOffLineMessage=a,hi.get().setConversationCacheByMessage(t),i.push(t))})),n.push(...i),this.isExistPersistedMessage(i)){const e=Hn(t);e&&s.push(e)}})),n.length)&&(null===(c=(l=this.watcher).batchMessage)||void 0===c||c.call(l,n));if(s.length&&hi.get().loadConvsationsIfNotExist(s),t){var u;i.ge(this.serverMsgSeqno)&&(this.serverMsgSeqno=i);const e=this.serverMsgSeqno.lessThanOrEqual(o);this.pullOfflineFinished||T.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 pi{static init(e){return this._loader||(this._loader=new pi(e)),this._loader}static get loader(){return this._loader}constructor(t){h(this,"options",void 0),h(this,"connectionStatus",e.ConnectionStatus.DISCONNECTED),h(this,"isInternalConnected",!1),h(this,"watcher",void 0),h(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},Ln.setServerInfo(this.getWebSocketUrl()),Ln.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 E(t)?w(r=t)&&/wss?:\/\//.test(r)?t:"ws://"+t:"wss://tt.mimelabs.xyz:8991";var r}registerMessage(){go(Do),go(Bo),go(Uo),go(jo),go(Ho),go(Ko),go(zo),go(Vo),go(Fo),go(Go),go(Po)}async connect(t){if(this.connectionStatus===e.ConnectionStatus.CONNECTED)return{code:e.ErrorCode.SUCCESS,userId:Mn.uid+""};if(this.connectionStatus===e.ConnectionStatus.CONNECTING)return{code:e.ErrorCode.BIZ_ERROR_CONNECTING};if("string"!=typeof t||0===t.length)return{code:e.ErrorCode.RC_CONN_USER_OR_PASSWD_ERROR};Pn.imInitToken=t;const r=await Ln.connect(t);var n;r===e.ErrorCode.SUCCESS&&(this.isInternalConnected=!0,hi.get().destroyed(),hi.create(this.options.appkey,Mn.uid,this.watcher.conversationState),null===(n=this.messageLoader)||void 0===n||n.stop(),this.messageLoader=new fi(this.watcher,this.options),ao(),uo.reset(),fo.reset(),Wo.reset());return{code:r,userId:Mn.uid+""}}reconnect(){return this.isInternalConnected?Promise.resolve({code:e.ErrorCode.CAN_NOT_RECONNECT}):this.connect(Pn.imInitToken)}disconnect(){return this.isInternalConnected=!1,Ln.close(),Promise.resolve()}getConnectionStatus(){return this.connectionStatus}assignWatcher(e){St(this.watcher).forEach((t=>{if(Object.prototype.hasOwnProperty.call(e,t)){const r=e[t];this.watcher[t]=m(r)?r:void 0}}))}resetWatcher(){St(this.watcher).forEach((e=>{this.watcher[e]=void 0}))}async connectionStatusListener(t){this.connectionStatus=t,setTimeout((()=>{switch(t){case e.ConnectionStatus.BLOCKED:case e.ConnectionStatus.KICKED_OFFLINE_BY_OTHER_CLIENT:case e.ConnectionStatus.DISCONNECT_BY_SERVER:this.handleDisconnect();break;case e.ConnectionStatus.CONNECTING:this.handleConnecting();break;case e.ConnectionStatus.CONNECTED:this.handleConnected();break;case e.ConnectionStatus.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.ConnectionStatus.CONNECTED&&hi.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===P.NewMessagePush){var r;const e=jn.NewMessageNotificationResp.decode(t);null===(r=this.messageLoader)||void 0===r||r.syncMsg(e.seqno)}else e===P.DialogChangedPush&&hi.get().syncConversationStatus()}authListener(e){Pn.setFileServerInfo(e.fileDomain,e.dialogFileDomain,e.cert),Mn.setLogged(e,Pn.imInitToken)}needReAuthProvider(){return!Mn.user.active||Mn.user.token!==Pn.imInitToken}needProfileProvider(){if(!this.needReAuthProvider()){const{deviceId:e,sessionId:t,uid:r}=Mn.user;return{deviceId:e,sessionId:t,uid:r}}return null}}h(pi,"_loader",void 0);var gi={exports:{}},yi={exports:{}},vi={exports:{}},mi={exports:{}},bi=Ci;function Ci(e,t){"string"==typeof e&&(t=e,e=void 0);var r=[];function n(e){if("string"!=typeof e){var t=o();if(Ci.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}Ci.verbose=!1;var wi=Oi,Ei=Dt,Si=Kt();function Oi(e,t,r){return"function"==typeof t?(r=t,t={}):t||(t={}),r?!t.xhr&&Si&&Si.readFile?Si.readFile(e,(function(n,o){return n&&"undefined"!=typeof XMLHttpRequest?Oi.xhr(e,t,r):n?r(n):r(null,t.binary?o:o.toString("utf8"))})):Oi.xhr(e,t,r):Ei(Oi,this,e,t)}Oi.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 _i={};!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)}}(_i);var Ii,Ti,Ri,ki,Ni,Ai,Li,Mi,xi,Di,Bi,Ui,ji,Pi={};function Fi(){return Ii||(Ii=1,function(e){var t=e,r=bs(),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])}(Pi)),Pi}function Gi(){if(Ri)return Ti;Ri=1,Ti=s;var e=Cs();((s.prototype=Object.create(e.prototype)).constructor=s).className="Field";var t,r=ws(),n=Fi(),o=bs(),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},Ti}function qi(){if(Ni)return ki;Ni=1,ki=n;var e=Cs();((n.prototype=Object.create(e.prototype)).constructor=n).className="OneOf";var t=Gi(),r=bs();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)})}},ki}function Hi(){if(Li)return Ai;Li=1,Ai=c;var e=Cs();((c.prototype=Object.create(e.prototype)).constructor=c).className="Namespace";var t,r,n,o=Gi(),i=bs(),s=qi();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},Ai}function zi(){if(xi)return Mi;xi=1,Mi=n;var e=Gi();((n.prototype=Object.create(e.prototype)).constructor=n).className="MapField";var t=Fi(),r=bs();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))}},Mi}function Ki(){if(Bi)return Di;Bi=1,Di=r;var e=Cs();((r.prototype=Object.create(e.prototype)).constructor=r).className="Method";var t=bs();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))},Di}function Vi(){if(ji)return Ui;ji=1,Ui=o;var e=Hi();((o.prototype=Object.create(e.prototype)).constructor=o).className="Service";var t=Ki(),r=bs(),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},Ui}var Wi,$i,Ji,Zi,Xi=Qi,Yi=Xt();function Qi(e){if(e)for(var t=Object.keys(e),r=0;r<t.length;++r)this[t[r]]=e[t[r]]}function es(){if($i)return Wi;$i=1,Wi=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=ws(),t=Fi(),r=bs();function n(e){return"missing required '"+e.name+"'"}return Wi}function ts(){if(Zi)return Ji;Zi=1,Ji=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=ws(),t=bs();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 Ji}Qi.create=function(e){return this.$type.create(e)},Qi.encode=function(e,t){return this.$type.encode(e,t)},Qi.encodeDelimited=function(e,t){return this.$type.encodeDelimited(e,t)},Qi.decode=function(e){return this.$type.decode(e)},Qi.decodeDelimited=function(e){return this.$type.decodeDelimited(e)},Qi.verify=function(e){return this.$type.verify(e)},Qi.fromObject=function(e){return this.$type.fromObject(e)},Qi.toObject=function(e,t){return this.$type.toObject(e,t)},Qi.prototype.toJSON=function(){return this.$type.toObject(this,Yi.toJSONOptions)};var rs,ns={};function os(){return rs||(rs=1,function(e){var t=e,r=ws(),n=bs();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")}}(ns)),ns}var is,ss,as,cs,ls,us,ds,hs,fs,ps,gs,ys={};function vs(){if(ss)return is;ss=1,is=g;var e=Hi();((g.prototype=Object.create(e.prototype)).constructor=g).className="Type";var t=ws(),r=qi(),n=Gi(),o=zi(),i=Vi(),s=Xi,a=Cr,c=Qt,l=bs(),u=Es(),d=es(),h=ts(),f=os(),p=ys;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)}},is}function ms(){if(cs)return as;cs=1,as=c;var e=Hi();((c.prototype=Object.create(e.prototype)).constructor=c).className="Root";var t,r,n,o=Gi(),i=ws(),s=qi(),a=bs();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},as}function bs(){return ls||(ls=1,function(e){var t,r,n=e.exports=Xt(),o=Fr;n.codegen=bi,n.fetch=wi,n.path=_i,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=vs());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=ws());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(ms()))}})}(mi)),mi.exports}function Cs(){if(ds)return us;ds=1,us=r,r.className="ReflectionObject";var e,t=bs();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},us}function ws(){if(fs)return hs;fs=1,hs=n;var e=Cs();((n.prototype=Object.create(e.prototype)).constructor=n).className="Enum";var t=Hi(),r=bs();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)},hs}function Es(){if(gs)return ps;gs=1,ps=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=ws(),t=Fi(),r=bs();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 ps}!function(e){var t=Xi;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)}}}(ys),function(e){var t=e.exports=Mt;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=Es(),t.decoder=es(),t.verifier=ts(),t.converter=os(),t.ReflectionObject=Cs(),t.Namespace=Hi(),t.Root=ms(),t.Enum=ws(),t.Type=vs(),t.Field=Gi(),t.OneOf=qi(),t.MapField=zi(),t.Service=Vi(),t.Method=Ki(),t.Message=Xi,t.wrappers=ys,t.types=Fi(),t.util=bs(),t.ReflectionObject._configure(t.Root),t.Namespace._configure(t.Type,t.Service,t.Enum),t.Root._configure(t.Type),t.Field._configure(t.Type)}(vi);var Ss=xs,Os=/[\s{}=;:[\],'"()<>]/g,_s=/(?:"([^"\\]*(?:\\.[^"\\]*)*)")/g,Is=/(?:'([^'\\]*(?:\\.[^'\\]*)*)')/g,Ts=/^ *[*/]+ */,Rs=/^\s*\*?\/*/,ks=/\n/g,Ns=/\s/,As=/\\(.?)/g,Ls={0:"\0",r:"\r",n:"\n",t:"\t"};function Ms(e){return e.replace(As,(function(e,t){switch(t){case"\\":case"":return t;default:return Ls[t]||""}}))}function xs(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(ks),h=0;h<d.length;++h)d[h]=d[h].replace(t?Rs:Ts,"").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?Is:_s;t.lastIndex=r-1;var n=t.exec(e);if(!n)throw l("string");return r=t.lastIndex,g(c),c=null,Ms(n[1])}();var i,s,p,y,v,m=0===r;do{if(r===n)return null;for(i=!1;Ns.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(Os.lastIndex=0,!Os.test(u(b++)))for(;b<n&&!Os.test(u(b));)++b;var C=e.substring(r,r=b);return'"'!==C&&"'"!==C||(c=C),C}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}})}xs.unescape=Ms;var Ds=na;na.filename=null,na.defaults={keepCase:!1};var Bs=Ss,Us=ms(),js=vs(),Ps=Gi(),Fs=zi(),Gs=qi(),qs=ws(),Hs=Vi(),zs=Ki(),Ks=Fi(),Vs=bs(),Ws=/^[1-9][0-9]*$/,$s=/^-?[1-9][0-9]*$/,Js=/^0[x][0-9a-fA-F]+$/,Zs=/^-?0[x][0-9a-fA-F]+$/,Xs=/^0[0-7]+$/,Ys=/^-?0[0-7]+$/,Qs=/^(?![eE])[0-9]*(?:\.[0-9]*)?(?:[eE][+-]?[0-9]+)?$/,ea=/^[a-zA-Z_][a-zA-Z_0-9]*$/,ta=/^(?:\.?[a-zA-Z_][a-zA-Z_0-9]*)(?:\.[a-zA-Z_][a-zA-Z_0-9]*)*$/,ra=/^(?:\.[a-zA-Z_][a-zA-Z_0-9]*)+$/;function na(e,t,r){t instanceof Us||(r=t,t=new Us),r||(r=na.defaults);var n,o,i,s,a,c=r.preferTrailingComment||!1,l=Bs(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}:Vs.camelCase;function b(e,t,r){var n=na.filename;return r||(na.filename=null),Error("illegal "+(t||"token")+" '"+e+"' ("+(n?n+", ":"")+"line "+l.line+")")}function C(){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 w(e){var t=u();switch(t){case"'":case'"':return d(t),C();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(Ws.test(e))return r*parseInt(e,10);if(Js.test(e))return r*parseInt(e,16);if(Xs.test(e))return r*parseInt(e,8);if(Qs.test(e))return r*parseFloat(e);throw b(e,"number",t)}(t,!0)}catch(r){if(e&&ta.test(t))return t;throw b(t,"value")}}function E(e,t){var r,n;do{!t||'"'!==(r=h())&&"'"!==r?e.push([n=S(u()),f("to",!0)?S(u()):n]):e.push(C())}while(f(",",!0));f(";")}function S(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($s.test(e))return parseInt(e,10);if(Zs.test(e))return parseInt(e,16);if(Ys.test(e))return parseInt(e,8);throw b(e,"id")}function O(){if(void 0!==n)throw b("package");if(n=u(),!ta.test(n))throw b(n,"name");v=v.define(n),f(";")}function _(){var e,t=h();switch(t){case"weak":e=i||(i=[]),u();break;case"public":u();default:e=o||(o=[])}t=C(),f(";"),e.push(t)}function I(){if(f("="),s=C(),!(y="proto3"===s)&&"proto2"!==s)throw b(s,"syntax");f(";")}function T(e,t){switch(t){case"option":return L(e,t),f(";"),!0;case"message":return k(e,t),!0;case"enum":return A(e,t),!0;case"service":return function(e,t){if(!ea.test(t=u()))throw b(t,"service name");var r=new Hs(t);R(r,(function(e){if(!T(r,e)){if("rpc"!==e)throw b(e);!function(e,t){var r=p(),n=t;if(!ea.test(t=u()))throw b(t,"name");var o,i,s,a,c=t;f("("),f("stream",!0)&&(i=!0);if(!ta.test(t=u()))throw b(t);o=t,f(")"),f("returns"),f("("),f("stream",!0)&&(a=!0);if(!ta.test(t=u()))throw b(t);s=t,f(")");var l=new zs(c,n,o,s,i,a);l.comment=r,R(l,(function(e){if("option"!==e)throw b(e);L(l,e),f(";")})),e.add(l)}(r,e)}})),e.add(r)}(e,t),!0;case"extend":return function(e,t){if(!ta.test(t=u()))throw b(t,"reference");var r=t;R(null,(function(t){switch(t){case"required":case"repeated":N(e,t,r);break;case"optional":N(e,y?"proto3_optional":"optional",r);break;default:if(!y||!ta.test(t))throw b(t);d(t),N(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=na.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(!ea.test(t=u()))throw b(t,"type name");var r=new js(t);R(r,(function(e){if(!T(r,e))switch(e){case"map":!function(e){f("<");var t=u();if(void 0===Ks.mapKey[t])throw b(t,"type");f(",");var r=u();if(!ta.test(r))throw b(r,"type");f(">");var n=u();if(!ea.test(n))throw b(n,"name");f("=");var o=new Fs(m(n),S(u()),t,r);R(o,(function(e){if("option"!==e)throw b(e);L(o,e),f(";")}),(function(){D(o)})),e.add(o)}(r);break;case"required":case"repeated":N(r,e);break;case"optional":N(r,y?"proto3_optional":"optional");break;case"oneof":!function(e,t){if(!ea.test(t=u()))throw b(t,"name");var r=new Gs(m(t));R(r,(function(e){"option"===e?(L(r,e),f(";")):(d(e),N(r,"optional"))})),e.add(r)}(r,e);break;case"extensions":E(r.extensions||(r.extensions=[]));break;case"reserved":E(r.reserved||(r.reserved=[]),!0);break;default:if(!y||!ta.test(e))throw b(e);d(e),N(r,"optional")}})),e.add(r)}function N(e,t,r){var n=u();if("group"!==n){if(!ta.test(n))throw b(n,"type");var o=u();if(!ea.test(o))throw b(o,"name");o=m(o),f("=");var i=new Ps(o,S(u()),n,t,r);if(R(i,(function(e){if("option"!==e)throw b(e);L(i,e),f(";")}),(function(){D(i)})),"proto3_optional"===t){var s=new Gs("_"+o);i.setOption("proto3_optional",!0),s.add(i),e.add(s)}else e.add(i);y||!i.repeated||void 0===Ks.packed[n]&&void 0!==Ks.basic[n]||i.setOption("packed",!1,!0)}else!function(e,t){var r=u();if(!ea.test(r))throw b(r,"name");var n=Vs.lcFirst(r);r===n&&(r=Vs.ucFirst(r));f("=");var o=S(u()),i=new js(r);i.group=!0;var s=new Ps(n,o,r,t);s.filename=na.filename,R(i,(function(e){switch(e){case"option":L(i,e),f(";");break;case"required":case"repeated":N(i,e);break;case"optional":N(i,y?"proto3_optional":"optional");break;case"message":k(i,e);break;case"enum":A(i,e);break;default:throw b(e)}})),e.add(i).add(s)}(e,t)}function A(e,t){if(!ea.test(t=u()))throw b(t,"name");var r=new qs(t);R(r,(function(e){switch(e){case"option":L(r,e),f(";");break;case"reserved":E(r.reserved||(r.reserved=[]),!0);break;default:!function(e,t){if(!ea.test(t))throw b(t,"name");f("=");var r=S(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);L(n,e),f(";")}),(function(){D(n)})),e.add(t,r,n.comment,n.options)}(r,e)}})),e.add(r)}function L(e,t){var r=f("(",!0);if(!ta.test(t=u()))throw b(t,"name");var n,o=t,i=o;r&&(f(")"),i=o="("+o+")",t=h(),ra.test(t)&&(n=t.slice(1),o+=t,u())),f("="),function(e,t,r,n){e.setParsedOption&&e.setParsedOption(t,r,n)}(e,i,M(e,o),n)}function M(e,t){if(f("{",!0)){for(var r={};!f("}",!0);){if(!ea.test(a=u()))throw b(a,"name");var n,o=a;if(f(":",!0),"{"===h())n=M(e,t+"."+a);else if("["===h()){var i;if(n=[],f("[",!0)){do{i=w(!0),n.push(i)}while(f(",",!0));f("]"),void 0!==i&&x(e,t+"."+a,i)}}else n=w(!0),x(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=w(!0);return x(e,t,c),c}function x(e,t,r){e.setOption&&e.setOption(t,r)}function D(e){if(f("[",!0)){do{L(e,"option")}while(f(",",!0));f("]")}return e}for(;null!==(a=u());)switch(a){case"package":if(!g)throw b(a);O();break;case"import":if(!g)throw b(a);_();break;case"syntax":if(!g)throw b(a);I();break;case"option":L(v,a),f(";");break;default:if(T(v,a)){g=!1;continue}throw b(a)}return na.filename=null,{package:n,imports:o,weakImports:i,syntax:s,root:t}}var oa,ia=aa,sa=/\/|\./;function aa(e,t){sa.test(e)||(e="google/protobuf/"+e+".proto",t={nested:{google:{nested:{protobuf:{nested:t}}}}}),aa[e]=t}aa("any",{Any:{fields:{type_url:{type:"string",id:1},value:{type:"bytes",id:2}}}}),aa("duration",{Duration:oa={fields:{seconds:{type:"int64",id:1},nanos:{type:"int32",id:2}}}}),aa("timestamp",{Timestamp:oa}),aa("empty",{Empty:{fields:{}}}),aa("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}}}}),aa("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}}}}),aa("field_mask",{FieldMask:{fields:{paths:{rule:"repeated",type:"string",id:1}}}}),aa.get=function(e){return aa[e]||null},function(e){var t=e.exports=vi.exports;t.build="full",t.tokenize=Ss,t.parse=Ds,t.common=ia,t.Root._configure(t.Type,t.parse,t.common)}(yi),function(e){e.exports=yi.exports}(gi);var ca=G(gi.exports);const la=e=>{const t=window.URL||window.webkitURL;return t?t.createObjectURL(e):""},ua=e=>{const t=e.name;return E(t)?t.substring(t.lastIndexOf(".")+1):e.type.indexOf("/")>0?e.type.substring(e.type.lastIndexOf("/")+1):""},da=e=>{(window.URL||window.webkitURL).revokeObjectURL(e)},ha=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 fa{constructor(e){h(this,"options",void 0),h(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=ua(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 pa=1680,ga=160,ya=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 va{constructor(e,t){h(this,"uploadInstance",void 0),h(this,"options",void 0),this.uploadInstance=e,this.options=t}async upload(e,t){try{const r=la(e),n=await ya(r);da(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/pa:n/pa;n>pa&&o>pa?e?(s=pa,i/=t):(i=pa,s/=t):n>pa&&o>ga?(i=pa,s/=t,s<ga&&(s=ga,i=n/(o/ga))):o>pa&&n>ga&&(s=pa,i/=t,i<ga&&(i=ga,s=o/(n/ga)))}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:ha(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 ma{constructor(e){h(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=la(e),n=await ya(r);da(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 ba;class Ca{constructor(e){h(this,"uploadInstance",void 0),this.uploadInstance=e}upload(e,t){var r;(r=e,O(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:ua(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=ba||new AudioContext;return ba=t,new Promise(((r,n)=>{t.decodeAudioData(e,(function(e){r({duration:e.duration,length:e.length})}),n)}))}}class wa{constructor(e){h(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:ua(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 Ea;!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"}(Ea||(Ea={}));const Sa=(t,r,n,o,i,s)=>({conversationType:t.conversationType,targetId:t.targetId,channelId:t.channelId,senderUserId:r,messageDirection:e.MessageDirection.SEND,isCounted:n.isCounted,isMentioned:!1,content:n.content,messageType:n.messageType,isOffLineMessage:!1,isPersited:n.isPersited,messageId:o,messageUId:i,sentTime:s,receivedTime:0,isStatusMessage:n.isStatusMessage,receivedStatus:e.ReceivedStatus.UNREAD,disableNotification:!1});let Oa=0;const _a=[Ao,ko];async function Ia(t,r,n){var o;if(!pi.loader||pi.loader.getConnectionStatus()!==e.ConnectionStatus.CONNECTED)return{code:e.ErrorCode.RC_NET_CHANNEL_INVALID};n=n||{};const i=JSON.stringify(Ot(r.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}(i)>81920)return{code:e.ErrorCode.RC_MSG_CONTENT_EXCEED_LIMIT};const s=qn(t);let a;a=p(null===(o=n)||void 0===o?void 0:o.messageId)&&n.messageId>0?n.messageId:function(){Oa++;const e=co();return Oa<e&&(Oa=e),23e13+Oa}(),uo.addMessage(a);const c=Sa(t,Mn.uid,r,a,"",function(){xa++;const e=co();xa<e&&(xa=e);return xa}());n.onSendBefore&&n.onSendBefore(c),r.isPersited&&hi.get().loadConvsationsIfNotExist([t]);const l=await Wo.getDialogAesKey(s);if(!l)return{code:e.ErrorCode.MSG_ENCRYPT_ERROR,data:c};const u=((e,t)=>{if(!E(e))return new Uint8Array;const r=Et.AES.encrypt(e,Et.enc.Utf8.parse(t.key),{iv:p(t.iv)?Et.enc.Utf8.parse(t.iv):void 0});return Xo(r.ciphertext.words)})(i,l),d={localId:rn.fromNumber(a),mediaFlag:_a.includes(r.messageType),mediaConstructor:r.objectId,mediaAttribute:"",msgPreContent:"",msgPostContent:"",msgContent:u};let h;if(t.conversationType===e.ConversationType.GROUP){var f,g;const t={...d,groupId:s};if(null!==(f=n)&&void 0!==f&&null!==(g=f.directionalUserIdList)&&void 0!==g&&g.length&&(t.assign=n.directionalUserIdList.join(",")),p(r.content.mentionedInfo)){var y;const n=r.content.mentionedInfo;n.type===e.MentionedType.ALL?t.atAll=!0:n.type===e.MentionedType.SINGAL&&null!==(y=n.userIdList)&&void 0!==y&&y.length&&(t.at=n.userIdList.map((e=>rn.fromString(e))))}h=await(v=t,Ln.send(P.SendGroupChatMessage,v,{encoder:eo.SendGroupChatMessageReq,decoder:oo}))}else{const e={...d,destId:s};h=await(e=>Ln.send(P.SendPrivateChatMessage,e,{encoder:Jn.SendPrivateChatMessageReq,decoder:jn.SendPrivateChatMessageResp}))(e)}var v;return h.code===e.ErrorCode.SUCCESS&&(c.sentTime=h.data.seqno.toNumber(),c.messageUId=h.data.msgId.toString(),hi.get().setConversationCacheByMessage(c)),{code:h.code,data:c}}const Ta=La(Ea.IMAGE,((e,t)=>new Bo({content:e.thumbnail,imageUri:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),Ra=La(Ea.GIF,((e,t)=>new Uo({gifDataSize:e.size,remoteUrl:e.url,width:e.width,height:e.height,user:t.user,extra:t.extra}))),ka=La(Ea.AUDIO,((e,t)=>new jo({remoteUrl:e.url,duration:e.duration,type:e.type,user:t.user,extra:t.extra}))),Na=La(Ea.FILE,((e,t)=>new Po({fileUrl:e.url,name:e.name,type:e.type,size:e.size,user:t.user,extra:t.extra}))),Aa=async(t,r)=>{const n=qn(t);fo.addMessage(r.messageUId);const o=await((e,t)=>{let r;return r=zn(e)?Ln.send(P.RecallGroupMessage,{groupId:e,msgId:rn.fromString(t)},{encoder:eo.RecallGroupChatMessageReq,decoder:Xr.BaseResp}):Ln.send(P.RecallPrivateMessage,{destId:e,msgId:rn.fromString(t)},{encoder:Jn.RecallPrivateChatMessageReq,decoder:Xr.BaseResp}),r})(n,r.messageUId);if(o.code!==e.ErrorCode.SUCCESS)return{code:o.code};const i=new Fo({sentTime:r.sentTime,messageUId:r.messageUId,...t}),s=Sa(t,Mn.uid,i,0,"",co());return hi.get().setConversationCacheByMessage(s),{code:e.ErrorCode.SUCCESS,data:s}};function La(t,r){return function(n,o,i,s){return new Promise((a=>{((e,t,r,n)=>{var o;const i=new fa({token:Pn.imInitToken,uploadUrl:Pn.fileUploadUrl,cert:Pn.cert,transformer:e=>({...e,url:Pn.getFileAbsoluteUri(e.url)})});let s;switch(t){case Ea.IMAGE:s=new va(i,r);break;case Ea.GIF:s=new ma(i);break;case Ea.AUDIO:s=new Ca(i);break;case Ea.FILE:s=new wa(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,t,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);Ia(n,t,s).then(a)},onFail:()=>{a({code:e.ErrorCode.UPLOAD_FILE_FAILED})}})}))}}let Ma,xa=1;class Da extends U{constructor(e){if(Da.imClient)return T.error("Please do not perform the init method repeatedly"),Da.imClient;super(),h(this,"options",void 0),h(this,"libLoader",void 0),h(this,"getServerTime",co),h(this,"sendMessage",Ia),h(this,"sendImageMessage",Ta),h(this,"sendGIFMessage",Ra),h(this,"sendHQVoiceMessage",ka),h(this,"sendFileMessage",Na),h(this,"recallMsg",Aa),this.options=e,this.fixedProtobuf(),p(e.logLevel)&&T.setLogLevel(e.logLevel),p(e.logStdout)&&T.setLogStdout(e.logStdout),T.debug("IMClient.init -> ",e.appkey),this.libLoader=pi.init(e),this.watch(),Da.imClient=this}fixedProtobuf(){ca.util.Long=rn,ca.configure()}watch(){this.libLoader.assignWatcher({onConnecting:()=>{this.emit(e.Events.CONNECTING)},onConnected:()=>{this.emit(e.Events.CONNECTED)},onDisconnect:()=>{this.emit(e.Events.DISCONNECT,this.libLoader.getConnectionStatus())},onSuspend:()=>{this.emit(e.Events.SUSPEND,this.libLoader.getConnectionStatus())},batchMessage:t=>{this.emit(e.Events.MESSAGES,{messages:t})},pullFinished:()=>{this.emit(e.Events.PULL_OFFLINE_MESSAGE_FINISHED)},conversationState:t=>{this.emit(e.Events.CONVERSATION,{conversations:t})}})}connect(e){return this.libLoader.connect(e)}disconnect(){return this.libLoader.disconnect()}getConnectionStatus(){return this.libLoader.getConnectionStatus()}async getRemoteHistoryMessages(t,r){const o=qn(t);return io({dialogId:o,offset:r.timestamp??0,count:r.count??20,newToOld:0===r.order}).then((t=>{let{code:r,data:i}=t;return new Promise((t=>{r===e.ErrorCode.SUCCESS?ri.parse({[o]:i.msg??{}},((r,n)=>{const s=n[o]??[];s.sort(((e,t)=>e.sentTime-t.sentTime)),t({code:e.ErrorCode.SUCCESS,data:{list:s,hasMore:!i.isEnd}})})):t({code:r,msg:n(r)})}))}))}async deleteRemoteMessage(e,t){return(r=qn(e),n=t.map((e=>e.messageUId)),Ln.send(P.DeleteChatMessages,{destId:r,msgIdList:n.map((e=>rn.fromString(e)))},{encoder:Jn.DeleteChatMessageReq,decoder:Xr.BaseResp})).then((e=>e.code));var r,n}async deleteRemoteMessageByTimestamp(e,t){return((e,t)=>Ln.send(P.ClearChatHistoryMessage,{destId:e,type:zn(e)?1:0,msgTime:rn.fromNumber(t)},{encoder:Jn.CleanHistoryMessageReq,decoder:Xr.BaseResp}))(qn(e),0===t?Number.MAX_VALUE:t).then((e=>e.code))}async getConversationList(t,r,n,o){const i={rows:t,type:r??0,offset:rn.fromNumber(n),newToOld:0===o},{code:s,data:a}=await(e=>Ln.send(P.GetDialogList,e,{encoder:Jn.GetWebDialogListReq,decoder:jn.GetWebDialogListResp}))(i);if(s!==e.ErrorCode.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(E);await Wo.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};hi.get().addLocalConversation(t);const r=hi.get().get(e);Object.assign(t,r),l.push(t)}}return{code:e.ErrorCode.SUCCESS,data:l}}getBlockConversationList(){const t=hi.get().getBlockConversationList();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})}getTopConversationList(){const t=hi.get().getTopConversationList();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})}async getConversation(t){const r=hi.get().get(t);if(!r)return{code:e.ErrorCode.CONVER_GET_ERROR};const{code:n,data:o}=await this.getRemoteHistoryMessages(t,{count:1,order:0});if(n!==e.ErrorCode.SUCCESS)return{code:e.ErrorCode.CONVER_GET_ERROR};const i=null==o?void 0:o.list[0],s={...t,...r,latestMessage:i};return{code:e.ErrorCode.SUCCESS,data:s}}removeConversation(e){return(e=>{let t;return t=zn(e)?Ln.send(P.DeleteGroupDialog,{groupId:e},{encoder:eo.DeleteGroupChatDialogReq,decoder:Xr.BaseResp}):Ln.send(P.DeletePrivateDialog,{destId:e},{encoder:Jn.DeletePrivateChatDialogReq,decoder:Xr.BaseResp}),t})(qn(e)).then((e=>e.code))}getUnreadMentionedCount(e){return hi.get().getUnreadMentionedCount(e)}getAllUnreadMentionedCount(){return hi.get().getAllUnreadMentionedCount()}getAllConversationState(){return hi.get().getAllConversationState()}getAllConversationUnreadCount(e,t){return hi.get().getAllUnreadCount(e,t)}getConversationUnreadCount(e){return hi.get().getUnreadCount(e)}clearConversationUnreadCount(e){hi.get().clearUnreadCount(e)}clearAllConversationsUnreadCount(){hi.get().clearAllUnreadCount()}getConversationNotificationLevel(e){return hi.get().getNotificationLevel(e)}setConversationNotificationStatus(t,r){return((e,t)=>{let r;return r=zn(e)?Ln.send(P.UpdateGroupChatMuteConfig,{groupId:e,muteFlag:t},{encoder:eo.UpdateGroupChatDialogMuteConfigReq,decoder:Xr.BaseResp}):Ln.send(P.UpdatePrivateChatMuteConfig,{destId:e,muteFlag:t},{encoder:Jn.UpdatePrivateChatDialogMuteConfigReq,decoder:Xr.BaseResp}),r})(qn(t),r===e.NotificationStatus.OPEN).then((n=>(!n.code&&hi.get().addStatus({...t,notificationStatus:r,notificationLevel:r==e.NotificationStatus.OPEN?e.NotificationLevel.AT_USER_NOTIFICATION:e.NotificationLevel.NOT_SET},!0),n.code)))}getConversationNotificationStatus(e){return hi.get().getNotificationStatus(e)}setConversationToTop(e,t){return((e,t)=>{let r;return r=zn(e)?Ln.send(P.UpdateGroupChatStickyConfig,{groupId:e,stickyFlag:t},{encoder:eo.UpdateGroupChatDialogStickyConfigReq,decoder:Xr.BaseResp}):Ln.send(P.UpdatePrivateChatStickyConfig,{destId:e,stickyFlag:t},{encoder:Jn.UpdatePrivateChatDialogStickyConfigReq,decoder:Xr.BaseResp}),r})(qn(e),t).then((r=>(!r.code&&hi.get().addStatus({...e,isTop:t},!0),r.code)))}saveConversationMessageDraft(e,t){hi.get().setDraft(e,t)}getConversationMessageDraft(e){return hi.get().getDraft(e)}clearConversationMessageDraft(e){hi.get().clearDraft(e)}formatConversation(e){const{dialog:t,msg:r}=e,n=t.destId??"",o=si(t);if(!o)return;const i=Wo.getDialogAesKeyFromLocal(n);if(!i)return;const s=ri.parseSingleDialogMessages(n,[r],i)[0];return s?(o.latestMessage=s,o):void 0}}h(Da,"imClient",void 0);const Ba=async(t,r,n)=>{if(r instanceof yo==!1)return T.warn("send message fail -> message parameter is not an instance of BaseMessage"),{code:e.ErrorCode.PARAMETER_ERROR};D("conversation",t,M,!0),Ua(t);const o=await Ma.sendMessage(t,r,n);return ja(t,o.code),o},Ua=e=>{const t="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+t)},ja=(t,r)=>{if(r!==e.ErrorCode.SUCCESS){const e="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.warn("send message fail ->"+r+":"+n(r)+","+e)}};e.CommandMessage=Go,e.ErrorDesc=n,e.FileMessage=Po,e.GIFMessage=Uo,e.HQVoiceMessage=jo,e.ImageMessage=Bo,e.TextMessage=Do,e.addEventListener=(e,t,r)=>{Ma.on(e,t,r)},e.clearAllMessagesUnreadStatus=()=>(T.debug("clear allMessagesUnreadStatus"),Ma.clearAllConversationsUnreadCount(),Promise.resolve({code:e.ErrorCode.SUCCESS})),e.clearHistoryMessages=async(t,r)=>{D("timestamp",r,(e=>k(e)&&e>=0),!0),D("conversation",t,M);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("clear message ->"+o);const i=await Ma.deleteRemoteMessageByTimestamp(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("clear message ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:e.ErrorCode.SUCCESS}},e.clearMessagesUnreadStatus=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("clear unreadMsgNum ->"+r),Ma.clearConversationUnreadCount(t),Promise.resolve({code:e.ErrorCode.SUCCESS})},e.clearTextMessageDraft=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("delete draft ->"+r),Ma.clearConversationMessageDraft(t),Promise.resolve({code:e.ErrorCode.SUCCESS})},e.connect=async t=>{D("token",t,R,!0);const r=await Ma.connect(t);return r.code===e.ErrorCode.SUCCESS?{code:r.code,data:{userId:r.userId}}:{code:r.code,msg:n(r.code)}},e.deleteMessages=async(t,r)=>{D("messages",r,(e=>C(e)&&!!e.length),!0),r.forEach((e=>{D("messages.messageUId",e.messageUId,R,!0),D("messages.sentTime",e.sentTime,k,!1),D("messages.messageDirection",e.messageDirection,(e=>1===e||2===e),!1)})),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("delete messages ->"+o);const i=await Ma.deleteRemoteMessage(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("delete message fail ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:e.ErrorCode.SUCCESS}},e.disconnect=()=>Ma.disconnect(),e.getAllConversationState=()=>{T.debug("getAllConversationState");const t=Ma.getAllConversationState();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},e.getAllUnreadMentionedCount=()=>{T.debug("getAllUnreadMentionedCount");const t=Ma.getAllUnreadMentionedCount();return Promise.resolve({code:e.ErrorCode.SUCCESS,data:t})},e.getBlockedConversationList=()=>Ma.getBlockConversationList(),e.getConnectionStatus=()=>Ma.getConnectionStatus(),e.getConversation=async t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get conversation ->"+r);const{code:o,data:i}=await Ma.getConversation(t);return o!==e.ErrorCode.SUCCESS?(T.warn("get conversation fail ->"+o+":"+n(o)+","+r),{code:o,msg:n(o)}):{code:o,data:i}},e.getConversationList=async t=>{T.debug("get conversation list ->");const{code:r,data:o}=await Ma.getConversationList((null==t?void 0:t.count)??20,null,(null==t?void 0:t.startTime)??0,(null==t?void 0:t.order)??0);return r!==e.ErrorCode.SUCCESS&&T.warn("get conversation list fail ->"+r+":"+n(r)),{code:r,msg:n(r),data:o}},e.getConversationNotificationLevel=t=>{D("options",t,M,!0),T.info("getConversationNotificationLevel ->targetId:"+t.targetId+",conversationType:"+t.conversationType);const r=Ma.getConversationNotificationLevel(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},e.getConversationNotificationStatus=t=>{D("options",t,M,!0),T.info("getConversationNotificationStatus ->targetId:"+t.targetId+",conversationType:"+t.conversationType);const r=Ma.getConversationNotificationStatus(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:r})},e.getHistoryMessages=async(t,r)=>{D("options.timestamp",r.timestamp??0,k),D("options.count",r.count??0,k),D("options.order",r.order??0,(e=>0===e||1===e)),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get history message ->"+o);const i=await Ma.getRemoteHistoryMessages(t,r);return i.code!==e.ErrorCode.SUCCESS&&T.warn("get history message fail ->"+i.code+":"+n(i.code)+","+o),i},e.getRemoteHistoryMessages=async(t,r)=>{D("options.timestamp",r.timestamp??0,k),D("options.count",r.count??0,k),D("options.order",r.order??0,(e=>0===e||1===e)),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get remote history message ->"+o);const i=await Ma.getRemoteHistoryMessages(t,r);return i.code!==e.ErrorCode.SUCCESS&&T.warn("get remote history message fail ->"+i.code+":"+n(i.code)+","+o),i},e.getServerTime=()=>Ma.getServerTime(),e.getTextMessageDraft=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get draft ->"+r);const n=Ma.getConversationMessageDraft(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},e.getTopConversationList=()=>Ma.getTopConversationList(),e.getTotalUnreadCount=(t,r)=>{if(T.debug("get total unread count -> ConversationType:"+JSON.stringify(r)+" includeMuted:"+t),D("includeMuted",t,N,!1),D("conversationTypes",r,A,!1),r)for(const e of r)D("conversationType",e,L,!0);const n=Ma.getAllConversationUnreadCount(r??[],t??!1);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},e.getUnreadCount=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("get unreadCount ->"+r);const n=Ma.getConversationUnreadCount(t);return Promise.resolve({code:e.ErrorCode.SUCCESS,data:n})},e.getUnreadMentionedCount=t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("get unreadMentionedCount ->"+r),Promise.resolve({code:e.ErrorCode.SUCCESS,data:Ma.getUnreadMentionedCount(t)})},e.init=e=>{Ma=Ma||new Da(e)},e.onceEventListener=function(e,t,r){Ma.once(e,t,r)},e.recallMessage=async(t,r)=>{D("options.messageUId",r.messageUId,R,!0),D("options.sentTime",r.sentTime,k,!0),D("conversation",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId+",messageUId:"+r.messageUId;T.debug("recall message ->"+o);const i=await Ma.recallMsg(t,r);return i.code!==e.ErrorCode.SUCCESS&&T.warn("recall message fail ->"+i.code+":"+n(i.code)+","+o),i},e.registerMessageType=(e,t,r,n,o)=>function(n){return o?new Vo(e,n):r?new Ko(e,n):t?new zo(e,n):new Ho(e,n)},e.removeConversation=async t=>{D("options",t,M,!0);const r="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("remove conversation ->"+r);const o=await Ma.removeConversation(t);return o!==e.ErrorCode.SUCCESS?(T.warn("remove conversation fail ->"+o+":"+n(o)+","+r),{code:o,msg:n(o)}):{code:o}},e.removeEventListener=(e,t,r)=>{Ma.off(e,t,r)},e.saveTextMessageDraft=(t,r)=>{D("options",t,M,!0),D("draft",r,R,!0);const n="conversationType:"+t.conversationType+",targetId:"+t.targetId;return T.debug("set draft ->"+n),Ma.saveConversationMessageDraft(t,r),Promise.resolve({code:e.ErrorCode.SUCCESS})},e.sendFileMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+o),Ua(e);const i=await Ma.sendFileMessage(e,t,r,n);return ja(e,i.code),i},e.sendGIFMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.endsWith("image/gif")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+o),Ua(e);const i=await Ma.sendGIFMessage(e,t,r,n);return ja(e,i.code),i},e.sendHQVoiceMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob),!0),Ua(e);const o=await Ma.sendHQVoiceMessage(e,t,r,n);return ja(e,o.code),o},e.sendImageMessage=async(e,t,r,n)=>{D("conversation",e,M,!0),D("msgBody.file",t.file,(e=>e instanceof Blob&&e.type.startsWith("image/")),!0);const o="conversationType:"+e.conversationType+",targetId:"+e.targetId;T.debug("send message ->"+o),Ua(e);const i=await Ma.sendImageMessage(e,t,r,n);return ja(e,i.code),i},e.sendMessage=Ba,e.sendTextMessage=(e,t,r)=>{const n=new Do(t);return Ba(e,n,r)},e.setConversationNotificationStatus=async(t,r)=>{D("options",t,M,!0),D("notificationStatus",r,(e=>1===e||2===e),!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("set conversation status ->"+o);const i=await Ma.setConversationNotificationStatus(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("set conversation status fail ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:i}},e.setConversationToTop=async function(t){let r=!(arguments.length>1&&void 0!==arguments[1])||arguments[1];D("options",t,M,!0);const o="conversationType:"+t.conversationType+",targetId:"+t.targetId;T.debug("set conversation status ->"+o);const i=await Ma.setConversationToTop(t,r);return i!==e.ErrorCode.SUCCESS?(T.warn("set conversation status fail ->"+i+":"+n(i)+","+o),{code:i,msg:n(i)}):{code:i}}}));