@tencentcloud/lite-chat 1.6.10 → 1.6.11

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/index.d.ts CHANGED
@@ -2588,6 +2588,7 @@ declare interface LOGIN_OPTIONS {
2588
2588
  MESSAGE_EXTENSIONS_DELETED = 'onMessageExtensionsDeleted',
2589
2589
  MESSAGE_REACTIONS_UPDATED = 'onMessageReactionsUpdated',
2590
2590
  SERVER_CONFIG_UPDATED = 'onServerConfigUpdated',
2591
+ GROUP_ONLINE_MEMBER_COUNT_CHANGED = 'onGroupOnlineMemberCountChanged',
2591
2592
  }
2592
2593
 
2593
2594
  enum TYPES {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencentcloud/lite-chat",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
4
4
  "description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
5
5
  "main": "standard.js",
6
6
  "types": "index.d.ts",
@@ -1 +1 @@
1
- const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){var n;const{message:{messageDataHandler:s,messageHelper:o}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),a=[],u=t.length;for(let l=0;l<u;l++){let u=t[l];if(i&&(u=d(u)),m(u.Event)&&Object.values(r).includes(u.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(u))continue;this._patchMessageType(u);const c=o.parseServerGroupMessage(u),g=this._createMessage(c);if(g.level=u.GroupInfo.From_AccountLevel,_(u.Event)){const e=Object.assign(Object.assign({},c),{elements:Object.assign({},(null===(n=null==c?void 0:c.elements)||void 0===n?void 0:n.content)||{})});if(this._avChatRoomHandler.isGroupAttributesUpdated(e)){this._avChatRoomHandler.handleGroupAttributesUpdated(e);continue}if(this._avChatRoomHandler.isGroupCounterUpdated(e)){this._avChatRoomHandler.handleGroupCounterUpdated(e);continue}}null!==this._filterDuplicateMessage(g)&&(s.isMessageSentByCurrentInstance(g)||(1===c.isModified&&(g.isModified=!0),_(u.Event)&&this._updateLocalOnlineMemberCountFromTips(u),a.push(g)))}return a}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.elements.type===n.MSG_GRP_SYS_NOTICE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return i.setElement(e.elements),i}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},S=()=>{const e=f("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return C(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||S()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}isGroupCounterUpdated(e){return this._parentPlugin.groupCounter.isGroupCounterUpdated(e)}handleGroupCounterUpdated(e){this._parentPlugin.groupCounter.handleGroupCounterUpdated(e)}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,S()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,S())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return C(e)?parseInt(e,10):20})()){const t=S()+(()=>{const e=f("polling_interval_plus");return C(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(C(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];Array.from(this._joinedGroupMap.values()).forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:O.handleJoinGroupResult(n.data):n})}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var G=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var P=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(O.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}})}_getOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=O.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}})}_isExpired(e){const t=O.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})})}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return O.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}};var A=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var E=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),G.init(e,t),P.init(e,t),D.init(e,t),A.init(e,t),E.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});O.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=O.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return O.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),O.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return O.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&O.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};var N=new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),O.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){O.onAVChatRoomSystemNotification(e)}_reset(){O.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{N as default};
1
+ const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,m=e=>e===i.GROUP_SYSTEM_MESSAGE;function d(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||m(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);m(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){var n;const{message:{messageDataHandler:s,messageHelper:o}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),a=[],u=t.length;for(let l=0;l<u;l++){let u=t[l];if(i&&(u=d(u)),m(u.Event)&&Object.values(r).includes(u.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(u))continue;this._patchMessageType(u);const c=o.parseServerGroupMessage(u),g=this._createMessage(c);if(g.level=u.GroupInfo.From_AccountLevel,_(u.Event)){const e=Object.assign(Object.assign({},c),{elements:Object.assign({},(null===(n=null==c?void 0:c.elements)||void 0===n?void 0:n.content)||{})});if(this._avChatRoomHandler.isGroupAttributesUpdated(e)){this._avChatRoomHandler.handleGroupAttributesUpdated(e);continue}if(this._avChatRoomHandler.isGroupCounterUpdated(e)){this._avChatRoomHandler.handleGroupCounterUpdated(e);continue}}null!==this._filterDuplicateMessage(g)&&(s.isMessageSentByCurrentInstance(g)||(1===c.isModified&&(g.isModified=!0),_(u.Event)&&this._updateLocalOnlineMemberCountFromTips(u),a.push(g)))}return a}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),m(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.elements.type===n.MSG_GRP_SYS_NOTICE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return i.setElement(e.elements),i}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=d(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},S=()=>{const e=f("polling_interval");return C(e)?parseInt(e,10):300},O=()=>{const e=f("polling_simplified_msg");return C(e)?parseInt(e,10):0};var b=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=R.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=R.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 R.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 R=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||S()}isPollingSimplifiedMessage(){return 0!==O()}isGroupAttributesUpdated(e){return this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e)}updateLocalOnlineMemberCount(e,t){const{notificationCenter:n,OuterEvent:{GROUP_ONLINE_MEMBER_COUNT_CHANGED:s}}=this._core;this._onlineMemberCountMap.set(e,t),n.emitOuterEvent(s,{name:s,data:{groupID:e,count:t.memberCount}})}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),b.getGroupOnlineMemberCount(u),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}isGroupCounterUpdated(e){return this._parentPlugin.groupCounter.isGroupCounterUpdated(e)}handleGroupCounterUpdated(e){this._parentPlugin.groupCounter.handleGroupCounterUpdated(e)}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,S()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:O()}:{longPollingKey:t,startSequence:n,simplifiedMessage:O()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,S())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return C(e)?parseInt(e,10):20})()){const t=S()+(()=>{const e=f("polling_interval_plus");return C(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(C(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];Array.from(this._joinedGroupMap.values()).forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:R.handleJoinGroupResult(n.data):n})}};var G=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&&R.reset(e),n})}};var P=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&R.reset(e),n})}};var E=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(R.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var A=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),y.init(e,t),G.init(e,t),P.init(e,t),E.init(e,t),b.init(e,t),D.init(e,t),A.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});R.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=R.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return R.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),R.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return R.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&R.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};var N=new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),R.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){R.onAVChatRoomSystemNotification(e)}_reset(){R.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{N as default};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,d=e=>e===i.GROUP_SYSTEM_MESSAGE;function m(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||d(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);d(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){var n;const{message:{messageDataHandler:s,messageHelper:o}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),a=[],u=t.length;for(let l=0;l<u;l++){let u=t[l];if(i&&(u=m(u)),d(u.Event)&&Object.values(r).includes(u.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(u))continue;this._patchMessageType(u);const c=o.parseServerGroupMessage(u),g=this._createMessage(c);if(g.level=u.GroupInfo.From_AccountLevel,_(u.Event)){const e=Object.assign(Object.assign({},c),{elements:Object.assign({},(null===(n=null==c?void 0:c.elements)||void 0===n?void 0:n.content)||{})});if(this._avChatRoomHandler.isGroupAttributesUpdated(e)){this._avChatRoomHandler.handleGroupAttributesUpdated(e);continue}if(this._avChatRoomHandler.isGroupCounterUpdated(e)){this._avChatRoomHandler.handleGroupCounterUpdated(e);continue}}null!==this._filterDuplicateMessage(g)&&(s.isMessageSentByCurrentInstance(g)||(1===c.isModified&&(g.isModified=!0),_(u.Event)&&this._updateLocalOnlineMemberCountFromTips(u),a.push(g)))}return a}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),d(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.elements.type===n.MSG_GRP_SYS_NOTICE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return i.setElement(e.elements),i}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=m(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},S=()=>{const e=f("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return C(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||S()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}isGroupCounterUpdated(e){return this._parentPlugin.groupCounter.isGroupCounterUpdated(e)}handleGroupCounterUpdated(e){this._parentPlugin.groupCounter.handleGroupCounterUpdated(e)}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,S()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,S())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return C(e)?parseInt(e,10):20})()){const t=S()+(()=>{const e=f("polling_interval_plus");return C(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(C(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];Array.from(this._joinedGroupMap.values()).forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var R=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:O.handleJoinGroupResult(n.data):n})}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var G=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&O.reset(e),n})}};var P=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(O.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="GetAVChatRoomOnlineMemberCount"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupOnlineMemberCount",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},OuterConstant:n}=this._core,s=t.getGroup(e);return s?s.type===n.GRP_AVCHATROOM?this._getOnlineMemberCount(e):this._parentPlugin.groupAction.getGroupOnlineMemberCount(e):{code:0,data:{memberCount:0}}})}_getOnlineMemberCount(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCount",{utils:{isEmpty:n}}=this._core,s=O.getLocalOnlineMemberCount(e);if(n(s)||this._isExpired(e)){const{memberCount:n=0}=yield this._getOnlineMemberCountFromServer(e);return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${n} from server.`),{code:0,data:{memberCount:n}}}return console.log(`${this._name}.${t} ok, groupID:${e} memberCount:${s.memberCount} from local.`),{code:0,data:{memberCount:s.memberCount}}})}_isExpired(e){const t=O.getLocalOnlineMemberCount(e),n=Date.now(),s=n-t.lastSyncTime>1e3*t.expireTime,o=n-t.latestUpdateTime>1e4,i=n-t.lastReqTime>3e3;return s&&o&&i}_getOnlineMemberCountFromServer(e){return n(this,void 0,void 0,function*(){const t="_getOnlineMemberCountFromServer";try{const t=yield function(e,t){return n(this,void 0,void 0,function*(){const n={GroupId:e};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_online_member_num",data:n})})}(e,this._core),{OnlineMemberNum:s=0,ExpireTime:o=a}=t||{},i=Date.now(),r={lastSyncTime:i,latestUpdateTime:i,lastReqTime:i,memberCount:s,expireTime:o};return O.updateLocalOnlineMemberCount(e,r),{memberCount:s}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}};var A=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var E=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),R.init(e,t),y.init(e,t),G.init(e,t),P.init(e,t),D.init(e,t),A.init(e,t),E.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});O.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=O.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return O.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),O.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return O.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&O.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};return new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),O.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){O.onAVChatRoomSystemNotification(e)}_reset(){O.reset()}_dispose(){this._reset();const{notificationCenter:e,InnerEvent:t}=this._core,{InnerEventSubType:n}=e;e.unSubscribeInnerEvent(t.MESSAGE_PUSH,n.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))(function(o,i){function r(e){try{u(s.next(e))}catch(e){i(e)}}function a(e){try{u(s.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n(function(e){e(t)})).then(r,a)}u((s=s.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const s="AV_MBR_LIST",o="AV_BAN_MBR",i={NORMAL_MESSAGE:3,GROUP_TIPS_HAS_ROAMING:4,GROUP_SYSTEM_MESSAGE:5,GROUP_TIPS_HAS_NO_ROAMING:6,BROADCAST_MESSAGE:17,MESSAGE_REVOKED:20,MESSAGE_REACTION:21,LIVE_CUSTOM_DATA:100},r={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},a=60,u=2603,l=2686,c=2688,g=3122;class p{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getCurrentPollingInterval(this._groupID)}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,function*(){const{longPollingKey:n,startSequence:s,startBroadcastSeq:o,simplifiedMessage:i}=e,r={Key:n,StartSeq:s,StartBroadcastSeq:o,DownsizeFlag:i,USP:1,HoldTime:90};return t.common.buildAndSendPacket({servcmd:"group_open_long_polling_http_svc.get_msg",data:r})})}(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getCurrentPollingInterval(this._groupID);this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}})}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop timerID:${this._timeoutID}`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class h{constructor(e){this._maxLength=e,this._map=new Map}set(e){var t;if(this._map.size>=this._maxLength){const e=(null===(t=this._map.entries().next().value)||void 0===t?void 0:t[0])||"";this._map.delete(e)}this._map.set(e,1)}has(e){return this._map.has(e)}delete(e){this.has(e)&&this._map.delete(e)}clear(){this._map.clear()}}const _=e=>e===i.GROUP_TIPS_HAS_NO_ROAMING||e===i.GROUP_TIPS_HAS_ROAMING,d=e=>e===i.GROUP_SYSTEM_MESSAGE;function m(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:u,CCD:l,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:u,CloudCustomData:l,From_Account:c,IsSystemMsg:g,GroupInfo:M(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(_(n)||d(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===i.BROADCAST_MESSAGE||(e=>e===i.NORMAL_MESSAGE)(n))&&function(t){const{core:{OuterConstant:n}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map(e=>{if(e.MsgType===n.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e})}(t);var s;_(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=null==i?void 0:i.map(e=>({UserId:e})));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);d(n)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:n}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:n,ImageUrl:"",NickName:""},t),e.MsgBody=Object.assign({Authentication:"",RemarkInfo:"",MsgKey:1e3*e.MsgTimeStamp},e.MsgBody),e.MsgBody=Object.keys(e.MsgBody).filter(e=>"MsgOperatorMemberExtraInfo"!==e).reduce((t,n)=>Object.assign(Object.assign({},t),{[n]:e.MsgBody[n]}),{})}(t)}(s),s}function M(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r,F_Ll:a}=n,u=t(n,["GN","GT","F_Hd","F_NN","F_Ll"]),l=Object.assign({GroupName:s,GroupType:o},u);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),a&&(l.From_AccountLevel=a),l}function v(e){let n=e;Array.isArray(e)||(n=[e]);const s=n.map(e=>{const{O_Account:n,Opt:s,L_Account:o,RT:i,UDF:r,OpInf:a,OnlineInf:u,MsgMemberExtraInfo:l}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),l&&(g.MsgMemberExtraInfo=function(e){return null==e?void 0:e.map(e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)})}(l)),u&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(u)),g});return Array.isArray(e)?s:s[0]}var I=new class{constructor(){this._name="MessageParser",this._sequenceList=new h(200),this._messageIDList=new h(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList({groupID:t,serverMessageList:n,isHistoryMessage:s});const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter(e=>!0===e.isModified),r=o.filter(e=>!1===e.isModified),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:u}}=this._core;i.length>0&&this._emitEvent({name:u,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e){const{groupID:t,serverMessageList:n,isHistoryMessage:s}=e;let o=[];this._avChatRoomHandler.isPollingSimplifiedMessage()&&!s?(n.sort((e,t)=>e.MS-t.MS),o=n.map(e=>e.MS)):(n.sort((e,t)=>e.MsgSeq-t.MsgSeq),o=n.map(e=>e.MsgSeq)),console.log(`${this._name}._sortServerMessageList groupID:${t} count:${o.length} sequenceList:${o}`),o.length=0}_handleMessageList(e,t){var n;const{message:{messageDataHandler:s,messageHelper:o}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),a=[],u=t.length;for(let l=0;l<u;l++){let u=t[l];if(i&&(u=m(u)),d(u.Event)&&Object.values(r).includes(u.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(u))continue;this._patchMessageType(u);const c=o.parseServerGroupMessage(u),g=this._createMessage(c);if(g.level=u.GroupInfo.From_AccountLevel,_(u.Event)){const e=Object.assign(Object.assign({},c),{elements:Object.assign({},(null===(n=null==c?void 0:c.elements)||void 0===n?void 0:n.content)||{})});if(this._avChatRoomHandler.isGroupAttributesUpdated(e)){this._avChatRoomHandler.handleGroupAttributesUpdated(e);continue}if(this._avChatRoomHandler.isGroupCounterUpdated(e)){this._avChatRoomHandler.handleGroupCounterUpdated(e);continue}}null!==this._filterDuplicateMessage(g)&&(s.isMessageSentByCurrentInstance(g)||(1===c.isModified&&(g.isModified=!0),_(u.Event)&&this._updateLocalOnlineMemberCountFromTips(u),a.push(g)))}return a}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),d(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e){const{Event:t}=e;return Object.values(i).includes(t)?(e=>e===i.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===i.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===i.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.elements.type===n.MSG_GRP_SYS_NOTICE&&(s=n.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:s,isSystemMessage:o,flow:"in"}));return i.setElement(e.elements),i}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const n=this._messageIDList.has(e.ID);return n?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${n}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:n}}=this._core,{ToGroupId:s,MsgBody:{RevokeMsgList:o},RevokerInfo:{Revoker_Account:i,Reason:r=""}}=e,a=[];o.forEach(e=>{const{TinyId:n,MsgClientTime:o,Random:u,MsgSeq:l}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${u}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:l};a.push(c)}),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.Content)||(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.info("MessageStacked",`count:${t} groupID:${e.join(",")}`),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let n=0;n<r;n++){let r=e[n];s&&(r=m(r));const a=t.parseServerGroupMessage(r);if(!Object.values(i).includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const u=this._createMessage(a);u.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(u.ID)||(o.push(u),this._broadcastMessageIDMap.set(u.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=a}=s,r=Date.now();let u=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(u)?u={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(u.latestUpdateTime=r,u.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,u)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const f=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},S=()=>{const e=f("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=f("polling_simplified_msg");return C(e)?parseInt(e,10):0};var O=new class{constructor(){this._name="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=R.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=R.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 R.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 R=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._onlineMemberCountMap=new Map,this._pollingIntervalMap=new Map,this._pollingNoMessageCountMap=new Map,this._membersReqInfoMap=new Map,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,I.init(e,this),e.ssoLog.debug("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],a=Object.values(r).includes(s.ReportType);i===t&&a&&this.reset(o)}}getCurrentPollingInterval(e){return this._pollingIntervalMap.get(e)||S()}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)}handleGroupAttributesUpdated(e){this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e)}updateLocalOnlineMemberCount(e,t){const{notificationCenter:n,OuterEvent:{GROUP_ONLINE_MEMBER_COUNT_CHANGED:s}}=this._core;this._onlineMemberCountMap.set(e,t),n.emitOuterEvent(s,{name:s,data:{groupID:e,count:t.memberCount}})}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){const{OuterConstant:{GRP_LIVE:e}}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=[...this._joinedGroupMap.values()].filter(t=>t.type===e)),t}handleJoinGroupResult(e){return n(this,void 0,void 0,function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a=[]}=e,{groupID:u}=r;if(yield this._preCheck(r),this._joinedGroupMap.set(u,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${u}`),O.getGroupOnlineMemberCount(u),a.length>0&&I.onMessageReceived(u,a,!0),!t(i)){return{code:0,data:this.startMessageLongPolling(e)}}return{code:0,data:{status:o.JOIN_STATUS_SUCCESS,group:r}}})}isGroupCounterUpdated(e){return this._parentPlugin.groupCounter.isGroupCounterUpdated(e)}handleGroupCounterUpdated(e){this._parentPlugin.groupCounter.handleGroupCounterUpdated(e)}_preCheck(e){return n(this,void 0,void 0,function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o},ssoLog:i}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=f("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:c,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[r,a]=this._joinedGroupMap.entries().next().value;if(a.selfInfo.role===n.GRP_MBR_ROLE_OWNER)this._parentPlugin.groupDataHandler.deleteLocalGroup(r);else try{yield o(r)}catch(e){i.debug("quitGroup",`${this._name}._preCheck quitGroup failed, groupID:${r} info:`,e)}this.reset(r)})}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingIntervalMap.set(i,S()),this._startPolling(i),this._reportLongPollingCount(),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(this._core.ssoLog.debug("_startPolling",`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new p({core:this._core,manager:this,groupID:e,getRequestParams:this._handleRequestParams.bind(this),onSuccess:this._handleSuccess.bind(this),onFail:this._handleFailure.bind(this)});t.start(),this._pollingInstanceMap.set(e,t)}_handleRequestParams(e){const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:n,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:b()}:{longPollingKey:t,startSequence:n,simplifiedMessage:b()}}_handleSuccess(e,t){const{ErrorCode:n}=t;if(0!==n){const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};return void console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t)}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;if(n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0)0!==this._getPollingNoMessageCount(e)&&(this._updatePollingNoMessageCount(e,0),this._pollingIntervalMap.set(e,S())),I.onMessageReceived(e,i);else{let t=this._getPollingNoMessageCount(e);if(t+=1,this._updatePollingNoMessageCount(e,t),t===(()=>{const e=f("polling_no_msg_count");return C(e)?parseInt(e,10):20})()){const t=S()+(()=>{const e=f("polling_interval_plus");return C(e)?parseInt(e,10):2e3})();this._pollingIntervalMap.set(e,t)}}r.length>0&&I.onBroadcastMessageReceived(r)}_handleFailure(e,t){const{ssoLog:n,utils:{safeStringify:s}}=this._core;n.warn("polling",`${this._name}._handleFailure groupID:${e} error: ${s(t)}`)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter(t=>t.type===e.GRP_AVCHATROOM)),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}updateLocalLiveGroup(e,t){this._joinedGroupMap.set(e,t),this._parentPlugin.groupDataHandler.updateLocalGroup([t])}handleLiveHistoryMessages(e,t){I.onMessageReceived(e,t,!0)}isOverFrequencyLimit(e){if(!this._membersReqInfoMap.has(e))return this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1;let{startTime:t,requestCount:n}=this._membersReqInfoMap.get(e);const{interval:s,count:o}=(()=>{const e=f("av_members_freq_limit");if(C(e)){const{interval:t,count:n}=JSON.parse(e);if(n>0&&t>0)return{interval:t,count:n}}return{interval:30,count:4}})();return Date.now()-t>1e3*s?(this._membersReqInfoMap.set(e,{startTime:Date.now(),requestCount:1}),!1):(n+=1,this._membersReqInfoMap.set(e,{startTime:t,requestCount:n}),n>o)}_stopPolling(e){if(this._core.ssoLog.debug("_stopPolling",`${this._name}._stopPolling groupID:${e}`),e){const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),this._onlineMemberCountMap.delete(e),this._pollingIntervalMap.delete(e),this._pollingNoMessageCountMap.delete(e),void this._membersReqInfoMap.delete(e)}for(const e of this._pollingInstanceMap.values())null==e||e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear(),this._pollingIntervalMap.clear(),this._pollingNoMessageCountMap.clear(),this._membersReqInfoMap.clear()}_updatePollingNoMessageCount(e,t){this._pollingNoMessageCountMap.set(e,t)}_getPollingNoMessageCount(e){return this._pollingNoMessageCountMap.get(e)||0}_reportLongPollingCount(){const e=this._joinedGroupMap.size;if(e>1){const{common:t,OuterConstant:n,ssoLog:s}=this._core,o=t.isUnlimitedAVChatRoom()?1:0,i=[],r=[];Array.from(this._joinedGroupMap.values()).forEach(({groupID:e,type:t})=>{t===n.GRP_LIVE?r.push(e):i.push(e)}),s.info("longPollingCount",String(e),{moreMessage:`av:${i.join(",")} live:${r.join(",")} code: ${o}`,eventType:29})}}reset(e){this._stopPolling(e),this._startBroadcastSequence=1,I.reset()}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{status:s,group:{type:o}}}=n;return o===t.GRP_AVCHATROOM?s===t.JOIN_STATUS_ALREADY_IN_GROUP?n:R.handleJoinGroupResult(n.data):n})}};var G=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&&R.reset(e),n})}};var P=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"dismissGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}dismissGroup(e){return n(this,void 0,void 0,function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.dismissGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&R.reset(e),n})}};var E=new class{constructor(){this._name="GetAVChatRoomMemberList"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"getGroupMemberList",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}getGroupMemberList(e){return n(this,void 0,void 0,function*(){const{appStore:{groupStore:t},helper:n,OuterConstant:o}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===o.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(s)){if(R.isOverFrequencyLimit(i)){throw{code:2996,message:`Over frequency limit: get_members-${i}`}}return this._getGroupMemberList(e)}}return this._parentPlugin.groupMember.getGroupMemberList(e)})}_getGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="_getGroupMemberList",{helper:s}=this._core;try{const s=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,offset:s=0}=e,o={GroupId:n,Timestamp:s};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.get_members",data:o})})}(e,this._core),{MemberList:o=[],NextTimestamp:i=0}=s||{},r=this._handleMemberList(o);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${r.length} nextOffset:${i}`),{code:0,data:{memberList:r,offset:i}}}catch(e){const n=new s.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}})}_handleMemberList(e){return e.map(e=>{const{Member_Account:t,NickName:n="",Avatar:s="",Remark:o="",JoinTime:i=0,Marks:r=[]}=e;return{userID:t,nick:n,avatar:s,remark:o,joinTime:i,marks:r,isOnline:!0}})}};var D=new class{constructor(){this._name="DeleteAVChatRoomMember"}init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"deleteGroupMember",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="deleteGroupMember",{appStore:{groupStore:n},utils:{isUndefined:s},helper:i,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new i.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(i.checkBusinessCapabilityBits(o))return this._deleteGroupMember(e);throw new i.ChatError({functionName:t,code:g})}return this._parentPlugin.groupMember.deleteGroupMember(e)})}_deleteGroupMember(e){return n(this,void 0,void 0,function*(){const t="_deleteGroupMember",{appStore:{groupStore:s},helper:o,ssoLog:i}=this._core,{groupID:r,duration:a=0,userIDList:u}=e;if(0===a)throw new o.ChatError({functionName:t,code:l});try{yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,userIDList:s,duration:o,reason:i}=e,r={GroupId:n,Members_Account:s,Duration:o,Description:i};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.ban_group_member",data:r})})}(e,this._core),i.debug(t,`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:s.getGroup(r),userIDList:u}}}catch(e){throw new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}};var A=new class{constructor(){this._name="MarkAVChatRoomMember"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"markGroupMemberList",context:this})}markGroupMemberList(e){return n(this,void 0,void 0,function*(){const t="markGroupMemberList",{groupID:s,markType:o,enableMark:i,userIDList:r=[]}=e,a=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,operationType:s,memberList:o}=e,i={GroupId:n,CommandType:s,MemberList:o};return t.common.buildAndSendPacket({servcmd:"group_open_avchatroom_http_svc.modify_user_info",data:i})})}(a,this._core),{MemberList:u=[]}=e||{},{successUserIDList:l,failureUserIDList:c}=this._handleResult(u,r);return{code:0,data:{successUserIDList:l,failureUserIDList:c},successLog:{message:`${this._name}.${t} ok, groupID:${s} markType:${o} enableMark:${i} success:${l.length} fail:${c.length}`}}}catch(e){throw new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map(e=>({Member_Account:e,Marks:[n]}))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach(t=>{e.find(e=>e.Member_Account===t)?n.push(t):s.push(t)}),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){e.ssoLog.debug("AVChatRoomAction.init"),y.init(e,t),G.init(e,t),P.init(e,t),E.init(e,t),O.init(e,t),D.init(e,t),A.init(e)}};var T=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t,ssoLog:n}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),n.debug("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s,ssoLog:o}=this._core,{groupID:i,longPollingKey:r,longPollingSequence:a=1}=e;if(n(r))return o.warn("startMessageLongPolling",`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});R.hasPollingInstance(i)&&this.stopMessageLongPolling({groupID:i});const u=R.getJoinedLiveList(),l=t.isUnlimitedAVChatRoom();!l&&u.length>0&&this.stopMessageLongPolling({groupID:u[0].groupID}),o.debug("startMessageLongPolling",`${this._name}.startMessageLongPolling isUnlimited:${l} groupID:${i} longPollingKey:${r} longPollingSequence:${a}`);const c={groupID:i,type:s.GRP_LIVE};return R.updateLocalLiveGroup(i,c),this._getLiveHistoryMessages({groupID:i,longPollingKey:r,startSequence:a}),R.startMessageLongPolling({group:c,longPollingKey:r,startSequence:a})}stopMessageLongPolling(e){const{groupID:t}=e;return R.reset(t),this._core.ssoLog.debug("stopMessageLongPolling",`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}_getLiveHistoryMessages(e){return n(this,void 0,void 0,function*(){const{ssoLog:t}=this._core,{groupID:s}=e;try{const o=yield function(e,t){return n(this,void 0,void 0,function*(){const{groupID:n,longPollingKey:s,startSequence:o}=e,i={GroupId:n,LongPollingKey:s,PullPreSeq:o};return t.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_huge_group_msg",data:i})})}(e,this._core),{RspMsgList:i=[]}=o||{};t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages ok, groupID:${s} count:${i.length}`),i.length>0&&R.handleLiveHistoryMessages(s,i)}catch(e){t.debug("_getLiveHistoryMessages",`${this._name}._getLiveHistoryMessages failed, groupID:${s} info:${e.message}`)}})}};return new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),R.init(t,n),L.init(t,n),T.init(t);const{notificationCenter:s,InnerEvent:o}=t,{InnerEventSubType:i}=s;s.subscribeInnerEvent(o.MESSAGE_PUSH,i.GROUP_SYSTEM_NOTIFICATION,this._onAVChatRoomSystemNotification,this),s.subscribeInnerEvent(o.LOGOUT,this._reset,this),s.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_onAVChatRoomSystemNotification(e){R.onAVChatRoomSystemNotification(e)}_reset(){R.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,t,r,i){return new(r||(r=Promise))(function(o,s){function n(e){try{a(i.next(e))}catch(e){s(e)}}function d(e){try{a(i.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(n,d)}a((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const t="friend",r=1e3,i=2700,o=2710,s=2711,n=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:`${c}Group`,REMARK:`${c}Remark`,ADDSOURCE:`${c}AddSource`,ADDWORDING:`${c}Wording`,ADDTIME:`${c}AddTime`},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function F(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}))})}function I(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){const{[t]:i=[],ActionStatus:o,ErrorCode:s,ErrorInfo:n,ErrorDisplay:d}=e;return{resultList:i.map(r),actionStatus:o,errorCode:s,errorInfo:n,errorDisplay:d}}const v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}};let A=class{constructor(e){var t;this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];const{userID:r,tagValueList:i=[],core:o}=e,s=null===(t=o.user.userProfile)||void 0===t?void 0:t.createProfile(r,i);this.userID=r,this.profile=s,i.forEach(e=>{const{tag:t,value:r}=e;t.indexOf("Tag_Profile_Custom")>-1&&this.friendCustomField.push({key:t,value:r});const i=v[t];null==i||i(this,r)})}update(e){const t=[];this.friendCustomField.forEach(e=>{t.push(e.key)}),e.forEach(e=>{const{tag:r,value:i}=e;r.indexOf("Tag_Profile_Custom")>-1&&(t.indexOf(r)>-1?this.friendCustomField.forEach(e=>{e.key===r&&(e.value=i)}):this.friendCustomField.push({key:r,value:i}));const o=v[r];null==o||o(this,i)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),t.registerApi({apiName:"getFriendProfile",context:this}),t.registerApi({apiName:"addFriend",context:this}),t.registerApi({apiName:"deleteFriend",context:this}),t.registerApi({apiName:"updateFriend",context:this}),t.registerApi({apiName:"checkFriend",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,o=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",`${t} getFriendListFromCache, data:${i(o)}`),{code:0,data:o}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){var r;const{ssoLog:i,helper:o}=this._core;try{i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer`);const o={From_Account:null===(r=this._core.store.get("login"))||void 0===r?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},s=yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{UserDataItem:t=[],StandardSequence:r,CustomSequence:i,FriendNum:o,CompleteFlag:s,NextStartIndex:n,ActionStatus:d,ErrorCode:a,ErrorInfo:c,ErrorDisplay:u}=e;return{friendList:t.map(e=>{var t;return{userID:e.To_Account,tagValueList:null===(t=e.ValueItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:r,customSequence:i,friendNumber:o,completeFlag:s,nextStartIndex:n,actionStatus:d,errorCode:a,errorInfo:c,errorDisplay:u}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get",data:t}))})}(o,this._core),{friendList:n,nextStartIndex:d,standardSequence:a,customSequence:c,completeFlag:u}=s;this._startIndex=d,this._standardSequence=a,this._customSequence=c,this._processFriendList(n),0===u?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer ok`)}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}getFriendProfile(t){return e(this,void 0,void 0,function*(){var i;try{let{userIDList:o}=t;o.length>r&&(o=o.slice(0,r));const{friendUserIdList:s,unFriendUserIdList:n}=this.partitionByIsFriend(o),d=this._createNonFriendErrorList(n);if(0===s.length)return{code:0,data:{friendList:[],failureUserIDList:d}};const a={From_Account:null===(i=this._core.store.get("login"))||void 0===i?void 0:i.userId,To_Account:s},c=(yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{InfoItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{friendProfileList:t.map(e=>{var t;return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null===(t=e.SnsProfileItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:t}))})}(a,this._core))||{},{successProfiles:u,failedProfiles:l}=this._processFriendProfileResponse(c);return{code:0,data:{friendList:u,failureUserIDList:[...l,...d]}}}catch(e){const{errorCode:t}=e||{};throw new this._core.helper.ChatError({code:t})}})}addFriend(r){return e(this,void 0,void 0,function*(){var i;const{helper:o,store:s,ssoLog:n}=this._core;try{const{to:d,source:c,type:u,wording:l,remark:p,groupName:h}=r,m={From_Account:null===(i=s.get("login"))||void 0===i?void 0:i.userId,AddFriendItem:[{To_Account:d,AddSource:c,AddWording:l,GroupName:h,Remark:p}],AddType:u},_=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}(m,this._core),{resultList:f=[]}=_,{userID:F,resultCode:I}=f[0];if(0===I)return n.debug("addFriend",`${t} addFriend ok`),{code:0,data:{userID:F}};if(I===a)return n.debug("addFriend",`${t} addFriend wait for the other party to agree`),{code:0,data:{userID:F,code:I,message:"wait for the other party to agree"}};throw new o.ChatError({functionName:"addFriend",code:I})}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}deleteFriend(i){return e(this,void 0,void 0,function*(){var o;const{store:s,ssoLog:n,helper:d}=this._core;try{let{userIDList:d,type:a}=i;const c=null===(o=s.get("login"))||void 0===o?void 0:o.userId;d.length>1e3&&(n.info("deleteFriend",`${t} deleteFriend the length of userIDList cannot exceed:1000`),d=d.slice(0,r));const{friendUserIdList:u,unFriendUserIdList:l}=this.partitionByIsFriend(d);if(0===u.length)return{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(l)}};const p={From_Account:c,To_Account:u,DeleteType:a},h=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}(p,this._core),{successUserIDList:m,failureUserIDList:_}=this._processOperationResult({resultList:h.resultList,includeRelation:!1});return{code:0,data:{successUserIDList:m,failureUserIDList:_}}}catch(e){const{errorCode:t}=e||{};throw new d.ChatError({code:t})}})}updateFriend(t){return e(this,void 0,void 0,function*(){var e;const{helper:r,store:o,appStore:{userStore:s}}=this._core;try{const{userID:n,remark:d,friendCustomField:a}=t,c=null===(e=o.get("login"))||void 0===e?void 0:e.userId;if(!s.getFriendMap().has(n))throw new r.ChatError({functionName:"updateFriend",code:i});const u={From_Account:c,UpdateItem:[{To_Account:n,SnsItem:this._buildSnsItemList(d,a)}]},l=yield F(u,this._core),{resultList:p}=l,{to:h,resultCode:m,resultInfo:_}=p[0];if(f(m)||0===m){return{code:0,data:this._updateLocalFriend({userID:h,remark:d,friendCustomField:a})}}throw new r.ChatError({functionName:"updateFriend",code:m,message:_})}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}checkFriend(t){return e(this,void 0,void 0,function*(){var e;const{OuterConstant:r,store:i,helper:o}=this._core;try{const{userIDList:o,type:s}=t,n=null===(e=i.get("login"))||void 0===e?void 0:e.userId,d={From_Account:n,To_Account:o,CheckType:s===r.SNS_CHECK_TYPE_SINGLE?s:r.SNS_CHECK_TYPE_BOTH},a=yield I(d,this._core),{successUserIDList:c=[],failureUserIDList:u=[]}=this._processOperationResult({resultList:a.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:c,failureUserIDList:u}}}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){const{userStore:e}=this._core.appStore;e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(r){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:i}}=this._core;e.debug("updateFriendList",`${t} updateFriendList data:${i(r)}`);const{userStore:o}=this._core.appStore,{addedFriendList:s=[],removedFriendList:n=[]}=r;s.length>0&&(s.forEach(e=>{const t=new A({userID:e,core:this._core});o.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:s}),this._emitFriendListUpdated()),n.length>0&&(n.forEach(e=>{o.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",`${t} updateFriendInfo data:${i(e)}`);const{appStore:{userStore:o,conversationStore:s},utils:{isEmpty:n}}=this._core,{userID:d,tagValueList:a}=e[0]||{},c=o.getFriend(d);if(n(a)||!c)return;const l=a.map(e=>({tag:e.BytesTag,value:e.BytesValue}));l.forEach(e=>{var t;const{tag:r,value:i}=e,o=null===(t=s.getConversation(`C2C${d}`))||void 0===t?void 0:t.remark;r===u.REMARK&&i!==o&&s.updateConversation(`C2C${d}`,{remark:i}),c.update(l)}),this._emitFriendListUpdated()}_processFriendList(e){const{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{const{userID:t,tagValueList:i}=e;if(this._isInvalidFriend(t))return;const o=new A({userID:t,tagValueList:i,core:this._core});r.getFriendMap().set(t,o)})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},user:{userProfile:r},ssoLog:i}=this._core;i.debug("_fetchFriendProfile",`${t} _fetchFriendProfile`);const o=[...e.getFriendMap().keys()],s=Math.ceil(o.length/100);for(let t=0;t<s;t++){const i=100*t,s=Math.min(i+100,o.length),n=o.slice(i,s),d=yield null==r?void 0:r.getUserProfile({userIDList:n});if(d&&d.data){d.data.forEach(t=>{const r=e.getFriend(t.userID);r&&(r.profile=t)})}this._emitFriendListUpdated()}})}_emitFriendListUpdated(){const{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,i=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:i})}_updateCustomField(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let r=!1;return t.forEach(({key:t,value:i})=>{const o=e.find(e=>e.key===t);o?o.value!==i&&(o.value=i,r=!0):(e.push({key:t,value:i}),r=!0)}),r}_updateLocalFriend(e){const{userStore:t}=this._core.appStore,{userID:r,remark:i,friendCustomField:o}=e,s=t.getFriend(r);if(s)return f(i)||(s.remark=i),Array.isArray(o)&&o.length>0&&this._updateCustomField(s.friendCustomField,o),this._emitFriendListUpdated(),s}_processOperationResult(e){const{resultList:t,includeRelation:r=!1}=e,{isEmpty:i}=this._core.utils,o=[],s=[];return Array.isArray(t)&&!i(t)&&t.forEach(e=>{const{userID:t,relation:i,resultCode:n,resultInfo:d}=e;if(f(n)||0===n){const e={userID:t};r&&(e.code=0,e.relation=i),o.push(e)}else s.push({userID:t,code:n,message:d})}),{successUserIDList:o,failureUserIDList:s}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){const r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&t.length>0&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){const{friendProfileList:t=[]}=e,{userStore:r}=this._core.appStore,i=[],o=[];return t.forEach(e=>{const{userID:t,resultCode:s,resultInfo:n,profileItem:d}=e;if(0===s){const e=new A({userID:t,tagValueList:d,core:this._core});i.push(e),r.getFriendMap().set(t,e)}else o.push({userID:t,code:s,message:n})}),{successProfiles:i,failedProfiles:o}}partitionByIsFriend(e){const t=[],r=[];return e.forEach(e=>{const{userStore:i}=this._core.appStore;i.getFriendMap().has(e)?t.push(e):r.push(e)}),{friendUserIdList:t,unFriendUserIdList:r}}isMyFriend(e){const{userStore:t}=this._core.appStore;return t.getFriendMap().has(e)}};var y=new class{init(e){this.core=e}};function S(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function E(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function D(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return C(yield i.buildAndSendPacket({servcmd:"sns.pendency_delete",data:o}))})}function C(e){const{ResultItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:t.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){this._core=e;const{helper:t,constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:i}}=e;t.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),t.registerApi({apiName:"acceptFriendApplication",context:this}),t.registerApi({apiName:"refuseFriendApplication",context:this}),t.registerApi({apiName:"deleteFriendApplication",context:this}),t.registerApi({apiName:"setFriendApplicationRead",context:this}),t.registerWorkflowStep(r.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.FRIEND_APPLICATION_LIST_RECOVER,this.syncFriendApplicationListFromServer,this)}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",`${t} getFriendApplicationListFromCache friendApplicationList:${r(i)}`),{code:0,data:{friendApplicationList:i,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:i,utils:{safeStringify:o}}=this._core,s="syncFriendApplicationListFromServer";try{const t=yield function(t){return e(this,void 0,void 0,function*(){var e;const{store:i,OuterConstant:o,common:s}=y.core,n={From_Account:null===(e=i.get("login"))||void 0===e?void 0:e.userId,PendencyType:o.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:t.startTime,LastSequence:t.currentSequence};return function(e){const{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:i,CurrentSequence:o,ActionStatus:s,ErrorCode:n,ErrorInfo:d,ErrorDisplay:a}=e;return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,avatar:e.Image})),startTime:r,unreadCount:i,currentSequence:o,actionStatus:s,errorCode:n,errorInfo:d,errorDisplay:a}}(yield s.buildAndSendPacket({servcmd:"sns.pendency_get",data:n}))})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:s,currentSequence:n}=t;this._startTime=s,this._currentSequence=n,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{const{userID:t,type:r}=e,i=this._createFriendApplication(e);this._friendApplicationMap.set(`${t}_${r}`,i)}),this._emitApplicationListUpdated()}catch(e){const r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw i.error("syncFriendApplicationListFromServer",`${t} ${s} error:`,{error:r}),r}})}acceptFriendApplication(t){return e(this,void 0,void 0,function*(){const{OuterConstant:{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:r}}=this._core;return[e,r].includes(t.type)||(t.type=r),this._operationApplication({functionName:"acceptFriendApplication",options:t,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(t){return e(this,void 0,void 0,function*(){const{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(`${e}_${t}`))throw new this._core.helper.ChatError({functionName:r,code:n})}_operationApplication(r){return e(this,void 0,void 0,function*(){const{functionName:e,options:i,protocolFunction:o}=r;console.log(`${t} ${e} options:`,i);try{const r=yield o(i),{resultList:s=[]}=r,{resultCode:n,resultInfo:d}=s[0];if(0===n)return console.log(`${t} ${e} ok`),{code:0,data:{}};throw{errorCode:n,errorInfo:d}}catch(r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var e;const{store:t,common:r}=y.core,i={From_Account:null===(e=t.get("login"))||void 0===e?void 0:e.userId,LatestPendencyTimeStamp:(o=Math.floor(Date.now()/1e3),s=0,Math.round(Number(o)*Math.pow(10,s))/Math.pow(10,s))};var o,s;return function(e){const{ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}(yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:i}))})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){const{from:t,addedApplicationList:r=[],removedApplicationList:i=[]}=e,{isEmpty:o}=this._core.utils;o(r)||this.onApplicationAdded(r,t),o(i)||this.onApplicationDeleted()}onApplicationAdded(e,t){var r;const{store:i,OuterConstant:o}=this._core,s=t===(null===(r=i.get("login"))||void 0===r?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{const t=`${e.userID}_${s}`;s!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:s})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function N(){return e(this,void 0,void 0,function*(){const{common:e}=y.core,t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return function(e){return M(e,e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))}(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}))})}function k(t){return e(this,void 0,void 0,function*(){const{name:e,userIDList:r}=t,{common:i}=y.core,o={From_Account:i.getCurrentUserID(),GroupName:[e],To_Account:r};return function(e){return M(e,e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield i.buildAndSendPacket({servcmd:"sns.group_add",data:o}))})}function P(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))})}function w(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=O(i,l),s={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:s}))})}function G(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=O(i,p),s={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:s}))})}function R(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{oldName:r,newName:i}=t,o={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:i};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:o}))})}function O(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function M(e,t){const{CurrentSequence:r,ActionStatus:i,ErrorCode:o,ErrorInfo:s,ErrorDisplay:n,ResultItem:d=[]}=e,a={currentSequence:r,actionStatus:i,errorCode:o,errorInfo:s,errorDisplay:n};return t&&d.length>0?Object.assign(Object.assign({},a),{resultList:d.map(t)}):a}class U{constructor(e){const{name:t="",userIDList:r=[]}=e;this.name=t,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){const t=this.userIDList.indexOf(e);t>-1&&(this.userIDList.splice(t,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),t.registerApi({apiName:"createFriendGroup",context:this}),t.registerApi({apiName:"deleteFriendGroup",context:this}),t.registerApi({apiName:"addToFriendGroup",context:this}),t.registerApi({apiName:"removeFromFriendGroup",context:this}),t.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendGroupMap.values()];return e.debug(`${t} getFriendGroupListFromCache, data:${r(i)}`),{code:0,data:i}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:e}=this._core,r="syncFriendGroupListFromServer";try{const i=yield N(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",`${t} ${r} ok. count: 0`),o.forEach(e=>{const t=new U(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(t){return e(this,void 0,void 0,function*(){const e="createFriendGroup";try{const{name:r}=t;this._checkGroupExist(e,r);const i=yield k(t),{successUserIDList:o,failureUserIDList:s}=this._parseCreateGroupResponse(i),n=new U({name:r,userIDList:o});return this._friendGroupMap.set(r,n),this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:s}}}catch(t){this._handleError(e,t)}})}deleteFriendGroup(t){return e(this,void 0,void 0,function*(){const e="deleteFriendGroup";try{const{name:r}=t;this._checkGroupNotExist(e,r),yield P(t);const i=this._friendGroupMap.get(r);return i&&(this._updateFriendGroup({name:r,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(r)),this._emitGroupListUpdated(),{code:0,data:i}}catch(t){this._handleError(e,t)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:w})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:G})})}renameFriendGroup(t){return e(this,void 0,void 0,function*(){const e="renameFriendGroup";try{const{oldName:r,newName:i}=t;this._checkGroupNotExist(e,r),this._checkGroupExist(e,i),yield R(t);const o=this._updateGroupNameInCache(r,i);return o&&this._updateFriendGroup({name:r,userIDList:o.userIDList,action:_,newName:i}),this._emitGroupListUpdated(),{code:0,data:o}}catch(t){this._handleError(e,t)}})}_updateFriendGroupMember(t){return e(this,void 0,void 0,function*(){const{functionName:e,params:r,protocolFunction:i}=t;try{const{name:t}=r;this._checkGroupNotExist(e,t);const o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(t,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(t){this._handleError(e,t)}})}_updateGroupNameInCache(e,t){const r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){const{resultList:t=[]}=e,r=[],i=[];return t.forEach(({userID:e,resultCode:t,resultInfo:o})=>{f(t)||0===t?r.push(e):i.push({userID:e,code:t,message:o})}),{successUserIDList:r,failureUserIDList:i}}_parseUpdateFriendGroupResponse(e,t){const{resultList:r=[]}=t,i=this._friendGroupMap.get(e),o=[],s=[],n=[];return r.forEach(t=>{0===t.resultCode?i&&(t.updateType===l?this._addFriendToGroup(e,t.userID,i,s):t.updateType===p&&this._removeFriendFromGroup(e,t.userID,i,n)):o.push({userID:t.userID,code:t.resultCode,message:t.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:s})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){const{name:t,userIDList:r,action:i,newName:o}=e,{userStore:s}=this._core.appStore;t&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{const r=s.getFriend(e);if(!r)return;const{groupList:n}=r;switch(i){case h:-1===n.indexOf(t)&&(n.push(t),r.count=n.length);break;case m:{const e=n.indexOf(t);e>-1&&(n.splice(e,1),r.count=n.length);break}case _:{if(!o)return;const e=n.indexOf(t);-1!==e&&(n[e]=o);break}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var q=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),t.registerApi({apiName:"addToBlacklist",context:this}),t.registerApi({apiName:"removeFromBlacklist",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(`${t} syncBlacklistFromServer`);const i={From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_get",s=e.generateProtocolData({servcmd:o,data:t}),n=`${s.head.seq}${o}`,d=yield i.sendPacket(s,{requestId:n}),{BlackListItem:a=[],StartIndex:c=0}=d;return{blackList:B(a),startIndex:c}})}(i,this._core),{blackList:s=[],startIndex:n=0}=o;return this._startIndex=n,this._addBlacklistMap(s),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r=this._preprocessBlacklist(t),i={From_Account:this._core.common.getCurrentUserID(),To_Account:r},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_add",s=e.generateProtocolData({servcmd:o,data:t}),n=`${s.head.seq}${o}`,d=yield i.sendPacket(s,{requestId:n}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(i,this._core),{blackList:s=[]}=o;return this._addBlacklistMap(s),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}removeFromBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r={From_Account:this._core.common.getCurrentUserID(),To_Account:t.userIDList},i=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_delete",s=e.generateProtocolData({servcmd:o,data:t}),n=`${s.head.seq}${o}`,d=yield i.sendPacket(s,{requestId:n}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(r,this._core),{blackList:o=[]}=i;return this._deleteBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateBlacklist",`${t} updateBlacklist data: ${i(e)}`);const{addedBlacklist:o=[],removedBlacklist:s=[]}=e;let n=!1;if(o.length>0){o.some(e=>!this._blacklistMap.has(e))&&(n=!0,this._addBlacklistMap(o.map(e=>({userID:e}))))}if(s.length>0){s.some(e=>this._blacklistMap.has(e))&&(n=!0,this._deleteBlacklistMap(s.map(e=>({userID:e}))))}n&&this._emitBlackListUpdated()}_addBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",`${t} _addBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t,addBlackTimeStamp:r=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:r})})}_deleteBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",`${t} _deleteBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)})}_preprocessBlacklist(e){let{userIDList:t}=e;const r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t.includes(r)&&(t=e.userIDList.filter(e=>e!==r)),t}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:r,ssoLog:i,utils:{safeStringify:o}}=this._core,s=Array.from(this._blacklistMap.keys());i.debug(`${t} _emitBlackListUpdated blackList:${o(s)}`),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:s})}};const x={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},$={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var W=new class{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(`${t} install`),this._core=e;const{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:s,WORKFLOW_STEP:n}}=e;y.init(e),g.init(e),T.init(e),b.init(e),q.init(e),r.registerValidateConfig({auth:$,params:x}),r.registerWorkflowStep(s.SYNC_SERVER_INFO_AFTER_LOGIN,n.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){q.syncBlacklistFromServer(),g.syncFriendListFromServer(),T.syncFriendApplicationListFromServer(),b.syncFriendGroupListFromServer()}onFriendModified(e){const{from:t,addedBlacklist:r,removedBlacklist:i,addedFriendList:o,removedFriendList:s,addedApplicationList:n,removedApplicationList:d,friendUpdateInfo:a,reportTime:c}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),{isEmpty:u}=this._core.utils;u(r)&&u(i)||q.updateBlacklist({addedBlacklist:r,removedBlacklist:i}),u(o)&&u(s)||(g.updateFriendList({addedFriendList:o,removedFriendList:s}),T.updateFriendApplicationList({from:t,removedApplicationList:o})),u(a)||g.updateFriendInfo(a),u(n)&&u(d)||T.updateFriendApplicationList({from:t,addedApplicationList:n,removedApplicationList:d}),c&&T.onApplicationRead()}_parseFriendListModification(e){const{PushType:t,From_Account:r,To_Account:i,ReportTime:o,BlackListAdd_Account:s=[],BlackListDel_Account:n=[],FriendAdd_Account:d=[],FriendDel_Account:a=[],PendencyAdd:c=[],FrienPencydDel_Account:u=[],FriendUpInfo:l=[]}=e,p=l.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:t,from:r,to:i,reportTime:o,addedBlacklist:s,removedBlacklist:n,addedFriendList:d,removedFriendList:a,addedApplicationList:c.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:p,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),q.dispose(),g.dispose(),T.dispose(),b.dispose()}};export{W as default};
1
+ function e(e,t,r,i){return new(r||(r=Promise))(function(o,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,d)}a((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const t="friend",r=1e3,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:`${c}Group`,REMARK:`${c}Remark`,ADDSOURCE:`${c}AddSource`,ADDWORDING:`${c}Wording`,ADDTIME:`${c}AddTime`},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function F(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}))})}function I(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){const{[t]:i=[],ActionStatus:o,ErrorCode:n,ErrorInfo:s,ErrorDisplay:d}=e;return{resultList:i.map(r),actionStatus:o,errorCode:n,errorInfo:s,errorDisplay:d}}const v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}};let A=class{constructor(e){var t;this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];const{userID:r,tagValueList:i=[],core:o}=e,n=null===(t=o.user.userProfile)||void 0===t?void 0:t.createProfile(r,i);this.userID=r,this.profile=n,i.forEach(e=>{const{tag:t,value:r}=e;t.indexOf("Tag_Profile_Custom")>-1&&this.friendCustomField.push({key:t,value:r});const i=v[t];null==i||i(this,r)})}update(e){const t=[];this.friendCustomField.forEach(e=>{t.push(e.key)}),e.forEach(e=>{const{tag:r,value:i}=e;r.indexOf("Tag_Profile_Custom")>-1&&(t.indexOf(r)>-1?this.friendCustomField.forEach(e=>{e.key===r&&(e.value=i)}):this.friendCustomField.push({key:r,value:i}));const o=v[r];null==o||o(this,i)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),t.registerApi({apiName:"getFriendProfile",context:this}),t.registerApi({apiName:"addFriend",context:this}),t.registerApi({apiName:"deleteFriend",context:this}),t.registerApi({apiName:"updateFriend",context:this}),t.registerApi({apiName:"checkFriend",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,o=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",`${t} getFriendListFromCache, data:${i(o)}`),{code:0,data:o}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){var r;const{ssoLog:i,helper:o}=this._core;try{i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer`);const o={From_Account:null===(r=this._core.store.get("login"))||void 0===r?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},n=yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{UserDataItem:t=[],StandardSequence:r,CustomSequence:i,FriendNum:o,CompleteFlag:n,NextStartIndex:s,ActionStatus:d,ErrorCode:a,ErrorInfo:c,ErrorDisplay:u}=e;return{friendList:t.map(e=>{var t;return{userID:e.To_Account,tagValueList:null===(t=e.ValueItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:r,customSequence:i,friendNumber:o,completeFlag:n,nextStartIndex:s,actionStatus:d,errorCode:a,errorInfo:c,errorDisplay:u}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get",data:t}))})}(o,this._core),{friendList:s,nextStartIndex:d,standardSequence:a,customSequence:c,completeFlag:u}=n;this._startIndex=d,this._standardSequence=a,this._customSequence=c,this._processFriendList(s),0===u?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer ok`)}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}getFriendProfile(t){return e(this,void 0,void 0,function*(){var i;try{let{userIDList:o}=t;o.length>r&&(o=o.slice(0,r));const{friendUserIdList:n,unFriendUserIdList:s}=this.partitionByIsFriend(o),d=this._createNonFriendErrorList(s);if(0===n.length)return{code:0,data:{friendList:[],failureUserIDList:d}};const a={From_Account:null===(i=this._core.store.get("login"))||void 0===i?void 0:i.userId,To_Account:n},c=(yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{InfoItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{friendProfileList:t.map(e=>{var t;return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null===(t=e.SnsProfileItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:t}))})}(a,this._core))||{},{successProfiles:u,failedProfiles:l}=this._processFriendProfileResponse(c);return{code:0,data:{friendList:u,failureUserIDList:[...l,...d]}}}catch(e){const{errorCode:t}=e||{};throw new this._core.helper.ChatError({code:t})}})}addFriend(r){return e(this,void 0,void 0,function*(){var i;const{helper:o,store:n,ssoLog:s,OuterConstant:d}=this._core;try{const{to:c,source:u,wording:l,remark:p,groupName:h,type:m=d.SNS_ADD_TYPE_BOTH}=r,_={From_Account:null===(i=n.get("login"))||void 0===i?void 0:i.userId,AddFriendItem:[{To_Account:c,AddSource:u,AddWording:l,GroupName:h,Remark:p}],AddType:m},f=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}(_,this._core),{resultList:F=[]}=f,{userID:I,resultCode:v}=F[0];if(0===v)return s.debug("addFriend",`${t} addFriend ok`),{code:0,data:{userID:I}};if(v===a)return s.debug("addFriend",`${t} addFriend wait for the other party to agree`),{code:0,data:{userID:I,code:v,message:"wait for the other party to agree"}};throw new o.ChatError({functionName:"addFriend",code:v})}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}deleteFriend(i){return e(this,void 0,void 0,function*(){var o;const{store:n,ssoLog:s,helper:d,OuterConstant:a}=this._core;try{let{userIDList:d,type:c=a.SNS_DELETE_TYPE_BOTH}=i;const u=null===(o=n.get("login"))||void 0===o?void 0:o.userId;d.length>1e3&&(s.info("deleteFriend",`${t} deleteFriend the length of userIDList cannot exceed:1000`),d=d.slice(0,r));const{friendUserIdList:l,unFriendUserIdList:p}=this.partitionByIsFriend(d);if(0===l.length)return{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(p)}};const h={From_Account:u,To_Account:l,DeleteType:c},m=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}(h,this._core),{successUserIDList:_,failureUserIDList:f}=this._processOperationResult({resultList:m.resultList,includeRelation:!1});return{code:0,data:{successUserIDList:_,failureUserIDList:f}}}catch(e){const{errorCode:t}=e||{};throw new d.ChatError({code:t})}})}updateFriend(t){return e(this,void 0,void 0,function*(){var e;const{helper:r,store:o,appStore:{userStore:n}}=this._core;try{const{userID:s,remark:d,friendCustomField:a}=t,c=null===(e=o.get("login"))||void 0===e?void 0:e.userId;if(!n.getFriendMap().has(s))throw new r.ChatError({functionName:"updateFriend",code:i});const u={From_Account:c,UpdateItem:[{To_Account:s,SnsItem:this._buildSnsItemList(d,a)}]},l=yield F(u,this._core),{resultList:p}=l,{to:h,resultCode:m,resultInfo:_}=p[0];if(f(m)||0===m){return{code:0,data:this._updateLocalFriend({userID:h,remark:d,friendCustomField:a})}}throw new r.ChatError({functionName:"updateFriend",code:m,message:_})}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}checkFriend(t){return e(this,void 0,void 0,function*(){var e;const{OuterConstant:r,store:i,helper:o}=this._core;try{const{userIDList:o,type:n}=t,s=null===(e=i.get("login"))||void 0===e?void 0:e.userId,d={From_Account:s,To_Account:o,CheckType:n===r.SNS_CHECK_TYPE_SINGLE?n:r.SNS_CHECK_TYPE_BOTH},a=yield I(d,this._core),{successUserIDList:c=[],failureUserIDList:u=[]}=this._processOperationResult({resultList:a.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:c,failureUserIDList:u}}}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){const{userStore:e}=this._core.appStore;e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(r){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:i}}=this._core;e.debug("updateFriendList",`${t} updateFriendList data:${i(r)}`);const{userStore:o}=this._core.appStore,{addedFriendList:n=[],removedFriendList:s=[]}=r;n.length>0&&(n.forEach(e=>{const t=new A({userID:e,core:this._core});o.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:n}),this._emitFriendListUpdated()),s.length>0&&(s.forEach(e=>{o.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",`${t} updateFriendInfo data:${i(e)}`);const{appStore:{userStore:o,conversationStore:n},utils:{isEmpty:s}}=this._core,{userID:d,tagValueList:a}=e[0]||{},c=o.getFriend(d);if(s(a)||!c)return;const l=a.map(e=>({tag:e.BytesTag,value:e.BytesValue}));l.forEach(e=>{var t;const{tag:r,value:i}=e,o=null===(t=n.getConversation(`C2C${d}`))||void 0===t?void 0:t.remark;r===u.REMARK&&i!==o&&n.updateConversation(`C2C${d}`,{remark:i}),c.update(l)}),this._emitFriendListUpdated()}_processFriendList(e){const{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{const{userID:t,tagValueList:i}=e;if(this._isInvalidFriend(t))return;const o=new A({userID:t,tagValueList:i,core:this._core});r.getFriendMap().set(t,o)})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},user:{userProfile:r},ssoLog:i}=this._core;i.debug("_fetchFriendProfile",`${t} _fetchFriendProfile`);const o=[...e.getFriendMap().keys()],n=Math.ceil(o.length/100);for(let t=0;t<n;t++){const i=100*t,n=Math.min(i+100,o.length),s=o.slice(i,n),d=yield null==r?void 0:r.getUserProfile({userIDList:s});if(d&&d.data){d.data.forEach(t=>{const r=e.getFriend(t.userID);r&&(r.profile=t)})}this._emitFriendListUpdated()}})}_emitFriendListUpdated(){const{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,i=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:i})}_updateCustomField(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let r=!1;return t.forEach(({key:t,value:i})=>{const o=e.find(e=>e.key===t);o?o.value!==i&&(o.value=i,r=!0):(e.push({key:t,value:i}),r=!0)}),r}_updateLocalFriend(e){const{userStore:t}=this._core.appStore,{userID:r,remark:i,friendCustomField:o}=e,n=t.getFriend(r);if(n)return f(i)||(n.remark=i),Array.isArray(o)&&o.length>0&&this._updateCustomField(n.friendCustomField,o),this._emitFriendListUpdated(),n}_processOperationResult(e){const{resultList:t,includeRelation:r=!1}=e,{isEmpty:i}=this._core.utils,o=[],n=[];return Array.isArray(t)&&!i(t)&&t.forEach(e=>{const{userID:t,relation:i,resultCode:s,resultInfo:d}=e;if(f(s)||0===s){const e={userID:t};r&&(e.code=0,e.relation=i),o.push(e)}else n.push({userID:t,code:s,message:d})}),{successUserIDList:o,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){const r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&t.length>0&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){const{friendProfileList:t=[]}=e,{userStore:r}=this._core.appStore,i=[],o=[];return t.forEach(e=>{const{userID:t,resultCode:n,resultInfo:s,profileItem:d}=e;if(0===n){const e=new A({userID:t,tagValueList:d,core:this._core});i.push(e),r.getFriendMap().set(t,e)}else o.push({userID:t,code:n,message:s})}),{successProfiles:i,failedProfiles:o}}partitionByIsFriend(e){const t=[],r=[];return e.forEach(e=>{const{userStore:i}=this._core.appStore;i.getFriendMap().has(e)?t.push(e):r.push(e)}),{friendUserIdList:t,unFriendUserIdList:r}}isMyFriend(e){const{userStore:t}=this._core.appStore;return t.getFriendMap().has(e)}};var S=new class{init(e){this.core=e}};function y(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=S.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function E(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=S.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function D(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=S.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return C(yield i.buildAndSendPacket({servcmd:"sns.pendency_delete",data:o}))})}function C(e){const{ResultItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:t.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){this._core=e;const{helper:t,constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:i}}=e;t.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),t.registerApi({apiName:"acceptFriendApplication",context:this}),t.registerApi({apiName:"refuseFriendApplication",context:this}),t.registerApi({apiName:"deleteFriendApplication",context:this}),t.registerApi({apiName:"setFriendApplicationRead",context:this}),t.registerWorkflowStep(r.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.FRIEND_APPLICATION_LIST_RECOVER,this.syncFriendApplicationListFromServer,this)}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",`${t} getFriendApplicationListFromCache friendApplicationList:${r(i)}`),{code:0,data:{friendApplicationList:i,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:i,utils:{safeStringify:o}}=this._core,n="syncFriendApplicationListFromServer";try{const t=yield function(t){return e(this,void 0,void 0,function*(){var e;const{store:i,OuterConstant:o,common:n}=S.core,s={From_Account:null===(e=i.get("login"))||void 0===e?void 0:e.userId,PendencyType:o.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:t.startTime,LastSequence:t.currentSequence};return function(e){const{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:i,CurrentSequence:o,ActionStatus:n,ErrorCode:s,ErrorInfo:d,ErrorDisplay:a}=e;return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,avatar:e.Image})),startTime:r,unreadCount:i,currentSequence:o,actionStatus:n,errorCode:s,errorInfo:d,errorDisplay:a}}(yield n.buildAndSendPacket({servcmd:"sns.pendency_get",data:s}))})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:n,currentSequence:s}=t;this._startTime=n,this._currentSequence=s,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{const{userID:t,type:r}=e,i=this._createFriendApplication(e);this._friendApplicationMap.set(`${t}_${r}`,i)}),this._emitApplicationListUpdated()}catch(e){const r=new this._core.helper.ChatError({functionName:n,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw i.error("syncFriendApplicationListFromServer",`${t} ${n} error:`,{error:r}),r}})}acceptFriendApplication(t){return e(this,void 0,void 0,function*(){const{OuterConstant:{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:r}}=this._core;return[e,r].includes(t.type)||(t.type=r),this._operationApplication({functionName:"acceptFriendApplication",options:t,protocolFunction:y})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(t){return e(this,void 0,void 0,function*(){const{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(`${e}_${t}`))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,function*(){const{functionName:e,options:i,protocolFunction:o}=r;console.log(`${t} ${e} options:`,i);try{const r=yield o(i),{resultList:n=[]}=r,{resultCode:s,resultInfo:d}=n[0];if(0===s)return console.log(`${t} ${e} ok`),{code:0,data:{}};throw{errorCode:s,errorInfo:d}}catch(r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var e;const{store:t,common:r}=S.core,i={From_Account:null===(e=t.get("login"))||void 0===e?void 0:e.userId,LatestPendencyTimeStamp:(o=Math.floor(Date.now()/1e3),n=0,Math.round(Number(o)*Math.pow(10,n))/Math.pow(10,n))};var o,n;return function(e){const{ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}(yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:i}))})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){const{from:t,addedApplicationList:r=[],removedApplicationList:i=[]}=e,{isEmpty:o}=this._core.utils;o(r)||this.onApplicationAdded(r,t),o(i)||this.onApplicationDeleted()}onApplicationAdded(e,t){var r;const{store:i,OuterConstant:o}=this._core,n=t===(null===(r=i.get("login"))||void 0===r?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{const t=`${e.userID}_${n}`;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function N(){return e(this,void 0,void 0,function*(){const{common:e}=S.core,t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return function(e){return M(e,e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))}(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}))})}function k(t){return e(this,void 0,void 0,function*(){const{name:e,userIDList:r}=t,{common:i}=S.core,o={From_Account:i.getCurrentUserID(),GroupName:[e],To_Account:r};return function(e){return M(e,e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield i.buildAndSendPacket({servcmd:"sns.group_add",data:o}))})}function P(t){return e(this,void 0,void 0,function*(){const{common:e}=S.core,r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))})}function w(t){return e(this,void 0,void 0,function*(){const{common:e}=S.core,{name:r,userIDList:i}=t,o=O(i,l),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))})}function G(t){return e(this,void 0,void 0,function*(){const{common:e}=S.core,{name:r,userIDList:i}=t,o=O(i,p),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))})}function R(t){return e(this,void 0,void 0,function*(){const{common:e}=S.core,{oldName:r,newName:i}=t,o={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:i};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:o}))})}function O(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function M(e,t){const{CurrentSequence:r,ActionStatus:i,ErrorCode:o,ErrorInfo:n,ErrorDisplay:s,ResultItem:d=[]}=e,a={currentSequence:r,actionStatus:i,errorCode:o,errorInfo:n,errorDisplay:s};return t&&d.length>0?Object.assign(Object.assign({},a),{resultList:d.map(t)}):a}class U{constructor(e){const{name:t="",userIDList:r=[]}=e;this.name=t,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){const t=this.userIDList.indexOf(e);t>-1&&(this.userIDList.splice(t,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),t.registerApi({apiName:"createFriendGroup",context:this}),t.registerApi({apiName:"deleteFriendGroup",context:this}),t.registerApi({apiName:"addToFriendGroup",context:this}),t.registerApi({apiName:"removeFromFriendGroup",context:this}),t.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendGroupMap.values()];return e.debug(`${t} getFriendGroupListFromCache, data:${r(i)}`),{code:0,data:i}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:e}=this._core,r="syncFriendGroupListFromServer";try{const i=yield N(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",`${t} ${r} ok. count: 0`),o.forEach(e=>{const t=new U(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(t){return e(this,void 0,void 0,function*(){const e="createFriendGroup";try{const{name:r}=t;this._checkGroupExist(e,r);const i=yield k(t),{successUserIDList:o,failureUserIDList:n}=this._parseCreateGroupResponse(i),s=new U({name:r,userIDList:o});return this._friendGroupMap.set(r,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(t){this._handleError(e,t)}})}deleteFriendGroup(t){return e(this,void 0,void 0,function*(){const e="deleteFriendGroup";try{const{name:r}=t;this._checkGroupNotExist(e,r),yield P(t);const i=this._friendGroupMap.get(r);return i&&(this._updateFriendGroup({name:r,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(r)),this._emitGroupListUpdated(),{code:0,data:i}}catch(t){this._handleError(e,t)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:w})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:G})})}renameFriendGroup(t){return e(this,void 0,void 0,function*(){const e="renameFriendGroup";try{const{oldName:r,newName:i}=t;this._checkGroupNotExist(e,r),this._checkGroupExist(e,i),yield R(t);const o=this._updateGroupNameInCache(r,i);return o&&this._updateFriendGroup({name:r,userIDList:o.userIDList,action:_,newName:i}),this._emitGroupListUpdated(),{code:0,data:o}}catch(t){this._handleError(e,t)}})}_updateFriendGroupMember(t){return e(this,void 0,void 0,function*(){const{functionName:e,params:r,protocolFunction:i}=t;try{const{name:t}=r;this._checkGroupNotExist(e,t);const o=yield i(r),{friendGroup:n,failureUserIDList:s}=this._parseUpdateFriendGroupResponse(t,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:s}}}catch(t){this._handleError(e,t)}})}_updateGroupNameInCache(e,t){const r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){const{resultList:t=[]}=e,r=[],i=[];return t.forEach(({userID:e,resultCode:t,resultInfo:o})=>{f(t)||0===t?r.push(e):i.push({userID:e,code:t,message:o})}),{successUserIDList:r,failureUserIDList:i}}_parseUpdateFriendGroupResponse(e,t){const{resultList:r=[]}=t,i=this._friendGroupMap.get(e),o=[],n=[],s=[];return r.forEach(t=>{0===t.resultCode?i&&(t.updateType===l?this._addFriendToGroup(e,t.userID,i,n):t.updateType===p&&this._removeFriendFromGroup(e,t.userID,i,s)):o.push({userID:t.userID,code:t.resultCode,message:t.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:n})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){const{name:t,userIDList:r,action:i,newName:o}=e,{userStore:n}=this._core.appStore;t&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{const r=n.getFriend(e);if(!r)return;const{groupList:s}=r;switch(i){case h:-1===s.indexOf(t)&&(s.push(t),r.count=s.length);break;case m:{const e=s.indexOf(t);e>-1&&(s.splice(e,1),r.count=s.length);break}case _:{if(!o)return;const e=s.indexOf(t);-1!==e&&(s[e]=o);break}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var q=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),t.registerApi({apiName:"addToBlacklist",context:this}),t.registerApi({apiName:"removeFromBlacklist",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(`${t} syncBlacklistFromServer`);const i={From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_get",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{BlackListItem:a=[],StartIndex:c=0}=d;return{blackList:B(a),startIndex:c}})}(i,this._core),{blackList:n=[],startIndex:s=0}=o;return this._startIndex=s,this._addBlacklistMap(n),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r=this._preprocessBlacklist(t),i={From_Account:this._core.common.getCurrentUserID(),To_Account:r},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_add",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(i,this._core),{blackList:n=[]}=o;return this._addBlacklistMap(n),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}removeFromBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r={From_Account:this._core.common.getCurrentUserID(),To_Account:t.userIDList},i=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_delete",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(r,this._core),{blackList:o=[]}=i;return this._deleteBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateBlacklist",`${t} updateBlacklist data: ${i(e)}`);const{addedBlacklist:o=[],removedBlacklist:n=[]}=e;let s=!1;if(o.length>0){o.some(e=>!this._blacklistMap.has(e))&&(s=!0,this._addBlacklistMap(o.map(e=>({userID:e}))))}if(n.length>0){n.some(e=>this._blacklistMap.has(e))&&(s=!0,this._deleteBlacklistMap(n.map(e=>({userID:e}))))}s&&this._emitBlackListUpdated()}_addBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",`${t} _addBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t,addBlackTimeStamp:r=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:r})})}_deleteBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",`${t} _deleteBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)})}_preprocessBlacklist(e){let{userIDList:t}=e;const r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t.includes(r)&&(t=e.userIDList.filter(e=>e!==r)),t}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:r,ssoLog:i,utils:{safeStringify:o}}=this._core,n=Array.from(this._blacklistMap.keys());i.debug(`${t} _emitBlackListUpdated blackList:${o(n)}`),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:n})}};const x={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=S.core;return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=S.core;return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{const{OuterConstant:t}=S.core;return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},$={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var W=new class{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(`${t} install`),this._core=e;const{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:s}}=e;S.init(e),g.init(e),T.init(e),b.init(e),q.init(e),r.registerValidateConfig({auth:$,params:x}),r.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,s.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){q.syncBlacklistFromServer(),g.syncFriendListFromServer(),T.syncFriendApplicationListFromServer(),b.syncFriendGroupListFromServer()}onFriendModified(e){const{from:t,addedBlacklist:r,removedBlacklist:i,addedFriendList:o,removedFriendList:n,addedApplicationList:s,removedApplicationList:d,friendUpdateInfo:a,reportTime:c}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),{isEmpty:u}=this._core.utils;u(r)&&u(i)||q.updateBlacklist({addedBlacklist:r,removedBlacklist:i}),u(o)&&u(n)||(g.updateFriendList({addedFriendList:o,removedFriendList:n}),T.updateFriendApplicationList({from:t,removedApplicationList:o})),u(a)||g.updateFriendInfo(a),u(s)&&u(d)||T.updateFriendApplicationList({from:t,addedApplicationList:s,removedApplicationList:d}),c&&T.onApplicationRead()}_parseFriendListModification(e){const{PushType:t,From_Account:r,To_Account:i,ReportTime:o,BlackListAdd_Account:n=[],BlackListDel_Account:s=[],FriendAdd_Account:d=[],FriendDel_Account:a=[],PendencyAdd:c=[],FrienPencydDel_Account:u=[],FriendUpInfo:l=[]}=e,p=l.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:t,from:r,to:i,reportTime:o,addedBlacklist:n,removedBlacklist:s,addedFriendList:d,removedFriendList:a,addedApplicationList:c.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:p,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),q.dispose(),g.dispose(),T.dispose(),b.dispose()}};export{W as default};