2025-04-09 18:55:14 +08:00

2 lines
140 KiB
JavaScript

'use strict';const e=2,t=4,o=10,s=11,r=12,i=14,n=15,u=20,a=23,p=26,l=27,h=29,c=34,g="onMessageReceived",d="onMessageModified",m="onMessageRevoked",_="onGroupListUpdated",M="groupAttributesUpdated",f="onGroupCounterUpdated",I="onTopicUpdated",y="error";class D{constructor(e=0,t=0){this.high=e,this.low=t}equal(e){return null!==e&&(this.low===e.low&&this.high===e.high)}toString(){const e=Number(this.high).toString(16);let t=Number(this.low).toString(16);if(t.length<8){let e=8-t.length;for(;e;)t="0"+t,e--}return e+t}}const L={TEST:{CHINA:{DEFAULT:"wss://wss-dev.tim.qq.com"},OVERSEA:{DEFAULT:"wss://wss-dev.tim.qq.com"},SINGAPORE:{DEFAULT:"wss://wsssgp-dev.im.qcloud.com"},KOREA:{DEFAULT:"wss://wsskr-dev.im.qcloud.com"},GERMANY:{DEFAULT:"wss://wssger-dev.im.qcloud.com"},IND:{DEFAULT:"wss://wssind-dev.im.qcloud.com"},JPN:{DEFAULT:"wss://wssjpn-dev.im.qcloud.com"},USA:{DEFAULT:"wss://wssusa-dev.im.qcloud.com"},INDONESIA:{DEFAULT:"wss://wssidn-dev.im.qcloud.com"}},PRODUCTION:{CHINA:{DEFAULT:"wss://wss.im.qcloud.com",BACKUP:"wss://wss.tim.qq.com",STAT:"https://events.im.qcloud.com",ANYCAST:"wss://162.14.13.203"},OVERSEA:{DEFAULT:"wss://wss.im.qcloud.com",BACKUP:"wss://wss.my-imcloud.com",STAT:"https://api.my-imcloud.com"},SINGAPORE:{DEFAULT:"wss://wsssgp.im.qcloud.com",BACKUP:"wss://wsssgp.my-imcloud.com",STAT:"https://apisgp.my-imcloud.com",ANYCAST:"wss://162.14.19.159"},KOREA:{DEFAULT:"wss://wsskr.im.qcloud.com",BACKUP:"wss://wsskr.my-imcloud.com",STAT:"https://apikr.my-imcloud.com",ANYCAST:"wss://162.14.13.104"},GERMANY:{DEFAULT:"wss://wssger.im.qcloud.com",BACKUP:"wss://wssger.my-imcloud.com",STAT:"https://apiger.my-imcloud.com",ANYCAST:"wss://162.14.3.17"},IND:{DEFAULT:"wss://wssind.my-imcloud.com",BACKUP:"wss://wssind.im.qcloud.com",STAT:"https://apiind.my-imcloud.com",ANYCAST:"wss://162.14.18.188"},JPN:{DEFAULT:"wss://wssjpn.im.qcloud.com",BACKUP:"wss://wssjpn.my-imcloud.com",STAT:"https://apijpn.my-imcloud.com"},USA:{DEFAULT:"wss://wssusa.im.qcloud.com",BACKUP:"wss://wssusa.my-imcloud.com",STAT:"https://apiusa.my-imcloud.com",ANYCAST:"wss://162.14.10.42"},INDONESIA:{DEFAULT:"wss://wssidn.im.qcloud.com",BACKUP:"wss://wssidn.my-imcloud.com",STAT:"https://apiidn.my-imcloud.com",ANYCAST:"wss://43.129.34.169"}}},G={ANDROID:2,IOS:3,MAC:4,WEB:7,WX_MP:8,QQ_MP:9,TT_MP:10,BAIDU_MP:11,ALI_MP:12,IPAD:13,UNI_NATIVE_APP:15},C="CHINA",b={HOST:{CURRENT:{DEFAULT:"wss://wss.im.qcloud.com",STAT:"https://events.im.qcloud.com"},setCurrent(e=C){this.CURRENT=L.PRODUCTION[e]}},NAME:{OPEN_IM:"openim",OPEN_IM_MSG_EXT:"openim_msg_ext_http_svc",GROUP:"group_open_http_svc",GROUP_AVCHATROOM:"group_open_avchatroom_http_svc",GROUP_COMMUNITY:"million_group_open_http_svc",GROUP_ATTR:"group_open_attr_http_svc",FRIEND:"sns",PROFILE:"profile",RECENT_CONTACT:"recentcontact",PIC:"openpic",BIG_GROUP_NO_AUTH:"group_open_http_noauth_svc",BIG_GROUP_LONG_POLLING:"group_open_long_polling_http_svc",BIG_GROUP_LONG_POLLING_NO_AUTH:"group_open_long_polling_http_noauth_svc",IM_OPEN_STAT:"imopenstat",WEB_IM:"webim",IM_COS_SIGN:"im_cos_sign_svr",CUSTOM_UPLOAD:"im_cos_msg",HEARTBEAT:"heartbeat",IM_OPEN_PUSH:"im_open_push",IM_OPEN_STATUS:"im_open_status",IM_LONG_MESSAGE:"im_long_msg",IM_CONFIG_MANAGER:"im_sdk_config_mgr",STAT_SERVICE:"StatSvc",OVERLOAD_PUSH:"OverLoadPush",IM_MSG_AUDIT_MGR:"im_msg_audit_mgr",TUIROOM_SVR:"tui_room_svr",IM_OPEN_TRANSLATE:"im_open_translate",IM_OPEN_SPEECH:"im_open_speech",MESSAGE_SEARCH:"message_search"},CHANNEL:{SOCKET:1,XHR:2,AUTO:0},NAME_VERSION:{openim:"v4",group_open_http_svc:"v4",sns:"v4",profile:"v4",recentcontact:"v4",openpic:"v4",group_open_http_noauth_svc:"v4",group_open_long_polling_http_svc:"v4",group_open_long_polling_http_noauth_svc:"v4",imopenstat:"v4",im_cos_sign_svr:"v4",im_cos_msg:"v4",webim:"v4",im_open_push:"v4",im_open_status:"v4"}},T={SEARCH_MSG:new D(0,Math.pow(2,0)).toString(),SEARCH_GRP_SNS:new D(0,Math.pow(2,1)).toString(),AVCHATROOM_HISTORY_MSG:new D(0,Math.pow(2,2)).toString(),GRP_COMMUNITY:new D(0,Math.pow(2,3)).toString(),MSG_TO_SPECIFIED_GRP_MBR:new D(0,Math.pow(2,4)).toString(),AVCHATROOM_MBR_LIST:new D(0,Math.pow(2,6)).toString(),USER_STATUS:new D(0,Math.pow(2,7)).toString(),CONV_MARK:new D(0,Math.pow(2,9)).toString(),CONV_GROUP:new D(0,Math.pow(2,10)).toString(),AVCHATROOM_BAN_MBR:new D(0,Math.pow(2,11)).toString(),MSG_EXT:new D(0,Math.pow(2,13)).toString(),GRP_COUNTER:new D(0,Math.pow(2,15)).toString(),MSG_REACTION:new D(Math.pow(2,16)).toString()},A="group_profile",S="group_member_profile";b.HOST.setCurrent(C);const v="undefined"!=typeof wx&&"function"==typeof wx.getSystemInfoSync&&Boolean(wx.getSystemInfoSync().fontSizeSetting);v&&wx.createGamePortal;const w="undefined"!=typeof qq&&"function"==typeof qq.getSystemInfoSync&&Boolean(qq.getSystemInfoSync().fontSizeSetting),N="undefined"!=typeof tt&&"function"==typeof tt.getSystemInfoSync&&Boolean(tt.getSystemInfoSync().fontSizeSetting),R="undefined"!=typeof swan&&"function"==typeof swan.getSystemInfoSync&&Boolean(swan.getSystemInfoSync().fontSizeSetting),k="undefined"!=typeof my&&"function"==typeof my.getSystemInfoSync&&Boolean(my.getSystemInfoSync().fontSizeSetting),E="undefined"!=typeof jd&&"function"==typeof jd.getSystemInfoSync,$="undefined"!=typeof uni&&"undefined"==typeof window&&"function"==typeof uni.requireNativePlugin,P=v||w||N||R||k||$||E,U=("undefined"!=typeof uni||"undefined"!=typeof window)&&!P;w?qq:N?tt:R?swan:k?my:v?wx:$?uni:!E||jd;const q=U&&window&&window.navigator&&window.navigator.userAgent||"",O=/(micromessenger|webbrowser)/i.test(q),F=/AppleWebKit\/([\d.]+)/i.exec(q);F&&parseFloat(F.pop());const x=function(){let e="WEB";return O?e="WEB":w?e="QQ_MP":N?e="TT_MP":R?e="BAIDU_MP":k?e="ALI_MP":v?e="WX_MP":$&&(e="UNI_NATIVE_APP"),G[e]}();!function(){const e=q.match(/OS (\d+)_/i);e&&e[1]&&e[1]}(),function(){const e=q.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);if(!e)return null;const t=e[1]&&parseFloat(e[1]),o=e[2]&&parseFloat(e[2]);t&&o&&parseFloat(e[1]+"."+e[2])}(),function(){const e=q.match(/Chrome\/(\d+)/);e&&e[1]&&parseFloat(e[1])}();const V=/MSIE/.test(q)||q.indexOf("Trident")>-1&&q.indexOf("rv:11.0")>-1;!function(){const e=/MSIE\s(\d+)\.\d/.exec(q);let t=e&&parseFloat(e[1]);!t&&/Trident\/7.0/i.test(q)&&/rv:11.0/.test(q)&&(t=11)}(),function(){const e=q.match(/TBS\/(\d+)/i);if(e&&e[1])e[1]}();const H="TIMTextElem",j="TIMImageElem",B="TIMSoundElem",K="TIMFileElem",J="TIMFaceElem",W="TIMVideoFileElem",z="TIMLocationElem",X="TIMGroupTipElem",Y="TIMGroupSystemNoticeElem",Q="TIMCustomElem",Z="TIMRelayElem",ee="High",te="Normal",oe="Low",se="Lowest",re="C2C",ie="GROUP",ne="TOPIC",ue="@TIM#SYSTEM",ae="Private",pe="Public",le="ChatRoom",he="AVChatRoom",ce="Community",ge="Owner",de="Admin",me="Member",_e="Custom",Me=1,fe=3,Ie=4,ye=5,De="AcceptAndNotify",Le="AlreadyInGroup",Ge="__kImSDK_MesssageAtALL__";let Ce,be;Ce="undefined"!=typeof console?console:"undefined"!=typeof global&&global.console?global.console:"undefined"!=typeof window&&window.console?window.console:{};const Te=function(){},Ae=["assert","clear","count","debug","dir","dirxml","error","group","groupCollapsed","groupEnd","info","log","profile","profileEnd","table","time","timeEnd","timeStamp","trace","warn"];let Se=Ae.length;for(;Se--;)be=Ae[Se],console[be]||(Ce[be]=Te);var ve=Ce;const we=function(){return(new Date).getTime()+0};let Ne=0;function Re(){return ut()?"%c Chat %c":"Chat"}function ke(){const e=function(){const e=new Date;return e.setTime(we()),e}();return e.toLocaleTimeString("en-US",{hour12:!1})+"."+function(e){let t;switch(e.toString().length){case 1:t="00"+e;break;case 2:t="0"+e;break;default:t=e}return t}(e.getMilliseconds())}const Ee={arguments2String(e){let t="";if(1===e.length)t=e[0];else for(let o=0,s=e.length;o<s;o++)Je(e[o])?We(e[o])?t+=Ye(e[o]):t+=JSON.stringify(e[o]):t+=e[o],t+=" ";return t},_exec(e,t){ut()?ve[e](Re(),"background:#0abf5b; padding:1px; border-radius:3px; color: #fff","background:transparent",ke(),t):ve[e](`${Re()} ${ke()} ${t}`)},d:function(){if(Ne<=-1){const e=this.arguments2String(arguments);this._exec("debug",e)}},l:function(){if(Ne<=0){const e=this.arguments2String(arguments);this._exec("log",e)}},log:function(){if(Ne<=0){const e=this.arguments2String(arguments);this._exec("log",e)}},i:function(){if(Ne<=1){const e=this.arguments2String(arguments);this._exec("info",e)}},w:function(){if(Ne<=2){const e=this.arguments2String(arguments);this._exec("warn",e)}},e:function(){if(Ne<=3){const e=this.arguments2String(arguments);this._exec("error",e)}},setLevel:function(e){e<4&&this._exec("log","set level from "+Ne+" to "+e),Ne=e},getLevel:function(){return Ne}},$e={JPG:1,JPEG:1,GIF:2,PNG:3,BMP:4,UNKNOWN:255},Pe="Tag_Profile_IM_Nick",Ue="Tag_Profile_IM_Image",qe="JoinedSuccess",Oe="WaitAdminApproval",Fe="@TGS#_",xe="@TOPIC#_",Ve=function(e){return null!==e&&("number"==typeof e&&!isNaN(e-0)||"object"==typeof e&&e.constructor===Number)},He=function(e){return"string"==typeof e},je=function(e){if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let o=t;for(;null!==Object.getPrototypeOf(o);)o=Object.getPrototypeOf(o);return t===o},Be=function(e){return"function"==typeof Array.isArray?Array.isArray(e):"array"===ze(e)},Ke=function(e){return void 0===e},Je=function(e){return Be(e)||function(e){return null!==e&&"object"==typeof e}(e)},We=function(e){return e instanceof Error},ze=function(e){return Object.prototype.toString.call(e).match(/^\[object (.*)\]$/)[1].toLowerCase()};Date.now||(Date.now=function(){return(new Date).getTime()});const Xe=function(e,t,o,s){if(!Je(e)||!Je(t))return 0;let r=0;const i=Object.keys(t);let n;for(let u=0,a=i.length;u<a;u++)if(n=i[u],!(Ke(t[n])||o&&o.includes(n)))if(Je(e[n])&&Je(t[n]))r+=Xe(e[n],t[n],o,s);else{if(s&&s.includes(t[n]))continue;e[n]!==t[n]&&(e[n]=t[n],r+=1)}return r},Ye=function(e){return JSON.stringify(e,["message","code"])},Qe=function(e){const t=e||99999999;return Math.round(Math.random()*t)},Ze={},et=function(e){if(0===Object.getOwnPropertyNames(e).length)return Object.create(null);const t=Array.isArray(e)?[]:Object.create(null);let o="";for(const s in e)null!==e[s]?void 0!==e[s]?(o=typeof e[s],["string","number","function","boolean"].indexOf(o)>=0?t[s]=e[s]:t[s]=et(e[s])):t[s]=void 0:t[s]=null;return t};function ot(e,t){if(!Be(e)||!Be(t))return!1;let o=!1;return t.forEach(({key:t,value:s})=>{const r=e.find(e=>e.key===t);r?r.value!==s&&(r.value=s,o=!0):(e.push({key:t,value:s}),o=!0)}),o}const st=e=>e===he,rt=({type:e,groupID:t})=>e===ce||(""+t).startsWith(Fe)&&!(""+t).includes(xe),it=e=>(""+e).startsWith(Fe)&&(""+e).includes(xe);function nt(e){return e.split(xe)[0]}function ut(){return!V&&!P}function at(e,t){if(!e)return;let o=e;return t&&(e.startsWith("http://")?o=e.replace(/^http:\/\/[^/]+/,t):e.startsWith("https://")&&(o=e.replace(/^https:\/\/[^/]+/,t))),o}function pt(e,t=!0,o=!0){const s=Date.now();return t?o?s-e+" ms":Math.round((s-e)/1e3)+" s":o?s-e:Math.round((s-e)/1e3)}const lt=Object.prototype.hasOwnProperty;function ht(e){if(null==e)return!0;if("boolean"==typeof e)return!1;if("number"==typeof e)return 0===e;if("string"==typeof e)return 0===e.length;if("function"==typeof e)return 0===e.length;if(Array.isArray(e))return 0===e.length;if(e instanceof Error)return""===e.message;if(je(e)){for(const t in e)if(lt.call(e,t))return!1;return!0}return!("map"!==ze(e)&&!function(e){return"set"===ze(e)}(e)&&!function(e){return"file"===ze(e)}(e))&&0===e.size}const ct=function(e){return{code:0,data:e||{}}};class gt extends Error{constructor(e){super();const{code:t,message:o,data:s}=e;this.code=t,this.message=o||this._getErrorMessage(this.code),this.data=s||{}}}const dt=2101,mt=2114,_t=2600,Mt=2601,ft=2602,It=2603,yt=2620,Dt=2621,Lt=2622,Gt=2623,Ct=2660,bt=2661,Tt=2662,At=2681,St=2682,vt=2683,wt=2684,Nt=2685,Rt=2686,kt=2687,Et=2805,$t=2903,Pt=3122,Ut=3123;let qt=null;const Ot=function(e){return Promise.resolve(ct(e))},Ft=function(e,t=!1){if(e instanceof gt)return t&&null!==qt&&qt.emit(y,e),Promise.reject(e);if(e instanceof Error){const e=new gt({code:$t});return t&&null!==qt&&qt.emit(y,e),Promise.reject(e)}if(Ke(e)||Ke(e.code))return Promise.reject(new gt({code:$t}));const o=new gt(e);return t&&null!==qt&&qt.emit(y,o),Promise.reject(o)};const xt={A2KEY_AND_TINYID_UPDATED:"_inner1",CLOUD_CONFIG_UPDATED:"_inner2",PROFILE_UPDATED:"_inner3",CONV_SYNC_COMPLETED:"_inner4",C2C_UNREAD_HANDLE_COMPLETED:"_inner5"},Vt="messageReceivedGroup",Ht="messageReceivedGroupAVPush",jt="messageReceivedGroupAVPull",Bt={info:4,warning:5,error:6},Kt={wifi:1,"2g":2,"3g":3,"4g":4,"5g":5,unknown:6,none:7,online:8},Jt={login:4};class Wt{constructor(e){this._n="SSOLogData",this.eventType=Jt[e]||0,this.timestamp=0,this.networkType=8,this.code=0,this.message="",this.moreMessage="",this.extension=e,this.costTime=0,this.duplicate=!1,this.level=4,this.uiPlatform=void 0,this._sentFlag=!1,this._startts=we()}static bindEventStatModule(e){Wt.prototype._eventStatModule=e}updateTimeStamp(){this.timestamp=we()}start(e){return this._startts=e,this}end(e=!1){if(this._sentFlag)return;const t=we();0===this.costTime&&(this.costTime=t-this._startts),this.setMoreMessage(`startts:${this._startts} endts:${t}`),e?(this._sentFlag=!0,this._eventStatModule&&this._eventStatModule.pushIn(this)):setTimeout(()=>{this._sentFlag=!0,this._eventStatModule&&this._eventStatModule.pushIn(this)},0)}setError(e,t,o){if(!(e instanceof Error))return Ee.w(this._n+".setError value not instanceof Error, please check!"),this;if(this._sentFlag)return this;if(this.setNetworkType(o),t)e.code&&this.setCode(e.code),e.message&&this.setMoreMessage(e.message);else{const e=Et;this.setCode(e)}return this.setLevel("error"),this}setCode(e){return Ke(e)||this._sentFlag||("ECONNABORTED"===e&&(this.code=103),Ve(e)?this.code=e:Ee.w(this._n+".setCode value not a number, please check!",e,typeof e)),this}setMessage(e){return Ke(e)||this._sentFlag||(Ve(e)&&(this.message=e.toString()),He(e)&&(this.message=e)),this}setCostTime(e){return this.costTime=e,this}setLevel(e){return Ke(e)||this._sentFlag||(this.level=Bt[e]),this}setMoreMessage(e){return ht(this.moreMessage)?this.moreMessage=""+e:this.moreMessage+=" "+e,this}setNetworkType(e){if(Ke(e))Ee.w(this._n+".setNetworkType value is undefined, please check!");else{const t=Kt[e.toLowerCase()];Ke(t)||(this.networkType=t)}return this}getStartTs(){return this._startts}setUIPlatform(e){this.uiPlatform=e}setExtension(e){return this.extension=e,this}setEventType(e){return this.eventType=e,this}}const zt="send_group_msg",Xt="get_joined_group_list",Yt="get_group_self_member_info",Qt="create_group",Zt="destroy_group",eo="modify_group_base_info",to="apply_join_group",oo="apply_join_group_noauth",so="quit_group",ro="get_group_public_info",io="change_group_owner",no="handle_apply_join_group",uo="handle_invite_join_permission_group",ao="handle_invite_join_group",po="group_msg_recall",lo="msg_read_report",ho="group_msg_get",co="get_group_msg_receipt",go="group_msg_receipt",mo="get_group_msg_receipt_detail",_o="get_pendency",Mo="deletemsg",fo="get_msg",Io="get_msg_noauth",yo="get_online_member_num",Do="delete_group_ramble_msg_by_seq",Lo="modify_group_msg",Go="set_group_attr",Co="modify_group_attr",bo="delete_group_attr",To="clear_group_attr",Ao="get_group_attr",So="group_set_key_values",vo="group_get_key_values",wo="batch_get_group_notify",No="update_group_counter",Ro="get_group_counter",ko="get_group_member_info",Eo="get_members",$o="get_specified_group_member_info",Po="add_group_member",Uo="delete_group_member",qo="ban_group_member",Oo="modify_group_member_info",Fo="modify_user_info",xo={UNSEND:"unSend",SUCCESS:"success",FAIL:"fail"},Vo={NOT_START:"notStart",PENDING:"pending",RESOLVED:"resolved",REJECTED:"rejected"};class Ho{constructor(e){this.type=H,this.content={text:e.text||""}}setText(e){this.content.text=e}sendable(){return 0!==this.content.text.length}}class jo{constructor(e,t){this._imageMemoryURL="",this._fileDownloadProxy=t,P?this.createImageDataASURLInWXMiniApp(e.file):this.createImageDataASURLInWeb(e.file),this._initImageInfoModel(),this.type=j,this._percent=0,this.content={imageFormat:e.imageFormat||$e.UNKNOWN,uuid:e.uuid,imageInfoArray:[]},this.initImageInfoArray(e.imageInfoArray),this._autoFixUrl()}_initImageInfoModel(){const e=this;this._ImageInfoModel=function(t){this.instanceID=Qe(9999999),this.sizeType=t.type||0,this.type=0,this.size=t.size||0,this.width=t.width||0,this.height=t.height||0,this.imageUrl=t.imageUrl||t.url||"",this.url=at(t.url||e._imageMemoryURL,e._fileDownloadProxy)},this._ImageInfoModel.prototype={setSizeType(e){this.sizeType=e},setType(e){this.type=e},setImageUrl(e){e&&(this.imageUrl=e)},getImageUrl(){return this.imageUrl}}}initImageInfoArray(e){let t=0,o=null,s=null;for(;t<=2;)s=Ke(e)||Ke(e[t])?{type:0,size:0,width:0,height:0,url:""}:e[t],o=new this._ImageInfoModel(s),o.setSizeType(t+1),o.setType(t),this.addImageInfo(o),t++;this.updateAccessSideImageInfoArray()}updateImageInfoArray(e){const t=this.content.imageInfoArray.length;let o;for(let s=0;s<t;s++)o=this.content.imageInfoArray[s],e[s].size&&(o.size=e[s].size),e[s].url&&o.setImageUrl(e[s].url),e[s].width&&(o.width=e[s].width),e[s].height&&(o.height=e[s].height)}_autoFixUrl(){const e=this.content.imageInfoArray.length;let t="",o="";const s=["http","https"];let r=null;for(let i=0;i<e;i++)this.content.imageInfoArray[i].url&&(r=this.content.imageInfoArray[i],""!==r.imageUrl&&(o=r.imageUrl.slice(0,r.imageUrl.indexOf("://")+1),t=r.imageUrl.slice(r.imageUrl.indexOf("://")+1),s.indexOf(o)<0&&(o="https:"),this.content.imageInfoArray[i].setImageUrl([o,t].join(""))))}updatePercent(e){this._percent=e,this._percent>1&&(this._percent=1)}updateImageFormat(e){this.content.imageFormat=$e[e.toUpperCase()]||$e.UNKNOWN}createImageDataASURLInWeb(e){void 0!==e&&e.files.length>0&&(this._imageMemoryURL=window.URL.createObjectURL(e.files[0]))}createImageDataASURLInWXMiniApp(e){e&&e.url&&(this._imageMemoryURL=e.url)}replaceImageInfo(e,t){this.content.imageInfoArray[t]instanceof this._ImageInfoModel||(this.content.imageInfoArray[t]=e)}addImageInfo(e){this.content.imageInfoArray.length>=3||this.content.imageInfoArray.push(e)}updateAccessSideImageInfoArray(){const e=this.content.imageInfoArray,{width:t=0,height:o=0}=e[0];0!==t&&0!==o&&(!function(e){const t=e[2];e[2]=e[1],e[1]=t;for(let o=0;o<e.length;o++)e[o].setType(o)}(e),Object.assign(e[2],function(e){const{originUrl:t,originWidth:o,originHeight:s,min:r=198}=e,i=parseInt(o),n=parseInt(s),u={url:void 0,width:0,height:0};if((i<=n?i:n)<=r)u.url=t,u.width=i,u.height=n;else{n<=i?(u.width=Math.ceil(i*r/n),u.height=r):(u.width=r,u.height=Math.ceil(n*r/i));const e=t&&t.indexOf("?")>-1?t+"&":t+"?";u.url=198===r?e+"imageView2/3/w/198/h/198":e+"imageView2/3/w/720/h/720"}if(Ke(t)){const{url:e,...t}=u;return t}return u}({originWidth:t,originHeight:o,min:720})))}sendable(){return 0!==this.content.imageInfoArray.length&&(""!==this.content.imageInfoArray[0].imageUrl&&0!==this.content.imageInfoArray[0].size)}}class Bo{constructor(e){this.type=J,this.content=e||null}sendable(){return null!==this.content}}class Ko{constructor(e,t){this.type=B,this._percent=0,this.content={downloadFlag:2,second:e.second,size:e.size,url:at(e.url,t),remoteAudioUrl:e.url||"",uuid:e.uuid}}updatePercent(e){this._percent=e,this._percent>1&&(this._percent=1)}updateAudioUrl(e){this.content.remoteAudioUrl=e}sendable(){return""!==this.content.remoteAudioUrl}}const Jo={from:!0,groupID:!0,groupName:!0,to:!0};class Wo{constructor(e){this.type=X,this.content={},this._initContent(e)}_initContent(e){Object.keys(e).forEach(t=>{switch(t){case"remarkInfo":break;case"groupProfile":this.content.groupProfile={},this._initGroupProfile(e[t]);break;case"operatorInfo":break;case"memberInfoList":case"msgMemberInfo":this._updateMemberList(e[t]);break;case"memberExtraInfo":case"onlineMemberInfo":break;case"memberNum":this.content[t]=e[t],this.content.memberCount=e[t];break;case"newGroupProfile":this.content.newGroupProfile={},this._initNewGroupProfile(e[t]);break;default:this.content[t]=e[t]}}),this.content.userIDList||(this.content.userIDList=[this.content.operatorID])}_initGroupProfile(e){const t=Object.keys(e);for(let o=0;o<t.length;o++){const s=t[o];Jo[s]&&(this.content.groupProfile[s]=e[s])}}_updateMemberList(e){ht(this.content.memberList)?this.content.memberList=e:this.content.memberList.forEach(t=>{e.forEach(e=>{t.userID===e.userID&&Object.assign(t,e)})})}_initNewGroupProfile(e){const t=Object.keys(e);for(let o=0;o<t.length;o++){const s=t[o];"muteAllMembers"!==s?this.content.newGroupProfile[s]=e[s]:this.content.newGroupProfile[s]=1===e[s]}}}const zo={from:!0,groupID:!0,groupName:!0,to:!0};class Xo{constructor(e){this.type=Y,this.content={},this._initContent(e)}_initContent(e){Object.keys(e).forEach(t=>{switch(t){case"memberInfoList":break;case"remarkInfo":this.content.handleMessage=e[t];break;case"groupProfile":this.content.groupProfile={},this._initGroupProfile(e[t]);break;default:this.content[t]=e[t]}})}_initGroupProfile(e){const t=Object.keys(e);for(let o=0;o<t.length;o++){const s=t[o];zo[s]&&("groupName"===s?this.content.groupProfile.name=e[s]:this.content.groupProfile[s]=e[s])}}}class Yo{constructor(e,t){this.type=K,this._percent=0;const o=this._getFileInfo(e);this.content={downloadFlag:2,fileUrl:at(e.url||e.fileUrl,t)||"",uuid:e.uuid,fileName:o.name||"",fileSize:o.size||0}}_getFileInfo(e){if(!Ke(e.fileName)&&!Ke(e.fileSize))return{size:e.fileSize,name:e.fileName};const t=e.file.files[0];if($){if(t.path&&-1!==t.path.indexOf(".")){const e=t.path.slice(t.path.lastIndexOf(".")+1).toLowerCase();t.type=e,t.name||(t.name=`${Qe(999999)}.${e}`)}t.name||(t.type="",t.name=t.path.slice(t.path.lastIndexOf("/")+1).toLowerCase()),t.suffix&&(t.type=t.suffix),t.url||(t.url=t.path)}return{size:t.size,name:t.name}}updatePercent(e){this._percent=e,this._percent>1&&(this._percent=1)}updateFileUrl(e){this.content.fileUrl=e}sendable(){return""!==this.content.fileUrl&&(""!==this.content.fileName&&0!==this.content.fileSize)}}class Qo{constructor(e){this.type=Q,this.content={data:e.data||"",description:e.description||"",extension:e.extension||""}}setData(e){return this.content.data=e,this}setDescription(e){return this.content.description=e,this}setExtension(e){return this.content.extension=e,this}sendable(){return 0!==this.content.data.length||0!==this.content.description.length||0!==this.content.extension.length}}class Zo{constructor(e,t){this.type=W,this._percent=0,this.content={remoteVideoUrl:e.remoteVideoUrl||e.videoUrl||"",videoFormat:e.videoFormat,videoSecond:parseInt(e.videoSecond,10),videoSize:e.videoSize,videoUrl:at(e.videoUrl,t),videoDownloadFlag:2,videoUUID:e.videoUUID,thumbUUID:e.thumbUUID,thumbFormat:e.thumbFormat,thumbWidth:e.thumbWidth,snapshotWidth:e.thumbWidth,thumbHeight:e.thumbHeight,snapshotHeight:e.thumbHeight,thumbSize:e.thumbSize,snapshotSize:e.thumbSize,thumbDownloadFlag:2,thumbUrl:at(e.thumbUrl,t),snapshotUrl:at(e.thumbUrl,t)}}updatePercent(e){this._percent=e,this._percent>1&&(this._percent=1)}updateVideoUrl(e){e&&(this.content.remoteVideoUrl=e)}updateSnapshotInfo(e){const{snapshotUrl:t,snapshotWidth:o,snapshotHeight:s}=e;ht(t)||(this.content.thumbUrl=this.content.snapshotUrl=t),ht(o)||(this.content.thumbWidth=this.content.snapshotWidth=Number(o)),ht(s)||(this.content.thumbHeight=this.content.snapshotHeight=Number(s))}sendable(){return""!==this.content.remoteVideoUrl}}class es{constructor(e){this.type=z;const{description:t,longitude:o,latitude:s}=e;this.content={description:t,longitude:o,latitude:s}}sendable(){return!0}}class ts{constructor(e,t){if(this.from=e.from,this.messageSender=e.from,this.time=e.time,this.messageSequence=e.sequence,this.clientSequence=e.clientSequence||e.sequence,this.messageRandom=e.random,this.cloudCustomData=e.cloudCustomData||"",this.clientTime=e.clientTime||void 0,e.ID)this.ID=e.ID||"",this.nick=e.nick||"",this.avatar=e.avatar||"",e.messageBody?this.messageBody=JSON.parse(JSON.stringify(e.messageBody)):this.messageBody=[{type:e.type,payload:e.payload}],e.conversationType?e.conversationType.startsWith(re)?this.receiverUserID=e.to:e.conversationType.startsWith(ie)&&(this.receiverGroupID=e.to):e.receiverGroupID?this.receiverGroupID=e.receiverGroupID:e.receiverUserID&&(this.receiverUserID=e.receiverUserID),this.messageReceiver=e.to||e.messageReceiver;else{this.nick=e.nick||"",this.avatar=e.avatar||"",this.messageBody=[];const o=e.elements[0].type,s=e.elements[0].content;this._patchRichMediaPayload(o,s),this._updateRichMediaDownloadUrl(o,s,t),o===Z?this.messageBody.push({type:o,payload:new os(s).content}):this.messageBody.push({type:o,payload:s}),e.groupID&&(this.receiverGroupID=e.groupID,this.messageReceiver=e.groupID),e.to&&(this.receiverUserID=e.to,this.messageReceiver=e.to),this.ID=`${e.tinyID}-${e.clientTime}-${e.random}`}}_patchRichMediaPayload(e,t){e===j?t.imageInfoArray.forEach(e=>{!e.imageUrl&&e.url&&(e.imageUrl=e.url,e.sizeType=e.type,1===e.type?e.type=0:3===e.type&&(e.type=1))}):e===W?!t.remoteVideoUrl&&t.videoUrl&&(t.remoteVideoUrl=t.videoUrl):e===B?!t.remoteAudioUrl&&t.url&&(t.remoteAudioUrl=t.url):e===K&&!t.fileUrl&&t.url&&(t.fileUrl=t.url,t.url=void 0)}_updateRichMediaDownloadUrl(e,t,o){o&&(e===j?t.imageInfoArray.forEach(e=>{e.url=at(e.url,o)}):e===W?(t.videoUrl=at(t.videoUrl,o),t.snapshotUrl=at(t.thumbUrl,o),t.snapshotHeight=t.thumbHeight,t.snapshotWidth=t.thumbWidth):e===B?t.url=at(t.url,o):e===K&&(t.fileUrl=at(t.fileUrl,o)))}}var os=class{constructor(e,t){if(this.type=Z,this.content={downloadKey:"",pbDownloadKey:"",messageList:[],title:"",abstractList:[],compatibleText:"",version:0,layersOverLimit:!1},e.downloadKey){const{downloadKey:t,pbDownloadKey:o,title:s,abstractList:r,compatibleText:i,version:n}=e;this.content.downloadKey=t,this.content.pbDownloadKey=o,this.content.title=s,this.content.abstractList=r,this.content.compatibleText=i,this.content.version=n||0}else if(ht(e.messageList))1===e.layersOverLimit&&(this.content.layersOverLimit=!0);else{const{messageList:o,title:s,abstractList:r,compatibleText:i,version:n}=e,u=[];o.forEach(e=>{if(!ht(e)){const o=new ts(e,t);u.push(o)}}),this.content.messageList=u,this.content.title=s,this.content.abstractList=r,this.content.compatibleText=i,this.content.version=n||0}}sendable(){return!ht(this.content.messageList)||!ht(this.content.downloadKey)}};const ss={1:ee,2:te,3:oe,4:se};class rs{constructor(e){this.ID="",this.conversationID=e.conversationID||null,this.conversationType=e.conversationType||re,this.conversationSubType=e.conversationSubType,this.time=e.time||Math.ceil(Date.now()/1e3),this.sequence=e.sequence||0,this.clientSequence=e.clientSequence||e.sequence||0,this.random=e.random||0===e.random?e.random:Qe(),this.priority=this._computePriority(e.priority),this.nick=e.nick||"",this.avatar=e.avatar||"",this.isPeerRead=!1,this.nameCard="",this.hasRiskContent=function(e){let t=!1;return e&&e>1&&(t=!0),t}(e.checkResult),this._elements=[],this.isPlaceMessage=e.isPlaceMessage||0,this.isRevoked=2===e.isPlaceMessage||8===e.msgFlagBits,this.from=e.from||null,this.to=e.to||null,this.flow="",this.isSystemMessage=e.isSystemMessage||!1,this.protocol=e.protocol||"JSON",this.isResend=!1,this.isRead=!1,this.status=e.status||xo.SUCCESS,this._onlineOnlyFlag=!1,this._groupAtInfoList=[],this._relayFlag=!1,this.atUserList=[],this.cloudCustomData=e.cloudCustomData||"",this.isDeleted=!1,this.isModified=!1,this._isExcludedFromUnreadCount=!(!e.messageControlInfo||1!==e.messageControlInfo.excludedFromUnreadCount),this._isExcludedFromLastMessage=!(!e.messageControlInfo||1!==e.messageControlInfo.excludedFromLastMessage),this.clientTime=e.clientTime||Math.floor(we()/1e3)||0,this.senderTinyID=e.senderTinyID||e.tinyID||"",this.readReceiptInfo=e.readReceiptInfo||{readCount:void 0,unreadCount:void 0,isPeerRead:void 0},this.needReadReceipt=!0===e.needReadReceipt||1===e.needReadReceipt,this.version=e.messageVersion||0,this.isBroadcastMessage=e.isBroadcastMessage||!1,this._receiverList=e.receiverList||void 0,this.isSupportExtension=!0===e.isSupportExtension||1===e.isSupportExtension,this.revoker=e.revokerInfo&&e.revokerInfo.revoker||"",this.revokerInfo=e.revokerInfo||{userID:"",nick:"",avatar:""},this.revokeReason=e.revokeReason||"",this.reInitialize(e.currentUser),this.extractGroupInfo(e.groupProfile||null),this.handleGroupAtInfo(e),this.initC2CReadReceiptInfo(e.readReceiptSentByPeer)}get elements(){return this._elements}getElements(){return this._elements}extractGroupInfo(e){if(null===e)return;He(e.nick)&&(this.nick=e.nick),He(e.avatar)&&(this.avatar=e.avatar);const{messageFromAccountExtraInformation:t}=e;je(t)&&He(t.nameCard)&&(this.nameCard=t.nameCard)}handleGroupAtInfo(e){e.payload&&e.payload.atUserList&&e.payload.atUserList.forEach(e=>{e!==Ge?(this._groupAtInfoList.push({groupAtAllFlag:0,groupAtUserID:e}),this.atUserList.push(e)):(this._groupAtInfoList.push({groupAtAllFlag:1}),this.atUserList.push(Ge))}),Be(e.groupAtInfo)&&e.groupAtInfo.forEach(e=>{0===e.groupAtAllFlag?this.atUserList.push(e.groupAtUserID):1===e.groupAtAllFlag&&this.atUserList.push(Ge)})}getGroupAtInfoList(){return this._groupAtInfoList}_initProxy(){this._elements[0]&&(this.payload=this._elements[0].content,this.type=this._elements[0].type)}reInitialize(e){e&&(this.status=this.from?xo.SUCCESS:xo.UNSEND,!this.from&&(this.from=e)),this._initFlow(e),this._initSequence(e),this._concatConversationID(e),this.generateMessageID()}isSendable(){return 0!==this._elements.length&&(!0===this._relayFlag||"function"==typeof this._elements[0].sendable&&this._elements[0].sendable())}_initTo(e){this.conversationType===ie&&(this.to=e.groupID)}_initSequence(e){0===this.clientSequence&&e&&(this.clientSequence=function(e){if(!e)return!1;if(void 0===Ze[e]){const t=new Date;let o=("3"+t.getHours()).slice(-2),s=("0"+t.getMinutes()).slice(-2),r=("0"+t.getSeconds()).slice(-2);Ze[e]=parseInt([o,s,r,"0001"].join("")),o=null,s=null,r=null,Ee.l("autoIncrementIndex start index:"+Ze[e])}return Ze[e]++}(e)),0===this.sequence&&this.conversationType===re&&(this.sequence=this.clientSequence)}generateMessageID(){this.from===ue&&(this.senderTinyID="144115198244471703"),this.ID=`${this.senderTinyID}-${this.clientTime}-${this.random}`}_initFlow(e){""!==e&&(e===this.from?(this.flow="out",this.isRead=!0):this.flow="in")}_concatConversationID(e){const{to:t}=this;let o="";const s=this.conversationType;s!==ue?(o=s===re?e===this.from?t:this.from:this.to,this.conversationID=o?`${s}${o}`:null):this.conversationID=ue}isElement(e){return e instanceof Ho||e instanceof jo||e instanceof Bo||e instanceof Ko||e instanceof Yo||e instanceof Zo||e instanceof Wo||e instanceof Xo||e instanceof Qo||e instanceof es||e instanceof os}setElement(e,t){if(this.isElement(e))return this._elements=[e],void this._initProxy();const o=e=>{if(e.type&&e.content)switch(e.type){case H:this.setTextElement(e.content);break;case j:this.setImageElement(e.content,t);break;case B:this.setAudioElement(e.content,t);break;case K:this.setFileElement(e.content,t);break;case W:this.setVideoElement(e.content,t);break;case Q:this.setCustomElement(e.content);break;case z:this.setLocationElement(e.content);break;case X:this.setGroupTipElement(e.content);break;case Y:this.setGroupSystemNoticeElement(e.content);break;case J:this.setFaceElement(e.content);break;case Z:this.setMergerElement(e.content,t)}};if(Be(e))for(let s=0;s<e.length;s++)o(e[s]);else o(e);this._initProxy()}clearElement(){this._elements.length=0}setTextElement(e){const t="string"==typeof e?e:e.text,o=new Ho({text:t});this._elements.push(o)}setImageElement(e,t){const o=new jo(e,t);this._elements.push(o)}setAudioElement(e,t){const o=new Ko(e,t);this._elements.push(o)}setFileElement(e,t){const o=new Yo(e,t);this._elements.push(o)}setVideoElement(e,t){const o=new Zo(e,t);this._elements.push(o)}setLocationElement(e){const t=new es(e);this._elements.push(t)}setCustomElement(e){const t=new Qo(e);this._elements.push(t)}setGroupTipElement(e){let t={};const o=e.operationType;if(ht(e.memberInfoList)?e.operatorInfo&&(t=e.operatorInfo):o!==Me&&o!==fe&&o!==Ie&&o!==ye||(t=e.memberInfoList[0]),!ht(e.memberExtraInfo)){const{reason:t}=e.memberExtraInfo;e.msgMemberInfo.forEach(e=>{e.reason=t})}const{nick:s,avatar:r}=t;He(s)&&(this.nick=s),He(r)&&(this.avatar=r);const i=new Wo(e);this._elements.push(i)}setGroupSystemNoticeElement(e){const t=new Xo(e);this._elements.push(t)}setFaceElement(e){const t=new Bo(e);this._elements.push(t)}setMergerElement(e,t){const o=new os(e,t);this._elements.push(o)}setIsRead(e){this.isRead=e}setRelayFlag(e){this._relayFlag=e}_computePriority(e){if(Ke(e))return te;if(He(e)&&-1!==Object.values(ss).indexOf(e))return e;if(Ve(e)){const t=""+e;if(-1!==Object.keys(ss).indexOf(t))return ss[t]}return te}setNickAndAvatar(e){const{nick:t,avatar:o}=e;He(t)&&(this.nick=t),He(o)&&(this.avatar=o)}setNameCard(e){He(e)&&(this.nameCard=e)}initC2CReadReceiptInfo(e){this.conversationType===re&&!0===this.needReadReceipt&&(this.readReceiptInfo.isPeerRead=1===e)}}class is{constructor(e){this._groupModule=e,this._n="GroupTipsHandler",this._cachedGroupTipsMap=new Map,this._checkCountMap=new Map,this.MAX_CHECK_COUNT=4,this._getTopicPendingMap=new Map}onCheckTimer(e){e%1==0&&this._cachedGroupTipsMap.size>0&&this._checkCachedGroupTips()}_checkCachedGroupTips(){this._cachedGroupTipsMap.forEach((e,t)=>{let o=this._checkCountMap.get(t);const s=this._groupModule.hasLocalGroup(t);Ee.l(`${this._n}._checkCachedGroupTips groupID:${t} hasLocalGroup:${s} checkCount:${o}`),s?(this._notifyCachedGroupTips(t),this._checkCountMap.delete(t),this._groupModule.deleteUnjoinedAVChatRoom(t)):o>=this.MAX_CHECK_COUNT?(this._deleteCachedGroupTips(t),this._checkCountMap.delete(t)):(o++,this._checkCountMap.set(t,o))})}onNewGroupTips(e){Ee.d(`${this._n}.onReceiveGroupTips count:${e.dataList.length}`);const{eventDataList:t,result:o,AVChatRoomMessageList:r}=this.newGroupTipsStoredAndSummary(e);if(r.length>0&&this._groupModule.onAVChatRoomMessage(r),t.length>0){this._groupModule.updateNextMessageSeq(t);this._groupModule.getModule(s).onNewMessage({conversationOptionsList:t,isInstantMessage:!0})}o.length>0&&(this._groupModule.emitOuterEvent(g,o),this.handleMessageList(o))}newGroupTipsStoredAndSummary(e){const{event:t,dataList:r}=e;let i=null;const n=[],u=[],a={},p=[];for(let l=0,h=r.length;l<h;l++){const e=et(r[l]);if(6===t){if(this._groupModule.isGroupAttributesUpdatedNotice(e))continue;if(this._groupModule.isGroupCountersNotice(e))continue}const{groupProfile:{groupID:h,communityType:c=0,topicID:g,invisible:d}}=e;let m=void 0;const _=this._groupModule.isMessageFromTopic(c,g);if(_){m=ne,e.to=g;const t=this._groupModule.getModule(o);t.hasLocalTopic(h,g)||this._getTopicPendingMap.has(g)||(this._getTopicPendingMap.set(g,1),t.getTopicList({groupID:h,topicIDList:[g]}).finally(()=>{this._getTopicPendingMap.delete(g)}))}const M=this._groupModule.hasLocalGroup(h);if(!M&&this._groupModule.isUnjoinedAVChatRoom(h))continue;if(!M&&!_){this._cacheGroupTipsAndProbe({groupID:h,event:t,item:e});continue}if(this._groupModule.isMessageFromOrToAVChatroom(h)){e.event=t,p.push(e);continue}if(e.currentUser=this._groupModule.getMyUserID(),e.conversationType=ie,i=new rs(e),i.setElement({type:X,content:{...e.elements,groupProfile:e.groupProfile}}),i.isSystemMessage=!1,1===d){this._qualityStat(i);continue}const f=this._groupModule.getModule(s),{conversationID:I,sequence:y}=i;if(6===t)i._onlineOnlyFlag=!0,u.push(i);else{if(!f.pushIntoNoticeResult(u,i))continue}if(this._groupModule.isMessageFromCommunityOfTopic(c,g))continue;if(6===t&&f.getLocalConversation(I))continue;6!==t&&this._qualityStat(i);const D=f.isRemoteRead({conversationID:I,sequence:y});if(Ke(a[I])){let e=0;"in"===i.flow&&(i._isExcludedFromUnreadCount||i._onlineOnlyFlag||D||(e=1)),a[I]=n.push({conversationID:I,unreadCount:e,type:Ke(m)?i.conversationType:m,subType:i.conversationSubType,lastMessage:i._isExcludedFromLastMessage?"":i})-1}else{const e=a[I];n[e].type=i.conversationType,n[e].subType=i.conversationSubType,n[e].lastMessage=i._isExcludedFromLastMessage?"":i,"in"===i.flow&&(i._isExcludedFromUnreadCount||i._onlineOnlyFlag||D||n[e].unreadCount++)}}return{eventDataList:n,result:u,AVChatRoomMessageList:p}}_qualityStat(e){this._groupModule.getModule(p).addMessageSequence({key:Vt,message:e})}handleMessageList(e){e.forEach(e=>{switch(e.payload.operationType){case 1:this._onNewMemberComeIn(e);break;case 2:this._onMemberQuit(e);break;case 3:this._onMemberKickedOut(e);break;case 4:this._onMemberSetAdmin(e);break;case 5:this._onMemberCancelledAdmin(e);break;case 6:this._onGroupProfileModified(e);break;case 7:this._onMemberInfoModified(e);break;case 8:this._onTopicProfileUpdated(e);break;default:Ee.w(`${this._n}.handleMessageList unknown operationType:${e.payload.operationType}`)}})}_onNewMemberComeIn(e){const{memberNum:t,groupProfile:{groupID:o}}=e.payload,s=this._groupModule.getLocalGroupProfile(o);s&&Ve(t)&&s.memberCount!==t&&(s.memberCount=t,this._updateConversationGroupProfile(s))}_onMemberQuit(e){const{memberNum:t,groupProfile:{groupID:o}}=e.payload,s=this._groupModule.getLocalGroupProfile(o);s&&Ve(t)&&s.memberCount!==t&&(s.memberCount=t,this._updateConversationGroupProfile(s));this._groupModule.getGroupMemberHandler().deleteLocalGroupMembers(o,e.payload.userIDList)}_onMemberKickedOut(e){const{memberNum:t,groupProfile:{groupID:o}}=e.payload,s=this._groupModule.getLocalGroupProfile(o);s&&Ve(t)&&s.memberCount!==t&&(s.memberCount=t,this._updateConversationGroupProfile(s));this._groupModule.getGroupMemberHandler().deleteLocalGroupMembers(o,e.payload.userIDList)}_updateConversationGroupProfile(e){this._groupModule.getModule(s).updateConversationGroupProfile([e])}_onMemberSetAdmin(e){const t=e.payload.groupProfile.groupID,o=e.payload.userIDList,s=this._groupModule.getGroupMemberHandler();o.forEach(e=>{const o=s.getLocalGroupMemberInfo(t,e);o&&o.updateRole(de)})}_onMemberCancelledAdmin(e){const t=e.payload.groupProfile.groupID,o=e.payload.userIDList,s=this._groupModule.getGroupMemberHandler();o.forEach(e=>{const o=s.getLocalGroupMemberInfo(t,e);o&&o.updateRole(me)})}_onGroupProfileModified(e){const{newGroupProfile:t,groupProfile:o}=e.payload,{groupID:s}=o,r=this._groupModule.getLocalGroupProfile(s);Object.keys(t).forEach(e=>{switch(e){case"ownerID":this._ownerChanged(r,t);break;case"groupName":r.name=t[e];break;default:r[e]=t[e]}});const i=!r.isSupportTopic;this._groupModule.emitGroupListUpdate(!0,i)}_ownerChanged({groupID:e},t){const o=this._groupModule.getLocalGroupProfile(e),s=this._groupModule.getMyUserID();if(s===t.ownerID){o.updateGroup({selfInfo:{role:ge}});const t=this._groupModule.getGroupMemberHandler(),r=t.getLocalGroupMemberInfo(e,s),i=this._groupModule.getLocalGroupProfile(e).ownerID,n=t.getLocalGroupMemberInfo(e,i);r&&r.updateRole(ge),n&&n.updateRole(me)}}_onMemberInfoModified(e){const{to:t,payload:{groupProfile:o,memberList:s}}=e,r=o.groupID;it(t)&&this._updateTopicMuteTime(e);const i=this._groupModule.getGroupMemberHandler();s.forEach(e=>{const t=i.getLocalGroupMemberInfo(r,e.userID);t&&Ve(e.muteTime)&&t.updateMuteUntil(e.muteTime)})}_updateTopicMuteTime(e){const{to:t,payload:{groupProfile:s,memberList:r=[]}}=e,i=this._groupModule.getModule(o),{groupID:n}=s,u=i.getLocalTopic(n,t);if(u){let e=!1;for(let t=0;t<r.length;t++){const o=r[t];if(o.userID===this._groupModule.getMyUserID()&&o.muteTime>=0){u.updateSelfInfo({muteTime:o.muteTime}),e=!0;break}}e&&this._groupModule.emitOuterEvent(I,{groupID:n,topic:u})}}_onTopicProfileUpdated(e){const{groupProfile:{groupID:t},newTopicInfo:s}=e.payload;this._groupModule.getModule(o).onTopicProfileUpdated({groupID:t,topicID:e.to,...s})}_cacheGroupTips(e,t){this._cachedGroupTipsMap.has(e)||this._cachedGroupTipsMap.set(e,[]),this._cachedGroupTipsMap.get(e).push(t)}_deleteCachedGroupTips(e){this._cachedGroupTipsMap.has(e)&&this._cachedGroupTipsMap.delete(e)}_notifyCachedGroupTips(e){const t=this._cachedGroupTipsMap.get(e)||[];t.forEach(e=>{this.onNewGroupTips(e)}),this._deleteCachedGroupTips(e),Ee.l(`${this._n}._notifyCachedGroupTips groupID:${e} count:${t.length}`)}_cacheGroupTipsAndProbe(e){const{groupID:t,event:o,item:s}=e;this._cacheGroupTips(t,{event:o,dataList:[s]}),this._groupModule.getGroupSimplifiedInfo(t).then(e=>{const{type:o}=e;o===he?this._groupModule.hasLocalGroup(t)?this._notifyCachedGroupTips(t):this._groupModule.setUnjoinedAVChatRoom(t):(this._groupModule.updateGroupMap([e]),this._notifyCachedGroupTips(t))}),this._checkCountMap.has(t)||this._checkCountMap.set(t,0),Ee.l(`${this._n}._cacheGroupTipsAndProbe groupID:${t}`)}reset(){this._cachedGroupTipsMap.clear(),this._checkCountMap.clear(),this._getTopicPendingMap.clear()}}class ns{constructor(e){this._groupModule=e,this._n="CommonGroupHandler",this.tempConversationList=null,this._cachedGroupMessageMap=new Map,this._checkCountMap=new Map,this.MAX_CHECK_COUNT=4,this.PAGING_GRP_COUNT_LIMIT=200,this._getTopicPendingMap=new Map,this._pagingStatus=Vo.NOT_START,this._pagingGetCostList=[];e.getInnerEmitterInstance().on(xt.A2KEY_AND_TINYID_UPDATED,this.syncGroupList,this)}onCheckTimer(e){e%1==0&&this._cachedGroupMessageMap.size>0&&this._checkCachedGroupMessage()}_checkCachedGroupMessage(){this._cachedGroupMessageMap.forEach((e,t)=>{let o=this._checkCountMap.get(t);const s=this._groupModule.hasLocalGroup(t);Ee.l(`${this._n}._checkCachedGroupMessage groupID:${t} hasLocalGroup:${s} checkCount:${o}`),s?(this._notifyCachedGroupMessage(t),this._checkCountMap.delete(t),this._groupModule.deleteUnjoinedAVChatRoom(t)):o>=this.MAX_CHECK_COUNT?(this._deleteCachedGroupMessage(t),this._checkCountMap.delete(t)):(o++,this._checkCountMap.set(t,o))})}handleUpdateGroupLastMessage(e){const t=this._n+".handleUpdateGroupLastMessage";if(0===this._groupModule.getGroupMap().size)return void(this.tempConversationList=e);let o,s,r,i=!1;for(let a=0,p=e.length;a<p;a++)o=e[a],o.type===ie&&0!==o.lastMessage.lastSequence&&null!==o.lastMessage.payload&&(s=o.conversationID.split(/^GROUP/)[1],r=this._groupModule.getLocalGroupProfile(s),r&&(n=r.lastMessage,u=o.lastMessage,JSON.stringify(n)!==JSON.stringify(u)&&(r.lastMessage={...o.lastMessage},i=!0)));var n,u;Ee.l(`${t} conversation count:${e.length}, local group count:${this._groupModule.getLocalGroupList().length} isGroupListUpdated:${i}`),i&&(this._groupModule.sortLocalGroupList(),this._groupModule.emitGroupListUpdate(!0,!1))}onNewGroupMessage(e){Ee.d(`${this._n}.onNewGroupMessage count:${e.dataList.length}`);const{conversationOptionsList:t,messageList:o,AVChatRoomMessageList:r}=this._newGroupMessageStoredAndSummary(e);if(r.length>0&&this._groupModule.onAVChatRoomMessage(r),this._groupModule.filterModifiedMessage(o),t.length>0){this._groupModule.updateNextMessageSeq(t);this._groupModule.getModule(s).onNewMessage({conversationOptionsList:t,isInstantMessage:e.isInstantMessage||!0,updateUnreadCount:e.updateUnreadCount||!0})}const i=this._groupModule.filterUnmodifiedMessage(o);i.length>0&&this._groupModule.emitOuterEvent(g,i),o.length=0}_newGroupMessageStoredAndSummary(e){const{dataList:r,event:i,isInstantMessage:n}=e;let u=null;const a=[],p=[],l=[],h={},c=this._groupModule.getFileDownloadProxy(),g=r.length;g>1&&r.sort((e,t)=>e.sequence-t.sequence);const d=this._groupModule.getModule(s),m=this._groupModule.getModule(t);for(let t=0;t<g;t++){const e=et(r[t]),{groupProfile:{groupID:s,communityType:g=0,topicID:_,invisible:M}}=e;let f=void 0;const I=this._groupModule.isMessageFromTopic(g,_);if(I){f=ne,e.to=_;const t=this._groupModule.getModule(o);t.hasLocalTopic(s,_)||this._getTopicPendingMap.has(_)||(this._getTopicPendingMap.set(_,1),t.getTopicList({groupID:s,topicIDList:[_]}).finally(()=>{this._getTopicPendingMap.delete(_)}))}const y=this._groupModule.hasLocalGroup(s);if(!y&&this._groupModule.isUnjoinedAVChatRoom(s))continue;if(!y&&!I){this._cacheGroupMessageAndProbe({groupID:s,event:i,item:e});continue}if(this._groupModule.isMessageFromOrToAVChatroom(s)){e.event=i,l.push(e);continue}if(e.currentUser=this._groupModule.getMyUserID(),e.conversationType=ie,e.isSystemMessage=!!e.isSystemMessage,u=new rs(e),u.setElement(e.elements,c),1===M){this._qualityStat(n,u);continue}let D=1===r[t].isModified;if(d.isMessageSentByCurrentInstance(u)?u.isModified=D:D=!1,1===e.onlineOnlyFlag)u._onlineOnlyFlag=!0,d.isMessageSentByCurrentInstance(u)||p.push(u);else{if(this._groupModule.isMessageFromCommunityOfTopic(g,_)){p.push(u);continue}if(u.from===this._groupModule.getMyUserID()){const t=d.getLatestMessageSentByMe(u.conversationID);if(t){const{nick:o,avatar:s}=t;o===u.nick&&s===u.avatar||(d.modifyMessageSentByMe({conversationID:e,latestNick:u.nick,latestAvatar:u.avatar}),m.mockOnNickAvatarModified(u.nick,u.avatar))}}if(!d.pushIntoMessageList(p,u,D))continue;this._qualityStat(n,u);const{conversationID:e,sequence:t}=u,o=d.isRemoteRead({conversationID:e,sequence:t});if(Ke(h[e])){let t=0;"in"===u.flow&&(u._isExcludedFromUnreadCount||o||(t=1)),h[e]=a.push({conversationID:e,unreadCount:t,type:Ke(f)?u.conversationType:f,subType:u.conversationSubType,lastMessage:u._isExcludedFromLastMessage?"":u})-1}else{const t=h[e];a[t].type=Ke(f)?u.conversationType:f,a[t].subType=u.conversationSubType,a[t].lastMessage=u._isExcludedFromLastMessage?"":u,"in"===u.flow&&(u._isExcludedFromUnreadCount||o||a[t].unreadCount++)}}}return{conversationOptionsList:a,messageList:p,AVChatRoomMessageList:l}}_qualityStat(e,t){const o=this._groupModule.getModule(p);o.addMessageSequence({key:Vt,message:t}),e&&t.clientTime>0&&o.addMessageDelay(t.clientTime)}onGroupMessageRevoked(e){const t=this._groupModule.getModule(s),o=[];e.dataList.forEach(e=>{const{revokedInfos:s}=e.elements,{revokerInfo:r}=e;Ke(s)||s.forEach(e=>{const s=ht(e.topicID)?"GROUP"+e.groupID:"GROUP"+e.topicID,i=t.getLocalConversation(s),n=e.revokerInfo&&e.revokerInfo.revoker||r&&r.revoker,u=r&&r.reason||"";let a;if(st(i.type))a={conversationID:s,sequence:e.sequence,ID:`${e.tinyID}-${e.clientTime}-${e.random}`};else{const o=t.revoke(s,e.sequence,e.random);o?a=o:(a={conversationID:s,sequence:e.sequence},e.tinyID&&e.clientTime&&e.random&&(a.ID=`${e.tinyID}-${e.clientTime}-${e.random}`),e.time&&(a.time=e.time))}a&&(a.revoker=n,a.revokeReason=u,a.revokerInfo={userID:n,nick:"",avatar:""},o.push(a))})}),0!==o.length&&(t.onMessageRevoked(o),t.updateRevokerInfo(o).then(e=>{this._groupModule.emitOuterEvent(m,e)}))}_groupListTreeShaking(e){const t=new Map([...this._groupModule.getGroupMap()]);for(let s=0,r=e.length;s<r;s++)t.delete(e[s].groupID);if(this._groupModule.hasJoinedAVChatRoom()){this._groupModule.getJoinedAVChatRoom().forEach(e=>{t.delete(e)})}this._groupModule.getGroupMap().forEach((e,o)=>{e.isSupportTopic&&t.delete(o)});const o=[...t.keys()];for(let s=0,r=o.length;s<r;s++)this._groupModule.deleteGroup(o[s])}syncGroupList(e=!1){this._pagingStatus===Vo.NOT_START&&this._groupModule.clearGroupMap();const t=["Type","Name","FaceUrl","NextMsgSeq","LastMsgTime","AtInfoList","LastRecallTime"],o=this.PAGING_GRP_COUNT_LIMIT,s=[];if(!0===e)return this._pagingGetGroupListWithTopic({limit:o,offset:0,groupBaseInfoFilter:t,groupList:s});const r=this._n+".syncGroupList",i=new Wt("syncGroupList");return this._pagingGetGroupList({limit:o,offset:0,groupBaseInfoFilter:t,groupList:s}).then(()=>{const e=function(e){if(!Be(e)||0===e.length)return;let t=0;return e.forEach(e=>{t+=e}),(t/e.length).toFixed(0)}(this._pagingGetCostList),t=function(e){if(!Be(e)||0===e.length)return;let t=0;return e.forEach(e=>{t+=e}),t.toFixed(0)}(this._pagingGetCostList);this._pagingGetCostList.length=0,this._pagingStatus=Vo.RESOLVED,this._groupListTreeShaking(s),this._groupModule.updateGroupMap(s);const o=`count:${this._groupModule.getLocalGroupList().length} sum:${t} avg:${e}`;return Ee.l(`${r} ok. ${o}`),i.setNetworkType(this._groupModule.getNetworkType()).setMessage(o).end(),this.tempConversationList&&(this.handleUpdateGroupLastMessage(this.tempConversationList),this.tempConversationList=null),this._groupModule.emitGroupListUpdate(!0,!0),ct({groupList:this._groupModule.getLocalGroupList()})}).catch(e=>(this._pagingStatus=Vo.REJECTED,this._groupModule.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ee.e(r+" failed. error:",e),Ft(e)))}getGroupList(){const e=this._n+".getGroupList";if(Ee.l(`${e} pagingStatus:${this._pagingStatus}`),this._pagingStatus===Vo.REJECTED||this._pagingStatus===Vo.NOT_START)return this.syncGroupList().then(()=>{const e=this._groupModule.getLocalGroupList();return ct({groupList:e,isSyncCompleted:this.isPagingGetCompleted()})}).catch(t=>(Ee.e(e+" failed. error:",t),Ft(t)));const t=this._groupModule.getLocalGroupList();return Ee.l(`${e}. returned group count:${t.length}`),Ot({groupList:t,isSyncCompleted:this.isPagingGetCompleted()})}isPagingGetCompleted(){return this._pagingStatus===Vo.RESOLVED}_pagingGetGroupList(e){const t=this._n+"._pagingGetGroupList";let{isCommunityRelay:o=!1,limit:s,offset:r,groupBaseInfoFilter:i,groupList:n}=e;const u=Date.now();return this._groupModule.request({protocolName:Xt,requestData:{type:o?ce:void 0,memberAccount:this._groupModule.getMyUserID(),limit:s,offset:r,responseFilter:{groupBaseInfoFilter:i,selfInfoFilter:["Role","JoinTime","MsgFlag","MsgSeq"]}}}).then(e=>{const{groups:a=[],totalCount:p}=e.data;n.push(...a),this._handleGroupAtInfoWithoutTopic(o,a);const l=r+s,h=!(p>l),c=`offset:${r} limit:${s} totalCount:${p} isCompleted:${h} currentCount:${n.length} isCommunityRelay:${o}`;return this._pagingGetCostList.push(pt(u,!1)),Ee.l(`${t} ok. ${c} cost:${pt(u)}`),o||h?!o&&h?(Ee.l(t+" start to get community list"),r=0,this._pagingGetGroupList({limit:s,offset:r,groupBaseInfoFilter:i,groupList:n,isCommunityRelay:!0})):o&&!h?(r=l,this._pagingGetGroupList({limit:s,offset:r,groupBaseInfoFilter:i,groupList:n,isCommunityRelay:!0})):ct({groupList:n}):(r=l,this._pagingGetGroupList({limit:s,offset:r,groupBaseInfoFilter:i,groupList:n}))}).catch(e=>10018===e.code?(Ee.w(`${this.logPrefix} response size exceeds the limit, request count:${s}`),s=50,this._pagingGetGroupList({limit:s,offset:r,groupBaseInfoFilter:i,groupList:n,isCommunityRelay:o})):o?(11e3===e.code&&Ee.l(t+" ok. community unavailable"),Ot({groupList:n})):Ft(e))}_pagingGetGroupListWithTopic(e){const t=this._n+"._pagingGetGroupListWithTopic";let{limit:o,offset:s,groupBaseInfoFilter:r,groupList:i}=e;const n=Date.now();return this._groupModule.request({protocolName:Xt,requestData:{type:ce,memberAccount:this._groupModule.getMyUserID(),limit:o,offset:s,responseFilter:{groupBaseInfoFilter:r,selfInfoFilter:["Role","JoinTime","MsgFlag","MsgSeq"]},isSupportTopic:1}}).then(e=>{const{groups:u=[],totalCount:a}=e.data;i.push(...u);const p=s+o,l=!(a>p);if(Ee.l(`${t} ok. offset:${s} limit:${o} totalCount:${a} isCompleted:${l} currentCount:${i.length} cost:${pt(n)}`),!l)return s=p,this._pagingGetGroupListWithTopic({limit:o,offset:s,groupBaseInfoFilter:r,groupList:i});this._groupModule.updateGroupMap(i),this._groupModule.emitGroupListUpdate(!0,!1);const h=this._groupModule.getLocalGroupList().filter(e=>!0===e.isSupportTopic);return ct({groupList:h})}).catch(e=>10018===e.code?(Ee.w(`${this.logPrefix} response size exceeds the limit, request count:${o}`),o=50,this._pagingGetGroupListWithTopic({limit:o,offset:s,groupBaseInfoFilter:r,groupList:i})):Ft(e))}_cacheGroupMessage(e,t){this._cachedGroupMessageMap.has(e)||this._cachedGroupMessageMap.set(e,[]),this._cachedGroupMessageMap.get(e).push(t)}_deleteCachedGroupMessage(e){this._cachedGroupMessageMap.has(e)&&this._cachedGroupMessageMap.delete(e)}_notifyCachedGroupMessage(e){const t=this._cachedGroupMessageMap.get(e)||[];t.forEach(e=>{this.onNewGroupMessage(e)}),this._deleteCachedGroupMessage(e),Ee.l(`${this._n}._notifyCachedGroupMessage groupID:${e} count:${t.length}`)}_cacheGroupMessageAndProbe(e){const{groupID:t,event:o,item:s}=e;this._cacheGroupMessage(t,{event:o,dataList:[s]}),this._groupModule.getGroupSimplifiedInfo(t).then(e=>{const{type:o}=e;o===he?this._groupModule.hasLocalGroup(t)?this._notifyCachedGroupMessage(t):this._groupModule.setUnjoinedAVChatRoom(t):(this._groupModule.updateGroupMap([e]),this._notifyCachedGroupMessage(t))}),this._checkCountMap.has(t)||this._checkCountMap.set(t,0),Ee.l(`${this._n}._cacheGroupMessageAndProbe groupID:${t}`)}_handleGroupAtInfoWithoutTopic(e,t){e&&0!==t.length&&t.forEach(e=>{const{groupID:t,groupAtInfoList:o}=e,r=[];if(!Ke(o)){o.forEach(e=>{r.push({...e,groupID:t})});this._groupModule.getModule(s).onNewGroupAtTips({dataList:r})}})}setPagingGroupCount(e){Ke(e)||(this.PAGING_GRP_COUNT_LIMIT=parseInt(e,10))}reset(){this.PAGING_GRP_COUNT_LIMIT=200,this._cachedGroupMessageMap.clear(),this._checkCountMap.clear(),this._getTopicPendingMap.clear(),this._pagingStatus=Vo.NOT_START,this._pagingGetCostList=[]}}const us=1,as=2,ps=3,ls=4,hs=5;class cs{constructor(e){this._groupModule=e,this._n="GroupAttributesHandler",this._groupAttributesMap=new Map,this._groupAttributesCopy={},this.CACHE_EXPIRE_TIME=3e4;this._groupModule.getInnerEmitterInstance().on(xt.CLOUD_CONFIG_UPDATED,this._onCloudConfigUpdated,this)}_onCloudConfigUpdated(){const e=this._groupModule.getCloudConfig("grp_attr_cache_time");Ke(e)||(this.CACHE_EXPIRE_TIME=Number(e))}updateLocalMainSequenceOnReconnected(){this._groupAttributesMap.forEach(e=>{e.localMainSequence=0})}isGroupAttributesUpdatedNotice(e){const{to:t,elements:{newGroupProfile:o}}=e,s=!Ke(o)&&!ht(o.groupAttributeOption);return s&&this._onGroupAttributesUpdated({groupID:t,groupAttributeOption:o.groupAttributeOption}),s}_onGroupAttributesUpdated(e){const{groupID:t,groupAttributeOption:o}=e,{mainSequence:s,isWithChangedAttributeInfo:r,groupAttributeList:i=[],operationType:n}=o;if(Ee.l(this._n+".onGroupAttributesUpdated. "+`groupID:${t} isWithChangedAttributeInfo:${r} operationType:${n}`),Ke(n))return;this._groupAttributesCopy=this._getCachedAttributes({groupID:t});const{localMainSequence:u}=this._getLocalGroupAttributes(t),a=s-u;if(0!==a){if(1===r&&1===a)return this._refreshCachedGroupAttributes({groupID:t,remoteMainSequence:s,groupAttributeList:i,operationType:n}),void this._emitGroupAttributesUpdated(t);if(this._hasLocalGroupAttributes(t)){const{avChatRoomKey:e}=this._getLocalGroupAttributes(t);this._getGroupAttributes({groupID:t,avChatRoomKey:e}).then(()=>{this._emitGroupAttributesUpdated(t)})}}}initGroupAttributesCache(e){const{groupID:t,avChatRoomKey:o}=e;this._groupAttributesMap.set(t,{lastUpdateTime:0,localMainSequence:0,remoteMainSequence:0,attributes:new Map,avChatRoomKey:o}),Ee.l(`${this._n}.initGroupAttributesCache groupID:${t} avChatRoomKey:${o}`)}initGroupAttributes(e){const{groupID:t,groupAttributes:o}=e,{remoteMainSequence:s,avChatRoomKey:r}=this._getLocalGroupAttributes(t),i=new Wt("initGroupAttributes");return i.setMessage(`groupID:${t} avChatRoomKey:${r} mainSequence:${s}`),this._groupModule.request({protocolName:Go,requestData:{groupID:t,avChatRoomKey:r,mainSequence:s,groupAttributeList:this._transformGroupAttributes(o)}}).then(e=>{Ee.l(`${this._n}.initGroupAttributes ok. groupID:${t}`);const{mainSequence:s,groupAttributeList:r}=e.data,n=[...r];return n.forEach(e=>{e.value=o[e.key]}),this._groupAttributesCopy=this._getCachedAttributes({groupID:t}),this._refreshCachedGroupAttributes({groupID:t,remoteMainSequence:s,groupAttributeList:n,operationType:us}),this._emitGroupAttributesUpdated(t),i.setNetworkType(this._groupModule.getNetworkType()).end(),ct({groupAttributes:o})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ft(e)))}setGroupAttributes(e){const t=this._n+".setGroupAttributes",{groupID:o,groupAttributes:s}=e,{remoteMainSequence:r,avChatRoomKey:i,attributes:n}=this._getLocalGroupAttributes(o),u=this._transformGroupAttributes(s);u.forEach(e=>{const{key:t}=e;e.sequence=0,n.has(t)&&(e.sequence=n.get(t).sequence)});const a=new Wt("setGroupAttributes");return a.setMessage(`groupID:${o} groupAttributes:${JSON.stringify(s)}`),Ee.l(`${t}. groupID:${o} mainSequence:${r}`),this._groupModule.request({protocolName:Co,requestData:{groupID:o,avChatRoomKey:i,mainSequence:r,groupAttributeList:u}}).then(e=>{Ee.l(t+" ok.");const{mainSequence:r,groupAttributeList:i}=e.data,n=[...i];return n.forEach(e=>{e.value=s[e.key]}),this._groupAttributesCopy=this._getCachedAttributes({groupID:o}),this._refreshCachedGroupAttributes({groupID:o,remoteMainSequence:r,groupAttributeList:n,operationType:as}),this._emitGroupAttributesUpdated(o),a.setNetworkType(this._groupModule.getNetworkType()).end(),ct({groupAttributes:s})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{a.setError(e,t,o).end()}),Ft(e)))}deleteGroupAttributes(e){const{groupID:t,keyList:o=[]}=e,{remoteMainSequence:s,avChatRoomKey:r,attributes:i}=this._getLocalGroupAttributes(t);let n=[...i.keys()],u=To,a=ps;const p={groupID:t,avChatRoomKey:r,mainSequence:s},l=[];o.length>0&&(n=[],u=bo,a=ls,o.forEach(e=>{let t=0;i.has(e)&&(t=i.get(e).sequence,n.push(e)),l.push({key:e,sequence:t})}),p.groupAttributeList=l);const h=new Wt("deleteGroupAttributes");return h.setMessage(`groupID:${t} mainSequence:${s} keyList:${o} protocolName:${u}`),this._groupModule.request({protocolName:u,requestData:p}).then(e=>{Ee.l(`${this._n}.deleteGroupAttributes ok. groupID:${t}`);const{mainSequence:o}=e.data;return this._groupAttributesCopy=this._getCachedAttributes({groupID:t}),this._refreshCachedGroupAttributes({groupID:t,remoteMainSequence:o,groupAttributeList:l,operationType:a}),this._emitGroupAttributesUpdated(t),h.setNetworkType(this._groupModule.getNetworkType()).end(),ct({keyList:n})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{h.setError(e,t,o).end()}),Ft(e)))}getGroupAttributes(e){const t=this._n+".getGroupAttributes",{groupID:o}=e,{avChatRoomKey:s,lastUpdateTime:r,localMainSequence:i,remoteMainSequence:n}=this._getLocalGroupAttributes(o),u=new Wt("getGroupAttributes");if(u.setMessage(`groupID:${o} localMainSequence:${i} remoteMainSequence:${n} keyList:${e.keyList}`),Date.now()-r>=this.CACHE_EXPIRE_TIME||i<n)return this._getGroupAttributes({groupID:o,avChatRoomKey:s}).then(s=>{u.setMoreMessage("get attributes from remote. count:"+s.length).setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(`${t} from remote. groupID:${o}`);const r=this._getCachedAttributes(e);return ct({groupAttributes:r})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{u.setError(e,t,o).end()}),Ft(e)));u.setMoreMessage("get attributes from cache").setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(`${t} from cache. groupID:${o}`);const a=this._getCachedAttributes(e);return Ot({groupAttributes:a})}_getGroupAttributes(e){let t=0;return Ke(e.avChatRoomKey)||(t=1),this._groupModule.request({protocolName:Ao,requestData:{...e,groupType:t}}).then(t=>{Ee.l(`${this._n}._getGroupAttributes ok. groupID:${e.groupID}`);const{mainSequence:o,groupAttributeList:s}=t.data,r=[...s];return Ke(o)||this._refreshCachedGroupAttributes({groupID:e.groupID,remoteMainSequence:o,groupAttributeList:r,operationType:hs}),s}).catch(e=>Ft(e))}_refreshCachedGroupAttributes(e){const{groupID:t,remoteMainSequence:o,groupAttributeList:s,operationType:r}=e;if(this._hasLocalGroupAttributes(t)){const e=this._getLocalGroupAttributes(t),{localMainSequence:i}=e;if(r===hs||o-i==1)e.remoteMainSequence=o,e.localMainSequence=o,e.lastUpdateTime=Date.now(),this._updateCachedAttributes({groupAttributes:e,groupAttributeList:s,operationType:r});else{if(i===o)return;e.remoteMainSequence=o}this._groupAttributesMap.set(t,e);const n=`operationType:${r} localMainSequence:${i} remoteMainSequence:${o}`;Ee.l(`${this._n}._refreshCachedGroupAttributes. ${n}`)}}_getCachedAttributes(e){const{groupID:t,keyList:o=[]}=e,s={};if(this._hasLocalGroupAttributes(t)){const{attributes:e}=this._getLocalGroupAttributes(t);if(o.length>0)o.forEach(t=>{e.has(t)&&(s[t]=e.get(t).value)});else for(const t of e.keys())s[t]=e.get(t).value}return s}_updateCachedAttributes(e){const{groupAttributes:t,groupAttributeList:o,operationType:s}=e;s!==ps?s!==ls?(s===us&&t.attributes.clear(),o.forEach(e=>{const{key:o,value:s,sequence:r}=e;t.attributes.set(o,{value:s,sequence:r})})):o.forEach(e=>{t.attributes.delete(e.key)}):t.attributes.clear()}_hasLocalGroupAttributes(e){return this._groupAttributesMap.has(e)}_getLocalGroupAttributes(e){return this._hasLocalGroupAttributes(e)||this.initGroupAttributesCache({groupID:e}),this._groupAttributesMap.get(e)}_transformGroupAttributes(e){const t=[];return Object.keys(e).forEach(o=>{t.push({key:o,value:e[o]})}),t}_emitGroupAttributesUpdated(e){const t=this._getCachedAttributes({groupID:e}),{updatedKeyList:o,deletedKeyList:s}=this._computeAttrChangedInfo(t);Ee.l(`${this._n}._emitGroupAttributesUpdated update:${o.length}, delete:${s.length}`),0===o.length&&0===s.length||this._groupModule.emitOuterEvent(M,{groupID:e,groupAttributes:t,updatedKeyList:o,deletedKeyList:s})}_computeAttrChangedInfo(e){const t=[],o=[];return Object.keys(e).forEach(o=>{e[o]!==this._groupAttributesCopy[o]&&t.push(o)}),Object.keys(this._groupAttributesCopy).forEach(t=>{Ke(e[t])&&o.push(t)}),this._groupAttributesCopy={},{updatedKeyList:t,deletedKeyList:o}}deleteLocalGroupAttributes(e){this._hasLocalGroupAttributes(e)&&this._groupAttributesMap.delete(e)}reset(){this._groupAttributesMap.clear(),this._groupAttributesCopy={},this.CACHE_EXPIRE_TIME=3e4}}const gs="Set",ds="Increase",ms="Decrease";class _s{constructor(e){this._groupModule=e,this._n="GroupCountersHandler",this._groupCountersMap=new Map,this.EXPIRE_TIME=3e4;this._groupModule.getInnerEmitterInstance().on(xt.CLOUD_CONFIG_UPDATED,this._onCloudConfigUpdated,this)}_onCloudConfigUpdated(){const e=this._groupModule.getCloudConfig("grp_counter_expire_time");Ke(e)||(this.EXPIRE_TIME=Number(e))}isGroupCountersNotice(e){const{to:t,elements:{groupCounterInfo:o}}=e;let s=!1;return ht(o)||(this._onGroupCountersUpdated({groupID:t,groupCounterInfo:o}),s=!0),s}_onGroupCountersUpdated(e){const{groupID:t,groupCounterInfo:o}=e;o.forEach(e=>{const{type:o,groupCounterSeq:s,counterList:r=[]}=e;0!==o&&2!==o||(this._updateLocalGroupCounters({groupID:t,groupCounterSeq:s,counterList:r}),r.forEach(e=>{this._groupModule.emitOuterEvent(f,{groupID:t,key:e.key,value:e.value})})),1===o&&this._deleteLocalGroupCounters({groupID:t,groupCounterSeq:s,counterList:r})}),Ee.l(`${this._n}._onGroupCountersUpdated groupID:${t}`)}initGroupCountersCache(e){const{groupID:t,avChatRoomKey:o}=e;this._groupCountersMap.set(t,{lastUpdateTime:0,groupCounterSeq:0,counters:new Map,avChatRoomKey:o}),Ee.l(`${this._n}.initGroupCountersCache groupID:${t} avChatRoomKey:${o}`)}setGroupCounters(e){if(!this._groupModule.canIUse(T.GRP_COUNTER))return this._groupModule.cannotUseCommercialAbility("setGroupCounters");const t=this._n+".setGroupCounters",{groupID:o,counters:s}=e,r=this._convertObjectToList(s),{avChatRoomKey:i}=this._getLocalGroupCounters(o),n=`groupID:${o} count:${r.length}`,u=new Wt("setGroupCounters");return u.setMessage(""+n),Ee.l(`${t}. ${n}`),this._updateGroupCounters({groupID:o,counterList:r,avChatRoomKey:i,mode:gs}).then(e=>(u.end(),Ee.l(t+" ok."),ct({counters:e}))).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{u.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}increaseGroupCounter(e){const t="increaseGroupCounter";if(!this._groupModule.canIUse(T.GRP_COUNTER))return this._groupModule.cannotUseCommercialAbility(t);const o=`${this._n}.${t}`,{groupID:s,key:r,value:i}=e,{avChatRoomKey:n}=this._getLocalGroupCounters(s),u=`groupID:${s} key:${r} value:${i}`,a=new Wt(t);a.setMessage(""+u),Ee.l(`${o}. ${u}`);const p=[{key:r,value:i}];return this._updateGroupCounters({groupID:s,counterList:p,avChatRoomKey:n,mode:ds}).then(e=>(a.end(),Ee.l(o+" ok."),ct({counters:e}))).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{a.setError(e,t,o).end()}),Ee.e(o+" failed. error:",e),Ft(e)))}decreaseGroupCounter(e){const t="decreaseGroupCounter";if(!this._groupModule.canIUse(T.GRP_COUNTER))return this._groupModule.cannotUseCommercialAbility(t);const o=`${this._n}.${t}`,{groupID:s,key:r,value:i}=e,{avChatRoomKey:n}=this._getLocalGroupCounters(s),u=`groupID:${s} key:${r} value:${i}`,a=new Wt(t);a.setMessage(""+u),Ee.l(`${o}. ${u}`);const p=[{key:r,value:i}];return this._updateGroupCounters({groupID:s,counterList:p,avChatRoomKey:n,mode:ms}).then(e=>(a.end(),Ee.l(o+" ok."),ct({counters:e}))).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{a.setError(e,t,o).end()}),Ee.e(o+" failed. error:",e),Ft(e)))}getGroupCounters(e){if(!this._groupModule.canIUse(T.GRP_COUNTER))return this._groupModule.cannotUseCommercialAbility("getGroupCounters");const t=this._n+".getGroupCounters",{groupID:o,keyList:s=[]}=e,{avChatRoomKey:r,lastUpdateTime:i}=this._getLocalGroupCounters(o),n=new Wt("getGroupCounters");if(n.setMessage("groupID:"+o),Date.now()-i>=this.EXPIRE_TIME)return this._getRemoteGroupCounters({groupID:o,avChatRoomKey:r}).then(e=>{n.setMoreMessage("from remote. count:"+e.length).end(),Ee.l(`${t} from remote. groupID:${o}`);const r=this._getLocalCounters(o,s);return ct({counters:r})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{n.setError(e,t,o).end()}),Ft(e)));n.setMoreMessage("from cache").end(),Ee.l(`${t} from cache. groupID:${o}`);const u=this._getLocalCounters(o,s);return Ot({counters:u})}_getRemoteGroupCounters(e){return this._groupModule.request({protocolName:Ro,requestData:{...e}}).then(t=>{const{counterList:o=[],groupCounterSeq:s}=t.data;return this._updateLocalGroupCounters({groupID:e.groupID,counterList:o,groupCounterSeq:s}),Ee.l(`${this._n}._getRemoteGroupCounters ok. groupID:${e.groupID}`),o}).catch(e=>Ft(e))}_convertObjectToList(e){const t=[];return Object.keys(e).forEach(o=>{t.push({key:o,value:e[o]})}),t}_updateGroupCounters(e){const t=this._n+"._updateGroupCounters",{groupID:o,avChatRoomKey:s,mode:r}=e;return Ee.l(`${t}. groupID:${o} avChatRoomKey:${s} mode:${r}`),this._groupModule.request({protocolName:No,requestData:{...e}}).then(e=>{Ee.l(t+" ok.");const{counterList:o=[]}=e.data,s={};return o.forEach(e=>{const{key:t,value:o}=e;s[t]=o}),s}).catch(e=>Ft(e))}_hasLocalGroupCounters(e){return this._groupCountersMap.has(e)}_getLocalGroupCounters(e){return this._hasLocalGroupCounters(e)||this.initGroupCountersCache({groupID:e}),this._groupCountersMap.get(e)}_updateLocalGroupCounters(e){const{groupID:t,counterList:o=[],groupCounterSeq:s}=e;if(this._hasLocalGroupCounters(t)){const{counters:e,avChatRoomKey:r,groupCounterSeq:i}=this._getLocalGroupCounters(t);if(s>0&&s<i)return;o.forEach(t=>{const{key:o,value:s}=t;e.set(o,s)}),this._groupCountersMap.set(t,{lastUpdateTime:Date.now(),groupCounterSeq:s,counters:e,avChatRoomKey:r})}}_deleteLocalGroupCounters(e){const{groupID:t,counterList:o=[],groupCounterSeq:s}=e;if(this._hasLocalGroupCounters(t)){const{counters:e,avChatRoomKey:r}=this._getLocalGroupCounters(t);o.forEach(t=>{e.delete(t.key)}),this._groupCountersMap.set(t,{lastUpdateTime:Date.now(),groupCounterSeq:s,counters:e,avChatRoomKey:r})}}_getLocalCounters(e,t){const o={};if(!this._hasLocalGroupCounters(e))return o;const{counters:s}=this._getLocalGroupCounters(e);if(t.length>0)t.forEach(e=>{s.has(e)&&(o[e]=s.get(e))});else for(const r of s.keys())o[r]=s.get(r);return o}reset(){this._groupCountersMap.clear(),this.EXPIRE_TIME=3e4}}class Ms{constructor(e){const{manager:t,groupID:o,onInit:s,onSuccess:r,onFail:i}=e;this._n="Polling",this._manager=t,this._groupModule=t._groupModule,this._onInit=s,this._onSuccess=r,this._onFail=i,this._groupID=o,this._timeoutID=-1,this._isRunning=!1,this._protocolName=fo}start(){const e=this._groupModule.isLoggedIn();e||(this._protocolName=Io),Ee.l(`${this._n}.start pollingInterval:${this._manager.getPollingInterval()} isLoggedIn:${e}`),this._isRunning=!0,this._request()}isRunning(){return this._isRunning}_request(){const e=this._onInit(this._groupID);this._groupModule.request({protocolName:this._protocolName,requestData:e}).then(e=>{this._onSuccess(this._groupID,e),this.isRunning()&&(clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),this._manager.getPollingInterval()))}).catch(e=>{this._onFail(this._groupID,e),this.isRunning()&&(clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),this._manager.MAX_POLLING_INTERVAL))})}stop(){Ee.l(this._n+".stop"),this._timeoutID>0&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}getPollingTimerID(){return this._timeoutID}}class fs{constructor(e){this.value=e,this.next=null}}class Is{constructor(e){this.MAX_LENGTH=e,this.pTail=null,this.pNodeToDel=null,this.map=new Map}set(e){const t=new fs(e);if(this.map.size<this.MAX_LENGTH)null===this.pTail?(this.pTail=t,this.pNodeToDel=t):(this.pTail.next=t,this.pTail=t),this.map.set(e,1);else{let o=this.pNodeToDel;this.pNodeToDel=this.pNodeToDel.next,this.map.delete(o.value),o.next=null,o=null,this.pTail.next=t,this.pTail=t,this.map.set(e,1)}}has(e){return this.map.has(e)}delete(e){this.has(e)&&this.map.delete(e)}tail(){return this.pTail}size(){return this.map.size}data(){return Array.from(this.map.keys())}reset(){let e;for(;null!==this.pNodeToDel;)e=this.pNodeToDel,this.pNodeToDel=this.pNodeToDel.next,e.next=null,e=null;this.pTail=null,this.map.clear()}}const ys=["groupID","name","avatar","type","introduction","notification","ownerID","selfInfo","createTime","infoSequence","lastInfoTime","lastMessage","nextMessageSeq","memberNum","maxMemberNum","memberList","joinOption","groupCustomField","muteAllMembers","isSupportTopic","inviteOption","_lastRevokedTime"];class Ds{constructor(e){this.groupID="",this.name="",this.avatar="",this.type="",this.introduction="",this.notification="",this.ownerID="",this.createTime="",this.infoSequence="",this.lastInfoTime="",this.selfInfo={messageRemindType:"",joinTime:"",nameCard:"",role:"",userID:"",memberCustomField:void 0,readedSequence:0,excludedUnreadSequenceList:void 0},this.lastMessage={lastTime:"",lastSequence:"",fromAccount:"",messageForShow:""},this.nextMessageSeq="",this.memberNum="",this.memberCount="",this.maxMemberNum="",this.maxMemberCount="",this.joinOption="",this.inviteOption="",this.groupCustomField=[],this.muteAllMembers=!1,this.isSupportTopic=!1,this._lastRevokedTime=0,this._initGroup(e)}set memberNum(e){}set maxMemberNum(e){}get memberNum(){return this.memberCount}get maxMemberNum(){return this.maxMemberCount}_initGroup(e){for(const t in e)ys.indexOf(t)<0||("selfInfo"!==t?("memberNum"===t&&(this.memberCount=e[t]),"maxMemberNum"===t&&(this.maxMemberCount=e[t]),"isSupportTopic"!==t?this[t]=e[t]:this.isSupportTopic=1===e[t]):this.updateSelfInfo(e[t]))}updateGroup(e){e.appid=void 0,e.grossTopicNextMsgSeq=void 0,e.selfInfo&&(e.selfInfo.grossTopicReadSeq=void 0);const t=JSON.parse(JSON.stringify(e));t.lastMsgTime&&(this.lastMessage.lastTime=t.lastMsgTime),Ke(t.muteAllMembers)||("On"===t.muteAllMembers?t.muteAllMembers=!0:t.muteAllMembers=!1),t.groupCustomField&&ot(this.groupCustomField,t.groupCustomField),Ke(t.memberNum)||(this.memberCount=t.memberNum),Ke(t.maxMemberNum)||(this.maxMemberCount=t.maxMemberNum),Ke(t.isSupportTopic)||(this.isSupportTopic=Ve(t.isSupportTopic)?1===t.isSupportTopic:t.isSupportTopic),Xe(this,t,["members","errorCode","lastMsgTime","groupCustomField","memberNum","maxMemberNum","isSupportTopic"]),Be(t.members)&&t.members.length>0&&t.members.forEach(e=>{e.userID===this.selfInfo.userID&&Xe(this.selfInfo,e,["sequence"])})}updateSelfInfo({nameCard:e,joinTime:t,role:o,messageRemindType:s,readedSequence:r,excludedUnreadSequenceList:i}){const n={nameCard:e,joinTime:t,role:o,messageRemindType:s,readedSequence:r,excludedUnreadSequenceList:i};Xe(this.selfInfo,{...n},[],["",null,void 0,0,NaN])}setSelfNameCard(e){this.selfInfo.nameCard=e}}const Ls={3:!0,4:!0,5:!0,6:!0,17:!0,20:!0,21:!0};class Gs{constructor(e){this._groupModule=e,this._n="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this.sequencesLinkedList=new Is(200),this.messageIDLinkedList=new Is(100),this._reportMessageStackedCount=0,this._onlineMemberCountMap=new Map,this.DEFAULT_EXPIRE_TIME=60,this.DEFAULT_POLLING_INTERVAL=300,this.MAX_POLLING_INTERVAL=2e3,this._pollingInterval=this.DEFAULT_POLLING_INTERVAL,this.DEFAULT_POLLING_NO_MESSAGE_COUNT=20,this.DEFAULT_POLLING_INTERVAL_PLUS=2e3,this._pollingNoMessageCount=0,this._startBroadcastSeq=1,this._broadcastMessageIDMap=new Map,this.DEFAULT_POLLING_SIMPLIFIED_MSG=0}hasJoinedAVChatRoom(){return this._joinedGroupMap.size>0}checkJoinedAVChatRoomByID(e){return this._joinedGroupMap.has(e)}getJoinedAVChatRoom(){return this._joinedGroupMap.size>0?[...this._joinedGroupMap.keys()]:[]}_updateRequestData(e){const t=this._pollingRequestInfoMap.get(e);return e===[...this._pollingInstanceMap.keys()][0]?{...t,startBroadcastSeq:this._startBroadcastSeq,simplifiedMessage:this.DEFAULT_POLLING_SIMPLIFIED_MSG}:{...t,simplifiedMessage:this.DEFAULT_POLLING_SIMPLIFIED_MSG}}_handleSuccess(e,t){const{key:o,nextSeq:s,rspMsgList:r,errorCode:i,nextBroadcastSeq:n,broadcastMessageList:u}=t.data;if(0!==i){const o=this._pollingRequestInfoMap.get(e),s=new Wt("longPollingAVError"),r=o?`${o.key}-${o.startSeq}`:"requestInfo is undefined";s.setMessage(`${e}-${r}-${t.errorInfo}`).setCode(t.errorCode).setNetworkType(this._groupModule.getNetworkType()).end(!0)}else{if(!this.checkJoinedAVChatRoomByID(e))return;He(o)&&Ve(s)&&this._pollingRequestInfoMap.set(e,{key:o,startSeq:s}),Ve(n)&&n>this._startBroadcastSeq&&(this._startBroadcastSeq=n),Be(r)&&r.length>0?(r.forEach(e=>{e.to=e.groupID}),this.onMessage(r,e)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===this.DEFAULT_POLLING_NO_MESSAGE_COUNT&&(this._pollingInterval=this.DEFAULT_POLLING_INTERVAL+this.DEFAULT_POLLING_INTERVAL_PLUS)),this._onBroadcastMessage(u)}}_handleFailure(e,t){}onMessage(e,t){if(!Be(e)||0===e.length)return;let o=this._n+".onMessage";t&&(o+=" groupID:"+t),0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._pollingInterval=this.DEFAULT_POLLING_INTERVAL);let i=null;const n=[],u=this._getModule(s),a=this._getModule(p),l=e.length;l>1&&e.sort((e,t)=>e.sequence-t.sequence);const h=this._getModule(r).isUnlimitedAVChatRoom();let d=!1;if(Ee.getLevel()<=0){const t=e.map(e=>e.sequence);Ee.l(`${o} count:${t.length} sequenceList:${t}`),t.length=0}for(let s=0;s<l;s++){const t=this.restoreMessageFromSimplified(e[s]);if(!Ls[t.event]){Ee.w(`${o}. unknown event:${t.event}`);continue}if(6===t.event){if(this._groupModule.isGroupAttributesUpdatedNotice(t))continue;if(this._groupModule.isGroupCountersNotice(t))continue}if(20===t.event){this.handleMessageRevokedNotice(t);continue}if(21===t.event){this._getModule(c).onMessageReactionNotify({event:21,dataList:t.elements.messageReactionNotifyList});continue}i=this.packMessage(t,t.event);const r=1===t.isModified;if(d=1===t.isHistoryMessage,!h){if(this.sequencesLinkedList.has(i.sequence))continue;this.sequencesLinkedList.set(i.sequence)}const p=this.messageIDLinkedList.has(i.ID);if(p){Ee.w(`${o} ID:${i.ID} has:${p}`);continue}this.messageIDLinkedList.set(i.ID);let l=!1;if(this._isMessageSentByCurrentInstance(i)?r&&(l=!0,i.isModified=r,u.updateMessageIsModifiedProperty(i)):l=!0,l){if(i.conversationType===ue&&5===i.payload.operationType&&this._onGroupDismissed(i.payload.groupProfile.groupID),!d&&i.conversationType!==ue){const e=i.conversationID.replace(ie,"");this._pollingInstanceMap.has(e)?this._groupModule.isLoggedIn()&&a.addMessageSequence({key:jt,message:i}):(i.type!==X&&i.clientTime>0&&a.addMessageDelay(i.clientTime),a.addMessageSequence({key:Ht,message:i}))}n.push(i)}}if(0===n.length)return;if(this._groupModule.filterModifiedMessage(n),!d){const e=this.packConversationOption(n);e.length>0&&u.onNewMessage({conversationOptionsList:e,isInstantMessage:!0})}this._checkMessageStacked(n);const m=this._groupModule.filterUnmodifiedMessage(n);m.length>0&&this._groupModule.emitOuterEvent(g,m),n.length=0}handleMessageRevokedNotice(e){const{groupID:t,elements:{revokeMsgList:o},revokerInfo:r}=e,i=[];if(o.forEach(e=>{const{tinyID:o,clientTime:s,random:n,sequence:u}=e,a={conversationID:`${ie}${t}`,ID:`${o}-${s}-${n}`,revoker:r.revoker,revokeReason:r.reason||"",revokerInfo:{userID:r.revoker,nick:"",avatar:""},sequence:u};i.push(a)}),0===i.length)return;this._getModule(s).updateRevokerInfo(i).then(e=>{this._groupModule.emitOuterEvent(m,e)})}isBroadcastOrNormal(e){return 3===e||17===e}isGroupTip(e){return 4===e||6===e}isGroupSystemNotice(e){return 5===e}restoreGroupTipElements(e={}){const{operatorInfo:t={},operatorID:o,userIDList:s=[],operationType:r}=e;Ve(e.groupJoinType)||1!==r&&2!==r||(e.groupJoinType=2===r?0:1);const{userID:i=o,avatar:n="",nick:u=""}=t;e.operatorInfo={userID:i,avatar:n,nick:u};const a=s.map(e=>({userID:e}));return e.memberInfoList=e.memberInfoList||a,e}restoreMessageFromSimplified(e){const{event:t}=e;if(this.isBroadcastOrNormal(t)&&(e.cloudCustomData=e.cloudCustomData||"",e.elements=e.elements.map(e=>{if(e.type===Q){const{content:t={}}=e;e.content={data:"",description:"",extension:"",...t}}return e})),(this.isGroupTip(t)||this.isGroupSystemNotice(t))&&(e.from=e.from||"@TIM#SYSTEM"),this.isGroupTip(t)){e.elements=this.restoreGroupTipElements(e.elements);const{elements:t={}}=e,{operationType:o,operatorInfo:s={}}=t;if(1===o){const e=[{userID:s.userID}];t.memberInfoList=t.memberInfoList||e}}if(this.isGroupSystemNotice(t)){let{memberInfoList:t,operatorInfo:o={}}=e.elements;t||(t=o),e.elements.memberInfoList={userID:e.elements.operatorID,avatar:"",nick:"",...t},e.elements={authentication:"",remarkInfo:"",messageKey:1e3*e.time,...e.elements};const s=Object.keys(e.elements).filter(e=>"operatorInfo"!==e).reduce((t,o)=>({...t,[o]:e.elements[o]}),{});e.elements=s}return e}_onGroupDismissed(e){Ee.l(`${this._n}._onGroupDismissed groupID:${e}`),this._groupModule.deleteLocalGroupAndConversation(e),this.reset(e)}_checkMessageStacked(e){const t="MessageStacked",o=e.length;if(o>=100&&(this._groupModule.outputWarning(t,o),this._reportMessageStackedCount<5)){new Wt(t).setNetworkType(this._groupModule.getNetworkType()).setMessage(`count:${o} groupID:${[...this._joinedGroupMap.keys()]}`).setLevel("warning").end(),this._reportMessageStackedCount+=1}}_isMessageSentByCurrentInstance(e){return!!this._getModule(s).isMessageSentByCurrentInstance(e)}packMessage(e,t){e.currentUser=this._groupModule.getMyUserID(),e.conversationType=5===t?ue:ie,e.isSystemMessage=!!e.isSystemMessage;const o=new rs(e),s=this.packElements(e,t);return o.setElement(s,this._groupModule.getFileDownloadProxy()),o}packElements(e,t){return 4===t||6===t?(this._updateMemberCountByGroupTips(e),{type:X,content:{...e.elements,groupProfile:e.groupProfile}}):5===t?{type:Y,content:{...e.elements,groupProfile:{...e.groupProfile,groupID:e.groupID}}}:e.elements}packConversationOption(e){const t=new Map;for(let o=0;o<e.length;o++){const s=e[o],r=s.conversationID;if(t.has(r)){const e=t.get(r);e.lastMessage=s,"in"===s.flow&&e.unreadCount++}else t.set(r,{conversationID:s.conversationID,unreadCount:"out"===s.flow?0:1,type:s.conversationType,subType:s.conversationSubType,lastMessage:s})}return[...t.values()]}_updateMemberCountByGroupTips(e){const{groupProfile:{groupID:t},elements:{onlineMemberInfo:o}}=e;if(ht(o))return;const{onlineMemberNum:s=0,expireTime:r=this.DEFAULT_EXPIRE_TIME}=o,i=this._onlineMemberCountMap.get(t)||{},n=Date.now();ht(i)?Object.assign(i,{lastReqTime:0,lastSyncTime:0,latestUpdateTime:n,memberCount:s,expireTime:r}):(i.latestUpdateTime=n,i.memberCount=s),this._onlineMemberCountMap.set(t,i)}_onBroadcastMessage(e){if(ht(e))return;const t=[],o=e.length;let s=null;for(let r=0;r<o;r++){const o=this.restoreMessageFromSimplified(e[r]);Ls[o.event]?(s=this.packMessage(o,o.event),s.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(s.ID)||(t.push(s),this._broadcastMessageIDMap.set(s.ID,1))):Ee.w(`${this._n}._onBroadcastMessage unknown event:${o.event}`)}t.length>0&&this._groupModule.emitOuterEvent(g,t)}start(e){if(this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void(t.isRunning()||t.start())}const t=new Ms({manager:this,groupID:e,onInit:this._updateRequestData.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t),Ee.l(`${this._n}.start groupID:${e}`)}handleJoinResult(e){return this._preCheck().then(()=>{const{longPollingKey:t,group:o}=e,s=o.groupID;return this._joinedGroupMap.set(s,o),this._groupModule.updateGroupMap([o]),this._groupModule.deleteUnjoinedAVChatRoom(s),this._groupModule.emitGroupListUpdate(!0,!1),Ke(t)?Ot({status:qe,group:o}):Promise.resolve()})}startRunLoop(e){return this.handleJoinResult(e).then(()=>{const{longPollingKey:t,group:o,startSeq:s=0}=e,r=o.groupID;return this._pollingRequestInfoMap.set(r,{key:t,startSeq:s}),this.start(r),this._groupModule.isLoggedIn()?Ot({status:qe,group:o}):Ot({status:qe})})}_preCheck(){if(this._getModule(r).isUnlimitedAVChatRoom())return Promise.resolve();if(!this.hasJoinedAVChatRoom())return Promise.resolve();const[e,t]=this._joinedGroupMap.entries().next().value;if(this._groupModule.isLoggedIn()){if(!(t.selfInfo.role===ge||t.ownerID===this._groupModule.getMyUserID()))return this._groupModule.quitGroup(e);this._groupModule.deleteLocalGroupAndConversation(e)}else this._groupModule.deleteLocalGroupAndConversation(e);return this.reset(e),Promise.resolve()}joinWithoutAuth(e){const{groupID:t}=e,o=this._n+".joinWithoutAuth",r=new Wt("joinWithoutAuth");return this._groupModule.request({protocolName:oo,requestData:e}).then(({data:{longPollingKey:e}})=>{if(this._groupModule.probeNetwork().then(([o,s])=>{r.setNetworkType(s).setMessage(`groupID:${t} longPollingKey:${e}`).end(!0)}),Ke(e))return Ft({code:Tt});Ee.l(`${o} ok. groupID:${t}`);this._getModule(s).setCompleted(`${ie}${t}`);const i=new Ds({groupID:t});return this.startRunLoop({group:i,longPollingKey:e}),ct({status:qe})}).catch(e=>(Ee.e(`${o} failed. groupID:${t} error:`,e),this._groupModule.probeNetwork().then(([o,s])=>{r.setError(e,o,s).setMessage("groupID:"+t).end(!0)}),Ft(e))).finally(()=>{this._groupModule.getModule(i).reportAtOnce()})}getGroupOnlineMemberCount(e){const t=this._onlineMemberCountMap.get(e)||{},o=Date.now();return ht(t)||o-t.lastSyncTime>1e3*t.expireTime&&o-t.latestUpdateTime>1e4&&o-t.lastReqTime>3e3?(t.lastReqTime=o,this._onlineMemberCountMap.set(e,t),this._getGroupOnlineMemberCount(e).then(e=>ct({memberCount:e.memberCount})).catch(e=>Ft(e))):Ot({memberCount:t.memberCount})}_getGroupOnlineMemberCount(e){const t=this._n+"._getGroupOnlineMemberCount";return this._groupModule.requestOnlineCount(e).then(o=>{const s=this._onlineMemberCountMap.get(e)||{},{memberCount:r=0,expireTime:i=this.DEFAULT_EXPIRE_TIME}=o.data;Ee.l(`${t} ok. groupID:${e} memberCount:${r} expireTime:${i}`);const n=Date.now();return ht(s)&&(s.lastReqTime=n),this._onlineMemberCountMap.set(e,Object.assign(s,{lastSyncTime:n,latestUpdateTime:n,memberCount:r,expireTime:i})),{memberCount:r}}).catch(o=>{Ee.w(t+" failed. error:",o);return new Wt("_getGroupOnlineMemberCount").setCode(o.code).setMessage(`groupID:${e} error:${JSON.stringify(o)}`).setNetworkType(this._groupModule.getNetworkType()).end(),Promise.reject(o)})}_getModule(e){return this._groupModule.getModule(e)}setPollingInterval(e){Ke(e)||(Ve(e)?this._pollingInterval=this.DEFAULT_POLLING_INTERVAL=e:this._pollingInterval=this.DEFAULT_POLLING_INTERVAL=parseInt(e,10))}setPollingIntervalPlus(e){Ke(e)||(Ve(e)?this.DEFAULT_POLLING_INTERVAL_PLUS=e:this.DEFAULT_POLLING_INTERVAL_PLUS=parseInt(e,10))}setPollingNoMessageCount(e){Ke(e)||(Ve(e)?this.DEFAULT_POLLING_NO_MESSAGE_COUNT=e:this.DEFAULT_POLLING_NO_MESSAGE_COUNT=parseInt(e,10))}setPollingSimplifiedMessage(e){Ke(e)||"0"!==e&&"1"!==e||(this.DEFAULT_POLLING_SIMPLIFIED_MSG=parseInt(e,10))}getPollingInterval(){return this._pollingInterval}onAVChatRoomMemberBanned(e){const{groupID:t}=e.payload.groupProfile;Ee.l(`${this._n}.onAVChatRoomMemberBanned groupID:${t}`),this._groupModule.deleteLocalGroupAndConversation(t),this.reset(t)}restartPolling(){Ee.l(`${this._n}.restartPolling count:${this._pollingInstanceMap.size}`);for(const e of this._pollingInstanceMap.values())e.stop(),e.start()}getPollingTimerID(e){if(!this._pollingInstanceMap.has(e))return-1;const t=this._pollingInstanceMap.get(e).getPollingTimerID();return Ee.l(`${this._n}.getPollingTimerID groupID:${e} timerID:${t}`),t}reset(e){if(e){Ee.l(`${this._n}.reset groupID:${e}`);const t=this._pollingInstanceMap.get(e);t&&t.stop(),this._pollingInstanceMap.delete(e),this._joinedGroupMap.delete(e),this._pollingRequestInfoMap.delete(e),this._onlineMemberCountMap.delete(e)}else{Ee.l(this._n+".reset all");for(const e of this._pollingInstanceMap.values())e.stop();this._pollingInstanceMap.clear(),this._joinedGroupMap.clear(),this._pollingRequestInfoMap.clear(),this._onlineMemberCountMap.clear(),this._broadcastMessageIDMap.clear()}this.sequencesLinkedList.reset(),this.messageIDLinkedList.reset(),this._reportMessageStackedCount=0,this._pollingInterval=this.DEFAULT_POLLING_INTERVAL=300,this.DEFAULT_POLLING_NO_MESSAGE_COUNT=20,this.DEFAULT_POLLING_INTERVAL_PLUS=2e3,this._pollingNoMessageCount=0}}class Cs{constructor(e){this.userID="",this.avatar="",this.nick="",this.role="",this.joinTime="",this.lastSendMsgTime="",this.nameCard="",this.muteUntil=0,this.memberCustomField=[],this.isOnline="Online"===e.onlineStatus,this._initMember(e)}_initMember(e){this.updateMember(e)}updateMember(e){const t=[null,void 0,"",0,NaN];e.memberCustomField&&ot(this.memberCustomField,e.memberCustomField),Xe(this,e,["memberCustomField","marks","onlineStatus"],t)}updateRole(e){["Owner","Admin","Member"].indexOf(e)<0||(this.role=e)}updateMuteUntil(e){Ke(e)||(this.muteUntil=Math.floor((Date.now()+1e3*e)/1e3))}updateNameCard(e){Ke(e)||(this.nameCard=e)}updateMemberCustomField(e){e&&ot(this.memberCustomField,e)}}class bs{constructor(e){this._groupModule=e,this._n="GroupMemberHandler",this.groupMemberListMap=new Map,this.DEFAULT_MEMBER_INFO_FILTER=["Role","JoinTime","NameCard","ShutUpUntil","OnlineStatus"],this._groupModule.getInnerEmitterInstance().on(xt.PROFILE_UPDATED,this._onProfileUpdated,this)}_onProfileUpdated({data:e}){for(let t=0;t<e.length;t++){const o=e[t];this.groupMemberListMap.forEach(e=>{e.has(o.userID)&&e.get(o.userID).updateMember({nick:o.nick,avatar:o.avatar})})}}deleteGroupMemberList(e){this.groupMemberListMap.delete(e)}getGroupMemberList({groupID:e,role:o,offset:s=0,count:r=15,filter:i}){const n=this._n+".getGroupMemberList",u=this._groupModule.hasLocalGroup(e);if(Ee.l(`${n} groupID:${e} role:${o} offset:${s} count:${r} hasLocalGroup:${u}`),!u)return Ot({memberList:[],offset:0});if(this._groupModule.getLocalGroupProfile(e).type===he){if(this._groupModule.canIUse(T.AVCHATROOM_MBR_LIST))return this._getAVChatRoomMemberList({groupID:e,offset:s,filter:i});this._groupModule.outputWarning("LiveOnlineMember")}let a;o!==de&&o!==ge&&o!==me||(a=o);const p=new Wt("getGroupMemberList");let l=0;const h={groupID:e,limit:r>100?100:r,memberRoleFilter:a?[a]:void 0,memberInfoFilter:this.DEFAULT_MEMBER_INFO_FILTER};rt({groupID:e})?h.next=""+s:(h.offset=s,l=s+r);let c=[];return this._groupModule.request({protocolName:ko,requestData:h}).then(({data:{members:o,memberNum:s,next:r}})=>{if(Ke(r)||(l=ht(r)?0:r),!Be(o)||0===o.length)return l=0,Promise.resolve([]);this._groupModule.hasLocalGroup(e)&&(this._groupModule.getLocalGroupProfile(e).memberNum=s),c=this._updateLocalGroupMemberMap(e,o);return this._groupModule.getModule(t).getUserProfile({userIDList:o.map(e=>e.userID),tagList:[Pe,Ue]})}).then(t=>{const{data:o}=t;if(!Be(o)||0===o.length)return Ot({memberList:[],offset:l});const i=o.map(e=>({userID:e.userID,nick:e.nick,avatar:e.avatar}));return this._updateLocalGroupMemberMap(e,i),c.length<r&&(l=0),p.setNetworkType(this._groupModule.getNetworkType()).setMessage(`groupID:${e} offset:${s} count:${r}`).end(),Ee.l(n+" ok."),ct({memberList:c,offset:l})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{p.setError(e,t,o).end()}),Ee.e(n+" failed. error:",e),Ft(e)))}_getAVChatRoomMemberList({groupID:e,offset:t,filter:o}){const s=this._n+"._getAVChatRoomMemberList",r=new Wt("_getAVChatRoomMemberList");return r.setMessage(`groupID:${e} offset:${t} filter:${o}`),this._groupModule.request({protocolName:Eo,requestData:{groupID:e,offset:t,filter:o}}).then(t=>{const{memberList:o=[],offset:i=0}=t.data;r.setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(`${s} ok. member count:${o.length}, next request timestamp:${i}`);const n=o.map(e=>({...e,onlineStatus:"Online"})),u=this._updateLocalGroupMemberMap(e,n);return ct({memberList:u,offset:i})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{r.setError(e,t,o).end()}),Ee.e(s+" failed. error:",e),Ft(e)))}getGroupMemberProfile(e){const o="getGroupMemberProfile",s=`${this._n}.${o}`;let r="groupID:"+e.groupID;e.userIDList.length>5?r+=" userIDList.length:"+e.userIDList.length:r+=" userIDList:"+e.userIDList,Ee.l(`${s} ${r}`),e.userIDList.length>50&&(e.userIDList=e.userIDList.slice(0,50));const{groupID:i,userIDList:n}=e,u=this._groupModule.getLocalGroupProfile(i);if(u&&st(u.type)){const e=kt;return Ft({code:e,message:this._groupModule.getErrorMessage(e,o)})}const a=new Wt(o);return a.setMessage(r),this._getGroupMemberProfileAdvance({...e,userIDList:n}).then(e=>{const{members:o}=e.data;if(!Be(o)||0===o.length)return Ot([]);this._updateLocalGroupMemberMap(i,o);return this._groupModule.getModule(t).getUserProfile({userIDList:o.map(({userID:e})=>e),tagList:[Pe,Ue]})}).then(e=>{const t=e.data.map(({userID:e,nick:t,avatar:o})=>({userID:e,nick:t,avatar:o}));this._updateLocalGroupMemberMap(i,t);const o=n.filter(e=>this.hasLocalGroupMember(i,e)).map(e=>this.getLocalGroupMemberInfo(i,e));return a.setNetworkType(this._groupModule.getNetworkType()).end(),ct({memberList:o})})}addGroupMember(e){const t=this._n+".addGroupMember",{groupID:o}=e,s=this._groupModule.getLocalGroupProfile(o),{type:r}=s,i=new Wt("addGroupMember");if(i.setMessage(`groupID:${o} groupType:${r}`),st(r)){const e=new gt({code:bt});return i.setError(e,!0,this._groupModule.getNetworkType()).end(),Ft(e)}return e.userIDList=e.userIDList.map(e=>({userID:e})),Ee.l(`${t} groupID:${o}`),this._groupModule.request({protocolName:Po,requestData:e}).then(({data:{members:o}})=>{Ee.l(t+" ok");const r=o.filter(e=>1===e.result).map(e=>e.userID),n=o.filter(e=>0===e.result).map(e=>e.userID),u=o.filter(e=>2===e.result).map(e=>e.userID),a=o.filter(e=>4===e.result).map(e=>e.userID),p=`groupID:${e.groupID}, successUserIDList:${r}, failureUserIDList:${n}, existedUserIDList:${u}, overLimitUserIDList:`+a;return i.setNetworkType(this._groupModule.getNetworkType()).setMoreMessage(p).end(),0===r.length?ct({successUserIDList:r,failureUserIDList:n,existedUserIDList:u,overLimitUserIDList:a}):(s.memberCount+=r.length,this._updateConversationGroupProfile(s),ct({successUserIDList:r,failureUserIDList:n,existedUserIDList:u,overLimitUserIDList:a,group:s}))}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}deleteGroupMember(e){const t=this._n+".deleteGroupMember",{groupID:o,userIDList:s}=e,r=this._groupModule.getLocalGroupProfile(o);if(Ke(r))return Ft({code:It});if(st(r.type)){return this._groupModule.canIUse(T.AVCHATROOM_BAN_MBR)?this._banAVChatRoomMember(e):this._groupModule.cannotUseCommercialAbility("deleteGroupMember")}const i=`groupID:${o} ${s.length>5?"userIDList.length:"+s.length:"userIDList:"+s}`;Ee.l(`${t} groupID:${o} userIDList:`,s);const n=new Wt("deleteGroupMember");return n.setMessage(i),this._groupModule.request({protocolName:Uo,requestData:e}).then(()=>(n.setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(t+" ok"),r.memberCount-=1,this._updateConversationGroupProfile(r),this.deleteLocalGroupMembers(o,s),ct({group:r,userIDList:s}))).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{n.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}_updateConversationGroupProfile(e){this._groupModule.getModule(s).updateConversationGroupProfile([e])}_banAVChatRoomMember(e){const t=this._n+"._banAVChatRoomMember",{groupID:o,userIDList:s}=e,r=`groupID:${o} ${s.length>5?"userIDList.length:"+s.length:"userIDList:"+s}`,i=new Wt("_banAVChatRoomMember");i.setMessage(r),Ee.l(`${t} groupID:${o} userIDList:`,s);const n=this._groupModule.getLocalGroupProfile(o);return Ke(e.duration)||0===e.duration?Ft({code:Rt}):this._groupModule.request({protocolName:qo,requestData:e}).then(()=>(i.setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(t+" ok"),this.deleteLocalGroupMembers(o,s),ct({group:n,userIDList:s}))).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}setGroupMemberMuteTime(e){const{groupID:t,userID:o,muteTime:s}=e,r=this._n+".setGroupMemberMuteTime";if(o===this._groupModule.getMyUserID())return Ft({code:Nt});const i=`groupID:${t} userID:${o} muteTime:${s}`;Ee.l(`${r} ${i}`);const n=new Wt("setGroupMemberMuteTime");return n.setMessage(i),this.modifyGroupMemberInfo({groupID:t,userID:o,muteTime:s}).then(e=>{n.setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(r+" ok");const o=this._groupModule.getLocalGroupProfile(t);return ct({group:o,member:e})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{n.setError(e,t,o).end()}),Ee.e(r+" failed. error:",e),Ft(e)))}setGroupMemberRole(e){const t=this._n+".setGroupMemberRole",{groupID:o,userID:s,role:r}=e,i=`groupID:${o} userID:${s} role:${r}`,n=this._groupModule.getLocalGroupProfile(o);if(!n||n.type===ae||n.type===he)return Ft({code:St});if(n&&n.selfInfo.role!==ge)return Ft({code:At});const u=[de,me];if(rt({groupID:o})&&u.push(_e),u.indexOf(r)<0)return Ft({code:vt});if(s===this._groupModule.getMyUserID())return Ft({code:wt});const a=new Wt("setGroupMemberRole");return a.setMessage(i),Ee.l(`${t} ${i}`),this.modifyGroupMemberInfo({groupID:o,userID:s,role:r}).then(e=>(a.setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(t+" ok"),ct({group:n,member:e}))).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{a.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}_filterProfanity(e,t){const o=this._groupModule.getModule(h);if(!o)return!0;const{isAllowedToSend:s,modifiedText:r}=o.filterText(t[e],S);return!0===s&&(t[e]=r,!0)}setGroupMemberNameCard(e){const t="setGroupMemberNameCard",o=`${this._n}.${t}`;if(e.nameCard&&!1===this._filterProfanity("nameCard",e))return Ft({code:Ut});const{groupID:s,userID:r=this._groupModule.getMyUserID(),nameCard:i}=e,n=`groupID:${s} userID:${r} nameCard:${i}`;Ee.l(`${o} ${n}`);const u=this._groupModule.getLocalGroupProfile(s);if(u&&st(u.type)){const e=kt;return Ft({code:e,message:this._groupModule.getErrorMessage(e,t)})}const a=new Wt(t);return a.setMessage(n),this.modifyGroupMemberInfo({groupID:s,userID:r,nameCard:i}).then(e=>{Ee.l(o+" ok"),a.setNetworkType(this._groupModule.getNetworkType()).end();const t=this._groupModule.getLocalGroupProfile(s);return r===this._groupModule.getMyUserID()&&t&&t.setSelfNameCard(i),ct({group:t,member:e})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{a.setError(e,t,o).end()}),Ee.e(o+" failed. error:",e),Ft(e)))}setGroupMemberCustomField(e){const t="setGroupMemberCustomField",o=`${this._n}.${t}`,{groupID:s,userID:r=this._groupModule.getMyUserID(),memberCustomField:i}=e,n=`groupID:${s} userID:${r} memberCustomField:${JSON.stringify(i)}`;Ee.l(`${o} ${n}`);const u=this._groupModule.getLocalGroupProfile(s);if(u&&st(u.type)){const e=kt;return Ft({code:e,message:this._groupModule.getErrorMessage(e,t)})}const a=new Wt(t);return a.setMessage(n),this.modifyGroupMemberInfo({groupID:s,userID:r,memberCustomField:i}).then(e=>{a.setNetworkType(this._groupModule.getNetworkType()).end(),Ee.l(o+" ok");const t=this._groupModule.getLocalGroupProfile(s);return ct({group:t,member:e})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{a.setError(e,t,o).end()}),Ee.e(o+" failed. error:",e),Ft(e)))}modifyGroupMemberInfo(e){let{groupID:t,userID:o}=e,s=void 0;return it(t)&&(s=t,t=nt(s)),this._groupModule.request({protocolName:Oo,requestData:{...e,groupID:t,topicID:s}}).then(()=>{if(this.hasLocalGroupMember(t,o)){const s=this.getLocalGroupMemberInfo(t,o);return Ke(e.muteTime)||s.updateMuteUntil(e.muteTime),Ke(e.role)||s.updateRole(e.role),Ke(e.nameCard)||s.updateNameCard(e.nameCard),Ke(e.memberCustomField)||s.updateMemberCustomField(e.memberCustomField),s}const s=this._groupModule.getLocalGroupProfile(t);if(s&&!st(s.type))return this.getGroupMemberProfile({groupID:t,userIDList:[o]}).then(({data:{memberList:[e]}})=>e)})}markGroupMemberList(e){const t=this._n+".markGroupMemberList",{groupID:o,markType:s,enableMark:r,userIDList:i=[]}=e,n=`groupID:${o} markType:${s} enableMark:${r} userIDList count:${i.length}`;Ee.l(`${t} ${n}`);let u=2;const a=[];!0===r&&(u=1);let p=[...i];var l;i.length>500&&(p=i.slice(0,500),Ee.w(`${t} ${l=500,"the length of userIDList cannot exceed "+l}`)),p.forEach(e=>{a.push({userID:e,markType:[s]})}),p=null;const h=new Wt("markGroupMemberList");return h.setMessage(n),this._groupModule.request({protocolName:Fo,requestData:{groupID:o,operationType:u,memberList:a}}).then(e=>{const{memberList:o=[]}=e.data,s=[],r=[];o.length===i.length?s.push(...i):(o.forEach(e=>{s.push(e.userID)}),i.forEach(e=>{s.includes(e)||r.push(e)}));const n=`success count:${s.length} fail count:${r.length}`;return h.setNetworkType(this._groupModule.getNetworkType()).setMessage(n).end(),Ee.l(`${t} ok. ${n}`),ct({successUserIDList:s,failureUserIDList:r})}).catch(e=>(this._groupModule.probeNetwork().then(([t,o])=>{h.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}_getGroupMemberProfileAdvance(e){return this._groupModule.request({protocolName:$o,requestData:{...e,memberInfoFilter:e.memberInfoFilter?e.memberInfoFilter:this.DEFAULT_MEMBER_INFO_FILTER}})}_updateLocalGroupMemberMap(e,t){if(!Be(t)||0===t.length)return[];return t.map(t=>(this.hasLocalGroupMember(e,t.userID)?this.getLocalGroupMemberInfo(e,t.userID).updateMember(t):this.setLocalGroupMember(e,new Cs(t)),this.getLocalGroupMemberInfo(e,t.userID)))}deleteLocalGroupMembers(e,t){const o=this.groupMemberListMap.get(e);o&&t.forEach(e=>{o.delete(e)})}getLocalGroupMemberInfo(e,t){return this.groupMemberListMap.has(e)?this.groupMemberListMap.get(e).get(t):null}setLocalGroupMember(e,t){if(this.groupMemberListMap.has(e))this.groupMemberListMap.get(e).set(t.userID,t);else{const o=(new Map).set(t.userID,t);this.groupMemberListMap.set(e,o)}}getLocalGroupMemberList(e){return this.groupMemberListMap.get(e)}hasLocalGroupMember(e,t){return this.groupMemberListMap.has(e)&&this.groupMemberListMap.get(e).has(t)}hasLocalGroupMemberMap(e){return this.groupMemberListMap.has(e)}reset(){this.groupMemberListMap.clear()}}const Ts=1,As=15;class Ss{constructor(e){this._groupModule=e,this._n="GroupSystemNoticeHandler",this.pendencyMap=new Map}onNewGroupSystemNotice(e){const{dataList:t,isSyncingEnded:o,isInstantMessage:r}=e;Ee.d(`${this._n}.onReceiveSystemNotice count:${t.length}`);const{eventDataList:i,result:n}=this.newSystemNoticeStoredAndSummary({notifiesList:t,isInstantMessage:r});if(i.length>0){this._groupModule.getModule(s).onNewMessage({conversationOptionsList:i,isInstantMessage:r}),this._onReceivedGroupSystemNotice({result:n,isInstantMessage:r})}r?n.length>0&&this._groupModule.emitOuterEvent(g,n):!0===o&&this._clearGroupSystemNotice()}newSystemNoticeStoredAndSummary({notifiesList:e,isInstantMessage:t}){let o=null;const r=e.length;let i=0;const n=[],u={conversationID:ue,unreadCount:0,type:ue,subType:null,lastMessage:null};for(i=0;i<r;i++){const r=e[i],{groupProfile:{communityType:a=0,topicID:p},elements:{topicIDList:l,operationType:h}}=r;if(!(2!==a||ht(p)&&ht(l))){if([17,18,20].includes(h)){this._handleTopicSystemNotice(r);continue}ht(p)||(r.to=p)}if(r.elements.operationType===As)continue;r.currentUser=this._groupModule.getMyUserID(),r.conversationType=ue,r.conversationID=ue,o=new rs(r),o.setElement({type:Y,content:{...r.elements,groupProfile:{...r.groupProfile}}}),o.isSystemMessage=!0,(1===o.sequence&&1===o.random||2===o.sequence&&2===o.random)&&(o.sequence=Qe(),o.random=Qe(),o.generateMessageID(),Ee.l(`${this._n}.newSystemNoticeStoredAndSummary sequence and random maybe duplicated, regenerate. ID:${o.ID}`));this._groupModule.getModule(s).pushIntoNoticeResult(n,o)&&(t?u.unreadCount++:o.setIsRead(!0),u.subType=o.conversationSubType)}return u.lastMessage=n[n.length-1],{eventDataList:n.length>0?[u]:[],result:n}}_clearGroupSystemNotice(){this._getPendencyList().then(e=>{e.forEach(e=>{this.pendencyMap.set(`${e.from}_${e.groupID}_${e.to}`,e)});const t=this._groupModule.getModule(s).getLocalMessageList(ue),o=[];t.forEach(e=>{const{operatorID:t,operationType:s,groupProfile:r}=e.payload;if(s===Ts){const s=`${t}_${r.groupID}_${r.to}`,i=this.pendencyMap.get(s);i&&Ve(i.handled)&&0!==i.handled&&o.push(e)}}),this.deleteGroupSystemNotice({messageList:o})})}deleteGroupSystemNotice(e){const t=this._n+".deleteGroupSystemNotice";return Be(e.messageList)&&0!==e.messageList.length?(Ee.l(t+" "+e.messageList.map(e=>e.ID)),this._groupModule.request({protocolName:Mo,requestData:{messageListToDelete:e.messageList.map(e=>({from:ue,messageSeq:e.clientSequence,messageRandom:e.random}))}}).then(()=>{Ee.l(t+" ok");const o=this._groupModule.getModule(s);return e.messageList.forEach(e=>{o.deleteLocalMessage(e)}),ct()}).catch(e=>(Ee.e(t+" error:",e),Ft(e)))):Ot()}_getPendencyList(e={}){const{type:t,startTime:o=0,limit:s=20}=e;return this._groupModule.request({protocolName:_o,requestData:{type:t,startTime:o,limit:s,handleAccount:this._groupModule.getMyUserID()}}).then(e=>{const t=e.data.pendencyList;return 0!==e.data.nextStartTime?this._getPendencyList({startTime:e.data.nextStartTime}).then(e=>[...t,...e]):t})}getGroupApplicationList(){return this._getPendencyList().then(e=>this._getPendencyList({type:ce}).then(t=>(e.push(...t),this._handlePendencyResult(e))).catch(t=>this._handlePendencyResult(e)))}_handlePendencyResult(e){const t=[];return e.forEach(e=>{this.pendencyMap.set(`${e.from}_${e.groupID}_${e.to}`,e),0===e.handled&&t.push({applicant:e.from,applicantNick:e.fromUserNickName,groupName:e.groupName,groupID:e.groupID,authentication:e.authentication,messageKey:e.time,applicationType:e.applicationType,userID:e.userID,note:e.note})}),Ot({applicationList:t})}_onReceivedGroupSystemNotice({result:e,isInstantMessage:t}){t&&e.forEach(e=>{switch(e.payload.operationType){case 1:break;case 2:this._onApplyGroupRequestAgreed(e);break;case 3:break;case 4:this._onMemberKicked(e);break;case 5:this._onGroupDismissed(e);break;case 6:break;case 7:this._onInviteGroup(e);break;case 8:this._onQuitGroup(e);break;case 9:this._onSetManager(e);break;case 10:this._onDeleteManager(e);break;case 11:case 12:case 15:break;case 20:this._onMessageRemindTypeSynced(e);break;case 21:this._groupModule.onAVChatRoomMemberBanned(e)}})}_onApplyGroupRequestAgreed(e){const t=e.payload.groupProfile.groupID;this._groupModule.hasLocalGroup(t)||this._groupModule.getGroupProfile({groupID:t}).then(({data:{group:e}})=>{if(e){this._groupModule.updateGroupMap([e]);const t=!e.isSupportTopic;this._groupModule.emitGroupListUpdate(!0,t)}})}_onMemberKicked(e){const t=e.payload.groupProfile.groupID;this._groupModule.hasLocalGroup(t)&&this._groupModule.deleteLocalGroupAndConversation(t)}_onGroupDismissed(e){const t=e.payload.groupProfile.groupID;this._groupModule.hasLocalGroup(t)&&this._groupModule.deleteLocalGroupAndConversation(t);const{_AVChatRoomHandler:o}=this._groupModule;o&&o.checkJoinedAVChatRoomByID(t)&&o.reset(t)}_onInviteGroup(e){const t=e.payload.groupProfile.groupID;this._groupModule.hasLocalGroup(t)||this._groupModule.getGroupProfile({groupID:t}).then(({data:{group:e}})=>{e&&(this._groupModule.updateGroupMap([e]),this._groupModule.emitGroupListUpdate())})}_onQuitGroup(e){const t=e.payload.groupProfile.groupID;this._groupModule.hasLocalGroup(t)&&this._groupModule.deleteLocalGroupAndConversation(t)}_onSetManager(e){const{to:t,groupID:o}=e.payload.groupProfile,s=this._groupModule.getGroupMemberHandler().getLocalGroupMemberInfo(o,t);s&&s.updateRole(de)}_onDeleteManager(e){const{to:t,groupID:o}=e.payload.groupProfile,s=this._groupModule.getGroupMemberHandler().getLocalGroupMemberInfo(o,t);s&&s.updateRole(me)}_onMessageRemindTypeSynced(e){const{groupID:t}=e.payload.groupProfile,o=e.payload.messageRemindType;this._groupModule.getModule(s).onGroupMessageRemindTypeUpdated({groupID:t,messageRemindType:o})}_handleTopicSystemNotice(e){const{groupProfile:{groupID:t,topicID:s},elements:{operationType:r,topicIDList:i,messageRemindType:n}}=e,u=this._groupModule.getModule(o);17===r?u.onTopicCreated({groupID:t,topicID:s}):18===r?u.onTopicDeleted({groupID:t,topicIDList:i}):20===r&&u.onTopicMessageRemindTypeUpdated({groupID:t,topicID:s,messageRemindType:n})}reset(){this.pendencyMap.clear()}}class vs extends class{constructor(e){this._m=e,this._n=""}isLoggedIn(){return this._m.getModule(r).isLoggedIn()}isOversea(){return this._m.getModule(r).isOversea()}isPrivateNetWork(){return this._m.getModule(r).isPrivateNetWork()}getFileDownloadProxy(){return this._m.getModule(r).getFileDownloadProxy()}getMyUserID(){return this._m.getModule(r).getUserID()}getMyTinyID(){return this._m.getModule(r).getTinyID()}getSDKAppID(){return this._m.getModule(r).getSDKAppID()}isIntl(){return this._m.getModule(r).isIntl()}isUsingChatCore(){return this._m.getModule(r).isUsingChatCore()}isDevMode(){return this._m.getModule(r).isDevMode()}getModule(e){return this._m.getModule(e)}getPlatform(){return x}getNetworkType(){return this._m.getModule(n).getNetworkType()}probeNetwork(e){return this._m.getModule(n).probe(e)}getCloudConfig(e){return this._m.getModule(a).getCloudConfig(e)}emitOuterEvent(e,t){this._m.getOuterEmitterInstance().emit(e,t)}emitInnerEvent(e,t){this._m.getInnerEmitterInstance().emit(e,t)}getInnerEmitterInstance(){return this._m.getInnerEmitterInstance()}generateTjgID(e){return this._m.getModule(r).getTinyID()+"-"+e.random}filterModifiedMessage(e){if(ht(e))return;const t=e.filter(e=>!0===e.isModified);t.length>0&&this.emitOuterEvent(d,t)}filterUnmodifiedMessage(e){if(ht(e))return[];return e.filter(e=>!1===e.isModified)}request(e){return this._m.getModule(u).request(e)}canIUse(e){return this._m.getModule(l).canIUse(e)}getErrorMessage(e,t,o){return this._m.getErrorMessage(e,t,o)}outputWarning(e,t,o){const s=this.getErrorMessage(e,t,o);s&&Ee.w(s)}cannotUseCommercialAbility(e){const t=Pt;return Ft({code:t,message:this.getErrorMessage(t,e)})}}{constructor(e){super(e),this._n="GroupModule",this._commonGroupHandler=new ns(this),this._groupAttributesHandler=new cs(this),this._groupCountersHandler=new _s(this),this._AVChatRoomHandler=new Gs(this),this._groupTipsHandler=new is(this),this._groupSystemNoticeHandler=new Ss(this),this._groupMemberHandler=new bs(this),this.groupMap=new Map,this._unjoinedAVChatRoomList=new Map,this._receiptDetailCompleteMap=new Map,this._onlineMemberCountMap=new Map,this._timeoutIDs=[];this.getInnerEmitterInstance().on(xt.CLOUD_CONFIG_UPDATED,this._onCloudConfigUpdated,this)}_onCloudConfigUpdated(){const e=this.getCloudConfig("polling_interval"),t=this.getCloudConfig("polling_interval_plus"),o=this.getCloudConfig("polling_no_msg_count"),s=this.getCloudConfig("polling_simplified_msg"),r=this.getCloudConfig("paging_grp_count");Ee.l(`${this._n}._onCloudConfigUpdated pollingInterval:${e} pollingIntervalPlus:${t} pollingNoMessageCount:${o} pollingSimplifiedMessage:${s} pagingGroupCount:${r}`),this._AVChatRoomHandler.setPollingInterval(e),this._AVChatRoomHandler.setPollingIntervalPlus(t),this._AVChatRoomHandler.setPollingNoMessageCount(o),this._AVChatRoomHandler.setPollingSimplifiedMessage(s),this._commonGroupHandler.setPagingGroupCount(r)}onCheckTimer(e){this.isLoggedIn()&&(this._commonGroupHandler.onCheckTimer(e),this._groupTipsHandler.onCheckTimer(e))}guardForAVChatRoom(e){if(e.conversationType===ie){const t=it(e.to)?nt(e.to):e.to;return this.hasLocalGroup(t)?Ot():this.getGroupProfile({groupID:t}).then(o=>{const s=o.data.group.type;if(Ee.l(`${this._n}.guardForAVChatRoom. groupID:${t} type:${s}`),s===he){const o=dt;return Ft(new gt({code:o,message:this.getErrorMessage(o,e.from,t),data:{message:e}}))}return Ot()})}return Ot()}checkJoinedAVChatRoomByID(e){return this._AVChatRoomHandler.checkJoinedAVChatRoomByID(e)}onNewGroupMessage(e){this._commonGroupHandler.onNewGroupMessage(e)}updateNextMessageSeq(e){if(Be(e)){const t=this.getModule(o);e.forEach(e=>{const o=e.conversationID.replace(ie,"");it(o)&&t.updateLastMessage(o,e.lastMessage),this.groupMap.has(o)&&(this.groupMap.get(o).nextMessageSeq=e.lastMessage.sequence+1)})}}onNewGroupTips(e){this._groupTipsHandler.onNewGroupTips(e)}onGroupMessageRevoked(e){this._commonGroupHandler.onGroupMessageRevoked(e)}onNewGroupSystemNotice(e){this._groupSystemNoticeHandler.onNewGroupSystemNotice(e)}onGroupMessageReadNotice(e){e.dataList.forEach(e=>{const{groupMessageReadNotice:t}=e.elements;if(!Ke(t)){const e=this.getModule(s);t.forEach(t=>{const{groupID:o,topicID:s,lastMessageSeq:r}=t;Ee.d(`${this._n}.onGroupMessageReadNotice groupID:${o} lastMessageSeq:${r}`);let i=`${ie}${o}`,n=!0;ht(s)||(i=`${ie}${s}`,n=!1),e.updateIsReadAfterReadReport({conversationID:i,lastMessageSeq:r}),e.updateUnreadCount(i,n),e.clearGroupAtInfoList(i,n)})}})}onReadReceiptList(e){Ee.d(this._n+".onReadReceiptList options:",JSON.stringify(e)),e.dataList.forEach(e=>{const{groupProfile:t,elements:o}=e,{groupID:r}=t,i=this.getModule(s),{readReceiptList:n}=o;i.updateReadReceiptInfo({groupID:r,readReceiptList:n})})}onGroupMessageModified(e){Ee.d(this._n+".onGroupMessageModified options:",JSON.stringify(e));const t=this.getModule(s);e.dataList.forEach(e=>{t.onMessageModified({...e,conversationType:ie,to:e.topicID?e.topicID:e.groupID})})}deleteGroupSystemNotice(e){this._groupSystemNoticeHandler.deleteGroupSystemNotice(e)}initGroupMap(e){this.groupMap.set(e.groupID,new Ds(e))}clearGroupMap(){this.groupMap.clear()}deleteGroup(e){this.groupMap.delete(e)}updateGroupMap(e){const t=this.getModule(s);let o;e.forEach(e=>{o=e.groupID,this.groupMap.has(o)?this.groupMap.get(o).updateGroup(e):(this.groupMap.set(o,new Ds(e)),t.deleteGroupRoamingMessageInfo(o))});const r=this.getMyUserID();for(const[,s]of this.groupMap)s.selfInfo.userID=r,"Owner"===s.selfInfo.role&&(s.ownerID=r)}getGroupMap(){return this.groupMap}getLocalGroupList(){return[...this.groupMap.values()]}getLocalGroupProfile(e){return this.groupMap.get(e)}sortLocalGroupList(){const e=[...this.groupMap].filter(([e,t])=>!ht(t.lastMessage));e.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime),this.groupMap=new Map([...e])}updateGroupLastMessage(e){this._commonGroupHandler.handleUpdateGroupLastMessage(e)}emitGroupListUpdate(e=!0,t=!0){const o=this.getLocalGroupList();if(e&&this.emitOuterEvent(_),t){const e=JSON.parse(JSON.stringify(o));this.getModule(s).updateConversationGroupProfile(e)}}getMyNameCardByGroupID(e){const t=this.getLocalGroupProfile(e);return t?t.selfInfo.nameCard:""}isPagingGetCompleted(){return this._commonGroupHandler.isPagingGetCompleted()}getMessageRemindType(e){if(!Be(e)||0===e.length)return;const t=e.filter(e=>!st(this.getLocalGroupProfile(e).type));0!==t.length&&(Ee.l(`${this._n}.getMessageRemindType groupIDList:${t}`),this.getGroupProfileAdvance({groupIDList:t,responseFilter:{memberInfoFilter:["MsgFlag"]}}).then(e=>{const{successGroupList:t}=e.data,o=this.getModule(s);t.forEach(e=>{o.onGroupMessageRemindTypeUpdated({groupID:e.groupID,messageRemindType:Be(e.members)?e.members[0].messageRemindType:""})})}))}getGroupList(){return this._commonGroupHandler.getGroupList()}syncCommunityWithTopic(){return this._commonGroupHandler.syncGroupList(!0)}getGroupProfile(e){const t=this._n+".getGroupProfile",o=new Wt("getGroupProfile"),{groupID:r,groupCustomFieldFilter:i}=e;Ee.l(`${t} groupID:${r}`);const n={groupIDList:[r],responseFilter:{groupBaseInfoFilter:["Type","Name","Introduction","Notification","FaceUrl","Owner_Account","CreateTime","InfoSeq","LastInfoTime","LastMsgTime","MemberNum","MaxMemberNum","ApplyJoinOption","NextMsgSeq","ShutUpAllMember","InviteJoinOption"],groupCustomFieldFilter:i,memberInfoFilter:["Role","JoinTime","MsgSeq","MsgFlag","NameCard"]}};return this.getGroupProfileAdvance(n).then(({data:{successGroupList:e,failureGroupList:i}})=>{if(Ee.l(t+" ok"),i.length>0)return Ft(i[0]);let n;if(st(e[0].type)&&!this.hasLocalGroup(r)?n=new Ds(e[0]):(this.updateGroupMap(e),n=this.getLocalGroupProfile(r)),!n.isSupportTopic){this.getModule(s).updateConversationGroupProfile([n])}return o.setNetworkType(this.getNetworkType()).setMessage(`groupID:${r} type:${n.type} muteAllMembers:${n.muteAllMembers} ownerID:${n.ownerID}`).end(),ct({group:n})}).catch(s=>(this.probeNetwork().then(([t,r])=>{o.setError(s,t,r).setMessage("groupID:"+e.groupID).end()}),Ee.e(t+" failed. error:",s),Ft(s)))}getGroupProfileAdvance(e){const t=this._n+".getGroupProfileAdvance",{groupIDList:o}=e;Be(o)&&o.length>50&&(this.outputWarning("GetGroupProfileLimit"),o.length=50);const s=[],r=[];o.forEach(e=>{rt({groupID:e})?r.push(e):s.push(e)});const i=[];if(s.length>0){const t=this._getGroupProfileAdvance({...e,groupIDList:s});i.push(t)}if(r.length>0){const t=this._getGroupProfileAdvance({...e,groupIDList:r,relayFlag:s.length>0});i.push(t)}return Promise.all(i).then(e=>{const t=[],o=[];return e.forEach(e=>{t.push(...e.successGroupList),o.push(...e.failureGroupList)}),ct({successGroupList:t,failureGroupList:o})}).catch(e=>(Ee.e(t+" failed. error:",e),Ft(e)))}_getGroupProfileAdvance(e){const{relayFlag:t=!1,...o}=e;return this.request({protocolName:Yt,requestData:o}).then(e=>{Ee.l(this._n+"._getGroupProfileAdvance ok. options:",o);const{groups:t}=e.data;return{successGroupList:t.filter(e=>Ke(e.errorCode)||0===e.errorCode),failureGroupList:t.filter(e=>e.errorCode&&0!==e.errorCode).map(e=>new gt({code:e.errorCode,message:e.errorInfo,data:{groupID:e.groupID}}))}}).catch(o=>t&&rt({groupID:e.groupIDList[0]})?{successGroupList:[],failureGroupList:[]}:Ft(o))}createGroup(o){const s=[pe,ae,le,he,ce],r=this._n+".createGroup",{type:i,groupID:n}=o;if(o.name&&!1===this._filterProfanity("name",o))return Ft({code:Ut});if(o.introduction&&!1===this._filterProfanity("introduction",o))return Ft({code:Ut});if(o.notification&&!1===this._filterProfanity("notification",o))return Ft({code:Ut});if(!s.includes(i))return Ft({code:_t});if(!rt({type:i})){if(!ht(n)&&rt({groupID:n}))return Ft({code:ft});o.isSupportTopic=void 0}if(st(i)&&!Ke(o.memberList)&&o.memberList.length>0&&(o.memberList=void 0),this._canIUseJoinOption(i)||Ke(o.joinOption)||(o.joinOption=void 0),rt({type:i})){if(!ht(n)&&!rt({groupID:n}))return Ft({code:ft});o.isSupportTopic=!0===o.isSupportTopic?1:0}const u=new Wt("createGroup");Ee.l(r+" options:",o);let a=null,p=[];return this.request({protocolName:Qt,requestData:{...o,ownerID:this.getMyUserID(),webPushFlag:1}}).then(s=>{const{groupID:i,overLimitUserIDList:n=[]}=s.data;a=i,p=n;const l=`groupType:${o.type} groupID:${i} overLimitUserIDList:${n}`;if(u.setNetworkType(this.getNetworkType()).setMessage(l).end(),Ee.l(`${r} ok. ${l}`),o.type===he)return this.getGroupProfile({groupID:i});if(o.type===ce&&1===o.isSupportTopic)return this.getGroupProfile({groupID:i});ht(o.memberList)||ht(n)||(o.memberList=o.memberList.filter(e=>-1===n.indexOf(e.userID))),this.updateGroupMap([{...o,groupID:i}]);const h=this.getModule(e);let c="",g=0;o.type===ce?(c=this.isIntl()?"Create Community":"创建社群",g=1):c=this.isIntl()?"Create Group":"创建群组";const d=this.getModule(t).getMyNick(),m=h.createCustomMessage({to:i,conversationType:ie,payload:{data:JSON.stringify({businessID:"group_create",content:c,cmd:g,opUser:d||this.getMyUserID(),version:4})}});return h.sendMessageInstance(m),this.emitGroupListUpdate(),this.getGroupProfile({groupID:i})}).then(e=>{const{group:t}=e.data,{nameCard:o,joinTime:s}=t.selfInfo;return t.updateSelfInfo({nameCard:o,joinTime:s,messageRemindType:De,role:ge}),ct({group:t,overLimitUserIDList:p})}).catch(e=>{if(u.setMessage("groupType:"+o.type),this.probeNetwork().then(([t,o])=>{u.setError(e,t,o).end()}),10010===e.code||10007===e.code){this._silentlyGetGroupProfile(e.code,a),this.updateGroupMap([{...o,groupID:a}]);const t=this.getLocalGroupProfile(a);return t.selfInfo.role=ge,ct({group:t,overLimitUserIDList:p})}return Ee.e(r+" failed. error:",e),Ft(e)})}dismissGroup(e){const t=this._n+".dismissGroup",o="groupID:"+e;if(this.hasLocalGroup(e)&&this.getLocalGroupProfile(e).type===ae)return Ft(new gt({code:Lt}));const s=new Wt("dismissGroup");return s.setMessage(o),Ee.l(`${t} ${o}`),this.request({protocolName:Zt,requestData:{groupID:e}}).then(()=>(s.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok"),this.deleteLocalGroupAndConversation(e),this.checkJoinedAVChatRoomByID(e)&&this._AVChatRoomHandler.reset(e),this._groupAttributesHandler.deleteLocalGroupAttributes(e),ct({groupID:e}))).catch(e=>(this.probeNetwork().then(([t,o])=>{s.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}updateGroupProfile(e){const t=this._n+".updateGroupProfile";if(this.hasLocalGroup(e.groupID)){const o=this.getLocalGroupProfile(e.groupID).type;this._canIUseJoinOption(o)||Ke(e.joinOption)||(Ee.w(t+" joinOption is unavailable for Work/Meeting/AVChatRoom"),e.joinOption=void 0)}if(Ke(e.muteAllMembers)||(e.muteAllMembers?e.muteAllMembers="On":e.muteAllMembers="Off"),e.name&&!1===this._filterProfanity("name",e))return Ft({code:Ut});if(e.introduction&&!1===this._filterProfanity("introduction",e))return Ft({code:Ut});if(e.notification&&!1===this._filterProfanity("notification",e))return Ft({code:Ut});const o=new Wt("updateGroupProfile");return o.setMessage(JSON.stringify(e)),Ee.l(`${t} groupID:${e.groupID}`),this.request({protocolName:eo,requestData:e}).then(()=>{if(o.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok"),this.hasLocalGroup(e.groupID)){this.groupMap.get(e.groupID).updateGroup(e)}return ct({group:this.groupMap.get(e.groupID)})}).catch(e=>(this.probeNetwork().then(([t,s])=>{o.setError(e,t,s).end()}),Ee.l(t+" failed. error:",e),Ft(e)))}_filterProfanity(e,t){const o=this.getModule(h);if(!o)return!0;const{isAllowedToSend:s,modifiedText:r}=o.filterText(t[e],A);return!0===s&&(t[e]=r,!0)}joinGroup(e){const{groupID:t,type:o}=e,s=this._n+".joinGroup";if(o===ae)return Ft({code:Mt});if(this.deleteUnjoinedAVChatRoom(t),this.hasLocalGroup(t)){if(!this.isLoggedIn())return Ot({status:Le});const o=new Wt("applyJoinGroup");return this.getGroupProfile({groupID:t}).then(()=>(o.setNetworkType(this.getNetworkType()).setMessage(`groupID:${t} joinedStatus:${Le}`).end(),Ot({status:Le}))).catch(r=>(o.setNetworkType(this.getNetworkType()).setMessage(`groupID:${t} unjoined`).end(),Ee.w(`${s} ${t} was unjoined, now join!`),this.groupMap.delete(t),this.applyJoinGroup(e)))}return Ee.l(`${s} groupID:${t}`),this.isLoggedIn()?this.applyJoinGroup(e):this._AVChatRoomHandler.joinWithoutAuth(e)}applyJoinGroup(e){const t=this._n+".applyJoinGroup",{groupID:o,applyMessage:r}=e;if(!ht(r)&&!1===this._filterProfanity("applyMessage",e))return Ft({code:Ut});const i=new Wt("applyJoinGroup"),n={...e},u=this.canIUse(T.AVCHATROOM_HISTORY_MSG);u&&(n.historyMessageFlag=1);return this.getModule(s).deleteTopicRoamingMessageInfo(o),this.request({protocolName:to,requestData:n}).then(({data:{joinedStatus:e,longPollingKey:s,startSeq:r,avChatRoomFlag:n,avChatRoomKey:a,messageList:p}})=>{const l=`groupID:${o} joinedStatus:${e} longPollingKey:${s} startSeq:${r} avChatRoomFlag:${n} canGetAVChatRoomHistoryMessage:${u}, history message count:`+(ht(p)?0:p.length);switch(i.setNetworkType(this.getNetworkType()).setMessage(""+l).end(),Ee.l(`${t} ok. ${l}`),e){case Oe:return ct({status:Oe});case qe:return this.getGroupProfile({groupID:o}).then(({data:{group:e}})=>this._handleJoinResult({group:e,avChatRoomFlag:n,longPollingKey:s,startSeq:r,avChatRoomKey:a,messageList:p})).catch(e=>{if(10010===e.code||10007===e.code){this._silentlyGetGroupProfile(e.code,o);const t=new Ds({groupID:o});return this.updateGroupMap([t]),this._handleJoinResult({group:t,avChatRoomFlag:n,longPollingKey:s,startSeq:r,avChatRoomKey:a,messageList:p})}return Ee.e(t+" failed. error:",e),Ft(e)});default:{const e=new gt({code:Ct});return Ee.e(t+" failed. error:",e),Ft(e)}}}).catch(e=>(i.setMessage("groupID:"+o),this.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}_handleJoinResult(e){const{group:t,avChatRoomFlag:o,longPollingKey:r,startSeq:i,avChatRoomKey:n,messageList:u}=e,{groupID:a}=t;if(1===o){let e;return this.getModule(s).setCompleted(`${ie}${a}`),this._groupAttributesHandler.initGroupAttributesCache({groupID:a,avChatRoomKey:n}),this._groupCountersHandler.initGroupCountersCache({groupID:a,avChatRoomKey:n}),e=Ke(r)?this._AVChatRoomHandler.handleJoinResult({group:t}):this._AVChatRoomHandler.startRunLoop({group:t,longPollingKey:r,startSeq:i}),e.then(()=>{this._onAVChatRoomHistoryMessage(u,a)}),e}return this.emitGroupListUpdate(!0,!1),ct({status:qe,group:t})}quitGroup(e){const t=this._n+".quitGroup",o="groupID:"+e;Ee.l(`${t} ${o}`);const s=this.checkJoinedAVChatRoomByID(e);if(!s&&!this.hasLocalGroup(e))return Ft({code:Gt});if(s&&!this.isLoggedIn())return Ee.l(`${t} anonymously ok. ${o}`),this.deleteLocalGroupAndConversation(e),this._AVChatRoomHandler.reset(e),Ot({groupID:e});const r=new Wt("quitGroup");return r.setMessage(o),this.request({protocolName:so,requestData:{groupID:e}}).then(()=>(r.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok"),this.deleteLocalGroupAndConversation(e),s&&this._AVChatRoomHandler.reset(e),this._groupAttributesHandler.deleteLocalGroupAttributes(e),ct({groupID:e}))).catch(e=>(this.probeNetwork().then(([t,o])=>{r.setError(e,t,o).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}searchGroupByID(e){const t=this._n+".searchGroupByID",o={groupIDList:[e]},s=new Wt("searchGroupByID");return s.setMessage("groupID:"+e),Ee.l(`${t} groupID:${e}`),this.request({protocolName:ro,requestData:o}).then(({data:{groupProfile:e}})=>{if(0!==e[0].errorCode)throw new gt({code:e[0].errorCode,message:e[0].errorInfo});return s.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok"),ct({group:new Ds(e[0])})}).catch(e=>(this.probeNetwork().then(([t,o])=>{s.setError(e,t,o).end()}),Ee.w(t+" failed. error:",e),Ft(e)))}changeGroupOwner(e){const t=this._n+".changeGroupOwner";if(this.hasLocalGroup(e.groupID)&&this.getLocalGroupProfile(e.groupID).type===he)return Ft({code:yt});if(e.newOwnerID===this.getMyUserID())return Ft({code:Dt});const o=new Wt("changeGroupOwner");return o.setMessage(`groupID:${e.groupID} newOwnerID:${e.newOwnerID}`),Ee.l(`${t} groupID:${e.groupID}`),this.request({protocolName:io,requestData:e}).then(()=>{o.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok");const{groupID:s,newOwnerID:r}=e;this.groupMap.get(s).ownerID=r;const i=this._groupMemberHandler.getLocalGroupMemberList(s);if(i instanceof Map){const e=i.get(this.getMyUserID());Ke(e)||(e.updateRole("Member"),this.groupMap.get(s).selfInfo.role="Member");const t=i.get(r);Ke(t)||t.updateRole("Owner")}return this.emitGroupListUpdate(!0,!1),ct({group:this.groupMap.get(s)})}).catch(e=>(this.probeNetwork().then(([t,s])=>{o.setError(e,t,s).end()}),Ee.e(t+" failed. error:",e),Ft(e)))}getGroupApplicationList(){return this._groupSystemNoticeHandler.getGroupApplicationList()}handleGroupApplication(e){const t=this._n+".handleGroupApplication",{handleAction:o,handleMessage:s,message:r,application:i}=e;let n,u,a,p,l;r?(n=r.payload.operatorID,u=r.payload.groupProfile.groupID,a=r.payload.authentication,p=r.payload.messageKey):i&&(n=i.applicant,u=i.groupID,a=i.authentication,p=i.messageKey);let h=no;i&&2===i.applicationType&&(h=uo,l=i.userID);const c=new Wt("handleGroupApplication");return c.setMessage("groupID:"+u),Ee.l(`${t} groupID:${u}`),this.request({protocolName:h,requestData:{handleAction:o,handleMessage:s,applicant:n,invitee:l,groupID:u,authentication:a,messageKey:p}}).then(()=>(c.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok"),r&&this._groupSystemNoticeHandler.deleteGroupSystemNotice({messageList:[e.message]}),ct({group:this.getLocalGroupProfile(u)}))).catch(e=>(this.probeNetwork().then(([t,o])=>{c.setError(e,t,o).end()}),Ee.e(t+" failed. error",e),Ft(e)))}handleGroupInvitation(e){const t=this._n+".handleGroupInvitation",{groupProfile:{groupID:o},authentication:s,messageKey:r,operatorID:i}=e.message.payload,{handleAction:n}=e,u=new Wt("handleGroupInvitation");return u.setMessage(`groupID:${o} inviter:${i} handleAction:${n}`),Ee.l(`${t} groupID:${o} inviter:${i} handleAction:${n}`),this.request({protocolName:ao,requestData:{...e,inviter:i,groupID:o,authentication:s,messageKey:r}}).then(()=>(u.setNetworkType(this.getNetworkType()).end(),Ee.l(t+" ok"),this._groupSystemNoticeHandler.deleteGroupSystemNotice({messageList:[e.message]}),ct({group:this.getLocalGroupProfile(o)}))).catch(e=>(this.probeNetwork().then(([t,o])=>{u.setError(e,t,o).end()}),Ee.e(t+" failed. error",e),Ft(e)))}getGroupOnlineMemberCount(e){const t=this._n+".getGroupOnlineMemberCount",o=this._AVChatRoomHandler.checkJoinedAVChatRoomByID(e),s=this.hasLocalGroup(e);if(Ee.l(`${t} groupID:${e} isAVChatRoom:${o} has:${s}`),o)return this._AVChatRoomHandler.getGroupOnlineMemberCount(e);if(!s)return Ot({memberCount:0});const r=Date.now();if(this._onlineMemberCountMap.has(e)){const t=this._onlineMemberCountMap.get(e);if(r-t.lastReqTime<=6e4)return Ot({memberCount:t.memberCount});t.lastReqTime=r}return this.requestOnlineCount(e).then(o=>{const{memberCount:s=0}=o.data;return this._onlineMemberCountMap.set(e,{lastReqTime:Date.now(),memberCount:s}),Ee.l(`${t} ok. groupID:${e} memberCount:${s}`),Ot({memberCount:s})}).catch(e=>(Ee.w(t+" failed. error:",e),Promise.reject(e)))}requestOnlineCount(e){return this.request({protocolName:yo,requestData:{groupID:e}})}hasLocalGroup(e){return this.groupMap.has(e)}deleteLocalGroupAndConversation(e){const t=this.checkJoinedAVChatRoomByID(e);if(Ee.l(`${this._n}.deleteLocalGroupAndConversation isJoinedAVChatRoom:${t}`),t){this.getModule(s).deleteLocalConversation(`${ie}${e}`)}if(rt({groupID:e})){const t=this.getLocalGroupProfile(e);if(t&&!0===t.isSupportTopic){this.getModule(o).deleteTopicListInCommunity(e)}}this._deleteLocalGroup(e),this._onlineMemberCountMap.delete(e),this.emitGroupListUpdate(!0,!1)}_deleteLocalGroup(e){this.groupMap.delete(e),this._groupMemberHandler.deleteGroupMemberList(e)}sendMessage(e,t){if(Be(e._receiverList)&&e._receiverList.length>0){if(!this.canIUse(T.MSG_TO_SPECIFIED_GRP_MBR))return this.cannotUseCommercialAbility("group direct messages")}const o=this.createGroupMessagePack(e,t);return this.request(o)}createGroupMessagePack(e,t){let o=null;t&&t.offlinePushInfo&&(o=t.offlinePushInfo);let s="";He(e.cloudCustomData)&&e.cloudCustomData.length>0&&(s=e.cloudCustomData);const r=[];if(je(t)&&je(t.messageControlInfo)){const{excludedFromUnreadCount:e,excludedFromLastMessage:o,excludedFromContentModeration:s}=t.messageControlInfo;!0===e&&r.push("NoUnread"),!0===o&&r.push("NoLastMsg"),!0===s&&r.push("NoMsgCheck")}let i=void 0;Be(e._receiverList)&&e._receiverList.length>0&&(i=e._receiverList,e._receiverList.length>50&&(i=e._receiverList.slice(0,50),this.outputWarning("ReceiverListLimit")));const n=this.isOnlineMessage(e,t)?1:0,u=e.getGroupAtInfoList(),a={fromAccount:this.getMyUserID(),groupID:e.to,msgBody:e.getElements(),cloudCustomData:s,random:e.random,priority:e.priority,clientSequence:e.clientSequence,groupAtInfo:e.type!==H||ht(u)?void 0:u,onlineOnlyFlag:n,clientTime:e.clientTime,offlinePushInfo:o?{pushFlag:!0===o.disablePush?1:0,title:o.title||"",desc:o.description||"",ext:o.extension||"",apnsInfo:{badgeMode:!0===o.ignoreIOSBadge?1:0,isVoipPush:this._isVoipPush(o)},androidInfo:{OPPOChannelID:o.androidOPPOChannelID||""}}:void 0,messageControlInfo:0===n?r:void 0,needReadReceipt:!0!==e.needReadReceipt||this.isMessageFromOrToAVChatroom(e.to)?0:1,receiverList:i,isSupportExtension:!0===e.isSupportExtension?1:0,isRelayMessage:!0===e._relayFlag?1:0};return it(e.to)&&(a.groupID=nt(e.to),a.topicID=e.to),{protocolName:zt,tjgID:this.generateTjgID(e),requestData:a}}_isVoipPush(e){let t=void 0;return Ke(e.disableVoipPush)||(t=!1===e.disableVoipPush?1:0),t}revokeMessage(e){const t={groupID:e.to,msgSeqList:[{msgSeq:e.sequence}]};return it(e.to)&&(t.groupID=nt(e.to),t.topicID=e.to),this.request({protocolName:po,requestData:t})}deleteMessage(e){const{to:t,keyList:o}=e;Ee.l(`${this._n}.deleteMessage groupID:${t} count:${o.length}`);const s={groupID:t,deleter:this.getMyUserID(),keyList:o};return it(t)&&(s.groupID=nt(t),s.topicID=t),this.request({protocolName:Do,requestData:s})}modifyRemoteMessage(e){const{to:t,sequence:o,payload:s,type:r,version:i=0,cloudCustomData:n}=e;let u=t,a=void 0;it(t)&&(u=nt(t),a=t);let p=void 0;return function(e){return e===H||e===Q||e===z||e===J}(r)&&(p=[],p.push({type:r,content:s})),this.request({protocolName:Lo,requestData:{groupID:u,topicID:a,sequence:o,version:i,elements:p,cloudCustomData:n}})}getRoamingMessage(e){const t=this._n+".getRoamingMessage";let{conversationID:o,groupID:r,sequence:i}=e;const n=new Wt("getGroupRoamingMessages");let u=0,a=void 0;return it(r)&&(a=r,r=nt(a)),this._computeLastSequence({groupID:r,topicID:a,sequence:i}).then(e=>(u=e,Ee.l(`${t} groupID:${r} startSequence:${u}`),this.request({protocolName:ho,requestData:{groupID:r,count:21,sequence:u,topicID:a}}))).then(e=>{const{messageList:i,complete:p,invisibleSequenceList:l=[]}=e.data;let{nextSequence:h=0}=e.data;Ke(i)?Ee.l(`${t} ok. complete:${p} nextSequence:${h} but messageList is undefined!`):Ee.l(`${t} ok. complete:${p} nextSequence:${h} count:${i.length}`),n.setNetworkType(this.getNetworkType()).setMessage(`groupID:${r} topicID:${a} startSequence:${u} complete:${p} nextSequence:${h}`).end();const c=this.getModule(s);let g=[];return ht(i)?h>=1&&c.updateRoamingMessageSequence(o,h):(c.updateRoamingMessageSequence(o,h),g=c.onRoamingMessage(i,o),c.updateIsRead(o),c.patchConversationLastMessage(o)),(2===p||h<1)&&(c.setCompleted(o),h=""),Ee.l(`${t} nextReqID:${h}, stored message count:${g.length}, invisible sequence count:${l.length}`),{nextReqID:h+"",storedMessageList:g}}).catch(e=>(this.probeNetwork().then(([t,o])=>{n.setError(e,t,o).setMessage(`groupID:${r} topicID:${a} startSequence:${u}`).end()}),Ee.w(t+" failed. error:",e),Ft(e)))}_getGroupIDOfMessage(e){return e.conversationID.replace(ie,"")}getReadReceiptList(e){const t=this._n+".getReadReceiptList",o=this._getGroupIDOfMessage(e[0]),s=this.getMyUserID(),r=e.filter(e=>e.from===s&&!0===e.needReadReceipt).map(e=>({sequence:e.sequence}));if(Ee.l(`${t} groupID:${o} sequenceList:${JSON.stringify(r)}`),0===r.length)return Ot({messageList:e});const i=new Wt("getReadReceiptList");return i.setMessage("groupID:"+o),this.request({protocolName:co,requestData:{groupID:o,sequenceList:r}}).then(o=>{i.end(),Ee.l(t+" ok");const{readReceiptList:s}=o.data;return Be(s)&&s.forEach(t=>{e.forEach(e=>{0===t.code&&t.sequence===e.sequence&&(e.readReceiptInfo.readCount=t.readCount,e.readReceiptInfo.unreadCount=t.unreadCount)})}),ct({messageList:e})}).catch(e=>(this.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ee.w(t+" failed. error:",e),Ft(e)))}sendReadReceipt(e){const t=this._n+".sendReadReceipt",o=this._getGroupIDOfMessage(e[0]),s=new Wt("sendReadReceipt");s.setMessage("groupID:"+o);const r=this.getMyUserID(),i=e.filter(e=>e.from!==r&&!0===e.needReadReceipt).map(e=>({sequence:e.sequence}));return 0===i.length?Ft({code:mt}):(Ee.l(`${t}. sequenceList:${JSON.stringify(i)}`),this.request({protocolName:go,requestData:{groupID:o,sequenceList:i}}).then(e=>(s.end(),Ee.l(t+" ok"),ct())).catch(e=>(this.probeNetwork().then(([t,o])=>{s.setError(e,t,o).end()}),Ee.w(t+" failed. error:",e),Ft(e))))}getReadReceiptDetail(e){const{message:t,filter:o,cursor:s,count:r}=e,i=this._getGroupIDOfMessage(t),n=t.ID,u=t.sequence,a=this._n+".getReadReceiptDetail",p=this._receiptDetailCompleteMap.get(n)||!1,l=0!==o&&1!==o?0:o,h=He(s)?s:"",c=!Ve(r)||r<=0||r>=100?100:r,g=`groupID:${i} sequence:${u} cursor:${h} filter:${l} completeFlag:${p}`;Ee.l(`${a} ${g}`);const d={cursor:"",isCompleted:!1,messageID:n,unreadUserIDList:[],readUserIDList:[]},m=new Wt("getReadReceiptDetail");return m.setMessage(g),this.request({protocolName:mo,requestData:{groupID:i,sequence:u,flag:l,cursor:h,count:c}}).then(e=>{m.end();const{cursor:t,isCompleted:o,unreadUserIDList:s,readUserIDList:r}=e.data;return d.cursor=t,1===o&&(d.isCompleted=!0,this._receiptDetailCompleteMap.set(n,!0)),0===l?d.readUserIDList=r.map(e=>e.userID):1===l&&(d.unreadUserIDList=s.map(e=>e.userID)),Ee.l(a+" ok"),ct(d)}).catch(e=>(this.probeNetwork().then(([t,o])=>{m.setError(e,t,o).end()}),Ee.w(a+" failed. error:",e),Ft(e)))}getRoamingMessagesHopping(e){const t=this._n+".getRoamingMessagesHopping";let{groupID:o,count:r,sequence:i,direction:n}=e,u=i;if(Ke(i)){if(1===n)return Ot({messageList:[],isCompleted:!0,nextMessageSeq:""});if(this.hasLocalGroup(o)){const{nextMessageSeq:e}=this.getLocalGroupProfile(o);u=e>1?e-1:0}it(o)&&(u=0)}else 1===n&&(u=i+r-1);let a=void 0;it(o)&&(a=o,o=nt(a));const p=`${a?"topicID:"+a:"groupID:"+o} sequence:${i} direction:${n}`;Ee.l(`${t} ${p}`);const l=new Wt("getGroupRoamingMessagesHopping");return this.request({protocolName:ho,requestData:{groupID:o,topicID:a,count:r,sequence:u}}).then(o=>{const{messageList:r,complete:u}=o.data,a=`complete:${u} count:${r?r.length:0}`;if(Ee.l(`${t} ok. ${a}`),l.setNetworkType(this.getNetworkType()).setMessage(`${p} ${a}`).end(),2===u||ht(r)){const e=this._computeResult();return ct(e)}const h=`${ie}${e.groupID}`,c=this.getModule(s).onRoamingMessage(r,h,!1),g=this._computeResult({direction:n,sequence:i,remoteMessageList:r,processedMessageList:c});return ct(g)}).catch(e=>(this.probeNetwork().then(([t,s])=>{l.setError(e,t,s).setMessage(`groupID:${o} sequence:${i} count:${r}`).end()}),Ee.w(t+" failed. error:",e),Ft(e)))}_computeResult(e){const t={messageList:[],isCompleted:!1,nextMessageSeq:""};if(Ke(e))return t.isCompleted=!0,t;const{direction:o,sequence:s,remoteMessageList:r=[],processedMessageList:i=[]}=e,n=r.length;return 1===o?(t.nextMessageSeq=r[0].sequence+1,i.forEach(e=>{e.sequence>=s&&t.messageList.push(e)}),0===t.messageList.length&&r[0].sequence<s&&(t.isCompleted=!0,t.nextMessageSeq=""),t):(t.nextMessageSeq=r[n-1].sequence-1,t.messageList=[...i],0===t.nextMessageSeq&&(t.isCompleted=!0,t.nextMessageSeq=""),t)}setMessageRead({conversationID:e,lastMessageSeq:t}){const r=this._n+".setMessageRead";Ee.l(`${r} conversationID:${e} lastMessageSeq:${t}`),Ve(t)||this.outputWarning("DoNotModifyLastSeq");const i=new Wt("setGroupMessageRead");i.setMessage(`${e}-${t}`);let n=e.replace(ie,""),u=void 0;return it(n)&&(u=n,n=nt(u)),this.request({protocolName:lo,requestData:{groupID:n,topicID:u,messageReadSeq:t}}).then(()=>{i.setNetworkType(this.getNetworkType()).end(),Ee.l(r+" ok.");const a=this.getModule(s);a.updateIsReadAfterReadReport({conversationID:e,lastMessageSeq:t});let p=!0;if(!Ke(u)){p=!1;const e=this.getModule(o).getLocalTopic(n,u);e&&e.updateSelfInfo({readedSequence:t})}return a.updateUnreadCount(e,p),ct()}).catch(e=>(this.probeNetwork().then(([t,o])=>{i.setError(e,t,o).end()}),Ee.l(r+" failed. error:",e),Ft(e)))}_computeLastSequence(e){const{groupID:t,topicID:o,sequence:s}=e;return s>0?Promise.resolve(s):Ke(o)?this.getGroupLastSequence(t):Promise.resolve(0)}getGroupLastSequence(e){const t=this._n+".getGroupLastSequence",o=new Wt("getGroupLastSequence");let r=0,i="";const n="groupID:"+e;if(this.hasLocalGroup(e)){const s=this.getLocalGroupProfile(e),u=s.lastMessage;if(u.lastSequence>0&&!1===u.onlineOnlyFlag)return r=u.lastSequence,i=`${n}, ${r} from group.lastMessage.lastSequence`,Ee.l(`${t} ${i}`),o.setNetworkType(this.getNetworkType()).setMessage(i).end(),Promise.resolve(r);if(s.nextMessageSeq>1)return r=s.nextMessageSeq-1,i=`${n}, ${r} from group.nextMessageSeq`,Ee.l(`${t} ${i}`),o.setNetworkType(this.getNetworkType()).setMessage(i).end(),Promise.resolve(r)}const u=this.getModule(s).getLocalConversation("GROUP"+e);if(u&&u.lastMessage.lastSequence&&!1===u.lastMessage.onlineOnlyFlag)return r=u.lastMessage.lastSequence,i=`${n}, ${r} from conversation.lastMessage.lastSequence`,Ee.l(`${t} ${i}`),o.setNetworkType(this.getNetworkType()).setMessage(i).end(),Promise.resolve(r);const a={groupIDList:[e],responseFilter:{groupBaseInfoFilter:["NextMsgSeq"]}};return this.getGroupProfileAdvance(a).then(({data:{successGroupList:e}})=>(ht(e)?Ee.w(`${t} ${n}, empty successGroupList`):(r=e[0].nextMessageSeq-1,i=`${n}, ${r} from remote`,Ee.l(`${t} ${i}`)),o.setNetworkType(this.getNetworkType()).setMessage(i).end(),r)).catch(e=>(this.probeNetwork().then(([t,s])=>{o.setError(e,t,s).setMessage(n).end()}),Ee.w(t+" failed. error:",e),Ft(e)))}isMessageFromOrToAVChatroom(e){return this._AVChatRoomHandler.checkJoinedAVChatRoomByID(e)}hasJoinedAVChatRoom(){return this._AVChatRoomHandler.hasJoinedAVChatRoom()}getJoinedAVChatRoom(){return this._AVChatRoomHandler.getJoinedAVChatRoom()}isOnlineMessage(e,t){return!(!this._canIUseOnlineOnlyFlag(e)||!t||!0!==t.onlineUserOnly)}_canIUseOnlineOnlyFlag(e){const t=this.getJoinedAVChatRoom();return!t||!t.includes(e.to)||e.conversationType!==ie}_onAVChatRoomHistoryMessage(e,t){if(ht(e))return;Ee.l(`${this._n}._onAVChatRoomHistoryMessage groupID:${t} count:${e.length}`);const o=[];e.forEach(e=>{o.push({...e,isHistoryMessage:1})}),this.onAVChatRoomMessage(o,t)}onAVChatRoomMessage(e,t=""){this._AVChatRoomHandler.onMessage(e,t)}onAVChatRoomMemberBanned(e){this._AVChatRoomHandler.onAVChatRoomMemberBanned(e)}getGroupSimplifiedInfo(e){const t=new Wt("getGroupSimplifiedInfo"),o={groupIDList:[e],responseFilter:{groupBaseInfoFilter:["Type","Name"]}};return this.getGroupProfileAdvance(o).then(({data:{successGroupList:o}})=>(t.setNetworkType(this.getNetworkType()).setMessage(`groupID:${e} type:${o[0].type}`).end(),o[0])).catch(o=>{this.probeNetwork().then(([s,r])=>{t.setError(o,s,r).setMessage("groupID:"+e).end()})})}setUnjoinedAVChatRoom(e){this._unjoinedAVChatRoomList.set(e,1)}deleteUnjoinedAVChatRoom(e){this._unjoinedAVChatRoomList.has(e)&&this._unjoinedAVChatRoomList.delete(e)}isUnjoinedAVChatRoom(e){return this._unjoinedAVChatRoomList.has(e)}isGroupAttributesUpdatedNotice(e){return this._groupAttributesHandler.isGroupAttributesUpdatedNotice(e)}updateLocalMainSequenceOnReconnected(){this._groupAttributesHandler.updateLocalMainSequenceOnReconnected()}initGroupAttributes(e){return this._groupAttributesHandler.initGroupAttributes(e)}setGroupAttributes(e){return this._groupAttributesHandler.setGroupAttributes(e)}deleteGroupAttributes(e){return this._groupAttributesHandler.deleteGroupAttributes(e)}getGroupAttributes(e){return this._groupAttributesHandler.getGroupAttributes(e)}isMessageFromTopic(e,t){return 2===e&&!ht(t)}isMessageFromCommunityOfTopic(e,t){return 2===e&&ht(t)}getMessageExtensions(e,t){return Ee.l(`${this._n}.getMessageExtensions startSequence:${t}`),this.request({protocolName:vo,requestData:{groupID:e.to,messageSequence:e.sequence,startSequence:t}})}modifyMessageExtensions(e,t,o=1){return Ee.l(`${this._n}.modifyMessageExtensions operateType:${o}`),this.request({protocolName:So,requestData:{groupID:e.to,messageSequence:e.sequence,extensionList:t,operateType:o}})}_genNotifyReqList(e){const t=[];for(let o=0,s=e.length;o<s;o++){const s=e[o],r=this.getLocalGroupProfile(s),{type:i}=r,n=this._getGroupLastRevokedTime(s),u=1e3*we(),a={notifyType:1,limit:20,type:rt({type:i,groupID:s})?ce:void 0,groupID:s,beginTime:n,endTime:u};t.push(a)}return t}getGroupNotify(e){const t=this._n+".getGroupNotify",o=e.filter(e=>{const t=this.getLocalGroupProfile(e),{type:o,isSupportTopic:s}=t;return this.hasLocalGroup(e)&&!st(o)&&!s});let s="filteredGroupIDList.length:"+o.length;o.length<=10&&(s="filteredGroupIDList:"+JSON.stringify(o)),Ee.l(`${t} ${s}`),0!==o.length&&this.request({protocolName:wo,requestData:{notifyReqList:this._genNotifyReqList(e)}}).then(e=>{const{notifyRspList:o}=e.data,s=[];if(Be(o)){const e={dataList:[]};o.forEach(t=>{const{nextRevokedTime:o,groupID:r}=t;e.dataList.push({elements:{revokedInfos:this._genRevokedInfos(t)}}),0!==o?(this._setGroupLastRevokedTime(r,o),s.push(r)):this._setGroupLastRevokedTime(r,1e3*we())}),this.onGroupMessageRevoked(e)}s.length>0&&this.getGroupNotify(s);let r="nextGroupIDList.length:"+s.length;s.length<=10&&(r="nextGroupIDList:"+JSON.stringify(s)),Ee.l(`${t} ${r}`)}).catch(e=>{Ee.e(t+" failed. error:",e)})}_genRevokedInfos(e){const{notifyList:t,groupID:o}=e,s=[];return Be(t)&&t.forEach(e=>{s.push({groupID:o,sequence:e.sequence,random:e.random,revokerInfo:{...e.revokerInfo}})}),s}_getGroupLastRevokedTime(e){return this.hasLocalGroup(e)?this.getLocalGroupProfile(e)._lastRevokedTime:0}_setGroupLastRevokedTime(e,t){this.hasLocalGroup(e)&&(this.getLocalGroupProfile(e)._lastRevokedTime=t)}isGroupCountersNotice(e){return this._groupCountersHandler.isGroupCountersNotice(e)}setGroupCounters(e){return this._groupCountersHandler.setGroupCounters(e)}increaseGroupCounter(e){return this._groupCountersHandler.increaseGroupCounter(e)}decreaseGroupCounter(e){return this._groupCountersHandler.decreaseGroupCounter(e)}getGroupCounters(e){return this._groupCountersHandler.getGroupCounters(e)}getGroupMemberHandler(){return this._groupMemberHandler}getGroupMemberList(e){return this._groupMemberHandler.getGroupMemberList(e)}getGroupMemberProfile(e){return this._groupMemberHandler.getGroupMemberProfile(e)}addGroupMember(e){return this._groupMemberHandler.addGroupMember(e)}deleteGroupMember(e){return this._groupMemberHandler.deleteGroupMember(e)}setGroupMemberMuteTime(e){return this._groupMemberHandler.setGroupMemberMuteTime(e)}setGroupMemberRole(e){return this._groupMemberHandler.setGroupMemberRole(e)}setGroupMemberNameCard(e){return this._groupMemberHandler.setGroupMemberNameCard(e)}setGroupMemberCustomField(e){return this._groupMemberHandler.setGroupMemberCustomField(e)}markGroupMemberList(e){return this._groupMemberHandler.markGroupMemberList(e)}modifyGroupMemberInfo(e){return this._groupMemberHandler.modifyGroupMemberInfo(e)}restartPolling(){this._AVChatRoomHandler.restartPolling()}getPollingTimerID(e){if(!e)return-1;const t=this.getLocalGroupProfile(e);return t&&st(t.type)?this._AVChatRoomHandler.getPollingTimerID(e):-1}_canIUseJoinOption(e){return(e=>e===pe)(e)||rt({type:e})}_silentlyGetGroupProfile(e,t){const o=setTimeout(this.getGroupProfile.bind(this,{groupID:t}),3e3);this._timeoutIDs.push(o),Ee.l(`${this._n}._silentlyGetGroupProfile errorCode:${e} groupID:${t} timeoutIDs:${this._timeoutIDs}`)}_clearTimeoutIDs(){this._timeoutIDs.forEach(e=>{clearTimeout(e)}),this._timeoutIDs=[]}reset(){this.groupMap.clear(),this._unjoinedAVChatRoomList.clear(),this._receiptDetailCompleteMap.clear(),this._onlineMemberCountMap.clear(),this._commonGroupHandler.reset(),this._groupSystemNoticeHandler.reset(),this._groupTipsHandler.reset(),this._groupAttributesHandler.reset(),this._groupCountersHandler.reset(),this._AVChatRoomHandler.reset(),this._groupMemberHandler.reset(),this._clearTimeoutIDs()}}export{vs as default};