@tencentcloud/lite-chat 4.2.5 → 4.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencentcloud/lite-chat",
3
- "version": "4.2.5",
3
+ "version": "4.2.7",
4
4
  "description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
5
5
  "main": "standard.js",
6
6
  "types": "index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "default": "./plugins/*.js"
27
27
  }
28
28
  },
29
+ "miniprogram": "./",
29
30
  "keywords": ["chat", "real-time chat", "uni-app", "React Native", "Donut", "push", "messaging", "IM", "trtc"],
30
31
  "repository": {
31
32
  "type": "git",
@@ -1 +1 @@
1
- const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:n,messageHelper:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],a=t.length;for(let u=0;u<a;u++){let a=t[u];if(o&&(a=d(a)),m(a.Event)&&Object.values(r).includes(a.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(a))continue;this._patchMessageType(a);const l=s.parseServerGroupMessage(a),c=this._createMessage(l);c.level=a.GroupInfo.From_AccountLevel,_(a.Event)&&this._avChatRoomHandler.isGroupAttributesUpdated(l)?this._avChatRoomHandler.handleGroupAttributesUpdated(l):null!==this._filterDuplicateMessage(c)&&(n.isMessageSentByCurrentInstance(c)||(1===l.isModified&&(c.isModified=!0),_(a.Event)&&this._updateLocalOnlineMemberCountFromTips(a),i.push(c)))}return i}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.event===i.GROUP_SYSTEM_MESSAGE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,r=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return r.setElement(e.elements),r}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},S=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},C=()=>{const e=f("polling_interval");return S(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return S(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||C()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return!!this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)&&(this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e),!0)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return S(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,C()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,C())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return S(e)?parseInt(e,10):20})()){const t=C()+(()=>{const e=f("polling_interval_plus");return S(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(S(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];this._joinedGroupMap.values().forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:O.handleJoinGroupResult(n.data):n})}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var P=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var G=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(O.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}})}_getOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=O.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}})}_isExpired(e){const t=O.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})})}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return O.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}};var E=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var A=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),P.init(e,t),G.init(e,t),D.init(e,t),E.init(e,t),A.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});O.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=O.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return O.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),O.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return O.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&O.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};var N=new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),O.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){O.onAVChatRoomSystemNotification(e)}_reset(){O.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{N as default};
1
+ const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){var n;const{message:{messageDataHandler:s,messageHelper:o}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),a=[],u=t.length;for(let l=0;l<u;l++){let u=t[l];if(i&&(u=d(u)),m(u.Event)&&Object.values(r).includes(u.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(u))continue;this._patchMessageType(u);const c=o.parseServerGroupMessage(u),g=this._createMessage(c);if(g.level=u.GroupInfo.From_AccountLevel,_(u.Event)){const e=Object.assign(Object.assign({},c),{elements:Object.assign({},(null===(n=null==c?void 0:c.elements)||void 0===n?void 0:n.content)||{})});if(this._avChatRoomHandler.isGroupAttributesUpdated(e)){this._avChatRoomHandler.handleGroupAttributesUpdated(e);continue}if(this._avChatRoomHandler.isGroupCounterUpdated(e)){this._avChatRoomHandler.handleGroupCounterUpdated(e);continue}}null!==this._filterDuplicateMessage(g)&&(s.isMessageSentByCurrentInstance(g)||(1===c.isModified&&(g.isModified=!0),_(u.Event)&&this._updateLocalOnlineMemberCountFromTips(u),a.push(g)))}return a}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.elements.type===n.MSG_GRP_SYS_NOTICE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return i.setElement(e.elements),i}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},S=()=>{const e=f("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return C(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||S()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}isGroupCounterUpdated(e){return this._parentPlugin.groupCounter.isGroupCounterUpdated(e)}handleGroupCounterUpdated(e){this._parentPlugin.groupCounter.handleGroupCounterUpdated(e)}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,S()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,S())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return C(e)?parseInt(e,10):20})()){const t=S()+(()=>{const e=f("polling_interval_plus");return C(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(C(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];Array.from(this._joinedGroupMap.values()).forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:O.handleJoinGroupResult(n.data):n})}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var G=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var P=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(O.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}})}_getOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=O.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}})}_isExpired(e){const t=O.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})})}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return O.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}};var A=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var E=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),G.init(e,t),P.init(e,t),D.init(e,t),A.init(e,t),E.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});O.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=O.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return O.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),O.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return O.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&O.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};var N=new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),O.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){O.onAVChatRoomSystemNotification(e)}_reset(){O.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{N as default};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:n,messageHelper:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],a=t.length;for(let u=0;u<a;u++){let a=t[u];if(o&&(a=d(a)),m(a.Event)&&Object.values(r).includes(a.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(a))continue;this._patchMessageType(a);const l=s.parseServerGroupMessage(a),c=this._createMessage(l);c.level=a.GroupInfo.From_AccountLevel,_(a.Event)&&this._avChatRoomHandler.isGroupAttributesUpdated(l)?this._avChatRoomHandler.handleGroupAttributesUpdated(l):null!==this._filterDuplicateMessage(c)&&(n.isMessageSentByCurrentInstance(c)||(1===l.isModified&&(c.isModified=!0),_(a.Event)&&this._updateLocalOnlineMemberCountFromTips(a),i.push(c)))}return i}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.event===i.GROUP_SYSTEM_MESSAGE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,r=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return r.setElement(e.elements),r}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},S=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},C=()=>{const e=f("polling_interval");return S(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return S(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||C()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return!!this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)&&(this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e),!0)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return S(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,C()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,C())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return S(e)?parseInt(e,10):20})()){const t=C()+(()=>{const e=f("polling_interval_plus");return S(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(S(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];this._joinedGroupMap.values().forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:O.handleJoinGroupResult(n.data):n})}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var P=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var G=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(O.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}})}_getOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=O.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}})}_isExpired(e){const t=O.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})})}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return O.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}};var E=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var A=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),P.init(e,t),G.init(e,t),D.init(e,t),E.init(e,t),A.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});O.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=O.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return O.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),O.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return O.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&O.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};return new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),O.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){O.onAVChatRoomSystemNotification(e)}_reset(){O.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,d=e=>e===i.GROUP_SYSTEM_MESSAGE;function m(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||d(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);d(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){var n;const{message:{messageDataHandler:s,messageHelper:o}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),a=[],u=t.length;for(let l=0;l<u;l++){let u=t[l];if(i&&(u=m(u)),d(u.Event)&&Object.values(r).includes(u.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(u))continue;this._patchMessageType(u);const c=o.parseServerGroupMessage(u),g=this._createMessage(c);if(g.level=u.GroupInfo.From_AccountLevel,_(u.Event)){const e=Object.assign(Object.assign({},c),{elements:Object.assign({},(null===(n=null==c?void 0:c.elements)||void 0===n?void 0:n.content)||{})});if(this._avChatRoomHandler.isGroupAttributesUpdated(e)){this._avChatRoomHandler.handleGroupAttributesUpdated(e);continue}if(this._avChatRoomHandler.isGroupCounterUpdated(e)){this._avChatRoomHandler.handleGroupCounterUpdated(e);continue}}null!==this._filterDuplicateMessage(g)&&(s.isMessageSentByCurrentInstance(g)||(1===c.isModified&&(g.isModified=!0),_(u.Event)&&this._updateLocalOnlineMemberCountFromTips(u),a.push(g)))}return a}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),d(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.elements.type===n.MSG_GRP_SYS_NOTICE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return i.setElement(e.elements),i}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=m(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},S=()=>{const e=f("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return C(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||S()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}isGroupCounterUpdated(e){return this._parentPlugin.groupCounter.isGroupCounterUpdated(e)}handleGroupCounterUpdated(e){this._parentPlugin.groupCounter.handleGroupCounterUpdated(e)}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,S()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,S())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return C(e)?parseInt(e,10):20})()){const t=S()+(()=>{const e=f("polling_interval_plus");return C(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(C(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];Array.from(this._joinedGroupMap.values()).forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:O.handleJoinGroupResult(n.data):n})}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var G=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var P=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(O.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}})}_getOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=O.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}})}_isExpired(e){const t=O.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})})}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return O.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}};var A=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var E=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),G.init(e,t),P.init(e,t),D.init(e,t),A.init(e,t),E.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});O.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=O.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return O.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),O.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return O.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&O.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};return new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),O.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){O.onAVChatRoomSystemNotification(e)}_reset(){O.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}});
@@ -1 +1 @@
1
- const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))(function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(r,a)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{OuterConstant:s}=e.core;let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(`${t} fail:`,o),o}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){var t;const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===s.CONV_C2C?this.userProfile={userID:this.conversationID.replace(s.CONV_C2C,"")}:this.type===s.CONV_GROUP&&(!this.subType&&(null===(t=this.groupProfile)||void 0===t?void 0:t.type)&&(this.subType=this.groupProfile.type),n(this.groupProfile)&&(this.groupProfile={groupID:this.conversationID.replace(s.CONV_GROUP,""),selfInfo:{},lastMessage:{},type:this.subType}))}updateUnreadCount(t){var s;const{core:{OuterConstant:n,utils:{isUndefined:o},store:i}}=e,{nextUnreadCount:r,isFromGetConversations:a,isUnreadC2CMessage:c}=t;if(o(r))return;if(this.subType===n.GRP_AVCHATROOM)return void(this.unreadCount=0);if(a&&this.type===n.CONV_GROUP)return void(this.unreadCount=r);if(c&&this.type===n.CONV_C2C)return void(this.unreadCount=r);const l="1"===(null===(s=i.get("cloudConfig"))||void 0===s?void 0:s.support_unread_count_for_meeting);this.subType!==n.GRP_MEETING||l?this.unreadCount+=r:this.unreadCount=0}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,p=1;var C=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ:C}}=e;this._conversationStore=n,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach(e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter(e=>this._isConversationNeedShow(e.conversationID)).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach(e=>{const{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach(e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}}),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach(e=>{n=this.getLocalConversation(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))}),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),this._core.ssoLog.debug("updateLocalConversationList",` newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o||a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach(t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)});const r=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,CONV_C2C:o}}=this._core;e.forEach(e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===n){const e=i.replace(n,"");s.push(e)}}),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}}),i&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{safeStringify:o},ssoLog:i,apiMap:{getGroupProfile:r}}=this._core;let a=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),o=this.getLocalConversation(`${s}${e}`);t&&o&&(o.groupProfile=t,a=!0),o&&!o.getProfileCompleted()&&"function"==typeof r&&(yield r({groupID:e}))}))),a&&this.emitConversationListUpdate()}catch(e){i.debug("_updateGroupConversation",o(e))}})}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach(e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach(e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})})})}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){var t,s;e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:n},conversation:o}=this._core,i=this.getLocalConversationList();this._emitEvent({name:n,data:i,isSyncCompleted:null===(s=null===(t=null==o?void 0:o.syncConversationHandler)||void 0===t?void 0:t.isSyncCompleted)||void 0===s?void 0:s.call(t)}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach(s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.unreadCount)}),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter(e=>this._isConversationNeedShow(e.conversationID))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)}),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter(t=>e.includes(t.conversationID))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})})}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach(e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);C.patchMessageRemindType([n],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){if(0!==e.length)try{const s=yield function(e,s){return t(this,void 0,void 0,function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})})}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach(e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;C.patchMessageRemindType([i],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var f=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=C.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c})}_handleC2CConversation(e,s){return t(this,void 0,void 0,function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.appendToPinnedConversation(e)})}_handleGroupConversation(e,s){return t(this,void 0,void 0,function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)})}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach(e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach(e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.updateUnreadCount(o)})}})}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach(e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach(e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.updateUnreadCount(o),this._clearGroupAtInfoList(o)})})}setMessageRead(e){return t(this,void 0,void 0,function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})})}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=p,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach(e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))}),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=C.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter(e=>!e.atTypeArray.includes(r)),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map(e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}));yield function(e,s){return t(this,void 0,void 0,function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})})}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}})}_clearGroupAtInfoList(e,t=!0){const s=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.map(e=>e.time));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.map(e=>e.sequence));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${s}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}})}_setGroupMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})})}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${s}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}})}_shouldSetAllMessageRead(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach(e=>{const{Type:s,To_Account:i,GroupId:r}=e;let a;1===s?a=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.getLocalConversation(`${n.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))}),o&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})})}({fromAccount:r.getCurrentUserID(),operationType:!0===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}})}};var S=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:s}=this._core,n=[];e.forEach(e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)}),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}deleteConversation(e){return t(this,void 0,void 0,function*(){const{utils:{isString:t}}=this._core;if(t(e))return void(yield this._deleteConversation({conversationIDList:[e],flag:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)})}_deleteConversation(e){return t(this,void 0,void 0,function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}})}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter(e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach(e=>{var t;if(C.hasLocalConversation(e)){const s=(null===(t=C.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}}),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})})}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach(e=>{if(0===e.ResultCode){const s=1===e.Type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}}),this._deleteLocalConversationList(t),t}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var I=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,function*(){const{conversationID:t,draftText:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.emitConversationListUpdate(),{code:0,data:{conversation:n}}})}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[n],i=yield function(e,s){return t(this,void 0,void 0,function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})})}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach(e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)});const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach(e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})}),C.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}})}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})})}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;C.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}})}};var T=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:s,ssoLog:n}=this._core;e.forEach(e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map(e=>`${s.CONV_C2C}${e}`),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}})}setMessageRemindType(e){return t(this,void 0,void 0,function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,s),s}})}};var y=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach(e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}})}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}};var A=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})})}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,function*(){try{const s=yield function(){return t(this,void 0,void 0,function*(){const{common:t}=e.core,s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})})}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}})}_handleResult(e){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some(e=>{if(G(e))return!0}))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};var $=new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}};export{$ as default};
1
+ const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))(function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s(function(e){e(t)})).then(r,a)}c((n=n.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{OuterConstant:s}=e.core;let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(`${t} fail:`,o),o}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){var t;const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===s.CONV_C2C?this.userProfile={userID:this.conversationID.replace(s.CONV_C2C,"")}:this.type===s.CONV_GROUP&&(!this.subType&&(null===(t=this.groupProfile)||void 0===t?void 0:t.type)&&(this.subType=this.groupProfile.type),n(this.groupProfile)&&(this.groupProfile={groupID:this.conversationID.replace(s.CONV_GROUP,""),selfInfo:{},lastMessage:{},type:this.subType}))}updateUnreadCount(t){var s;const{core:{OuterConstant:n,utils:{isUndefined:o},store:i}}=e,{nextUnreadCount:r,isFromGetConversations:a,isUnreadC2CMessage:c}=t;if(o(r))return;if(this.subType===n.GRP_AVCHATROOM)return void(this.unreadCount=0);if(a&&this.type===n.CONV_GROUP)return void(this.unreadCount=r);if(c&&this.type===n.CONV_C2C)return void(this.unreadCount=r);const l="1"===(null===(s=i.get("cloudConfig"))||void 0===s?void 0:s.support_unread_count_for_meeting);this.subType!==n.GRP_MEETING||l?this.unreadCount+=r:this.unreadCount=0}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,p=1;var C=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ:C}}=e;this._conversationStore=n,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach(e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter(e=>this._isConversationNeedShow(e.conversationID)).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach(e=>{const{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach(e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}}),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach(e=>{n=this.getLocalConversation(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))}),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),this._core.ssoLog.debug("updateLocalConversationList",` newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o||a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach(t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)});const r=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,CONV_C2C:o}}=this._core;e.forEach(e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===n){const e=i.replace(n,"");s.push(e)}}),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}}),i&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{safeStringify:o},ssoLog:i,apiMap:{getGroupProfile:r}}=this._core;let a=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),o=this.getLocalConversation(`${s}${e}`);t&&o&&(o.groupProfile=t,a=!0),o&&!o.getProfileCompleted()&&"function"==typeof r&&(yield r({groupID:e}))}))),a&&this.emitConversationListUpdate()}catch(e){i.debug("_updateGroupConversation",o(e))}})}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach(e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach(e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})})})}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){var t,s;e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:n},conversation:o}=this._core,i=this.getLocalConversationList();this._emitEvent({name:n,data:i,isSyncCompleted:null===(s=null===(t=null==o?void 0:o.syncConversationHandler)||void 0===t?void 0:t.isSyncCompleted)||void 0===s?void 0:s.call(t)}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach(s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.unreadCount)}),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter(e=>this._isConversationNeedShow(e.conversationID))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)}),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter(t=>e.includes(t.conversationID))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})})}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach(e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);C.patchMessageRemindType([n],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,function*(){if(0!==e.length)try{const s=yield function(e,s){return t(this,void 0,void 0,function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})})}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach(e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;C.patchMessageRemindType([i],o)})}catch(e){console.error(`${this._name}.get fail:`,e)}})}};var f=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=C.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c})}_handleC2CConversation(e,s){return t(this,void 0,void 0,function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.appendToPinnedConversation(e)})}_handleGroupConversation(e,s){return t(this,void 0,void 0,function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)})}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach(e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach(e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.updateUnreadCount(o)})}})}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach(e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach(e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.updateUnreadCount(o),this._clearGroupAtInfoList(o)})})}setMessageRead(e){return t(this,void 0,void 0,function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})})}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=p,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach(e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))}),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=C.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter(e=>!e.atTypeArray.includes(r)),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map(e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}));yield function(e,s){return t(this,void 0,void 0,function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})})}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}})}_clearGroupAtInfoList(e,t=!0){const s=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.map(e=>e.time));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.map(e=>e.sequence));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${s}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}})}_setGroupMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})})}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${s}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}})}_shouldSetAllMessageRead(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach(e=>{const{Type:s,Peer_Account:i,GroupId:r}=e;let a;1===s?a=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.getLocalConversation(`${n.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))}),o&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})})}({fromAccount:r.getCurrentUserID(),operationType:!0===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}})}};var S=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:s}=this._core,n=[];e.forEach(e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)}),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}deleteConversation(e){return t(this,void 0,void 0,function*(){const{utils:{isString:t}}=this._core;if(t(e))return void(yield this._deleteConversation({conversationIDList:[e],flag:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)})}_deleteConversation(e){return t(this,void 0,void 0,function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}})}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter(e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach(e=>{var t;if(C.hasLocalConversation(e)){const s=(null===(t=C.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}}),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})})}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach(e=>{if(0===e.ResultCode){const s=1===e.Type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}}),this._deleteLocalConversationList(t),t}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e),this._core.message.messageHistory.completedHistoryConversations.delete(e)}};var I=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,function*(){const{conversationID:t,draftText:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.emitConversationListUpdate(),{code:0,data:{conversation:n}}})}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[n],i=yield function(e,s){return t(this,void 0,void 0,function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})})}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach(e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)});const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach(e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})}),C.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}})}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})})}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;C.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}})}};var T=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:s,ssoLog:n}=this._core;e.forEach(e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map(e=>`${s.CONV_C2C}${e}`),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}})}setMessageRemindType(e){return t(this,void 0,void 0,function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,s),s}})}};var y=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach(e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}})}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}};var A=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})})}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,function*(){try{const s=yield function(){return t(this,void 0,void 0,function*(){const{common:t}=e.core,s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})})}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}})}_handleResult(e){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some(e=>{if(G(e))return!0}))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};var $=new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}};export{$ as default};