@tencentcloud/lite-chat 1.4.1 → 1.5.0

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