@tencentcloud/lite-chat 1.4.0 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencentcloud/lite-chat",
3
- "version": "1.4.0",
3
+ "version": "1.4.2",
4
4
  "description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
5
5
  "main": "standard.js",
6
6
  "module": "standard.es.js",
@@ -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
+ const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,l=2603,u=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getPollingInterval()}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,(function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,(function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})}))}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getPollingInterval();this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}}))}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:l,CCD:u,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:l,CloudCustomData:u,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:I(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map((e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e}))}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=i.map((e=>({UserId:e}))));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter((e=>"MsgOperatorMemberExtraInfo"!==e)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]})),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r}=n,a=t(n,["GN","GT","F_Hd","F_NN"]),l=Object.assign({GroupName:s,GroupType:o},a);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),l}function I(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map((e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:l,MsgMemberExtraInfo:u}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),u&&(g.MsgMemberExtraInfo=function(e){return e.map((e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}))}(u)),l&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(l)),g}));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(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter((e=>!0===e.isModified)),r=o.filter((e=>!1===e.isModified)),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:l}}=this._core;i.length>0&&this._emitEvent({name:l,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort(((e,t)=>e.MS-t.MS)),o=n.map((e=>e.MS))):(n.sort(((e,t)=>e.MsgSeq-t.MsgSeq)),o=n.map((e=>e.MsgSeq))),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:n,messageHelper:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],a=t.length;for(let l=0;l<a;l++){let a=t[l];if(o&&(a=d(a)),m(a.Event)&&Object.values(r).includes(a.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(a))continue;this._patchMessageType(a);const u=s.parseServerGroupMessage(a),c=this._createMessage(u);_(a.Event)&&this._avChatRoomHandler.isGroupAttributesUpdated(u)?this._avChatRoomHandler.handleGroupAttributesUpdated(u):null!==this._filterDuplicateMessage(c)&&(n.isMessageSentByCurrentInstance(c)||(1===u.isModified&&(c.isModified=!0),_(a.Event)&&this._updateLocalOnlineMemberCountFromTips(a),i.push(c)))}return i}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.event===i.GROUP_SYSTEM_MESSAGE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,r=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return r.setElement(e.elements),r}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach((e=>{const{TinyId:n,MsgClientTime:o,Random:l,MsgSeq:u}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${l}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:u};a.push(c)})),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.createSSOLogData({method:"MessageStacked"}).setLogInfo({message:`count:${t} groupID:${e.join(",")}`}).end(),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const l=this._createMessage(a);l.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(l.ID)||(o.push(l),this._broadcastMessageIDMap.set(l.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let l=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(l)?l={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(l.latestUpdateTime=r,l.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,l)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const S=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},f=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},C=()=>{const e=S("polling_interval");return f(e)?parseInt(e,10):300},O=()=>{const 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){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}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 this._joinedGroupMap.size>0&&(e=[...this._joinedGroupMap.values()].filter((e=>e.type===TYPES.GRP_LIVE))),e}handleJoinGroupResult(e){return n(this,void 0,void 0,(function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a}=e,{groupID:l}=r;return yield this._preCheck(r),this._joinedGroupMap.set(l,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${l}`),a.length>0&&v.onMessageReceived(l,a,!0),t(i)?{status:o.JOIN_STATUS_SUCCESS,group:r}:this.startMessageLongPolling(e)}))}_preCheck(e){return n(this,void 0,void 0,(function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o}}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=S("polling_count_limit");return f(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[i,r]=this._joinedGroupMap.entries().next().value;r.selfInfo.role===n.GRP_MBR_ROLE_OWNER?this._parentPlugin.groupDataHandler.deleteLocalGroup(i):yield o(i),this.reset(i)}))}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingInterval=C(),this._startPolling(i),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(console.log(`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:O()}:{longPollingKey:t,startSequence:n,simplifiedMessage:O()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0===n)this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t);else{const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0?(0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._pollingInterval=C()),v.onMessageReceived(e,i)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===(()=>{const e=S("polling_no_msg_count");return f(e)?parseInt(e,10):20})()&&(this._pollingInterval=C()+(()=>{const e=S("polling_interval_plus");return f(e)?parseInt(e,10):2e3})())),r.length>0&&v.onBroadcastMessageReceived(r)}_handleFailure(e,t){console.warn(`${this._name}._handleFailure groupID:${e} error:`,t)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter((t=>t.type===e.GRP_AVCHATROOM))),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}_stopPolling(e){if(e){console.log(`${this._name}._stopPolling groupID:${e}`);const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),void this._onlineMemberCountMap.delete(e)}console.log(`${this._name}._stopPolling all`);for(const 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()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{group:{type:s}}}=n;return s===t.GRP_AVCHATROOM?b.handleJoinGroupResult(n.data):n}))}};var E=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&b.reset(e),n}))}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&b.reset(e),n}))}};var G=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,(function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s))return this._getGroupMemberList(e)}return this._parentPlugin.groupMember.getGroupMemberList(e)}))}_getGroupMemberList(e){return n(this,void 0,void 0,(function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})}))}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_handleMemberList(e){return e.map((e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}}))}};var A=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,(function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}}))}_getOnlineMemberCount(e){return n(this,void 0,void 0,(function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=b.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}}))}_isExpired(e){const t=b.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,(function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,(function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})}))}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return b.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,(function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,u=n.getGroup(a);if(s(u))throw new i.ChatError({functionName:t,code:l});if(u.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)}))}_deleteGroupMember(e){return n(this,void 0,void 0,(function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o}=this._core,{groupID:i,duration:r=0,userIDList:a}=e;if(0===r)throw new o.ChatError({functionName:t,code:u});try{yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})}))}(e,this._core),console.log(`${this._name}.${t} ok, groupID:${i}`);return{code:0,data:{group:s.getGroup(i),userIDList:a}}}catch(e){const n=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var D=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,(function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})}))}(a,this._core),{MemberList:l=[]}=e||{},{successUserIDList:u,failureUserIDList:c}=this._handleResult(l,r);return console.log(`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${u.length} fail:${c.length}`),{code:0,data:{successUserIDList:u,failureUserIDList:c}}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map((e=>({Member_Account:e,Marks:[n]})))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach((t=>{e.find((e=>e.Member_Account===t))?n.push(t):s.push(t)})),{successUserIDList:n,failureUserIDList:s})}};var 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)}};var L=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),console.log("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s}=this._core,{groupID:o,longPollingKey:i,longPollingSequence:r=1}=e;if(n(i))return console.warn(`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});b.hasPollingInstance(o)&&this.stopMessageLongPolling({groupID:o});const a=b.getJoinedLiveList();!t.isUnlimitedAVChatRoom()&&a.length>0&&this.stopMessageLongPolling({groupID:a[0]});const l={groupID:o,type:s.GRP_LIVE};return console.log(`${this._name}.startMessageLongPolling groupID:${o} longPollingKey:${i} longPollingSequence:${r}`),b.startMessageLongPolling({group:l,longPollingKey:i,startSequence:r})}stopMessageLongPolling(e){const{groupID:t}=e;return b.reset(t),console.log(`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}};var 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);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){b.onAVChatRoomSystemNotification(e)}_reset(){b.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{N as default};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,function(){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(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,l=2603,u=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getPollingInterval()}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,(function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,(function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})}))}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getPollingInterval();this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}}))}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:l,CCD:u,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:l,CloudCustomData:u,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:I(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map((e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e}))}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=i.map((e=>({UserId:e}))));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter((e=>"MsgOperatorMemberExtraInfo"!==e)).reduce(((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]})),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r}=n,a=t(n,["GN","GT","F_Hd","F_NN"]),l=Object.assign({GroupName:s,GroupType:o},a);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),l}function I(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map((e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:l,MsgMemberExtraInfo:u}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),u&&(g.MsgMemberExtraInfo=function(e){return e.map((e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}))}(u)),l&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(l)),g}));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(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter((e=>!0===e.isModified)),r=o.filter((e=>!1===e.isModified)),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:l}}=this._core;i.length>0&&this._emitEvent({name:l,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort(((e,t)=>e.MS-t.MS)),o=n.map((e=>e.MS))):(n.sort(((e,t)=>e.MsgSeq-t.MsgSeq)),o=n.map((e=>e.MsgSeq))),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:n,messageHelper:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],a=t.length;for(let l=0;l<a;l++){let a=t[l];if(o&&(a=d(a)),m(a.Event)&&Object.values(r).includes(a.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(a))continue;this._patchMessageType(a);const u=s.parseServerGroupMessage(a),c=this._createMessage(u);_(a.Event)&&this._avChatRoomHandler.isGroupAttributesUpdated(u)?this._avChatRoomHandler.handleGroupAttributesUpdated(u):null!==this._filterDuplicateMessage(c)&&(n.isMessageSentByCurrentInstance(c)||(1===u.isModified&&(c.isModified=!0),_(a.Event)&&this._updateLocalOnlineMemberCountFromTips(a),i.push(c)))}return i}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.event===i.GROUP_SYSTEM_MESSAGE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,r=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return r.setElement(e.elements),r}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach((e=>{const{TinyId:n,MsgClientTime:o,Random:l,MsgSeq:u}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${l}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:u};a.push(c)})),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.createSSOLogData({method:"MessageStacked"}).setLogInfo({message:`count:${t} groupID:${e.join(",")}`}).end(),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const l=this._createMessage(a);l.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(l.ID)||(o.push(l),this._broadcastMessageIDMap.set(l.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let l=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(l)?l={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(l.latestUpdateTime=r,l.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,l)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},S=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},C=()=>{const e=f("polling_interval");return S(e)?parseInt(e,10):300},O=()=>{const 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._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){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}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 this._joinedGroupMap.size>0&&(e=[...this._joinedGroupMap.values()].filter((e=>e.type===TYPES.GRP_LIVE))),e}handleJoinGroupResult(e){return n(this,void 0,void 0,(function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a}=e,{groupID:l}=r;return yield this._preCheck(r),this._joinedGroupMap.set(l,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${l}`),a.length>0&&v.onMessageReceived(l,a,!0),t(i)?{status:o.JOIN_STATUS_SUCCESS,group:r}:this.startMessageLongPolling(e)}))}_preCheck(e){return n(this,void 0,void 0,(function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o}}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return S(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[i,r]=this._joinedGroupMap.entries().next().value;r.selfInfo.role===n.GRP_MBR_ROLE_OWNER?this._parentPlugin.groupDataHandler.deleteLocalGroup(i):yield o(i),this.reset(i)}))}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingInterval=C(),this._startPolling(i),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(console.log(`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:O()}:{longPollingKey:t,startSequence:n,simplifiedMessage:O()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0===n)this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t);else{const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0?(0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._pollingInterval=C()),v.onMessageReceived(e,i)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===(()=>{const e=f("polling_no_msg_count");return S(e)?parseInt(e,10):20})()&&(this._pollingInterval=C()+(()=>{const e=f("polling_interval_plus");return S(e)?parseInt(e,10):2e3})())),r.length>0&&v.onBroadcastMessageReceived(r)}_handleFailure(e,t){console.warn(`${this._name}._handleFailure groupID:${e} error:`,t)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter((t=>t.type===e.GRP_AVCHATROOM))),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}_stopPolling(e){if(e){console.log(`${this._name}._stopPolling groupID:${e}`);const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),void this._onlineMemberCountMap.delete(e)}console.log(`${this._name}._stopPolling all`);for(const 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()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{group:{type:s}}}=n;return s===t.GRP_AVCHATROOM?b.handleJoinGroupResult(n.data):n}))}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&b.reset(e),n}))}};var E=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&b.reset(e),n}))}};var G=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,(function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s))return this._getGroupMemberList(e)}return this._parentPlugin.groupMember.getGroupMemberList(e)}))}_getGroupMemberList(e){return n(this,void 0,void 0,(function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})}))}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_handleMemberList(e){return e.map((e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}}))}};var A=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,(function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}}))}_getOnlineMemberCount(e){return n(this,void 0,void 0,(function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=b.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}}))}_isExpired(e){const t=b.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,(function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,(function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})}))}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return b.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,(function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,u=n.getGroup(a);if(s(u))throw new i.ChatError({functionName:t,code:l});if(u.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)}))}_deleteGroupMember(e){return n(this,void 0,void 0,(function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o}=this._core,{groupID:i,duration:r=0,userIDList:a}=e;if(0===r)throw new o.ChatError({functionName:t,code:u});try{yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})}))}(e,this._core),console.log(`${this._name}.${t} ok, groupID:${i}`);return{code:0,data:{group:s.getGroup(i),userIDList:a}}}catch(e){const n=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var D=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,(function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})}))}(a,this._core),{MemberList:l=[]}=e||{},{successUserIDList:u,failureUserIDList:c}=this._handleResult(l,r);return console.log(`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${u.length} fail:${c.length}`),{code:0,data:{successUserIDList:u,failureUserIDList:c}}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map((e=>({Member_Account:e,Marks:[n]})))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach((t=>{e.find((e=>e.Member_Account===t))?n.push(t):s.push(t)})),{successUserIDList:n,failureUserIDList:s})}};var T=new class{init(e,t){console.log("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),E.init(e,t),G.init(e,t),A.init(e,t),P.init(e,t),D.init(e)}};var L=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),console.log("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s}=this._core,{groupID:o,longPollingKey:i,longPollingSequence:r=1}=e;if(n(i))return console.warn(`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});b.hasPollingInstance(o)&&this.stopMessageLongPolling({groupID:o});const a=b.getJoinedLiveList();!t.isUnlimitedAVChatRoom()&&a.length>0&&this.stopMessageLongPolling({groupID:a[0]});const l={groupID:o,type:s.GRP_LIVE};return console.log(`${this._name}.startMessageLongPolling groupID:${o} longPollingKey:${i} longPollingSequence:${r}`),b.startMessageLongPolling({group:l,longPollingKey:i,startSequence:r})}stopMessageLongPolling(e){const{groupID:t}=e;return b.reset(t),console.log(`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}};return 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);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){b.onAVChatRoomSystemNotification(e)}_reset(){b.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}}));
@@ -1 +1 @@
1
- function e(e,r){var t={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&r.indexOf(s)<0&&(t[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)r.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(t[s[o]]=e[s[o]]);return t}function r(e,i,n,u){return new(n=n||Promise)(function(t,r){function o(e){try{a(u.next(e))}catch(e){r(e)}}function s(e){try{a(u.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?t(e.value):((r=e.value)instanceof n?r:new n(function(e){e(r)})).then(o,s)}a((u=u.apply(e,i||[])).next())})}let t=new class{init(e){this.core=e}},o="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,u=20,c={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5"},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND"},p={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&1<=e&&e<=100||"count must be a number between 1 and 100"},l={required:!1,rules:["string"],allowEmpty:!0},h={required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=t.core["OuterConstant"];if(!Array.isArray(r))return"groupTypeList should be an array";var o=[e.GRP_PUBLIC,e.GRP_COMMUNITY,e.GRP_WORK,e.GRP_MEETING];let s=!1;for(let e=0;e<r.length;e++)if(-1===o.indexOf(r[e])){s=!0;break}return!s||"groupTypeList should be supported group type"}},y=r=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&0<=e||r+" should be a number >= 0';"}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=t.core["OuterConstant"];return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},g={searchCloudMessages:{keywordList:c,keywordListMatchType:d,cursor:l,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=t.core["OuterConstant"],o=[e.MSG_TEXT,e.MSG_IMAGE,e.MSG_AUDIO,e.MSG_FILE,e.MSG_VIDEO,e.MSG_LOCATION,e.MSG_CUSTOM,e.MSG_MERGER];let s=!1;for(let e=0;e<r.length;e++)if(-1===o.indexOf(r[e])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=t.core["OuterConstant"];return!!(null!=e&&e.startsWith(r.CONV_C2C)||null!=e&&e.startsWith(r.CONV_GROUP)||e===r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:y("timePosition"),timePeriod:y("timePeriod")},searchCloudUsers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,miniBirthday:y("miniBirthday"),maxBirthday:y("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h}},C={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};var L=new class{install(e){this._core=e,t.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:C,params:g})}searchCloudMessages(v){return r(this,void 0,void 0,function*(){try{let{OuterConstant:i,helper:n,ssoLog:o}=this._core,s=o.createSSOLogData({method:"searchCloudMessages"}),{conversationID:a,timePeriod:u,timePosition:c}=v,d=e(v,["conversationID","timePeriod","timePosition"]),l=Object.assign({count:100},d);a&&(a.startsWith(i.CONV_C2C)?l.account=a.replace(i.CONV_C2C,""):a.startsWith(i.CONV_GROUP)&&(l.groupID=a.replace(i.CONV_GROUP,""))),this._setTimeRangeParams(l,{timePeriod:u,timePosition:c});var p=yield function(l){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,senderUserIDList:s,messageTypeList:a,endTime:i,startTime:n,cursor:u,account:c,groupID:d}=l,e={Count:e,KeywordList:r,MatchType:o,SendUserIDList:s,MsgTypeList:a,EndTime:i,StartTime:n,Cursor:u,PeerAccount:c,GroupID:d};return t.core.common.buildAndSendPacket({servcmd:"message_search.query",data:e})})}(l);if(!p)return{code:0,data:{}};var{ErrorCode:h,ErrorInfo:y,TotalCount:m,Cursor:g="",ConversationMsgs:C=[]}=p;if(0!==h)throw{errorCode:h,errorInfo:y};var L=`keywordList:${v.keywordList} keywordListMatchType:${v.keywordListMatchType} cursor:${v.cursor} res: totalCount:`+m,w=(s.setLogInfo({message:L}).end(),C.map(e=>{let{MsgList:r,Count:t,GroupID:s,UserID:o}=e,a=s?""+i.CONV_GROUP+s:""+i.CONV_C2C+o;return this._isSearchingAllConversations(v)&&1<t?{conversationID:a,messageCount:t,messageList:[]}:{conversationID:a,messageCount:t,messageList:r.map(e=>{return n.isEmpty(s)?(r=this._core,t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),(r=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}))).setElement(o.elements),r):(t=this._core,o=t.OuterConstant.CONV_GROUP,r=t.message.messageHelper.parseServerGroupMessage(e),(t=t.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:o,flow:"in"}))).setElement(r.elements),t);var r,t,o})}}));return{code:0,data:{searchResultList:w,cursor:g,totalCount:m}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudMessages"})}})}searchCloudUsers(w){return r(this,void 0,void 0,function*(){var d;try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:s,count:a=i}=w,u=e(w,["keywordListMatchType","count"]),c=Object.assign({count:a,keywordListMatchType:s===n.AND?1:0},u);this._setBirthdayRangeParams(c,w);var l=yield function(u){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,miniBirthday:s,maxBirthday:a,cursor:i,gender:n}=u,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:i,UserBirthStart:s,UserBirthEnd:a,Gender:n};return t.core.common.buildAndSendPacket({servcmd:"user_search.query",data:e})})}(c);if(!l)return{error:0,data:{}};var{ErrorCode:p,ErrorInfo:h,TotalCount:y,Cursor:m="",Users:g=[]}=l;if(0!==p)throw{errorCode:p,errorInfo:h};var C=`keywordList:${w.keywordList} keywordListMatchType:${w.keywordListMatchType} cursor:${w.cursor} count:${w.count} res: totalCount:`+y,L=(o.setLogInfo({message:C}).end(),[]);for(let e=0,r=g.length;e<r;e++){let{UserID:t,ProfileItems:o}=g[e];if(t!==this._core.OuterConstant.USER_NOT_FOUND&&""!==t){let e=o.map(e=>({tag:e.Tag,value:e.StrValue})),r=null==(d=this._core.user.userProfile)?void 0:d.createProfile(t,e);L.push(r)}}return{code:0,data:{searchResultList:L,cursor:m,totalCount:y}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudUsers"})}})}searchCloudGroupMembers(L){return r(this,void 0,void 0,function*(){try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:s=u,keywordListMatchType:a}=L,i=e(L,["count","keywordListMatchType"]),c=Object.assign({count:s,keywordListMatchType:a===n.AND?1:0},i),d=yield function(n){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,groupTypeList:s,cursor:a,groupIDList:i}=n,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:a,GroupType:s,GroupIdList:i};return t.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:e})})}(c);if(!d)return{code:0,data:{}};var{ErrorCode:p,ErrorInfo:h,GroupMembers:y=[],Cursor:m,TotalCount:g}=d;if(0!==p)throw{errorCode:p,errorInfo:h};var C=`keywordList:${L.keywordList} keywordListMatchType:${L.keywordListMatchType} cursor:${L.cursor} count:${L.count} res: totalCount:`+g;o.setLogInfo({message:C}).end();let l=new Map;return y.forEach(e=>{var{GroupID:r,GroupName:e,GroupType:t,GroupFaceUrl:o,GroupMemberUserName:s,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:n=""}=e,e={groupID:r,name:e,type:t,avatar:o},t={userID:a,nick:s,nameCard:i,avatar:n};if(l.has(r)){let e=l.get(r);e.memberList.push(t),l.set(r,e)}else l.set(r,{groupInfo:e,memberList:[t]})}),{code:0,data:{searchResultList:[...l.values()],cursor:m,totalCount:g}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}})}searchCloudGroups(C){return r(this,void 0,void 0,function*(){try{let o=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:s=a,keywordListMatchType:i}=C,u=e(C,["count","keywordListMatchType"]),c=Object.assign({count:s,keywordListMatchType:i===n.AND?1:0},u),d=yield function(i){return r(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:o,groupTypeList:s,cursor:a}=i,e={Count:e,Keywords:r,KeywordMatchType:o,Cursor:a,GroupType:s};return t.core.common.buildAndSendPacket({servcmd:"group_search.query",data:e})})}(c);if(!d)return{code:0,data:{}};var{ErrorCode:l,ErrorInfo:p,Groups:h,Cursor:y,TotalCount:m}=d;if(0!==l)throw{errorCode:l,errorInfo:p};var g=`keywordList:${C.keywordList} keywordListMatchType:${C.keywordListMatchType} cursor:${C.cursor} count:${C.count} res: totalCount:`+m;return o.setLogInfo({message:g}).end(),{code:0,data:{searchResultList:(null==h?void 0:h.map(e=>{var{GroupFaceUrl:e,GroupID:r,GroupIntroduction:t,GroupMemberNum:o,GroupName:s,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:n,GroupType:u,GroupAddOption:c,GroupInviteOption:d}=e;return{avatar:e,groupID:r,introduction:t,memberCount:o,name:s,ownerTinyID:a,ownerID:i,ownerNick:n,type:u,joinOption:c,inviteOption:d}}))||[],cursor:y,totalCount:m}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroups"})}})}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&0<r&&(e.startTime=t&&0<t?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&0<t&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:s}){var{ssoLog:a,helper:i}=this._core;let n=e;60020===e?n="SearchUnable":t!==o&&27003===e?n="SearchParamsError":t!==o&&60018===e&&(n="SearchOverLimit");t=new i.ChatError({code:n,message:r});throw a.getSSOLogData(s).setError(t).end(),t}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){var{miniBirthday:r,maxBirthday:t}=r;void 0!==r&&(e.miniBirthday=r,void 0===t)&&(e.maxBirthday=4294967295),void 0!==t&&(e.maxBirthday=t)}};export{L as default};
1
+ function e(e,r){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&r.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)r.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(t[o[s]]=e[o[s]])}return t}function r(e,r,t,o){return new(t||(t=Promise))((function(s,n){function a(e){try{u(o.next(e))}catch(e){n(e)}}function i(e){try{u(o.throw(e))}catch(e){n(e)}}function u(e){var r;e.done?s(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,i)}u((o=o.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(e){this.core=e}};const o="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,u=20,c={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||(!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5")},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||(!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND")},p={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&e>=1&&e<=100||"count must be a number between 1 and 100"},l={required:!1,rules:["string"],allowEmpty:!0},h={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core;if(!Array.isArray(e))return"groupTypeList should be an array";const o=[r.GRP_PUBLIC,r.GRP_COMMUNITY,r.GRP_WORK,r.GRP_MEETING];let s=!1;for(let r=0;r<e.length;r++)if(-1===o.indexOf(e[r])){s=!0;break}return!s||"groupTypeList should be supported group type"}},y=e=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:r=>"number"==typeof r&&r>=0||`${e} should be a number >= 0';`}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core;return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},g={searchCloudMessages:{keywordList:c,keywordListMatchType:d,cursor:l,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core,o=[r.MSG_TEXT,r.MSG_IMAGE,r.MSG_AUDIO,r.MSG_FILE,r.MSG_VIDEO,r.MSG_LOCATION,r.MSG_CUSTOM,r.MSG_MERGER];let s=!1;for(let r=0;r<e.length;r++)if(-1===o.indexOf(e[r])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core;return!(!(null==e?void 0:e.startsWith(r.CONV_C2C))&&!(null==e?void 0:e.startsWith(r.CONV_GROUP))&&e!==r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:y("timePosition"),timePeriod:y("timePeriod")},searchCloudUsers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,miniBirthday:y("miniBirthday"),maxBirthday:y("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:c,keywordListMatchType:d,cursor:l,count:p,groupTypeList:h}},C={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};var L=new class{constructor(){this.name="CloudSearch"}install(e){this._core=e,t.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:C,params:g})}searchCloudMessages(s){return r(this,void 0,void 0,(function*(){try{const{OuterConstant:o,helper:n,ssoLog:a}=this._core,i=a.createSSOLogData({method:"searchCloudMessages"}),{conversationID:u,timePeriod:c,timePosition:d}=s,p=e(s,["conversationID","timePeriod","timePosition"]),l=Object.assign({count:100},p);u&&(u.startsWith(o.CONV_C2C)?l.account=u.replace(o.CONV_C2C,""):u.startsWith(o.CONV_GROUP)&&(l.groupID=u.replace(o.CONV_GROUP,""))),this._setTimeRangeParams(l,{timePeriod:c,timePosition:d});const h=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,senderUserIDList:n,messageTypeList:a,endTime:i,startTime:u,cursor:c,account:d,groupID:p}=e,l={Count:r,KeywordList:o,MatchType:s,SendUserIDList:n,MsgTypeList:a,EndTime:i,StartTime:u,Cursor:c,PeerAccount:d,GroupID:p};return t.core.common.buildAndSendPacket({servcmd:"message_search.query",data:l})}))}(l);if(!h)return{code:0,data:{}};const{ErrorCode:y,ErrorInfo:m,TotalCount:g,Cursor:C="",ConversationMsgs:L=[]}=h;if(0!==y)throw{errorCode:y,errorInfo:m};const f=`keywordList:${s.keywordList} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} res: totalCount:${g}`;i.setLogInfo({message:f}).end();const w=L.map((e=>{const{MsgList:r,Count:t,GroupID:a,UserID:i}=e,u=a?`${o.CONV_GROUP}${a}`:`${o.CONV_C2C}${i}`;if(this._isSearchingAllConversations(s)&&t>1)return{conversationID:u,messageCount:t,messageList:[]};const c=r.map((e=>n.isEmpty(a)?function(e,r){const t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}));return s.setElement(o.elements),s}(e,this._core):function(e,r){const t=r.OuterConstant.CONV_GROUP,o=r.message.messageHelper.parseServerGroupMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}));return s.setElement(o.elements),s}(e,this._core)));return{conversationID:u,messageCount:t,messageList:c}}));return{code:0,data:{searchResultList:w,cursor:C,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudMessages"})}}))}searchCloudUsers(o){return r(this,void 0,void 0,(function*(){var a;try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:u,count:c=i}=o,d=e(o,["keywordListMatchType","count"]),p=Object.assign({count:c,keywordListMatchType:u===n.AND?1:0},d);this._setBirthdayRangeParams(p,o);const l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,miniBirthday:n,maxBirthday:a,cursor:i,gender:u}=e,c={Count:r,Keywords:o,KeywordMatchType:s,Cursor:i,UserBirthStart:n,UserBirthEnd:a,Gender:u};return t.core.common.buildAndSendPacket({servcmd:"user_search.query",data:c})}))}(p);if(!l)return{error:0,data:{}};const{ErrorCode:h,ErrorInfo:y,TotalCount:m,Cursor:g="",Users:C=[]}=l;if(0!==h)throw{errorCode:h,errorInfo:y};const L=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${m}`;s.setLogInfo({message:L}).end();const f=[];for(let e=0,r=C.length;e<r;e++){const{UserID:r,ProfileItems:t}=C[e];if(r===this._core.OuterConstant.USER_NOT_FOUND||""===r)continue;const o=t.map((e=>({tag:e.Tag,value:e.StrValue}))),s=null===(a=this._core.user.userProfile)||void 0===a?void 0:a.createProfile(r,o);f.push(s)}return{code:0,data:{searchResultList:f,cursor:g,totalCount:m}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudUsers"})}}))}searchCloudGroupMembers(o){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:a=u,keywordListMatchType:i}=o,c=e(o,["count","keywordListMatchType"]),d=Object.assign({count:a,keywordListMatchType:i===n.AND?1:0},c),p=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,groupTypeList:n,cursor:a,groupIDList:i}=e,u={Count:r,Keywords:o,KeywordMatchType:s,Cursor:a,GroupType:n,GroupIdList:i};return t.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:u})}))}(d);if(!p)return{code:0,data:{}};const{ErrorCode:l,ErrorInfo:h,GroupMembers:y=[],Cursor:m,TotalCount:g}=p;if(0!==l)throw{errorCode:l,errorInfo:h};const C=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${g}`;s.setLogInfo({message:C}).end();const L=new Map;return y.forEach((e=>{const{GroupID:r,GroupName:t,GroupType:o,GroupFaceUrl:s,GroupMemberUserName:n,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:u=""}=e,c={groupID:r,name:t,type:o,avatar:s},d={userID:a,nick:n,nameCard:i,avatar:u};if(L.has(r)){const e=L.get(r);e.memberList.push(d),L.set(r,e)}else L.set(r,{groupInfo:c,memberList:[d]})})),{code:0,data:{searchResultList:[...L.values()],cursor:m,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}}))}searchCloudGroups(o){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:i=a,keywordListMatchType:u}=o,c=e(o,["count","keywordListMatchType"]),d=Object.assign({count:i,keywordListMatchType:u===n.AND?1:0},c),p=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,groupTypeList:n,cursor:a}=e,i={Count:r,Keywords:o,KeywordMatchType:s,Cursor:a,GroupType:n};return t.core.common.buildAndSendPacket({servcmd:"group_search.query",data:i})}))}(d);if(!p)return{code:0,data:{}};const{ErrorCode:l,ErrorInfo:h,Groups:y,Cursor:m,TotalCount:g}=p;if(0!==l)throw{errorCode:l,errorInfo:h};const C=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${g}`;s.setLogInfo({message:C}).end();return{code:0,data:{searchResultList:(null==y?void 0:y.map((e=>function(e){const{GroupFaceUrl:r,GroupID:t,GroupIntroduction:o,GroupMemberNum:s,GroupName:n,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:u,GroupType:c,GroupAddOption:d,GroupInviteOption:p}=e;return{avatar:r,groupID:t,introduction:o,memberCount:s,name:n,ownerTinyID:a,ownerID:i,ownerNick:u,type:c,joinOption:d,inviteOption:p}}(e))))||[],cursor:m,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroups"})}}))}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&r>0&&(e.startTime=t&&t>0?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&t>0&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:s}){const{ssoLog:n,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":t!==o&&27003===e?i="SearchParamsError":t!==o&&60018===e&&(i="SearchOverLimit");const u=new a.ChatError({code:i,message:r});throw n.getSSOLogData(s).setError(u).end(),u}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){const{miniBirthday:t,maxBirthday:o}=r;void 0!==t&&(e.miniBirthday=t,void 0===o&&(e.maxBirthday=4294967295)),void 0!==o&&(e.maxBirthday=o)}};export{L as default};
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatCloud-search"]=r()}(this,function(){function f(e,r){var t={};for(s in e)Object.prototype.hasOwnProperty.call(e,s)&&r.indexOf(s)<0&&(t[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols)for(var o=0,s=Object.getOwnPropertySymbols(e);o<s.length;o++)r.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(t[s[o]]=e[s[o]]);return t}function L(e,i,n,u){return new(n=n||Promise)(function(t,r){function o(e){try{a(u.next(e))}catch(e){r(e)}}function s(e){try{a(u.throw(e))}catch(e){r(e)}}function a(e){var r;e.done?t(e.value):((r=e.value)instanceof n?r:new n(function(e){e(r)})).then(o,s)}a((u=u.apply(e,i||[])).next())})}let w=new class{init(e){this.core=e}},n="message",o="user",m={OR:"or",AND:"and"},e={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5"},r={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||!![m.OR,m.AND].includes(e)||"keywordListMatchType should be OR or AND"},t={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&1<=e&&e<=100||"count must be a number between 1 and 100"},s={required:!1,rules:["string"],allowEmpty:!0},a={required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=w.core["OuterConstant"];if(!Array.isArray(r))return"groupTypeList should be an array";var t=[e.GRP_PUBLIC,e.GRP_COMMUNITY,e.GRP_WORK,e.GRP_MEETING];let o=!1;for(let e=0;e<r.length;e++)if(-1===t.indexOf(r[e])){o=!0;break}return!o||"groupTypeList should be supported group type"}},i=r=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&0<=e||r+" should be a number >= 0';"}),u={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=w.core["OuterConstant"];return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},c={searchCloudMessages:{keywordList:e,keywordListMatchType:r,cursor:s,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:r=>{var e=w.core["OuterConstant"],t=[e.MSG_TEXT,e.MSG_IMAGE,e.MSG_AUDIO,e.MSG_FILE,e.MSG_VIDEO,e.MSG_LOCATION,e.MSG_CUSTOM,e.MSG_MERGER];let o=!1;for(let e=0;e<r.length;e++)if(-1===t.indexOf(r[e])){o=!0;break}return!o||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var r=w.core["OuterConstant"];return!!(null!=e&&e.startsWith(r.CONV_C2C)||null!=e&&e.startsWith(r.CONV_GROUP)||e===r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:i("timePosition"),timePeriod:i("timePeriod")},searchCloudUsers:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,miniBirthday:i("miniBirthday"),maxBirthday:i("maxBirthday"),gender:u},searchCloudGroupMembers:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,groupTypeList:a,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:e,keywordListMatchType:r,cursor:s,count:t,groupTypeList:a}},d={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};return new class{install(e){this._core=e,w.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:d,params:c})}searchCloudMessages(C){return L(this,void 0,void 0,function*(){try{let{OuterConstant:i,helper:n,ssoLog:e}=this._core,r=e.createSSOLogData({method:"searchCloudMessages"}),{conversationID:t,timePeriod:o,timePosition:s}=C,a=f(C,["conversationID","timePeriod","timePosition"]),u=Object.assign({count:100},a);t&&(t.startsWith(i.CONV_C2C)?u.account=t.replace(i.CONV_C2C,""):t.startsWith(i.CONV_GROUP)&&(u.groupID=t.replace(i.CONV_GROUP,""))),this._setTimeRangeParams(u,{timePeriod:o,timePosition:s});var c=yield function(d){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,senderUserIDList:o,messageTypeList:s,endTime:a,startTime:i,cursor:n,account:u,groupID:c}=d,e={Count:e,KeywordList:r,MatchType:t,SendUserIDList:o,MsgTypeList:s,EndTime:a,StartTime:i,Cursor:n,PeerAccount:u,GroupID:c};return w.core.common.buildAndSendPacket({servcmd:"message_search.query",data:e})})}(u);if(!c)return{code:0,data:{}};var{ErrorCode:d,ErrorInfo:l,TotalCount:h,Cursor:p="",ConversationMsgs:y=[]}=c;if(0!==d)throw{errorCode:d,errorInfo:l};var m=`keywordList:${C.keywordList} keywordListMatchType:${C.keywordListMatchType} cursor:${C.cursor} res: totalCount:`+h,g=(r.setLogInfo({message:m}).end(),y.map(e=>{let{MsgList:r,Count:t,GroupID:s,UserID:o}=e,a=s?""+i.CONV_GROUP+s:""+i.CONV_C2C+o;return this._isSearchingAllConversations(C)&&1<t?{conversationID:a,messageCount:t,messageList:[]}:{conversationID:a,messageCount:t,messageList:r.map(e=>{return n.isEmpty(s)?(r=this._core,t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),(r=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}))).setElement(o.elements),r):(t=this._core,o=t.OuterConstant.CONV_GROUP,r=t.message.messageHelper.parseServerGroupMessage(e),(t=t.message.messageFactory.createMessage(Object.assign(Object.assign({},r),{conversationType:o,flow:"in"}))).setElement(r.elements),t);var r,t,o})}}));return{code:0,data:{searchResultList:g,cursor:p,totalCount:h}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:n,functionName:"searchCloudMessages"})}})}searchCloudUsers(y){return L(this,void 0,void 0,function*(){var a;try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:r,count:t=20}=y,o=f(y,["keywordListMatchType","count"]),s=Object.assign({count:t,keywordListMatchType:r===m.AND?1:0},o);this._setBirthdayRangeParams(s,y);var i=yield function(n){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,miniBirthday:o,maxBirthday:s,cursor:a,gender:i}=n,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:a,UserBirthStart:o,UserBirthEnd:s,Gender:i};return w.core.common.buildAndSendPacket({servcmd:"user_search.query",data:e})})}(s);if(!i)return{error:0,data:{}};var{ErrorCode:n,ErrorInfo:u,TotalCount:c,Cursor:d="",Users:l=[]}=i;if(0!==n)throw{errorCode:n,errorInfo:u};var h=`keywordList:${y.keywordList} keywordListMatchType:${y.keywordListMatchType} cursor:${y.cursor} count:${y.count} res: totalCount:`+c,p=(e.setLogInfo({message:h}).end(),[]);for(let e=0,r=l.length;e<r;e++){let{UserID:t,ProfileItems:o}=l[e];if(t!==this._core.OuterConstant.USER_NOT_FOUND&&""!==t){let e=o.map(e=>({tag:e.Tag,value:e.StrValue})),r=null==(a=this._core.user.userProfile)?void 0:a.createProfile(t,e);p.push(r)}}return{code:0,data:{searchResultList:p,cursor:d,totalCount:c}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudUsers"})}})}searchCloudGroupMembers(p){return L(this,void 0,void 0,function*(){try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:r=20,keywordListMatchType:t}=p,o=f(p,["count","keywordListMatchType"]),s=Object.assign({count:r,keywordListMatchType:t===m.AND?1:0},o),a=yield function(i){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,groupTypeList:o,cursor:s,groupIDList:a}=i,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:s,GroupType:o,GroupIdList:a};return w.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:e})})}(s);if(!a)return{code:0,data:{}};var{ErrorCode:i,ErrorInfo:n,GroupMembers:c=[],Cursor:d,TotalCount:l}=a;if(0!==i)throw{errorCode:i,errorInfo:n};var h=`keywordList:${p.keywordList} keywordListMatchType:${p.keywordListMatchType} cursor:${p.cursor} count:${p.count} res: totalCount:`+l;e.setLogInfo({message:h}).end();let u=new Map;return c.forEach(e=>{var{GroupID:r,GroupName:e,GroupType:t,GroupFaceUrl:o,GroupMemberUserName:s,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:n=""}=e,e={groupID:r,name:e,type:t,avatar:o},t={userID:a,nick:s,nameCard:i,avatar:n};if(u.has(r)){let e=u.get(r);e.memberList.push(t),u.set(r,e)}else u.set(r,{groupInfo:e,memberList:[t]})}),{code:0,data:{searchResultList:[...u.values()],cursor:d,totalCount:l}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudGroupMembers"})}})}searchCloudGroups(h){return L(this,void 0,void 0,function*(){try{let e=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:r=20,keywordListMatchType:t}=h,o=f(h,["count","keywordListMatchType"]),s=Object.assign({count:r,keywordListMatchType:t===m.AND?1:0},o),a=yield function(a){return L(this,void 0,void 0,function*(){var{count:e,keywordList:r,keywordListMatchType:t,groupTypeList:o,cursor:s}=a,e={Count:e,Keywords:r,KeywordMatchType:t,Cursor:s,GroupType:o};return w.core.common.buildAndSendPacket({servcmd:"group_search.query",data:e})})}(s);if(!a)return{code:0,data:{}};var{ErrorCode:i,ErrorInfo:n,Groups:u,Cursor:c,TotalCount:d}=a;if(0!==i)throw{errorCode:i,errorInfo:n};var l=`keywordList:${h.keywordList} keywordListMatchType:${h.keywordListMatchType} cursor:${h.cursor} count:${h.count} res: totalCount:`+d;return e.setLogInfo({message:l}).end(),{code:0,data:{searchResultList:(null==u?void 0:u.map(e=>{var{GroupFaceUrl:e,GroupID:r,GroupIntroduction:t,GroupMemberNum:o,GroupName:s,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:n,GroupType:u,GroupAddOption:c,GroupInviteOption:d}=e;return{avatar:e,groupID:r,introduction:t,memberCount:o,name:s,ownerTinyID:a,ownerID:i,ownerNick:n,type:u,joinOption:c,inviteOption:d}}))||[],cursor:c,totalCount:d}}}catch(e){let{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudGroups"})}})}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&0<r&&(e.startTime=t&&0<t?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&0<t&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:o}){var{ssoLog:s,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":t!==n&&27003===e?i="SearchParamsError":t!==n&&60018===e&&(i="SearchOverLimit");t=new a.ChatError({code:i,message:r});throw s.getSSOLogData(o).setError(t).end(),t}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){var{miniBirthday:r,maxBirthday:t}=r;void 0!==r&&(e.miniBirthday=r,void 0===t)&&(e.maxBirthday=4294967295),void 0!==t&&(e.maxBirthday=t)}}});
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatCloud-search"]=r()}(this,(function(){"use strict";function e(e,r){var o={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(o[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(t=Object.getOwnPropertySymbols(e);s<t.length;s++)r.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(e,t[s])&&(o[t[s]]=e[t[s]])}return o}function r(e,r,o,t){return new(o||(o=Promise))((function(s,n){function a(e){try{u(t.next(e))}catch(e){n(e)}}function i(e){try{u(t.throw(e))}catch(e){n(e)}}function u(e){var r;e.done?s(e.value):(r=e.value,r instanceof o?r:new o((function(e){e(r)}))).then(a,i)}u((t=t.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o=new class{init(e){this.core=e}};const t="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,u=20,c={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||(!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5")},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||(!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND")},l={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&e>=1&&e<=100||"count must be a number between 1 and 100"},p={required:!1,rules:["string"],allowEmpty:!0},h={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core;if(!Array.isArray(e))return"groupTypeList should be an array";const t=[r.GRP_PUBLIC,r.GRP_COMMUNITY,r.GRP_WORK,r.GRP_MEETING];let s=!1;for(let r=0;r<e.length;r++)if(-1===t.indexOf(e[r])){s=!0;break}return!s||"groupTypeList should be supported group type"}},y=e=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:r=>"number"==typeof r&&r>=0||`${e} should be a number >= 0';`}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core;return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},C={searchCloudMessages:{keywordList:c,keywordListMatchType:d,cursor:p,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core,t=[r.MSG_TEXT,r.MSG_IMAGE,r.MSG_AUDIO,r.MSG_FILE,r.MSG_VIDEO,r.MSG_LOCATION,r.MSG_CUSTOM,r.MSG_MERGER];let s=!1;for(let r=0;r<e.length;r++)if(-1===t.indexOf(e[r])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core;return!(!(null==e?void 0:e.startsWith(r.CONV_C2C))&&!(null==e?void 0:e.startsWith(r.CONV_GROUP))&&e!==r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:y("timePosition"),timePeriod:y("timePeriod")},searchCloudUsers:{keywordList:c,keywordListMatchType:d,cursor:p,count:l,miniBirthday:y("miniBirthday"),maxBirthday:y("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:c,keywordListMatchType:d,cursor:p,count:l,groupTypeList:h,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:c,keywordListMatchType:d,cursor:p,count:l,groupTypeList:h}},g={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};return new class{constructor(){this.name="CloudSearch"}install(e){this._core=e,o.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:g,params:C})}searchCloudMessages(s){return r(this,void 0,void 0,(function*(){try{const{OuterConstant:t,helper:n,ssoLog:a}=this._core,i=a.createSSOLogData({method:"searchCloudMessages"}),{conversationID:u,timePeriod:c,timePosition:d}=s,l=e(s,["conversationID","timePeriod","timePosition"]),p=Object.assign({count:100},l);u&&(u.startsWith(t.CONV_C2C)?p.account=u.replace(t.CONV_C2C,""):u.startsWith(t.CONV_GROUP)&&(p.groupID=u.replace(t.CONV_GROUP,""))),this._setTimeRangeParams(p,{timePeriod:c,timePosition:d});const h=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,senderUserIDList:n,messageTypeList:a,endTime:i,startTime:u,cursor:c,account:d,groupID:l}=e,p={Count:r,KeywordList:t,MatchType:s,SendUserIDList:n,MsgTypeList:a,EndTime:i,StartTime:u,Cursor:c,PeerAccount:d,GroupID:l};return o.core.common.buildAndSendPacket({servcmd:"message_search.query",data:p})}))}(p);if(!h)return{code:0,data:{}};const{ErrorCode:y,ErrorInfo:m,TotalCount:C,Cursor:g="",ConversationMsgs:f=[]}=h;if(0!==y)throw{errorCode:y,errorInfo:m};const L=`keywordList:${s.keywordList} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} res: totalCount:${C}`;i.setLogInfo({message:L}).end();const w=f.map((e=>{const{MsgList:r,Count:o,GroupID:a,UserID:i}=e,u=a?`${t.CONV_GROUP}${a}`:`${t.CONV_C2C}${i}`;if(this._isSearchingAllConversations(s)&&o>1)return{conversationID:u,messageCount:o,messageList:[]};const c=r.map((e=>n.isEmpty(a)?function(e,r){const o=r.OuterConstant.CONV_C2C,t=r.message.messageHelper.parseServerPushMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},t),{conversationType:o,flow:"in"}));return s.setElement(t.elements),s}(e,this._core):function(e,r){const o=r.OuterConstant.CONV_GROUP,t=r.message.messageHelper.parseServerGroupMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},t),{conversationType:o,flow:"in"}));return s.setElement(t.elements),s}(e,this._core)));return{conversationID:u,messageCount:o,messageList:c}}));return{code:0,data:{searchResultList:w,cursor:g,totalCount:C}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:t,functionName:"searchCloudMessages"})}}))}searchCloudUsers(t){return r(this,void 0,void 0,(function*(){var a;try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:u,count:c=i}=t,d=e(t,["keywordListMatchType","count"]),l=Object.assign({count:c,keywordListMatchType:u===n.AND?1:0},d);this._setBirthdayRangeParams(l,t);const p=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,miniBirthday:n,maxBirthday:a,cursor:i,gender:u}=e,c={Count:r,Keywords:t,KeywordMatchType:s,Cursor:i,UserBirthStart:n,UserBirthEnd:a,Gender:u};return o.core.common.buildAndSendPacket({servcmd:"user_search.query",data:c})}))}(l);if(!p)return{error:0,data:{}};const{ErrorCode:h,ErrorInfo:y,TotalCount:m,Cursor:C="",Users:g=[]}=p;if(0!==h)throw{errorCode:h,errorInfo:y};const f=`keywordList:${t.keywordList} keywordListMatchType:${t.keywordListMatchType} cursor:${t.cursor} count:${t.count} res: totalCount:${m}`;s.setLogInfo({message:f}).end();const L=[];for(let e=0,r=g.length;e<r;e++){const{UserID:r,ProfileItems:o}=g[e];if(r===this._core.OuterConstant.USER_NOT_FOUND||""===r)continue;const t=o.map((e=>({tag:e.Tag,value:e.StrValue}))),s=null===(a=this._core.user.userProfile)||void 0===a?void 0:a.createProfile(r,t);L.push(s)}return{code:0,data:{searchResultList:L,cursor:C,totalCount:m}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:s,functionName:"searchCloudUsers"})}}))}searchCloudGroupMembers(t){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:a=u,keywordListMatchType:i}=t,c=e(t,["count","keywordListMatchType"]),d=Object.assign({count:a,keywordListMatchType:i===n.AND?1:0},c),l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,groupTypeList:n,cursor:a,groupIDList:i}=e,u={Count:r,Keywords:t,KeywordMatchType:s,Cursor:a,GroupType:n,GroupIdList:i};return o.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:u})}))}(d);if(!l)return{code:0,data:{}};const{ErrorCode:p,ErrorInfo:h,GroupMembers:y=[],Cursor:m,TotalCount:C}=l;if(0!==p)throw{errorCode:p,errorInfo:h};const g=`keywordList:${t.keywordList} keywordListMatchType:${t.keywordListMatchType} cursor:${t.cursor} count:${t.count} res: totalCount:${C}`;s.setLogInfo({message:g}).end();const f=new Map;return y.forEach((e=>{const{GroupID:r,GroupName:o,GroupType:t,GroupFaceUrl:s,GroupMemberUserName:n,GroupMemberUserID:a,GroupMemberNameCard:i,GroupMemberAvatar:u=""}=e,c={groupID:r,name:o,type:t,avatar:s},d={userID:a,nick:n,nameCard:i,avatar:u};if(f.has(r)){const e=f.get(r);e.memberList.push(d),f.set(r,e)}else f.set(r,{groupInfo:c,memberList:[d]})})),{code:0,data:{searchResultList:[...f.values()],cursor:m,totalCount:C}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:s,functionName:"searchCloudGroupMembers"})}}))}searchCloudGroups(t){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:i=a,keywordListMatchType:u}=t,c=e(t,["count","keywordListMatchType"]),d=Object.assign({count:i,keywordListMatchType:u===n.AND?1:0},c),l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,groupTypeList:n,cursor:a}=e,i={Count:r,Keywords:t,KeywordMatchType:s,Cursor:a,GroupType:n};return o.core.common.buildAndSendPacket({servcmd:"group_search.query",data:i})}))}(d);if(!l)return{code:0,data:{}};const{ErrorCode:p,ErrorInfo:h,Groups:y,Cursor:m,TotalCount:C}=l;if(0!==p)throw{errorCode:p,errorInfo:h};const g=`keywordList:${t.keywordList} keywordListMatchType:${t.keywordListMatchType} cursor:${t.cursor} count:${t.count} res: totalCount:${C}`;s.setLogInfo({message:g}).end();return{code:0,data:{searchResultList:(null==y?void 0:y.map((e=>function(e){const{GroupFaceUrl:r,GroupID:o,GroupIntroduction:t,GroupMemberNum:s,GroupName:n,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:u,GroupType:c,GroupAddOption:d,GroupInviteOption:l}=e;return{avatar:r,groupID:o,introduction:t,memberCount:s,name:n,ownerTinyID:a,ownerID:i,ownerNick:u,type:c,joinOption:d,inviteOption:l}}(e))))||[],cursor:m,totalCount:C}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:s,functionName:"searchCloudGroups"})}}))}_setTimeRangeParams(e,{timePeriod:r,timePosition:o}){r&&r>0&&(e.startTime=o&&o>0?o-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),o&&o>0&&(e.endTime=o)}_handleError({errorCode:e,errorMessage:r,searchType:o,functionName:s}){const{ssoLog:n,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":o!==t&&27003===e?i="SearchParamsError":o!==t&&60018===e&&(i="SearchOverLimit");const u=new a.ChatError({code:i,message:r});throw n.getSSOLogData(s).setError(u).end(),u}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){const{miniBirthday:o,maxBirthday:t}=r;void 0!==o&&(e.miniBirthday=o,void 0===t&&(e.maxBirthday=4294967295)),void 0!==t&&(e.maxBirthday=t)}}}));
@@ -1 +1 @@
1
- var t=new class{constructor(){this._conversationGroupMap=new Map}init(e){this._core=e}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(e){return this._conversationGroupMap.get(e)}setConversationGroup(e,t){this._conversationGroupMap.set(e,t)}};function o(e,s,i,c){return new(i=i||Promise)(function(o,t){function r(e){try{a(c.next(e))}catch(e){t(e)}}function n(e){try{a(c.throw(e))}catch(e){t(e)}}function a(e){var t;e.done?o(e.value):((t=e.value)instanceof i?t:new i(function(e){e(t)})).then(r,n)}a((c=c.apply(e,s||[])).next())})}let e=new class{init(e){this.core=e}},n="CONV_GROUP",r=2500,s=2503,a=1,i=2,c="NOT_STARTED",u="FETCHING",p="FINISHED",d="FAILED",v=0,l=1,C=1,h=2,m=3,f=1,I=2;function G(t){var{helper:o,constants:r}=e.core;if(!o.checkBusinessCapabilityBits(n))throw new o.ChatError({functionName:t,code:r.ERROR_CODE.NO_USE,replacement1:t})}function g(){var{notificationCenter:o,OuterEvent:r}=e.core;o.emitOuterEvent(r.CONVERSATION_GROUP_LIST_UPDATED,{name:r.CONVERSATION_GROUP_LIST_UPDATED,data:[...t.getConversationGroupMap().values()]})}function _(t){var{utils:{isUndefined:o},constants:{OuterConstant:r}}=e.core,{Type:t,To_Account:n,GroupId:s,ToGroupId:s=s,Peer_Account:c}=t;let u="";return t===a?o(c)?o(n)||(u=""+r.CONV_C2C+n):u=""+r.CONV_C2C+c:t===i&&(u=""+r.CONV_GROUP+s),u}function D(t){let o=[],{OuterConstant:r,common:{isC2CConv:n,isGroupConv:s}}=e.core,{conversationIDList:c,failureConversationIDList:u,additionalData:p={}}=t;return c.forEach(e=>{L(e,u),n(e)?o.push(Object.assign({ContactItem:{Type:a,To_Account:e.replace(r.CONV_C2C,"")}},p)):s(e)&&o.push(Object.assign({ContactItem:{Type:i,ToGroupId:e.replace(r.CONV_GROUP,"")}},p))}),o}function L(t,o){var{appStore:{conversationStore:n},common:{isC2CConv:a,isGroupConv:i}}=e.core;n.getConversation(t)?a(t)||i(t)||o.push({conversationID:t,code:s}):o.push({conversationID:t,code:r})}function N(t){var{isString:o}=e.core["utils"],r=[];if(o(t)){var n=t.length;if(0!==n)for(let e=n-1;0<=e;e--)"1"===t[e]&&r.push(Math.pow(2,n-e-1))}return r}function E(a){null!=a&&a.forEach((t,o)=>{var r=e.core["appStore"],{conversationID:t,data:n}=t,o=o===a.length-1;r.conversationStore.updateConversation(t,n,{emit:o})})}function S(t){var{conversationInfoList:t,fromAccount:o}=t,o={From_Account:o,MarkItem:t};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:o})}function O(t){var{fromAccount:t,groupName:o,conversationInfoList:r}=t,t={From_Account:t,UpdateType:1,UpdateGroup:{UpdateGroupType:I,OldGroupName:o,ContactUpdateItem:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:t})}var R=new class{init(e){var{registerApi:t}=e["helper"];this._core=e,t({apiName:"createConversationGroup",context:this})}createConversationGroup(a){return o(this,void 0,void 0,function*(){let{utils:{isPlainObject:s,isArray:i},appStore:c,ssoLog:o}=this._core;G("createConversationGroup");var u=o.createSSOLogData({method:"createConversationGroup"});u.setLogInfo({message:JSON.stringify(a)});let{groupName:p,conversationIDList:r}=a,l=[],n=this._generateConversationInfo(r,l);if(l.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:l}};try{let a=yield function(t){var{buildAndSendPacket:o,getCurrentUserID:r}=e.core["common"],{item:t,groupName:n}=t;return o({servcmd:"recentcontact.create_contact_group",data:{From_Account:r(),GroupContactItem:[{GroupName:n,ContactItem:t}]}})}({groupName:p,item:n});if(a){u.end();let{GroupResultItem:e=[]}=a,{GroupItem:r,ResultItem:o}=(null==e?void 0:e[0])||{},n=[];if(s(r)){let{GroupName:e,GroupId:o}=r;t.setConversationGroup(o,e),g()}if(i(o)){let a=[];o.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:r}=e,n=_(t);if(0===o){let t=c.conversationStore.getConversation(n);if(t&&!t.conversationGroupList.includes(p)){let e=t.conversationGroupList.slice();e.push(p),a.push({conversationID:n,data:{conversationGroupList:e}})}}else l.push({conversationID:n,code:o,message:r})}),0<a.length&&(E(a),g())}return{code:0,data:{successConversationIDList:n,failureConversationIDList:l}}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"createConversationGroup",code:t,message:o});throw u.setError(r).end(),r}})}_generateConversationInfo(e,t,o={}){let r=[],{OuterConstant:n,common:{isC2CConv:s,isGroupConv:c}}=this._core;return e.forEach(e=>{L(e,t),s(e)?r.push(Object.assign({Type:a,To_Account:e.replace(n.CONV_C2C,"")},o)):c(e)&&r.push(Object.assign({Type:i,ToGroupId:e.replace(n.CONV_GROUP,"")},o))}),r}},A=new class{constructor(){this._fetchConversationGroupStatus=c}init(e){var{helper:{registerApi:t,registerWorkflowStep:o},constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:n}}=e;this._core=e,t({apiName:"getConversationGroupList",context:this}),o(r.SYNC_SERVER_INFO_AFTER_LOGIN,n.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),o(r.SYNC_SERVER_INFO_AFTER_LOGIN,n.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,function*(){return G("getConversationGroupList"),this._fetchConversationGroupStatus===d&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...t.getConversationGroupMap().values()]}})}_syncConversationGroupList(){return o(this,void 0,void 0,function*(){return yield this._fetchConversationGroupList(0)})}_fetchConversationGroupList(r){return o(this,arguments,void 0,function*(n,s=[]){let{common:{getCurrentUserID:o},utils:{isArray:i}}=this._core;this._fetchConversationGroupStatus=u;try{let r=o(),a=yield function(){var{fromAccount:t,startIndex:o}={fromAccount:r,startIndex:n},t={From_Account:t,StartIndex:o};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:t})}();if(a){let{CompleteFlag:e,ContactItem:o=[],NextStartIndex:r=0,GroupItem:n=[]}=a;return(i(n)&&n.forEach(e=>{var{GroupName:e,GroupId:o}=e;t.setConversationGroup(o,e)}),s.push(...o),e===v)?this._fetchConversationGroupList(r):e===l?(this._fetchConversationGroupStatus=p,s):void 0}}catch(e){this._fetchConversationGroupStatus=d,console.error(e)}})}_updateConversation(e){var t=this._core["constants"]["WORKFLOW_STEP"],e=(null==(e=null==e?void 0:e.result)?void 0:e[t.CONVERSATION_GROUP_LIST_SYNC])||[];E(this._generateConversationUpdateFields(e)),g()}_generateConversationUpdateFields(e){let{utils:{isArray:i},appStore:c}=this._core,u=[];if(i(e)){let s;e.forEach(e=>{let o=[],{StandardMark:r,CustomMark:n="",ContactGroupId:a}=e;i(a)&&a.forEach(e=>{t.getConversationGroupMap().has(e)&&o.push(t.getConversationGroup(e))});e=_(e);(s=c.conversationStore.getConversation(e))&&u.push({conversationID:e,data:{markList:N(r),customData:n,conversationGroupList:[...o]}})})}return u}reset(){this._fetchConversationGroupStatus=c}dispose(){this.reset()}},T=new class{init(e){var{notificationCenter:t,helper:{registerApi:o},InnerEvent:{MESSAGE_PUSH:r},InnerEventSubType:{CONVERSATION_MARK_UPDATED:n,CONVERSATION_GROUP_ADD:a,CONVERSATION_GROUP_DELETED:s,CONVERSATION_GROUP_UPDATED:i}}=e;this._core=e,o({apiName:"renameConversationGroup",context:this}),o({apiName:"deleteConversationGroup",context:this}),o({apiName:"markConversation",context:this}),o({apiName:"setConversationCustomData",context:this}),o({apiName:"deleteConversationsFromGroup",context:this}),o({apiName:"addConversationsToGroup",context:this}),t.subscribeInnerEvent(r,a,this._handleConversationGroupAdd,this),t.subscribeInnerEvent(r,s,this._handleConversationGroupDeleted,this),t.subscribeInnerEvent(r,i,this._handleConversationGroupUpdated,this),t.subscribeInnerEvent(r,n,this._handleConversationMarkUpdated,this)}renameConversationGroup(r){return o(this,void 0,void 0,function*(){G("renameConversationGroup");let{common:{getCurrentUserID:n},ssoLog:o}=this._core,{oldName:a,newName:s}=r,i=o.createSSOLogData({method:"renameConversationGroup"});i.setLogInfo({message:`oldName:${a} newName:`+s});try{let r=yield function(){var{fromAccount:t,oldName:o,newName:r}={fromAccount:n(),oldName:a,newName:s},t={From_Account:t,UpdateType:1,UpdateGroup:{UpdateGroupType:f,OldGroupName:o,NewGroupName:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:t})}();if(r){i.end();let e=r["UpdateGroupResult"],o=e["GroupId"];t.setConversationGroup(o,s),g(),this._updateLocalConversationGroupName({oldName:a,newName:s})}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"renameConversationGroup",code:t,message:o});throw i.setError(r).end(),r}})}deleteConversationGroup(a){return o(this,void 0,void 0,function*(){G("deleteConversationGroup");let{common:{getCurrentUserID:r},ssoLog:o}=this._core,n=o.createSSOLogData({method:"deleteConversationGroup"});n.setLogInfo({message:"groupName:"+a});try{let o=yield function(){var{fromAccount:t,groupName:o}={fromAccount:r(),groupName:a},t={From_Account:t,GroupName:[o]};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:t})}();if(o){let e=o["GroupItem"],r=!1;null!=e&&e.forEach(e=>{var e=e["GroupId"],o=t.getConversationGroupMap();o.has(e)&&(o.delete(e),r=!0)}),r&&g(),this._deleteLocalConversationGroupName([a])}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:t,message:o});throw n.setError(r).end(),r}})}markConversation(h){return o(this,void 0,void 0,function*(){G("markConversation");let{utils:{isNumber:e},common:{getCurrentUserID:o},ssoLog:t,appStore:s}=this._core,{conversationIDList:r,markType:i,enableMark:c}=h,n=this._getFlagBit(i),u=[],p=[],a,l;var d=t.createSSOLogData({method:"markConversation"}),v=(d.setLogInfo({message:JSON.stringify(h)}),!0===c&&e(n)?a=[n]:l=[n],D({conversationIDList:r,failureConversationIDList:u,additionalData:{SetMark:a,ClearMark:l,OptType:C}}));if(u.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:u}};try{let t=yield S({conversationInfoList:v,fromAccount:o()});if(t){d.end();let e=t["ResultItem"],a=[];e.forEach(e=>{let{ContactItem:t,ResultCode:o,ResultInfo:r}=e,n=_(t);if(0===o){p.push(n);let o=s.conversationStore.getConversation(n);if(o){let t=o.markList.indexOf(i),e=!1===c&&-1!==t;if(!0===c&&-1===t)a.push({conversationID:n,data:{markList:[...o.markList,i]}});else if(e){let e=o.markList.slice();e.splice(t,1),a.push({conversationID:n,data:{markList:e}})}}}else u.push({conversationID:n,code:o,message:r})}),E(a)}return{code:0,data:{successConversationIDList:p,failureConversationIDList:u}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"markConversation",code:t,message:o});throw d.setError(r).end(),r}})}setConversationCustomData(n){return o(this,void 0,void 0,function*(){G("setConversationCustomData");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,{conversationIDList:o,customData:s}=n,i=[],c=[],u=t.createSSOLogData({method:"setConversationCustomData"});u.setLogInfo({message:JSON.stringify(n)});var r=D({conversationIDList:o,failureConversationIDList:i,additionalData:{CustomMark:s,OptType:h}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield S({fromAccount:e(),conversationInfoList:r});if(t){u.end();let e=t["ResultItem"],n=[];null!=e&&e.forEach(e=>{let{ContactItem:o,ResultCode:t,ResultInfo:r}=e;if(0===t){let e=_(o),t=(c.push(e),a.conversationStore.getConversation(e));t&&t.customData!==s&&n.push({conversationID:e,data:{customData:s}})}else i.push({conversationID:conversationID,code:t,message:r})}),E(n)}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"setConversationCustomData",code:t,message:o});throw u.setError(r).end(),r}})}deleteConversationsFromGroup(n){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:a}=this._core,s=t.createSSOLogData({method:"deleteConversationsFromGroup"}),{conversationIDList:o,groupName:i}=(s.setLogInfo({message:JSON.stringify(n)}),n),c=[],u=[],r=D({conversationIDList:o,failureConversationIDList:c,additionalData:{ContactOptType:2}});if(c.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:c}};try{let t=yield O({fromAccount:e(),groupName:i,conversationInfoList:r});if(t){s.end();let n=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o,r=_(e.ContactItem);if(0===e.ResultCode){let t=a.conversationStore.getConversation(r);if(t){let e=t.conversationGroupList.indexOf(i);-1!==e&&((o=t.conversationGroupList.slice()).splice(e,1),u.push(r),n.push({conversationID:r,data:{conversationGroupList:o}}))}}else c.push({conversationID:r,code:e.ResultCode,message:e.ResultInfo})}),0<n.length&&(g(),E(n))}return{code:0,data:{successConversationIDList:u,failureConversationIDList:c}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw s.setError(r).end(),r}})}addConversationsToGroup(u){return o(this,void 0,void 0,function*(){G("deleteConversationsFromGroup");let{common:{getCurrentUserID:e},ssoLog:t,appStore:n}=this._core,a=t.createSSOLogData({method:"addConversationsToGroup"}),{conversationIDList:o,groupName:s}=(a.setLogInfo({message:JSON.stringify(u)}),u),i=[],c=[],r=D({conversationIDList:o,failureConversationIDList:i,additionalData:{ContactOptType:1}});if(i.length===o.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{let t=yield O({fromAccount:e(),groupName:s,conversationInfoList:r});if(t){a.end();let r=[],{ContactResultItem:e}=t["UpdateGroupResult"];null!=e&&e.forEach(e=>{var o=_(e.ContactItem);if(0===e.ResultCode){let t=n.conversationStore.getConversation(o);if(t&&-1===t.conversationGroupList.indexOf(s)){let e=t.conversationGroupList.slice();e.push(s),c.push(o),r.push({conversationID:o,data:{conversationGroupList:e}})}}else i.push({conversationID:o,code:e.ResultCode,message:e.ResultInfo})}),0<r.length&&(g(),E(r))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(e){let{errorCode:t,errorInfo:o}=e,r=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:t,message:o});throw a.setError(r).end(),r}})}_updateLocalConversationGroupName(e){let t=this._core["appStore"],{oldName:o,newName:r}=e,n=[],a=[],s;Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var t;n=e.conversationGroupList,-1!==(s=n.indexOf(o))&&((t=n.slice()).splice(s,1,r),a.push({conversationID:e.conversationID,data:{conversationGroupList:t}}))}),E(a)}_deleteLocalConversationGroupName(n){var{utils:{isEmpty:e},appStore:t}=this._core;if(!e(n)){let r=[];Array.from(t.conversationStore.getConversationMap().values()).forEach(e=>{var{conversationID:e,conversationGroupList:t}=e,o=t.filter(e=>!n.includes(e));o.length<t.length&&r.push({conversationID:e,data:{conversationGroupList:o}})}),E(r)}}_getFlagBit(e){var t=e.toString(2),o=t.length;for(let e=o-1;0<=e;e--)if("1"===t[e])return o-e-1}_handleConversationGroupAdd(e){let o,{utils:{isArray:c},appStore:u}=this._core;null!=(o=null==e?void 0:e.RecentContactMod)&&o.forEach(e=>{var e=e["RecentContactCreateContactGroup"]["MsgContactGroupContactItem"];let i=!1;null!=e&&e.forEach(e=>{let{MsgGroupItem:o,MsgRecentContactItem:r}=e,{GroupId:n,GroupName:a}=o,s=[];t.getConversationGroup(n)!==a&&(t.setConversationGroup(n,a),i=!0),c(r)&&r.forEach(e=>{var t=_(e),o=u.conversationStore.getConversation(t);if(o&&(null==(e=o.conversationGroupList)||!e.includes(a))){let e=o.conversationGroupList.slice();e.push(a),s.push({conversationID:t,data:{conversationGroupList:e}})}}),i&&g(),E(s)})})}_handleConversationGroupDeleted(e){let o,{isArray:r}=this._core.utils;null!=(o=null==e?void 0:e.RecentContactMod)&&o.forEach(e=>{e=((null==e?void 0:e.RecentContactDelContactGroup)||{}).MsgGroupItem;if(r(e)){let n=!1,a=[];e.forEach(e=>{var{GroupId:e,GroupName:o}=e,r=t.getConversationGroupMap();r.has(e)&&(r.delete(e),n=!0,a.push(o))}),n&&g(),0<a.length&&this._deleteLocalConversationGroupName(a)}})}_handleConversationGroupUpdated(e){null!=(e=e.RecentContactMod)&&e.forEach(e=>{var{GroupId:e,GroupName:t,OldGroupName:o,RecentContactUpdateGroupItem:r,UpdateGroupType:n}=e["RecentContactUpdateContactGroup"]["MsgUpdateGroup"];1===n?this._handleGroupNameUpdated({groupID:e,newName:t,oldName:o}):2===n&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:r,groupName:o})})}_handleConversationMarkUpdated(e){let t,a=this._core.appStore;null!=(t=null==e?void 0:e.RecentContactMod)&&t.forEach(e=>{let{RecentContactMarkContactItem:t}=e["RecentContactMarkContact"],n=[];null!=t&&t.forEach(e=>{var{RecentContactItem:e,CustomMark:t,StandardMark:o,OptType:r}=e,e=_(e),e=a.conversationStore.getConversation(e);e&&(r===C?this._updateStandMark({conversation:e,standardMark:o,updateConversationList:n}):r===h?this._updateCustomMark({conversation:e,customMark:t,updateConversationList:n}):r===m&&(this._updateStandMark({conversation:e,standardMark:o,updateConversationList:n}),this._updateCustomMark({conversation:e,customMark:t,updateConversationList:n})))}),E(n)})}_updateStandMark(e){var{conversation:e,standardMark:t,updateConversationList:o}=e,t=N(t);!function(o,r){if(o===r)return 1;if(o&&r&&o.length===r.length){o.sort(),r.sort();for(let e=0,t=o.length;e<t;e++)if(o[e]!==r[e])return;return 1}}(e.markList,t)&&o.push({conversationID:e.conversationID,data:{markList:t}})}_updateCustomMark(e){var{conversation:e,customMark:t,updateConversationList:o}=e;e.customData!==t&&void 0!==t&&(e.customData=t,o.push({conversationID:e.conversationID,data:{customData:t}}))}_handleGroupNameUpdated(e){var{groupID:e,oldName:o,newName:r}=e;t.getConversationGroup(e)!==r&&(t.setConversationGroup(e,r),g(),this._updateLocalConversationGroupName({oldName:o,newName:r}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:e,groupName:a}){let s=this._core["appStore"],i=[];e.forEach(e=>{var{RecentContactItem:e,ContactOptType:t}=e,o=_(e),r=s.conversationStore.getConversation(o),n=r.conversationGroupList.indexOf(a);if(r){let e=r.conversationGroupList.slice();1===t&&-1===n?(e.push(a),i.push({conversationID:o,data:{conversationGroupList:e}})):2===t&&-1!==n&&(e.splice(n,1),i.push({conversationID:o,data:{conversationGroupList:e}}))}}),E(i)}dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t},InnerEventSubType:{CONVERSATION_MARK_UPDATED:o,CONVERSATION_GROUP_ADD:r,CONVERSATION_GROUP_DELETED:n,CONVERSATION_GROUP_UPDATED:a}}=this._core;e.unSubscribeInnerEvent(t,r,this._handleConversationGroupAdd,this),e.unSubscribeInnerEvent(t,n,this._handleConversationGroupDeleted,this),e.unSubscribeInnerEvent(t,a,this._handleConversationGroupUpdated,this),e.unSubscribeInnerEvent(t,o,this._handleConversationMarkUpdated,this)}};let y={required:!0,rules:["string"],allowEmpty:!1},U={required:!0,rules:["array"],allowEmpty:!1},M={createConversationGroup:{groupName:y,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:y,newName:Object.assign(Object.assign({},y),{customValidator:e=>!(32<e.length)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:U,groupName:y},deleteConversationsFromGroup:{conversationIDList:U,groupName:y},markConversation:{conversationIDList:U,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:e=>e<=0?"markType must be greater than 0":!(e>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:U,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>"string"!=typeof e?"customData must be string":!(256<e.length)||"customData length cannot longer than 256"}}},k={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};var b=new class{install(o){this._core=o,e.init(o),t.init(o),R.init(o),A.init(o),T.init(o),o.helper.registerValidateConfig({auth:k,params:M}),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.LOGOUT,this.reset,this),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.DESTROY,this.dispose,this)}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.DESTROY,this.dispose,this),T.dispose(),A.dispose()}reset(){A.reset()}};export{b as default};
1
+ var t=new class{constructor(){this._conversationGroupMap=new Map}init(t){this._core=t}getConversationGroupMap(){return this._conversationGroupMap}getConversationGroup(t){return this._conversationGroupMap.get(t)}setConversationGroup(t,o){this._conversationGroupMap.set(t,o)}};function o(t,o,e,n){return new(e||(e=Promise))((function(r,s){function a(t){try{c(n.next(t))}catch(t){s(t)}}function i(t){try{c(n.throw(t))}catch(t){s(t)}}function c(t){var o;t.done?r(t.value):(o=t.value,o instanceof e?o:new e((function(t){t(o)}))).then(a,i)}c((n=n.apply(t,o||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const e=new class{init(t){this.core=t}},n="CONV_GROUP",r=2500,s=2503,a=1,i=2,c="NOT_STARTED",u="FETCHING",p="FINISHED",d="FAILED",v=0,l=1,C=1,h=2,m=3,f=1,I=2;function G(t){const{helper:o,constants:r}=e.core;if(!o.checkBusinessCapabilityBits(n))throw new o.ChatError({functionName:t,code:r.ERROR_CODE.NO_USE,replacement1:t})}function g(){const{notificationCenter:o,OuterEvent:n}=e.core;o.emitOuterEvent(n.CONVERSATION_GROUP_LIST_UPDATED,{name:n.CONVERSATION_GROUP_LIST_UPDATED,data:[...t.getConversationGroupMap().values()]})}function _(t){const{utils:{isUndefined:o},constants:{OuterConstant:n}}=e.core,{Type:r,To_Account:s,GroupId:c,ToGroupId:u=c,Peer_Account:p}=t;let d="";return r===a?o(p)?o(s)||(d=`${n.CONV_C2C}${s}`):d=`${n.CONV_C2C}${p}`:r===i&&(d=`${n.CONV_GROUP}${u}`),d}function D(t){const o=[],{OuterConstant:n,common:{isC2CConv:r,isGroupConv:s}}=e.core,{conversationIDList:c,failureConversationIDList:u,additionalData:p={}}=t;return c.forEach((t=>{L(t,u),r(t)?o.push(Object.assign({ContactItem:{Type:a,To_Account:t.replace(n.CONV_C2C,"")}},p)):s(t)&&o.push(Object.assign({ContactItem:{Type:i,ToGroupId:t.replace(n.CONV_GROUP,"")}},p))})),o}function L(t,o){const{appStore:{conversationStore:n},common:{isC2CConv:a,isGroupConv:i}}=e.core;n.getConversation(t)?a(t)||i(t)||o.push({conversationID:t,code:s}):o.push({conversationID:t,code:r})}function N(t){const{utils:{isString:o}}=e.core,n=[];if(!o(t))return n;const r=t.length;if(0===r)return n;for(let o=r-1;o>=0;o--)"1"===t[o]&&n.push(Math.pow(2,r-o-1));return n}function E(t){null==t||t.forEach(((o,n)=>{const{appStore:r}=e.core,{conversationID:s,data:a}=o,i=n===t.length-1;r.conversationStore.updateConversation(s,a,{emit:i})}))}function S(t){const{conversationInfoList:o,fromAccount:n}=t,r={From_Account:n,MarkItem:o};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.mark_contact",data:r})}function O(t){const{fromAccount:o,groupName:n,conversationInfoList:r}=t,s={From_Account:o,UpdateType:1,UpdateGroup:{UpdateGroupType:I,OldGroupName:n,ContactUpdateItem:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:s})}var R=new class{init(t){const{helper:{registerApi:o}}=t;this._core=t,o({apiName:"createConversationGroup",context:this})}createConversationGroup(n){return o(this,void 0,void 0,(function*(){const{utils:{isPlainObject:o,isArray:r},appStore:s,ssoLog:a}=this._core;G("createConversationGroup");const i=a.createSSOLogData({method:"createConversationGroup"});i.setLogInfo({message:JSON.stringify(n)});const{groupName:c,conversationIDList:u}=n,p=[],d=this._generateConversationInfo(u,p);if(p.length===u.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:p}};try{const n=yield function(t){const{common:{buildAndSendPacket:o,getCurrentUserID:n}}=e.core,{item:r,groupName:s}=t;return o({servcmd:"recentcontact.create_contact_group",data:{From_Account:n(),GroupContactItem:[{GroupName:s,ContactItem:r}]}})}({groupName:c,item:d});if(n){i.end();const{GroupResultItem:e=[]}=n,{GroupItem:a,ResultItem:u}=(null==e?void 0:e[0])||{},d=[];if(o(a)){const{GroupName:o,GroupId:e}=a;t.setConversationGroup(e,o),g()}if(r(u)){const t=[];u.forEach((o=>{const{ContactItem:e,ResultCode:n,ResultInfo:r}=o,a=_(e);if(0===n){const o=s.conversationStore.getConversation(a);if(o&&!o.conversationGroupList.includes(c)){const e=o.conversationGroupList.slice();e.push(c),t.push({conversationID:a,data:{conversationGroupList:e}})}}else p.push({conversationID:a,code:n,message:r})})),t.length>0&&(E(t),g())}return{code:0,data:{successConversationIDList:d,failureConversationIDList:p}}}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"createConversationGroup",code:o,message:e});throw i.setError(n).end(),n}}))}_generateConversationInfo(t,o,e={}){const n=[],{OuterConstant:r,common:{isC2CConv:s,isGroupConv:c}}=this._core;return t.forEach((t=>{L(t,o),s(t)?n.push(Object.assign({Type:a,To_Account:t.replace(r.CONV_C2C,"")},e)):c(t)&&n.push(Object.assign({Type:i,ToGroupId:t.replace(r.CONV_GROUP,"")},e))})),n}};var A=new class{constructor(){this._fetchConversationGroupStatus=c}init(t){const{helper:{registerApi:o,registerWorkflowStep:e},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:r}}=t;this._core=t,o({apiName:"getConversationGroupList",context:this}),e(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_LIST_SYNC,this._syncConversationGroupList,this),e(n.SYNC_SERVER_INFO_AFTER_LOGIN,r.CONVERSATION_GROUP_UPDATE,this._updateConversation,this)}getConversationGroupList(){return o(this,void 0,void 0,(function*(){return G("getConversationGroupList"),this._fetchConversationGroupStatus===d&&(yield this._fetchConversationGroupList(0)),{code:0,data:[...t.getConversationGroupMap().values()]}}))}_syncConversationGroupList(){return o(this,void 0,void 0,(function*(){return yield this._fetchConversationGroupList(0)}))}_fetchConversationGroupList(n){return o(this,arguments,void 0,(function*(o,n=[]){const{common:{getCurrentUserID:r},utils:{isArray:s}}=this._core;this._fetchConversationGroupStatus=u;try{const a=r(),i=yield function(t){const{fromAccount:o,startIndex:n}=t,r={From_Account:o,StartIndex:n};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.get_contact_group",data:r})}({fromAccount:a,startIndex:o});if(i){const{CompleteFlag:o,ContactItem:e=[],NextStartIndex:r=0,GroupItem:a=[]}=i;if(s(a)&&a.forEach((o=>{const{GroupName:e,GroupId:n}=o;t.setConversationGroup(n,e)})),n.push(...e),o===v)return this._fetchConversationGroupList(r);if(o===l)return this._fetchConversationGroupStatus=p,n}}catch(t){this._fetchConversationGroupStatus=d,console.error(t)}}))}_updateConversation(t){var o;const{constants:{WORKFLOW_STEP:e}}=this._core,n=(null===(o=null==t?void 0:t.result)||void 0===o?void 0:o[e.CONVERSATION_GROUP_LIST_SYNC])||[];E(this._generateConversationUpdateFields(n)),g()}_generateConversationUpdateFields(o){const{utils:{isArray:e},appStore:n}=this._core,r=[];if(e(o)){let s;o.forEach((o=>{const a=[],{StandardMark:i,CustomMark:c="",ContactGroupId:u}=o;e(u)&&u.forEach((o=>{t.getConversationGroupMap().has(o)&&a.push(t.getConversationGroup(o))}));const p=_(o);s=n.conversationStore.getConversation(p),s&&r.push({conversationID:p,data:{markList:N(i),customData:c,conversationGroupList:[...a]}})}))}return r}reset(){this._fetchConversationGroupStatus=c}dispose(){this.reset()}};var T=new class{init(t){const{notificationCenter:o,helper:{registerApi:e},InnerEvent:{MESSAGE_PUSH:n},InnerEventSubType:{CONVERSATION_MARK_UPDATED:r,CONVERSATION_GROUP_ADD:s,CONVERSATION_GROUP_DELETED:a,CONVERSATION_GROUP_UPDATED:i}}=t;this._core=t,e({apiName:"renameConversationGroup",context:this}),e({apiName:"deleteConversationGroup",context:this}),e({apiName:"markConversation",context:this}),e({apiName:"setConversationCustomData",context:this}),e({apiName:"deleteConversationsFromGroup",context:this}),e({apiName:"addConversationsToGroup",context:this}),o.subscribeInnerEvent(n,s,this._handleConversationGroupAdd,this),o.subscribeInnerEvent(n,a,this._handleConversationGroupDeleted,this),o.subscribeInnerEvent(n,i,this._handleConversationGroupUpdated,this),o.subscribeInnerEvent(n,r,this._handleConversationMarkUpdated,this)}renameConversationGroup(n){return o(this,void 0,void 0,(function*(){G("renameConversationGroup");const{common:{getCurrentUserID:o},ssoLog:r}=this._core,{oldName:s,newName:a}=n,i=r.createSSOLogData({method:"renameConversationGroup"});i.setLogInfo({message:`oldName:${s} newName:${a}`});try{const n=yield function(t){const{fromAccount:o,oldName:n,newName:r}=t,s={From_Account:o,UpdateType:1,UpdateGroup:{UpdateGroupType:f,OldGroupName:n,NewGroupName:r}};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.update_contact_group",data:s})}({fromAccount:o(),oldName:s,newName:a});if(n){i.end();const{UpdateGroupResult:o}=n,{GroupId:e}=o;t.setConversationGroup(e,a),g(),this._updateLocalConversationGroupName({oldName:s,newName:a})}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"renameConversationGroup",code:o,message:e});throw i.setError(n).end(),n}}))}deleteConversationGroup(n){return o(this,void 0,void 0,(function*(){G("deleteConversationGroup");const{common:{getCurrentUserID:o},ssoLog:r}=this._core,s=r.createSSOLogData({method:"deleteConversationGroup"});s.setLogInfo({message:`groupName:${n}`});try{const r=yield function(t){const{fromAccount:o,groupName:n}=t,r={From_Account:o,GroupName:[n]};return e.core.common.buildAndSendPacket({servcmd:"recentcontact.del_contact_group",data:r})}({fromAccount:o(),groupName:n});if(r){const{GroupItem:o}=r;let e=!1;null==o||o.forEach((o=>{const{GroupId:n}=o,r=t.getConversationGroupMap();r.has(n)&&(r.delete(n),e=!0)})),e&&g(),this._deleteLocalConversationGroupName([n])}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"deleteConversationGroup",code:o,message:e});throw s.setError(n).end(),n}}))}markConversation(t){return o(this,void 0,void 0,(function*(){G("markConversation");const{utils:{isNumber:o},common:{getCurrentUserID:e},ssoLog:n,appStore:r}=this._core,{conversationIDList:s,markType:a,enableMark:i}=t,c=this._getFlagBit(a),u=[],p=[];let d,v;const l=n.createSSOLogData({method:"markConversation"});l.setLogInfo({message:JSON.stringify(t)}),!0===i&&o(c)?d=[c]:v=[c];const h=D({conversationIDList:s,failureConversationIDList:u,additionalData:{SetMark:d,ClearMark:v,OptType:C}});if(u.length===s.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:u}};try{const t=yield S({conversationInfoList:h,fromAccount:e()});if(t){l.end();const{ResultItem:o}=t,e=[];o.forEach((t=>{const{ContactItem:o,ResultCode:n,ResultInfo:s}=t,c=_(o);if(0===n){p.push(c);const t=r.conversationStore.getConversation(c);if(t){const o=t.markList.indexOf(a),n=!1===i&&-1!==o;if(!0===i&&-1===o)e.push({conversationID:c,data:{markList:[...t.markList,a]}});else if(n){const n=t.markList.slice();n.splice(o,1),e.push({conversationID:c,data:{markList:n}})}}}else u.push({conversationID:c,code:n,message:s})})),E(e)}return{code:0,data:{successConversationIDList:p,failureConversationIDList:u}}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"markConversation",code:o,message:e});throw l.setError(n).end(),n}}))}setConversationCustomData(t){return o(this,void 0,void 0,(function*(){G("setConversationCustomData");const{common:{getCurrentUserID:o},ssoLog:e,appStore:n}=this._core,{conversationIDList:r,customData:s}=t,a=[],i=[],c=e.createSSOLogData({method:"setConversationCustomData"});c.setLogInfo({message:JSON.stringify(t)});const u=D({conversationIDList:r,failureConversationIDList:a,additionalData:{CustomMark:s,OptType:h}});if(a.length===r.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:a}};try{const t=yield S({fromAccount:o(),conversationInfoList:u});if(t){c.end();const{ResultItem:o}=t,e=[];null==o||o.forEach((t=>{const{ContactItem:o,ResultCode:r,ResultInfo:c}=t;if(0===r){const t=_(o);i.push(t);const r=n.conversationStore.getConversation(t);r&&r.customData!==s&&e.push({conversationID:t,data:{customData:s}})}else a.push({conversationID:conversationID,code:r,message:c})})),E(e)}return{code:0,data:{successConversationIDList:i,failureConversationIDList:a}}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"setConversationCustomData",code:o,message:e});throw c.setError(n).end(),n}}))}deleteConversationsFromGroup(t){return o(this,void 0,void 0,(function*(){G("deleteConversationsFromGroup");const{common:{getCurrentUserID:o},ssoLog:e,appStore:n}=this._core,r=e.createSSOLogData({method:"deleteConversationsFromGroup"});r.setLogInfo({message:JSON.stringify(t)});const{conversationIDList:s,groupName:a}=t,i=[],c=[],u=D({conversationIDList:s,failureConversationIDList:i,additionalData:{ContactOptType:2}});if(i.length===s.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{const t=yield O({fromAccount:o(),groupName:a,conversationInfoList:u});if(t){r.end();const o=[],{UpdateGroupResult:{ContactResultItem:e}}=t;null==e||e.forEach((t=>{const e=_(t.ContactItem);if(0===t.ResultCode){const t=n.conversationStore.getConversation(e);if(t){const n=t.conversationGroupList.indexOf(a);if(-1!==n){const r=t.conversationGroupList.slice();r.splice(n,1),c.push(e),o.push({conversationID:e,data:{conversationGroupList:r}})}}}else i.push({conversationID:e,code:t.ResultCode,message:t.ResultInfo})})),o.length>0&&(g(),E(o))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:o,message:e});throw r.setError(n).end(),n}}))}addConversationsToGroup(t){return o(this,void 0,void 0,(function*(){G("deleteConversationsFromGroup");const{common:{getCurrentUserID:o},ssoLog:e,appStore:n}=this._core,r=e.createSSOLogData({method:"addConversationsToGroup"});r.setLogInfo({message:JSON.stringify(t)});const{conversationIDList:s,groupName:a}=t,i=[],c=[],u=D({conversationIDList:s,failureConversationIDList:i,additionalData:{ContactOptType:1}});if(i.length===s.length)return{code:0,data:{successConversationIDList:[],failureConversationIDList:i}};try{const t=yield O({fromAccount:o(),groupName:a,conversationInfoList:u});if(t){r.end();const o=[],{UpdateGroupResult:{ContactResultItem:e}}=t;null==e||e.forEach((t=>{const e=_(t.ContactItem);if(0===t.ResultCode){const t=n.conversationStore.getConversation(e);if(t){if(-1===t.conversationGroupList.indexOf(a)){const n=t.conversationGroupList.slice();n.push(a),c.push(e),o.push({conversationID:e,data:{conversationGroupList:n}})}}}else i.push({conversationID:e,code:t.ResultCode,message:t.ResultInfo})})),o.length>0&&(g(),E(o))}return{code:0,data:{successConversationIDList:c,failureConversationIDList:i}}}catch(t){const{errorCode:o,errorInfo:e}=t,n=new this._core.helper.ChatError({functionName:"deleteConversationsFromGroup",code:o,message:e});throw r.setError(n).end(),n}}))}_updateLocalConversationGroupName(t){const{appStore:o}=this._core,{oldName:e,newName:n}=t;let r=[];const s=[];let a=-1;Array.from(o.conversationStore.getConversationMap().values()).forEach((t=>{if(r=t.conversationGroupList,a=r.indexOf(e),-1!==a){const o=r.slice();o.splice(a,1,n),s.push({conversationID:t.conversationID,data:{conversationGroupList:o}})}})),E(s)}_deleteLocalConversationGroupName(t){const{utils:{isEmpty:o},appStore:e}=this._core;if(o(t))return;const n=[];Array.from(e.conversationStore.getConversationMap().values()).forEach((o=>{const{conversationID:e,conversationGroupList:r}=o,s=r.filter((o=>!t.includes(o)));s.length<r.length&&n.push({conversationID:e,data:{conversationGroupList:s}})})),E(n)}_getFlagBit(t){const o=t.toString(2),e=o.length;for(let t=e-1;t>=0;t--)if("1"===o[t])return e-t-1}_handleConversationGroupAdd(o){var e;const{utils:{isArray:n},appStore:r}=this._core;null===(e=null==o?void 0:o.RecentContactMod)||void 0===e||e.forEach((o=>{const{RecentContactCreateContactGroup:{MsgContactGroupContactItem:e}}=o;let s=!1;null==e||e.forEach((o=>{const{MsgGroupItem:e,MsgRecentContactItem:a}=o,{GroupId:i,GroupName:c}=e,u=[];t.getConversationGroup(i)!==c&&(t.setConversationGroup(i,c),s=!0),n(a)&&a.forEach((t=>{var o;const e=_(t),n=r.conversationStore.getConversation(e);if(n&&!(null===(o=n.conversationGroupList)||void 0===o?void 0:o.includes(c))){const t=n.conversationGroupList.slice();t.push(c),u.push({conversationID:e,data:{conversationGroupList:t}})}})),s&&g(),E(u)}))}))}_handleConversationGroupDeleted(o){var e;const{utils:{isArray:n}}=this._core;null===(e=null==o?void 0:o.RecentContactMod)||void 0===e||e.forEach((o=>{const{MsgGroupItem:e}=(null==o?void 0:o.RecentContactDelContactGroup)||{};if(n(e)){let o=!1;const n=[];e.forEach((e=>{const{GroupId:r,GroupName:s}=e,a=t.getConversationGroupMap();a.has(r)&&(a.delete(r),o=!0,n.push(s))})),o&&g(),n.length>0&&this._deleteLocalConversationGroupName(n)}}))}_handleConversationGroupUpdated(t){var o;null===(o=t.RecentContactMod)||void 0===o||o.forEach((t=>{const{RecentContactUpdateContactGroup:{MsgUpdateGroup:{GroupId:o,GroupName:e,OldGroupName:n,RecentContactUpdateGroupItem:r,UpdateGroupType:s}}}=t;1===s?this._handleGroupNameUpdated({groupID:o,newName:e,oldName:n}):2===s&&this._handleGroupAddOrDeleteFromConversation({groupInfoList:r,groupName:n})}))}_handleConversationMarkUpdated(t){var o;const{appStore:e}=this._core;null===(o=null==t?void 0:t.RecentContactMod)||void 0===o||o.forEach((t=>{const{RecentContactMarkContact:{RecentContactMarkContactItem:o}}=t,n=[];null==o||o.forEach((t=>{const{RecentContactItem:o,CustomMark:r,StandardMark:s,OptType:a}=t,i=_(o),c=e.conversationStore.getConversation(i);c&&(a===C?this._updateStandMark({conversation:c,standardMark:s,updateConversationList:n}):a===h?this._updateCustomMark({conversation:c,customMark:r,updateConversationList:n}):a===m&&(this._updateStandMark({conversation:c,standardMark:s,updateConversationList:n}),this._updateCustomMark({conversation:c,customMark:r,updateConversationList:n})))})),E(n)}))}_updateStandMark(t){const{conversation:o,standardMark:e,updateConversationList:n}=t,r=N(e);(function(t,o){if(t===o)return!0;if(!t||!o)return!1;if(t.length!==o.length)return!1;t.sort(),o.sort();for(let e=0,n=t.length;e<n;e++)if(t[e]!==o[e])return!1;return!0})(o.markList,r)||n.push({conversationID:o.conversationID,data:{markList:r}})}_updateCustomMark(t){const{conversation:o,customMark:e,updateConversationList:n}=t;o.customData!==e&&void 0!==e&&(o.customData=e,n.push({conversationID:o.conversationID,data:{customData:e}}))}_handleGroupNameUpdated(o){const{groupID:e,oldName:n,newName:r}=o;t.getConversationGroup(e)!==r&&(t.setConversationGroup(e,r),g(),this._updateLocalConversationGroupName({oldName:n,newName:r}))}_handleGroupAddOrDeleteFromConversation({groupInfoList:t,groupName:o}){const{appStore:e}=this._core,n=[];t.forEach((t=>{const{RecentContactItem:r,ContactOptType:s}=t,a=_(r),i=e.conversationStore.getConversation(a),c=i.conversationGroupList.indexOf(o);if(i){const t=i.conversationGroupList.slice();1===s&&-1===c?(t.push(o),n.push({conversationID:a,data:{conversationGroupList:t}})):2===s&&-1!==c&&(t.splice(c,1),n.push({conversationID:a,data:{conversationGroupList:t}}))}})),E(n)}dispose(){const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{CONVERSATION_MARK_UPDATED:e,CONVERSATION_GROUP_ADD:n,CONVERSATION_GROUP_DELETED:r,CONVERSATION_GROUP_UPDATED:s}}=this._core;t.unSubscribeInnerEvent(o,n,this._handleConversationGroupAdd,this),t.unSubscribeInnerEvent(o,r,this._handleConversationGroupDeleted,this),t.unSubscribeInnerEvent(o,s,this._handleConversationGroupUpdated,this),t.unSubscribeInnerEvent(o,e,this._handleConversationMarkUpdated,this)}};const y={required:!0,rules:["string"],allowEmpty:!1},U={required:!0,rules:["array"],allowEmpty:!1},M={createConversationGroup:{groupName:y,conversationIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameConversationGroup:{oldName:y,newName:Object.assign(Object.assign({},y),{customValidator:t=>!(t.length>32)||"newName length cannot longer than 32"})},deleteConversationGroup:[{required:!0,rules:["string"],allowEmpty:!1}],addConversationsToGroup:{conversationIDList:U,groupName:y},deleteConversationsFromGroup:{conversationIDList:U,groupName:y},markConversation:{conversationIDList:U,markType:{required:!0,rules:["number"],allowEmpty:!1,customValidator:t=>t<=0?"markType must be greater than 0":!(t>=Math.pow(2,64))||"markType must be less than 2^64"},enableMark:{required:!0,rules:["boolean"],allowEmpty:!1}},setConversationCustomData:{conversationIDList:U,customData:{required:!1,rules:["string"],allowEmpty:!0,customValidator:t=>"string"!=typeof t?"customData must be string":!(t.length>256)||"customData length cannot longer than 256"}}},k={createConversationGroup:!0,deleteConversationGroup:!0,renameConversationGroup:!0,getConversationGroupList:!0,addConversationsToGroup:!0,deleteConversationsFromGroup:!0,markConversation:!0,setConversationCustomData:!0};var b=new class{constructor(){this.name="ConversationGroup"}install(o){this._core=o,e.init(o),t.init(o),R.init(o),A.init(o),T.init(o),o.helper.registerValidateConfig({auth:k,params:M}),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.LOGOUT,this.reset,this),o.notificationCenter.subscribeInnerEvent(o.InnerEvent.DESTROY,this.dispose,this)}dispose(){const{notificationCenter:t,InnerEvent:o}=this._core;t.unSubscribeInnerEvent(o.LOGOUT,this.reset,this),t.unSubscribeInnerEvent(o.DESTROY,this.dispose,this),T.dispose(),A.dispose()}reset(){A.reset()}};export{b as default};