@tencentcloud/lite-chat 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,22 +1,37 @@
1
1
  {
2
2
  "name": "@tencentcloud/lite-chat",
3
- "version": "1.1.1",
3
+ "version": "1.2.1",
4
4
  "description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
5
- "main": "index.js",
6
- "module": "index.es.js",
5
+ "main": "standard.js",
6
+ "module": "standard.es.js",
7
7
  "types": "index.d.ts",
8
8
  "exports": {
9
- ".": {
10
- "import": "./index.es.js",
11
- "require": "./index.js",
12
- "types": "./index.d.ts"
9
+ ".": {
10
+ "import": "./standard.es.js",
11
+ "require": "./standard.js",
12
+ "types": "./index.d.ts"
13
+ },
14
+ "./basic": {
15
+ "import": "./basic.es.js",
16
+ "require": "./basic.js",
17
+ "types": "./index.d.ts"
18
+ },
19
+ "./standard": {
20
+ "import": "./standard.es.js",
21
+ "require": "./standard.js",
22
+ "types": "./index.d.ts"
23
+ },
24
+ "./professional": {
25
+ "import": "./professional.es.js",
26
+ "require": "./professional.js",
27
+ "types": "./index.d.ts"
28
+ },
29
+ "./plugins/*": {
30
+ "import": "./plugins/*.es.js",
31
+ "require": "./plugins/*.js",
32
+ "types": "./plugins/*.d.ts"
33
+ }
13
34
  },
14
- "./plugins/*": {
15
- "import": "./plugins/*.es.js",
16
- "require": "./plugins/*.js",
17
- "types": "./plugins/*.d.ts"
18
- }
19
- },
20
35
  "keywords": ["chat", "real-time chat", "uni-app", "React Native", "Donut", "push", "messaging", "IM", "trtc"],
21
36
  "repository": {
22
37
  "type": "git",
@@ -0,0 +1,8 @@
1
+ declare const avChatRoomPlugin: {
2
+ [key: string]: any;
3
+ };
4
+
5
+ export default avChatRoomPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/avchatroom' {
7
+ export default avChatRoomPlugin;
8
+ }
@@ -0,0 +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{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((s=s.apply(e,t||[])).next())}))}function s(e,t,s){return n(this,void 0,void 0,(function*(){const{helper:n,channel:o}=s,i=n.generateProtocolData({servcmd:e,data:t}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}"function"==typeof SuppressedError&&SuppressedError;const o="AV_MBR_LIST",i="AV_BAN_MBR",r={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},a={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},l=60,u=2603,c=2686,g=2688,p=3122;class h{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getPollingInterval()}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,(function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,(function*(){const{longPollingKey:n,startSequence:o,startBroadcastSeq:i,simplifiedMessage:r}=e;return s("group_open_long_polling_http_svc.get_msg",{Key:n,StartSeq:o,StartBroadcastSeq:i,DownsizeFlag:r,USP:1,HoldTime:90},t)}))}(e,this._core);this._onSuccess(this._groupID,t);const o=this._manager.getPollingInterval();this._runNextPolling(o)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}}))}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class _{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 m=e=>e===r.GROUP_TIPS_HAS_NO_ROAMING||e===r.GROUP_TIPS_HAS_ROAMING,d=e=>e===r.GROUP_SYSTEM_MESSAGE;function M(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:l,CCD:u,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:l,CloudCustomData:u,From_Account:c,IsSystemMsg:g,GroupInfo:I(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(m(n)||d(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===r.BROADCAST_MESSAGE||(e=>e===r.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;m(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=i.map((e=>({UserId:e}))));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);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 I(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r}=n,a=t(n,["GN","GT","F_Hd","F_NN"]),l=Object.assign({GroupName:s,GroupType:o},a);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),l}function 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:l,MsgMemberExtraInfo:u}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),u&&(g.MsgMemberExtraInfo=function(e){return e.map((e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}))}(u)),l&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(l)),g}));return Array.isArray(e)?s:s[0]}var f=new class{constructor(){this._name="MessageParser",this._sequenceList=new _(200),this._messageIDList=new _(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList(t,n);const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter((e=>!0===e.isModified)),r=o.filter((e=>!1===e.isModified)),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:l}}=this._core;i.length>0&&this._emitEvent({name:l,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e,t){t.sort(((e,t)=>e.MsgSeq-t.MsgSeq));const n=t.map((e=>e.MsgSeq));console.log(`${this._name}._sortServerMessageList groupID:${e} count:${n.length} sequenceList:${n}`),n.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:n,messageHelper:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],r=t.length;for(let l=0;l<r;l++){let r=t[l];if(o&&(r=M(r)),d(r.Event)&&Object.values(a).includes(r.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(r))continue;this._patchMessageType(r);const u=s.parseServerGroupMessage(r),c=this._createMessage(u);m(r.Event)&&this._avChatRoomHandler.isGroupAttributesUpdated(u)?this._avChatRoomHandler.handleGroupAttributesUpdated(u):null!==this._filterDuplicateMessage(c)&&(n.isMessageSentByCurrentInstance(c)||(1===u.isModified&&(c.isModified=!0),m(r.Event)&&this._updateLocalOnlineMemberCountFromTips(r),i.push(c)))}return i}_patchMessageType(e){const{OuterConstant:t}=this._core;m(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(r).includes(t)?(e=>e===r.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===r.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===r.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.event===r.GROUP_SYSTEM_MESSAGE&&(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:l,MsgSeq:u}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${l}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:u};a.push(c)})),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.createSSOLogData({method:"MessageStacked"}).setLogInfo({message:`count:${t} groupID:${e.join(",")}`}).end(),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],i=e.length;for(let n=0;n<i;n++){let i=e[n];s&&(i=M(i));const a=t.parseServerGroupMessage(i);if(!Object.values(r).includes(i.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${i.Event}`);continue}const l=this._createMessage(a);l.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(l.ID)||(o.push(l),this._broadcastMessageIDMap.set(l.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=l}=s,r=Date.now();let a=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(a)?a={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(a.latestUpdateTime=r,a.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,a)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const S=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},O=()=>{const e=S("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=S("polling_simplified_msg");return C(e)?parseInt(e,10):0};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._pollingInterval=300,this._pollingNoMessageCount=0,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,f.init(e,this),console.log("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],r=Object.values(a).includes(s.ReportType);i===t&&r&&this.reset(o)}}getPollingInterval(){return this._pollingInterval}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return!!this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)&&(this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e),!0)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){let e=[];return this._joinedGroupMap.size>0&&(e=[...this._joinedGroupMap.values()].filter((e=>e.type===TYPES.GRP_LIVE))),e}handleJoinGroupResult(e){return n(this,void 0,void 0,(function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a}=e,{groupID:l}=r;return yield this._preCheck(r),this._joinedGroupMap.set(l,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${l}`),a.length>0&&f.onMessageReceived(l,a,!0),t(i)?{status:o.JOIN_STATUS_SUCCESS,group:r}:this.startMessageLongPolling(e)}))}_preCheck(e){return n(this,void 0,void 0,(function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o}}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=S("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:g,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[i,r]=this._joinedGroupMap.entries().next().value;r.selfInfo.role===n.GRP_MBR_ROLE_OWNER?this._parentPlugin.groupDataHandler.deleteLocalGroup(i):yield o(i),this.reset(i)}))}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingInterval=O(),this._startPolling(i),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(console.log(`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new h({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)this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t);else{const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0?(0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._pollingInterval=O()),f.onMessageReceived(e,i)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===(()=>{const e=S("polling_no_msg_count");return C(e)?parseInt(e,10):20})()&&(this._pollingInterval=O()+(()=>{const e=S("polling_interval_plus");return C(e)?parseInt(e,10):2e3})())),r.length>0&&f.onBroadcastMessageReceived(r)}_handleFailure(e,t){console.warn(`${this._name}._handleFailure groupID:${e} error:`,t)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter((t=>t.type===e.GRP_AVCHATROOM))),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}_stopPolling(e){if(e){console.log(`${this._name}._stopPolling groupID:${e}`);const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),void this._onlineMemberCountMap.delete(e)}console.log(`${this._name}._stopPolling all`);for(const e of this._pollingInstanceMap.values())e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear()}reset(e){this._stopPolling(e),this._pollingInterval=300,this._pollingNoMessageCount=0,this._startBroadcastSequence=1,f.reset()}};var E=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.joinGroup(e),{data:{group:{type:s}}}=n;return s===t.GRP_AVCHATROOM?R.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&&R.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&&R.reset(e),n}))}};var A=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:s}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===s.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(o))return this._getGroupMemberList(e)}return this._parentPlugin.groupMember.getGroupMemberList(e)}))}_getGroupMemberList(e){return n(this,void 0,void 0,(function*(){const t="_getGroupMemberList",{helper:o}=this._core;try{const o=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,offset:o=0}=e;return s("group_open_avchatroom_http_svc.get_members",{GroupId:n,Timestamp:o},t)}))}(e,this._core),{MemberList:i=[],NextTimestamp:r=0}=o||{},a=this._handleMemberList(i);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${a.length} nextOffset:${r}`),{code:0,data:{memberList:a,offset:r}}}catch(e){const n=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_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 P=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*(){return s("group_open_http_svc.get_online_member_num",{GroupId:e},t)}))}(e,this._core),{OnlineMemberNum:o=0,ExpireTime:i=l}=t||{},r=Date.now(),a={lastSyncTime:r,latestUpdateTime:r,lastReqTime:r,memberCount:o,expireTime:i};return R.updateLocalOnlineMemberCount(e,a),{memberCount:o}}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 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:o,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new o.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(o.checkBusinessCapabilityBits(i))return this._deleteGroupMember(e);throw new o.ChatError({functionName:t,code:p})}return this._parentPlugin.groupMember.deleteGroupMember(e)}))}_deleteGroupMember(e){return n(this,void 0,void 0,(function*(){const t="_deleteGroupMember",{appStore:{groupStore:o},helper:i}=this._core,{groupID:r,duration:a=0,userIDList:l}=e;if(0===a)throw new i.ChatError({functionName:t,code:c});try{yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,userIDList:o,duration:i,reason:r}=e;return s("group_open_http_svc.ban_group_member",{GroupId:n,Members_Account:o,Duration:i,Description:r},t)}))}(e,this._core),console.log(`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:o.getGroup(r),userIDList:l}}}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var T=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:o,markType:i,enableMark:r,userIDList:a=[]}=e,l=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,operationType:o,memberList:i}=e;return s("group_open_avchatroom_http_svc.modify_user_info",{GroupId:n,CommandType:o,MemberList:i},t)}))}(l,this._core),{MemberList:u=[]}=e||{},{successUserIDList:c,failureUserIDList:g}=this._handleResult(u,a);return console.log(`${this._name}.${t} ok, groupID:${o} markType:${i} enableMark:${r} success:${c.length} fail:${g.length}`),{code:0,data:{successUserIDList:c,failureUserIDList:g}}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map((e=>({Member_Account:e,Marks:[n]})))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach((t=>{e.find((e=>e.Member_Account===t))?n.push(t):s.push(t)})),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){console.log("AVChatRoomAction.init"),E.init(e,t),y.init(e,t),G.init(e,t),A.init(e,t),P.init(e,t),D.init(e,t),T.init(e)}};var N=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),console.log("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s}=this._core,{groupID:o,longPollingKey:i,longPollingSequence:r=1}=e;if(n(i))return console.warn(`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});R.hasPollingInstance(o)&&this.stopMessageLongPolling({groupID:o});const a=R.getJoinedLiveList();!t.isUnlimitedAVChatRoom()&&a.length>0&&this.stopMessageLongPolling({groupID:a[0]});const l={groupID:o,type:s.GRP_LIVE};return console.log(`${this._name}.startMessageLongPolling groupID:${o} longPollingKey:${i} longPollingSequence:${r}`),R.startMessageLongPolling({group:l,longPollingKey:i,startSequence:r})}stopMessageLongPolling(e){const{groupID:t}=e;return R.reset(t),console.log(`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}};var $=new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),R.init(t,n),L.init(t,n),N.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(){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{$ as default};
@@ -0,0 +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{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((s=s.apply(e,t||[])).next())}))}function s(e,t,s){return n(this,void 0,void 0,(function*(){const{helper:n,channel:o}=s,i=n.generateProtocolData({servcmd:e,data:t}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}"function"==typeof SuppressedError&&SuppressedError;const o="AV_MBR_LIST",i="AV_BAN_MBR",r={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},a={GROUP_DISMISSED:5,QUIT_GROUP:8,AVCHATROOM_MEMBER_BANNED:21},l=60,u=2603,c=2686,g=2688,p=3122;class h{constructor(e){const{core:t,manager:n,groupID:s,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=n,this._timeoutID=-1,this._isRunning=!1,this._groupID=s,this._getRequestParams=o,this._onSuccess=i,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getPollingInterval()}`)}isRunning(){return this._isRunning}_request(){return n(this,void 0,void 0,(function*(){try{const e=this._getRequestParams(this._groupID),t=yield function(e,t){return n(this,void 0,void 0,(function*(){const{longPollingKey:n,startSequence:o,startBroadcastSeq:i,simplifiedMessage:r}=e;return s("group_open_long_polling_http_svc.get_msg",{Key:n,StartSeq:o,StartBroadcastSeq:i,DownsizeFlag:r,USP:1,HoldTime:90},t)}))}(e,this._core);this._onSuccess(this._groupID,t);const o=this._manager.getPollingInterval();this._runNextPolling(o)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}}))}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class _{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 m=e=>e===r.GROUP_TIPS_HAS_NO_ROAMING||e===r.GROUP_TIPS_HAS_ROAMING,d=e=>e===r.GROUP_SYSTEM_MESSAGE;function M(n){const s=function(e){const{E:n,MCT:s,MR:o,MP:i,MTS:r,GId:a,MS:l,CCD:u,F_Account:c,IsSys:g,GInf:p,MsgBody:h}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:n,MsgClientTime:s,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:l,CloudCustomData:u,From_Account:c,IsSystemMsg:g,GroupInfo:I(p),MsgBody:v(h)},_)}(n);return function(t){const{Event:n}=t;(m(n)||d(n))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");s=n,(s===r.BROADCAST_MESSAGE||(e=>e===r.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;m(n)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:n={},MsgMemberExtraInfo:s,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);s||(e.MsgBody.MsgMemberExtraInfo=i.map((e=>({UserId:e}))));1!==r||s||(e.MsgBody.MsgMemberExtraInfo=[{UserId:n.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},n)}(t);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 I(e){const n=e||{},{GN:s,GT:o,F_Hd:i,F_NN:r}=n,a=t(n,["GN","GT","F_Hd","F_NN"]),l=Object.assign({GroupName:s,GroupType:o},a);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),l}function 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:l,MsgMemberExtraInfo:u}=e,c=t(e,["O_Account","Opt","L_Account","RT","UDF","OpInf","OnlineInf","MsgMemberExtraInfo"]),g=Object.assign({Operator_Account:n,OpType:s,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}(a)),u&&(g.MsgMemberExtraInfo=function(e){return e.map((e=>{const{Img:n,NN:s}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:n,NickName:s},o)}))}(u)),l&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:n}=e;return{ExpireTime:t,OnlineMemberNum:n}}(l)),g}));return Array.isArray(e)?s:s[0]}var f=new class{constructor(){this._name="MessageParser",this._sequenceList=new _(200),this._messageIDList=new _(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(t,n,s=!1){this._sortServerMessageList(t,n);const o=this._handleMessageList(t,n);if(0===o.length)return;if(!s){const{appStore:{conversationStore:n},OuterConstant:{CONV_GROUP:s}}=this._core,i=(t=>{const{core:{common:{getMessagePreviewText:n}}}=e;return{lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:n(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null}})(o[o.length-1]);n.updateConversation(`${s}${t}`,{lastMessage:i})}this._checkMessageStacked(o);const i=o.filter((e=>!0===e.isModified)),r=o.filter((e=>!1===e.isModified)),{OuterEvent:{MESSAGE_RECEIVED:a,MESSAGE_MODIFIED:l}}=this._core;i.length>0&&this._emitEvent({name:l,data:i}),r.length>0&&this._emitEvent({name:a,data:r})}_sortServerMessageList(e,t){t.sort(((e,t)=>e.MsgSeq-t.MsgSeq));const n=t.map((e=>e.MsgSeq));console.log(`${this._name}._sortServerMessageList groupID:${e} count:${n.length} sequenceList:${n}`),n.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:n,messageHelper:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],r=t.length;for(let l=0;l<r;l++){let r=t[l];if(o&&(r=M(r)),d(r.Event)&&Object.values(a).includes(r.MsgBody.ReportType)){this._onGroupDismissed(e);break}if(null===this._filterMessageItem(r))continue;this._patchMessageType(r);const u=s.parseServerGroupMessage(r),c=this._createMessage(u);m(r.Event)&&this._avChatRoomHandler.isGroupAttributesUpdated(u)?this._avChatRoomHandler.handleGroupAttributesUpdated(u):null!==this._filterDuplicateMessage(c)&&(n.isMessageSentByCurrentInstance(c)||(1===u.isModified&&(c.isModified=!0),m(r.Event)&&this._updateLocalOnlineMemberCountFromTips(r),i.push(c)))}return i}_patchMessageType(e){const{OuterConstant:t}=this._core;m(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(r).includes(t)?(e=>e===r.MESSAGE_REVOKED)(t)?(this._handleMessageRevoked(e),null):(e=>e===r.LIVE_CUSTOM_DATA)(t)?(this._onLiveCustomData(e),null):(e=>e===r.MESSAGE_REACTION)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:n}=this._core;let s=n.CONV_GROUP;e.event===r.GROUP_SYSTEM_MESSAGE&&(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:l,MsgSeq:u}=e,c={conversationID:`${t.CONV_GROUP}${s}`,ID:`${n}-${o}-${l}`,revoker:i,revokeReason:r,revokerInfo:{userID:i,nick:"",avatar:""},sequence:u};a.push(c)})),0!==a.length&&this._emitEvent({name:n,data:a})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{ToGroupId:n,MsgSeq:s,MsgTimeStamp:o,MsgBody:i}=e,r=(null==i?void 0:i.MsgContent)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${n} sequence:${s} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;if(t>=100&&this._reportMessageStackedCount<5){const e=this._avChatRoomHandler.getJoinedGroups();this._core.ssoLog.createSSOLogData({method:"MessageStacked"}).setLogInfo({message:`count:${t} groupID:${e.join(",")}`}).end(),this._reportMessageStackedCount+=1}}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:n}}=this._core,s=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],i=e.length;for(let n=0;n<i;n++){let i=e[n];s&&(i=M(i));const a=t.parseServerGroupMessage(i);if(!Object.values(r).includes(i.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${i.Event}`);continue}const l=this._createMessage(a);l.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(l.ID)||(o.push(l),this._broadcastMessageIDMap.set(l.ID,1))}o.length>0&&this._emitEvent({name:n,data:o})}_updateLocalOnlineMemberCountFromTips(e){const{utils:{isEmpty:t}}=this._core,{ToGroupId:n,MsgBody:{OnlineMemberInfo:s}}=e;if(t(s))return;const{OnlineMemberNum:o=0,ExpireTime:i=l}=s,r=Date.now();let a=this._avChatRoomHandler.getLocalOnlineMemberCount(n);t(a)?a={lastReqTime:0,lastSyncTime:0,latestUpdateTime:r,memberCount:o,expireTime:i}:(a.latestUpdateTime=r,a.memberCount=o),this._avChatRoomHandler.updateLocalOnlineMemberCount(n,a)}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};const S=t=>{const{core:{store:n}}=e;return(n.get("cloudConfig")||{})[t]},C=t=>{const{core:{utils:{isUndefined:n}}}=e;return!n(t)},O=()=>{const e=S("polling_interval");return C(e)?parseInt(e,10):300},b=()=>{const e=S("polling_simplified_msg");return C(e)?parseInt(e,10):0};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._pollingInterval=300,this._pollingNoMessageCount=0,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,f.init(e,this),console.log("AVChatRoomHandler.init")}onAVChatRoomSystemNotification(e){const{OuterConstant:{GRP_AVCHATROOM:t}}=this._core,{GroupTips:n=[]}=e;for(let e=0;e<n.length;e++){const{MsgBody:s,GroupInfo:{GroupId:o,GroupType:i}}=n[e],r=Object.values(a).includes(s.ReportType);i===t&&r&&this.reset(o)}}getPollingInterval(){return this._pollingInterval}isPollingSimplifiedMessage(){return 0!==b()}isGroupAttributesUpdated(e){return!!this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)&&(this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e),!0)}updateLocalOnlineMemberCount(e,t){this._onlineMemberCountMap.set(e,t)}getLocalOnlineMemberCount(e){return this._onlineMemberCountMap.get(e)||{}}hasPollingInstance(e){return this._pollingInstanceMap.has(e)}getJoinedLiveList(){let e=[];return this._joinedGroupMap.size>0&&(e=[...this._joinedGroupMap.values()].filter((e=>e.type===TYPES.GRP_LIVE))),e}handleJoinGroupResult(e){return n(this,void 0,void 0,(function*(){const{utils:{isUndefined:t},OuterConstant:{CONV_GROUP:n},apiMap:{getConversationProfile:s},OuterConstant:o}=this._core,{longPollingKey:i,group:r,historyMessageList:a}=e,{groupID:l}=r;return yield this._preCheck(r),this._joinedGroupMap.set(l,r),this._parentPlugin.groupDataHandler.updateLocalGroup([r]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),s(`${n}${l}`),a.length>0&&f.onMessageReceived(l,a,!0),t(i)?{status:o.JOIN_STATUS_SUCCESS,group:r}:this.startMessageLongPolling(e)}))}_preCheck(e){return n(this,void 0,void 0,(function*(){const{common:t,OuterConstant:n,helper:s,apiMap:{quitGroup:o}}=this._core;if(t.isUnlimitedAVChatRoom()){if(this._pollingInstanceMap.size>(()=>{const e=S("polling_count_limit");return C(e)&&e>0?parseInt(e,10):20})())throw new s.ChatError({code:g,message:"the count of longPolling exceeds the max limit"});return}if(0===this._joinedAVChatRoomCount())return;if(e.type===n.GRP_LIVE)return;const[i,r]=this._joinedGroupMap.entries().next().value;r.selfInfo.role===n.GRP_MBR_ROLE_OWNER?this._parentPlugin.groupDataHandler.deleteLocalGroup(i):yield o(i),this.reset(i)}))}startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:n,startSequence:s=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:n,startSequence:s}),this._pollingInterval=O(),this._startPolling(i),{status:t.JOIN_STATUS_SUCCESS,group:o}}_startPolling(e){if(console.log(`${this._name}._startPolling groupID:${e}`),this._pollingInstanceMap.has(e)){const t=this._pollingInstanceMap.get(e);return void((null==t?void 0:t.isRunning())||null==t||t.start())}const t=new h({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)this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t);else{const{longPollingKey:t,startSequence:s}=this._pollingRequestInfoMap.get(e)||{};console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${s} errorCode:${n}`)}}_handleResponseData(e,t){const{Key:n,NextSeq:s,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;n&&s&&this._pollingRequestInfoMap.set(e,{longPollingKey:n,startSequence:s}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0?(0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._pollingInterval=O()),f.onMessageReceived(e,i)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===(()=>{const e=S("polling_no_msg_count");return C(e)?parseInt(e,10):20})()&&(this._pollingInterval=O()+(()=>{const e=S("polling_interval_plus");return C(e)?parseInt(e,10):2e3})())),r.length>0&&f.onBroadcastMessageReceived(r)}_handleFailure(e,t){console.warn(`${this._name}._handleFailure groupID:${e} error:`,t)}_joinedAVChatRoomCount(){const{OuterConstant:e}=this._core;let t=[];return this._joinedGroupMap.size>0&&(t=this.getJoinedGroups().filter((t=>t.type===e.GRP_AVCHATROOM))),t.length}_hasJoinedAVChatRoom(e){return this._joinedGroupMap.has(e)}getJoinedGroups(){return[...this._joinedGroupMap.values()]}_stopPolling(e){if(e){console.log(`${this._name}._stopPolling groupID:${e}`);const{appStore:{conversationStore:t},OuterConstant:{CONV_GROUP:n}}=this._core;t.deleteConversation(`${n}${e}`);const s=this._pollingInstanceMap.get(e);return null==s||s.stop(),this._parentPlugin.groupDataHandler.deleteLocalGroup(e),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),void this._onlineMemberCountMap.delete(e)}console.log(`${this._name}._stopPolling all`);for(const e of this._pollingInstanceMap.values())e.stop();this._pollingInstanceMap.clear(),this._pollingRequestInfoMap.clear(),this._joinedGroupMap.clear(),this._onlineMemberCountMap.clear()}reset(e){this._stopPolling(e),this._pollingInterval=300,this._pollingNoMessageCount=0,this._startBroadcastSequence=1,f.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:{group:{type:s}}}=n;return s===t.GRP_AVCHATROOM?R.handleJoinGroupResult(n.data):n}))}};var E=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:n}=e;n.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return n(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,n=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:s}}=n;return s===t.GRP_AVCHATROOM&&R.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&&R.reset(e),n}))}};var A=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:s}=this._core,{groupID:i}=e,r=t.getGroup(i);if((null==r?void 0:r.type)===s.GRP_AVCHATROOM){if(n.checkBusinessCapabilityBits(o))return this._getGroupMemberList(e)}return this._parentPlugin.groupMember.getGroupMemberList(e)}))}_getGroupMemberList(e){return n(this,void 0,void 0,(function*(){const t="_getGroupMemberList",{helper:o}=this._core;try{const o=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,offset:o=0}=e;return s("group_open_avchatroom_http_svc.get_members",{GroupId:n,Timestamp:o},t)}))}(e,this._core),{MemberList:i=[],NextTimestamp:r=0}=o||{},a=this._handleMemberList(i);return console.log(`${this._name}.${t} ok, groupID:${e.groupID} count:${a.length} nextOffset:${r}`),{code:0,data:{memberList:a,offset:r}}}catch(e){const n=new o.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_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 P=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*(){return s("group_open_http_svc.get_online_member_num",{GroupId:e},t)}))}(e,this._core),{OnlineMemberNum:o=0,ExpireTime:i=l}=t||{},r=Date.now(),a={lastSyncTime:r,latestUpdateTime:r,lastReqTime:r,memberCount:o,expireTime:i};return R.updateLocalOnlineMemberCount(e,a),{memberCount:o}}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 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:o,OuterConstant:r}=this._core,{groupID:a}=e,l=n.getGroup(a);if(s(l))throw new o.ChatError({functionName:t,code:u});if(l.type===r.GRP_AVCHATROOM){if(o.checkBusinessCapabilityBits(i))return this._deleteGroupMember(e);throw new o.ChatError({functionName:t,code:p})}return this._parentPlugin.groupMember.deleteGroupMember(e)}))}_deleteGroupMember(e){return n(this,void 0,void 0,(function*(){const t="_deleteGroupMember",{appStore:{groupStore:o},helper:i}=this._core,{groupID:r,duration:a=0,userIDList:l}=e;if(0===a)throw new i.ChatError({functionName:t,code:c});try{yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,userIDList:o,duration:i,reason:r}=e;return s("group_open_http_svc.ban_group_member",{GroupId:n,Members_Account:o,Duration:i,Description:r},t)}))}(e,this._core),console.log(`${this._name}.${t} ok, groupID:${r}`);return{code:0,data:{group:o.getGroup(r),userIDList:l}}}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var T=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:o,markType:i,enableMark:r,userIDList:a=[]}=e,l=this._generateRequestData(e);try{const e=yield function(e,t){return n(this,void 0,void 0,(function*(){const{groupID:n,operationType:o,memberList:i}=e;return s("group_open_avchatroom_http_svc.modify_user_info",{GroupId:n,CommandType:o,MemberList:i},t)}))}(l,this._core),{MemberList:u=[]}=e||{},{successUserIDList:c,failureUserIDList:g}=this._handleResult(u,a);return console.log(`${this._name}.${t} ok, groupID:${o} markType:${i} enableMark:${r} success:${c.length} fail:${g.length}`),{code:0,data:{successUserIDList:c,failureUserIDList:g}}}catch(e){const n=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}_generateRequestData(e){const{groupID:t,markType:n,enableMark:s,userIDList:o=[]}=e,i=!0===s?1:2,r=[...o];r.length>500&&console.warn(`${this._name}._generateRequestData, the length of userIDList cannot exceed 500`);return{groupID:t,operationType:i,memberList:r.map((e=>({Member_Account:e,Marks:[n]})))}}_handleResult(e,t){const n=[],s=[];return e.length===t.length?(n.push(...t),{successUserIDList:n,failureUserIDList:s}):(t.forEach((t=>{e.find((e=>e.Member_Account===t))?n.push(t):s.push(t)})),{successUserIDList:n,failureUserIDList:s})}};var L=new class{init(e,t){console.log("AVChatRoomAction.init"),y.init(e,t),E.init(e,t),G.init(e,t),A.init(e,t),P.init(e,t),D.init(e,t),T.init(e)}};var N=new class{constructor(){this._name="LiveHandler"}init(e){this._core=e;const{helper:t}=e;t.registerExperimentalAPI("startMessageLongPolling",this),t.registerExperimentalAPI("stopMessageLongPolling",this),console.log("LiveHandler.init")}startMessageLongPolling(e){const{common:t,utils:{isEmpty:n},OuterConstant:s}=this._core,{groupID:o,longPollingKey:i,longPollingSequence:r=1}=e;if(n(i))return console.warn(`${this._name}.startMessageLongPolling longPollingKey is empty.`),Promise.resolve({});R.hasPollingInstance(o)&&this.stopMessageLongPolling({groupID:o});const a=R.getJoinedLiveList();!t.isUnlimitedAVChatRoom()&&a.length>0&&this.stopMessageLongPolling({groupID:a[0]});const l={groupID:o,type:s.GRP_LIVE};return console.log(`${this._name}.startMessageLongPolling groupID:${o} longPollingKey:${i} longPollingSequence:${r}`),R.startMessageLongPolling({group:l,longPollingKey:i,startSequence:r})}stopMessageLongPolling(e){const{groupID:t}=e;return R.reset(t),console.log(`${this._name}.stopMessageLongPolling ok, groupID:${t}`),Promise.resolve({groupID:t})}};return new class{constructor(){this.name="AVChatRoom"}install(t,n){this._core=t,e.init(t),R.init(t,n),L.init(t,n),N.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(){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)}}}));
@@ -0,0 +1,9 @@
1
+ declare const cloudSearchPlugin: {
2
+ [key: string]: any;
3
+ };
4
+
5
+ export default cloudSearchPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/cloud-search' {
7
+ export default cloudSearchPlugin;
8
+ }
9
+
@@ -0,0 +1 @@
1
+ function e(e,r){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&r.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)r.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(t[o[s]]=e[o[s]])}return t}function r(e,r,t,o){return new(t||(t=Promise))((function(s,n){function a(e){try{c(o.next(e))}catch(e){n(e)}}function i(e){try{c(o.throw(e))}catch(e){n(e)}}function c(e){var r;e.done?s(e.value):(r=e.value,r instanceof t?r:new t((function(e){e(r)}))).then(a,i)}c((o=o.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(e){this.core=e}};const o="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,c=20,u={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||(!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5")},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||(!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND")},l={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&e>=1&&e<=100||"count must be a number between 1 and 100"},h={required:!1,rules:["string"],allowEmpty:!0},y={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core;if(!Array.isArray(e))return"groupTypeList should be an array";const o=[r.GRP_PUBLIC,r.GRP_COMMUNITY,r.GRP_WORK,r.GRP_MEETING];let s=!1;for(let r=0;r<e.length;r++)if(-1===o.indexOf(e[r])){s=!0;break}return!s||"groupTypeList should be supported group type"}},p=e=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:r=>"number"==typeof r&&r>=0||`${e} should be a number >= 0';`}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core;return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},g={searchCloudMessages:{keywordList:u,keywordListMatchType:d,cursor:h,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core,o=[r.MSG_TEXT,r.MSG_IMAGE,r.MSG_AUDIO,r.MSG_FILE,r.MSG_VIDEO,r.MSG_LOCATION,r.MSG_CUSTOM,r.MSG_MERGER];let s=!1;for(let r=0;r<e.length;r++)if(-1===o.indexOf(e[r])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=t.core;return!(!(null==e?void 0:e.startsWith(r.CONV_C2C))&&!(null==e?void 0:e.startsWith(r.CONV_GROUP))&&e!==r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:p("timePosition"),timePeriod:p("timePeriod")},searchCloudUsers:{keywordList:u,keywordListMatchType:d,cursor:h,count:l,miniBirthday:p("miniBirthday"),maxBirthday:p("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:u,keywordListMatchType:d,cursor:h,count:l,groupTypeList:y,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:u,keywordListMatchType:d,cursor:h,count:l,groupTypeList:y}},C={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};var L=new class{install(e){this._core=e,t.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:C,params:g})}searchCloudMessages(s){return r(this,void 0,void 0,(function*(){try{const{OuterConstant:o,helper:n,ssoLog:a}=this._core,i=a.createSSOLogData({method:"searchCloudMessages"}),{conversationID:c,timePeriod:u,timePosition:d}=s,l=e(s,["conversationID","timePeriod","timePosition"]),h=Object.assign({count:100},l);c&&(c.startsWith(o.CONV_C2C)?h.account=c.replace(o.CONV_C2C,""):c.startsWith(o.CONV_GROUP)&&(h.groupID=c.replace(o.CONV_GROUP,""))),this._setTimeRangeParams(h,{timePeriod:u,timePosition:d});const y=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,senderUserIDList:n,messageTypeList:a,endTime:i,startTime:c,cursor:u,account:d,groupID:l}=e,h={Count:r,KeywordList:o,MatchType:s,SendUserIDList:n,MsgTypeList:a,EndTime:i,StartTime:c,Cursor:u,PeerAccount:d,GroupID:l};return t.core.common.buildAndSendPacket({servcmd:"message_search.query",data:h})}))}(h);if(!y)return{code:0,data:{}};const{ErrorCode:p,ErrorInfo:m,TotalCount:g,Cursor:C="",ConversationMsgs:L=[]}=y;if(0!==p)throw{errorCode:p,errorInfo:m};const f=`keywordList:${s.keywordList} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} res: totalCount:${g}`;i.setLogInfo({message:f}).end();const w=L.map((e=>{const{MsgList:r,Count:t,GroupID:a,UserID:i}=e,c=a?`${o.CONV_GROUP}${a}`:`${o.CONV_C2C}${i}`;if(this._isSearchingAllConversations(s)&&t>1)return{conversationID:c,messageCount:t,messageList:[]};const u=r.map((e=>n.isEmpty(a)?function(e,r){const t=r.OuterConstant.CONV_C2C,o=r.message.messageHelper.parseServerPushMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}));return s.setElement(o.elements),s}(e,this._core):function(e,r){const t=r.OuterConstant.CONV_GROUP,o=r.message.messageHelper.parseServerGroupMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},o),{conversationType:t,flow:"in"}));return s.setElement(o.elements),s}(e,this._core)));return{conversationID:c,messageCount:t,messageList:u}}));return{code:0,data:{searchResultList:w,cursor:C,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:o,functionName:"searchCloudMessages"})}}))}searchCloudUsers(o){return r(this,void 0,void 0,(function*(){var a;try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:c,count:u=i}=o,d=e(o,["keywordListMatchType","count"]),l=Object.assign({count:u,keywordListMatchType:c===n.AND?1:0},d);this._setBirthdayRangeParams(l,o);const h=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,miniBirthday:n,maxBirthday:a,cursor:i,gender:c}=e,u={Count:r,Keywords:o,KeywordMatchType:s,Cursor:i,UserBirthStart:n,UserBirthEnd:a,Gender:c};return t.core.common.buildAndSendPacket({servcmd:"user_search.query",data:u})}))}(l);if(!h)return{error:0,data:{}};const{ErrorCode:y,ErrorInfo:p,TotalCount:m,Cursor:g="",Users:C=[]}=h;if(0!==y)throw{errorCode:y,errorInfo:p};const L=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${m}`;s.setLogInfo({message:L}).end();const f=[];for(let e=0,r=C.length;e<r;e++){const{UserID:r,ProfileItems:t}=C[e];if(r===this._core.OuterConstant.USER_NOT_FOUND||""===r)continue;const o=t.map((e=>({tag:e.Tag,value:e.StrValue}))),s=null===(a=this._core.user.userProfile)||void 0===a?void 0:a.createProfile(r,o);f.push(s)}return{code:0,data:{searchResultList:f,cursor:g,totalCount:m}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudUsers"})}}))}searchCloudGroupMembers(o){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:a=c,keywordListMatchType:i}=o,u=e(o,["count","keywordListMatchType"]),d=Object.assign({count:a,keywordListMatchType:i===n.AND?1:0},u),l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,groupTypeList:n,cursor:a,groupIDList:i}=e,c={Count:r,Keywords:o,KeywordMatchType:s,Cursor:a,GroupType:n,GroupIdList:i};return t.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:c})}))}(d);if(!l)return{code:0,data:{}};const{ErrorCode:h,ErrorInfo:y,GroupMembers:p,Cursor:m,TotalCount:g}=l;if(0!==h)throw{errorCode:h,errorInfo:y};const C=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${g}`;s.setLogInfo({message:C}).end();const L=new Map;return p.forEach((e=>{const{GroupID:r,GroupName:t,GroupType:o,GroupFaceUrl:s,GroupMemberUserName:n,GroupMemberUserID:a,GroupMemberNameCard:i}=e,c={groupID:r,name:t,type:o,avatar:s},u={userID:a,nick:n,nameCard:i};if(L.has(r)){const e=L.get(r);e.memberList.push(u),L.set(r,e)}else L.set(r,{groupInfo:c,memberList:[u]})})),{code:0,data:{searchResultList:[...L.values()],cursor:m,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}}))}searchCloudGroups(o){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:i=a,keywordListMatchType:c}=o,u=e(o,["count","keywordListMatchType"]),d=Object.assign({count:i,keywordListMatchType:c===n.AND?1:0},u),l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,groupTypeList:n,cursor:a}=e,i={Count:r,Keywords:o,KeywordMatchType:s,Cursor:a,GroupType:n};return t.core.common.buildAndSendPacket({servcmd:"group_search.query",data:i})}))}(d);if(!l)return{code:0,data:{}};const{ErrorCode:h,ErrorInfo:y,Groups:p,Cursor:m,TotalCount:g}=l;if(0!==h)throw{errorCode:h,errorInfo:y};const C=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${g}`;s.setLogInfo({message:C}).end();return{code:0,data:{searchResultList:(null==p?void 0:p.map((e=>function(e){const{GroupFaceUrl:r,GroupID:t,GroupIntroduction:o,GroupMemberNum:s,GroupName:n,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:c,GroupType:u}=e;return{avatar:r,groupID:t,introduction:o,memberCount:s,name:n,ownerTinyID:a,ownerID:i,ownerNick:c,type:u}}(e))))||[],cursor:m,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroups"})}}))}_setTimeRangeParams(e,{timePeriod:r,timePosition:t}){r&&r>0&&(e.startTime=t&&t>0?t-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),t&&t>0&&(e.endTime=t)}_handleError({errorCode:e,errorMessage:r,searchType:t,functionName:s}){const{ssoLog:n,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":t!==o&&27003===e?i="SearchParamsError":t!==o&&60018===e&&(i="SearchOverLimit");const c=new a.ChatError({code:i,message:r});throw n.getSSOLogData(s).setError(c).end(),c}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){const{miniBirthday:t,maxBirthday:o}=r;void 0!==t&&(e.miniBirthday=t,void 0===o&&(e.maxBirthday=4294967295)),void 0!==o&&(e.maxBirthday=o)}};export{L as default};
@@ -0,0 +1 @@
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatCloud-search"]=r()}(this,(function(){"use strict";function e(e,r){var o={};for(var t in e)Object.prototype.hasOwnProperty.call(e,t)&&r.indexOf(t)<0&&(o[t]=e[t]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(t=Object.getOwnPropertySymbols(e);s<t.length;s++)r.indexOf(t[s])<0&&Object.prototype.propertyIsEnumerable.call(e,t[s])&&(o[t[s]]=e[t[s]])}return o}function r(e,r,o,t){return new(o||(o=Promise))((function(s,n){function a(e){try{u(t.next(e))}catch(e){n(e)}}function i(e){try{u(t.throw(e))}catch(e){n(e)}}function u(e){var r;e.done?s(e.value):(r=e.value,r instanceof o?r:new o((function(e){e(r)}))).then(a,i)}u((t=t.apply(e,r||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const o=new class{init(e){this.core=e}};const t="message",s="user",n={OR:"or",AND:"and"},a=20,i=20,u=20,c={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||(!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5")},d={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||(!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND")},l={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&e>=1&&e<=100||"count must be a number between 1 and 100"},h={required:!1,rules:["string"],allowEmpty:!0},p={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core;if(!Array.isArray(e))return"groupTypeList should be an array";const t=[r.GRP_PUBLIC,r.GRP_COMMUNITY,r.GRP_WORK,r.GRP_MEETING];let s=!1;for(let r=0;r<e.length;r++)if(-1===t.indexOf(e[r])){s=!0;break}return!s||"groupTypeList should be supported group type"}},y=e=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:r=>"number"==typeof r&&r>=0||`${e} should be a number >= 0';`}),m={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core;return!![r.GENDER_FEMALE,r.GENDER_MALE].includes(e)||"gender is invalid"}},g={searchCloudMessages:{keywordList:c,keywordListMatchType:d,cursor:h,senderUserIDList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!!(Array.isArray(e)&&e.length<=5)||"senderUserIDList should be an array and length <= 5"},messageTypeList:{required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core,t=[r.MSG_TEXT,r.MSG_IMAGE,r.MSG_AUDIO,r.MSG_FILE,r.MSG_VIDEO,r.MSG_LOCATION,r.MSG_CUSTOM,r.MSG_MERGER];let s=!1;for(let r=0;r<e.length;r++)if(-1===t.indexOf(e[r])){s=!0;break}return!s||"messageTypeList should be supported message type"}},conversationID:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:r}=o.core;return!(!(null==e?void 0:e.startsWith(r.CONV_C2C))&&!(null==e?void 0:e.startsWith(r.CONV_GROUP))&&e!==r.CONV_SYSTEM)||"conversationID is invalid"}},timePosition:y("timePosition"),timePeriod:y("timePeriod")},searchCloudUsers:{keywordList:c,keywordListMatchType:d,cursor:h,count:l,miniBirthday:y("miniBirthday"),maxBirthday:y("maxBirthday"),gender:m},searchCloudGroupMembers:{keywordList:c,keywordListMatchType:d,cursor:h,count:l,groupTypeList:p,groupIDList:{required:!1,rules:["array"],allowEmpty:!0}},searchCloudGroups:{keywordList:c,keywordListMatchType:d,cursor:h,count:l,groupTypeList:p}},C={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0,searchCloudGroups:!0};return new class{install(e){this._core=e,o.init(e),e.helper.registerApi({apiName:"searchCloudMessages",context:this}),e.helper.registerApi({apiName:"searchCloudUsers",context:this}),e.helper.registerApi({apiName:"searchCloudGroupMembers",context:this}),e.helper.registerApi({apiName:"searchCloudGroups",context:this}),e.helper.registerValidateConfig({auth:C,params:g})}searchCloudMessages(s){return r(this,void 0,void 0,(function*(){try{const{OuterConstant:t,helper:n,ssoLog:a}=this._core,i=a.createSSOLogData({method:"searchCloudMessages"}),{conversationID:u,timePeriod:c,timePosition:d}=s,l=e(s,["conversationID","timePeriod","timePosition"]),h=Object.assign({count:100},l);u&&(u.startsWith(t.CONV_C2C)?h.account=u.replace(t.CONV_C2C,""):u.startsWith(t.CONV_GROUP)&&(h.groupID=u.replace(t.CONV_GROUP,""))),this._setTimeRangeParams(h,{timePeriod:c,timePosition:d});const p=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,senderUserIDList:n,messageTypeList:a,endTime:i,startTime:u,cursor:c,account:d,groupID:l}=e,h={Count:r,KeywordList:t,MatchType:s,SendUserIDList:n,MsgTypeList:a,EndTime:i,StartTime:u,Cursor:c,PeerAccount:d,GroupID:l};return o.core.common.buildAndSendPacket({servcmd:"message_search.query",data:h})}))}(h);if(!p)return{code:0,data:{}};const{ErrorCode:y,ErrorInfo:m,TotalCount:g,Cursor:C="",ConversationMsgs:f=[]}=p;if(0!==y)throw{errorCode:y,errorInfo:m};const L=`keywordList:${s.keywordList} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} res: totalCount:${g}`;i.setLogInfo({message:L}).end();const w=f.map((e=>{const{MsgList:r,Count:o,GroupID:a,UserID:i}=e,u=a?`${t.CONV_GROUP}${a}`:`${t.CONV_C2C}${i}`;if(this._isSearchingAllConversations(s)&&o>1)return{conversationID:u,messageCount:o,messageList:[]};const c=r.map((e=>n.isEmpty(a)?function(e,r){const o=r.OuterConstant.CONV_C2C,t=r.message.messageHelper.parseServerPushMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},t),{conversationType:o,flow:"in"}));return s.setElement(t.elements),s}(e,this._core):function(e,r){const o=r.OuterConstant.CONV_GROUP,t=r.message.messageHelper.parseServerGroupMessage(e),s=r.message.messageFactory.createMessage(Object.assign(Object.assign({},t),{conversationType:o,flow:"in"}));return s.setElement(t.elements),s}(e,this._core)));return{conversationID:u,messageCount:o,messageList:c}}));return{code:0,data:{searchResultList:w,cursor:C,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:t,functionName:"searchCloudMessages"})}}))}searchCloudUsers(t){return r(this,void 0,void 0,(function*(){var a;try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:u,count:c=i}=t,d=e(t,["keywordListMatchType","count"]),l=Object.assign({count:c,keywordListMatchType:u===n.AND?1:0},d);this._setBirthdayRangeParams(l,t);const h=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,miniBirthday:n,maxBirthday:a,cursor:i,gender:u}=e,c={Count:r,Keywords:t,KeywordMatchType:s,Cursor:i,UserBirthStart:n,UserBirthEnd:a,Gender:u};return o.core.common.buildAndSendPacket({servcmd:"user_search.query",data:c})}))}(l);if(!h)return{error:0,data:{}};const{ErrorCode:p,ErrorInfo:y,TotalCount:m,Cursor:g="",Users:C=[]}=h;if(0!==p)throw{errorCode:p,errorInfo:y};const f=`keywordList:${t.keywordList} keywordListMatchType:${t.keywordListMatchType} cursor:${t.cursor} count:${t.count} res: totalCount:${m}`;s.setLogInfo({message:f}).end();const L=[];for(let e=0,r=C.length;e<r;e++){const{UserID:r,ProfileItems:o}=C[e];if(r===this._core.OuterConstant.USER_NOT_FOUND||""===r)continue;const t=o.map((e=>({tag:e.Tag,value:e.StrValue}))),s=null===(a=this._core.user.userProfile)||void 0===a?void 0:a.createProfile(r,t);L.push(s)}return{code:0,data:{searchResultList:L,cursor:g,totalCount:m}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:s,functionName:"searchCloudUsers"})}}))}searchCloudGroupMembers(t){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroupMembers"}),{count:a=u,keywordListMatchType:i}=t,c=e(t,["count","keywordListMatchType"]),d=Object.assign({count:a,keywordListMatchType:i===n.AND?1:0},c),l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,groupTypeList:n,cursor:a,groupIDList:i}=e,u={Count:r,Keywords:t,KeywordMatchType:s,Cursor:a,GroupType:n,GroupIdList:i};return o.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:u})}))}(d);if(!l)return{code:0,data:{}};const{ErrorCode:h,ErrorInfo:p,GroupMembers:y,Cursor:m,TotalCount:g}=l;if(0!==h)throw{errorCode:h,errorInfo:p};const C=`keywordList:${t.keywordList} keywordListMatchType:${t.keywordListMatchType} cursor:${t.cursor} count:${t.count} res: totalCount:${g}`;s.setLogInfo({message:C}).end();const f=new Map;return y.forEach((e=>{const{GroupID:r,GroupName:o,GroupType:t,GroupFaceUrl:s,GroupMemberUserName:n,GroupMemberUserID:a,GroupMemberNameCard:i}=e,u={groupID:r,name:o,type:t,avatar:s},c={userID:a,nick:n,nameCard:i};if(f.has(r)){const e=f.get(r);e.memberList.push(c),f.set(r,e)}else f.set(r,{groupInfo:u,memberList:[c]})})),{code:0,data:{searchResultList:[...f.values()],cursor:m,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:s,functionName:"searchCloudGroupMembers"})}}))}searchCloudGroups(t){return r(this,void 0,void 0,(function*(){try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudGroups"}),{count:i=a,keywordListMatchType:u}=t,c=e(t,["count","keywordListMatchType"]),d=Object.assign({count:i,keywordListMatchType:u===n.AND?1:0},c),l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:t,keywordListMatchType:s,groupTypeList:n,cursor:a}=e,i={Count:r,Keywords:t,KeywordMatchType:s,Cursor:a,GroupType:n};return o.core.common.buildAndSendPacket({servcmd:"group_search.query",data:i})}))}(d);if(!l)return{code:0,data:{}};const{ErrorCode:h,ErrorInfo:p,Groups:y,Cursor:m,TotalCount:g}=l;if(0!==h)throw{errorCode:h,errorInfo:p};const C=`keywordList:${t.keywordList} keywordListMatchType:${t.keywordListMatchType} cursor:${t.cursor} count:${t.count} res: totalCount:${g}`;s.setLogInfo({message:C}).end();return{code:0,data:{searchResultList:(null==y?void 0:y.map((e=>function(e){const{GroupFaceUrl:r,GroupID:o,GroupIntroduction:t,GroupMemberNum:s,GroupName:n,GroupOwnerTinyID:a,GroupOwnerUserID:i,GroupOwnerUserName:u,GroupType:c}=e;return{avatar:r,groupID:o,introduction:t,memberCount:s,name:n,ownerTinyID:a,ownerID:i,ownerNick:u,type:c}}(e))))||[],cursor:m,totalCount:g}}}catch(e){const{errorCode:r,errorInfo:o}=e||{};this._handleError({errorCode:r,errorInfo:o,searchType:s,functionName:"searchCloudGroups"})}}))}_setTimeRangeParams(e,{timePeriod:r,timePosition:o}){r&&r>0&&(e.startTime=o&&o>0?o-r:this._core.helper.timeManager.getServerTimeSeconds()-r),e.startTime&&e.startTime<0&&(e.startTime=void 0),o&&o>0&&(e.endTime=o)}_handleError({errorCode:e,errorMessage:r,searchType:o,functionName:s}){const{ssoLog:n,helper:a}=this._core;let i=e;60020===e?i="SearchUnable":o!==t&&27003===e?i="SearchParamsError":o!==t&&60018===e&&(i="SearchOverLimit");const u=new a.ChatError({code:i,message:r});throw n.getSSOLogData(s).setError(u).end(),u}_isSearchingAllConversations(e){return this._core.helper.isEmpty(e.conversationID)}_setBirthdayRangeParams(e,r){const{miniBirthday:o,maxBirthday:t}=r;void 0!==o&&(e.miniBirthday=o,void 0===t&&(e.maxBirthday=4294967295)),void 0!==t&&(e.maxBirthday=t)}}}));
@@ -1 +1 @@
1
- function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function r(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,r)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",s="GROUP",n="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",u="TIMImageElem",d="TIMSoundElem",c="TIMFileElem",g="TIMFaceElem",p="TIMVideoFileElem",v="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",C="TIMCustomElem",_="TIMRelayElem",M="AcceptAndNotify",y="AcceptNotNotify",f="Discard",T="AcceptNotNotifyExceptAt";var I,L,S;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(I||(I={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(L||(L={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(S||(S={}));const E=e=>void 0===e,D=e=>"string"==typeof e,O=e=>"function"==typeof Array.isArray?Array.isArray(e):"array"===(e=>{var t;return null===(t=Object.prototype.toString.call(e).match(/^\[object (.*)\]$/))||void 0===t?void 0:t[1].toLowerCase()})(e),R=e=>O(e)||(e=>null!==e&&"object"==typeof e)(e),k=(e,t,s,n)=>{if(!R(e)||!R(t))return 0;let o=0;const i=Object.keys(t);let a;for(let r=0,l=i.length;r<l;r++)if(a=i[r],!(E(t[a])||s&&s.includes(a)))if(R(e[a])&&R(t[a]))o+=k(e[a],t[a],s,n);else{if(n&&n.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},P=(e,t)=>{if(E(t))return"";switch(e){case l:return t.text||"";case u:return"[Image]";case v:return"[Location]";case d:return"[Voice]";case p:return"[Video]";case c:return"[File]";case C:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case g:return"[Animated Sticker]";case _:return"[Chat Record]";default:return""}},G=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:P(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function N(e){const t=[];if(!D(e))return t;const s=e.length;if(0===s)return t;for(let n=s-1;n>=0;n--)"1"===e[n]&&t.push(2**(s-n-1));return t}class U{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=G(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark="",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){E(this.userProfile)&&this.type===t?this.userProfile={}:E(this.groupProfile)&&this.type===s&&(this.groupProfile={}),this.subType&&this.type===s&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;E(o)||(this.subType!==i?a&&this.type===s||a&&this.type===n||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=G(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:n,time:o}=e;return this.type===t&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}}var A=new class{constructor(){this._name="ConversationFactory",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0,this._pagingConvIDMap=new Map,this._convMap=new Map,this._convTotalUnreadCount=0}install(e){this._core=e;const{notificationCenter:t,InnerEvent:s,helper:n}=e;n.registerApi("getConversationList",this),n.registerApi("getConversationProfile",this),n.registerApi("setMessageRead",this),n.registerApi("getTotalUnreadMessageCount",this),n.registerApi("setConversationDraft",this),t.subscribeInnerEvent(s.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(s.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(s.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(s.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(s.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(s.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(s.DESTROY,this._dispose,this),console.log(`${this._name}.install`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this._onConversationListUpdate()}_handleMessageDeleted(e){var s,n,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(a.length||0)-1;e>=0;e--)if(!a[e].isDeleted){r=a[e];break}const l=this._convMap.get(e);if(!l)return;let u=!1;l.lastMessage.lastSequence===r.sequence&&l.lastMessage.lastTime===r.time||((null===(i=null===(o=this._core)||void 0===o?void 0:o.helper)||void 0===i?void 0:i.isEmpty(r))&&(r=void 0),l.updateLastMessage(r),u=!0),e.startsWith(t)&&this._updateUnreadCount(e),u&&(this._onConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. \n update conversationID:${e} with lastMessage:`,l.lastMessage))}_handleMessageRevoked(e){console.log(`${this._name}._handleMessageRevoked`,JSON.stringify(e));const{messageList:t=[],updateUnreadCount:s=!0}=e;if(0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this._convMap.get(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))})),o&&this._onConversationListUpdate()}_handleMessageModified(e){var t,s;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:n,message:o}=e,i=this._convMap.get(n);if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(i))return;const{lastMessage:a}=i;a&&a.lastTime===o.time&&a.lastSequence===o.sequence&&a.version!==o.version&&(a.type=o.type,a.payload=o.payload,a.messageForShow=P(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this._onConversationListUpdate(),console.log(`${this._name} conversationID:${n} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this._onConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){try{this._pagingStatus=I.PENDING;const s=yield function(t,s){return e(this,void 0,void 0,(function*(){const{pagingTimeStamp:e,pagingStartIndex:n,pagingPinnedTimeStamp:o,pagingPinnedStartIndex:i}=t;try{const t="recentcontact.page_get",a=null==s?void 0:s.helper.generateProtocolData({servcmd:t,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:null==s?void 0:s.store.get("login").userId,StartIndex:n,TimeStamp:e,TopStartIndex:i,TopTimeStamp:o}}),r=`${a.head.seq}${t}`;return yield s.channel.sendPacket(a,{requestId:r})}catch(e){throw console.warn(`ConversationService.pagingGetConvList error: ${e}`),e}}))}({pagingTimeStamp:t?this._pagingTimeStamp:0,pagingStartIndex:t?this._pagingStartIndex:0,pagingPinnedTimeStamp:t?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:t?this._pagingPinnedStartIndex:0},this._core);if(s){const{CompleteFlag:e,SessionItem:n=[],TimeStamp:o,StartIndex:i,TopTimeStamp:a,TopStartIndex:r}=s;if(n.length>0){const e=this._getConvOptions(n);this._pagingConvIDMap=new Map([...this._pagingConvIDMap,...e.map((e=>[e.conversationID,1]))]),this._updateLocalConvList({conversationOptionsList:e,isFromGetConversations:!0,updateUnreadCount:!0}),this._onConversationListUpdate()}this._pagingTimeStamp=o,this._pagingStartIndex=i,this._pagingPinnedTimeStamp=a,this._pagingPinnedStartIndex=r,1!==e&&this._pagingGetConvList(t)}}catch(e){throw console.error(`${this._name}._pagingGetConvList fail:`,e),e}}))}_getConvOptions(e){const n=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return n.map((e=>{var n,i,a,r,l,u,d,c,g,p,v,h;if(E(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===L.C2C){const s={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},p=null===(a=null===(i=null===(n=this._core)||void 0===n?void 0:n.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[s]);return{conversationID:`${t}${e.userID}`,type:t,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(r=e.lastMsg)||void 0===r?void 0:r.elements[0])?null===(l=e.lastMsg)||void 0===l?void 0:l.elements[0].type:null,payload:(null===(u=e.lastMsg)||void 0===u?void 0:u.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(d=e.lastMsg)||void 0===d?void 0:d.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(g=null===(c=e.lastMsg)||void 0===c?void 0:c.revokerInfo)||void 0===g?void 0:g.revoker)||null},unreadCount:0,userProfile:p,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${s}${e.groupID}`,type:s,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(p=e.lastMsg)||void 0===p?void 0:p.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(v=e.lastMsg)||void 0===v?void 0:v.revokerInfo)||void 0===h?void 0:h.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}))}_convertConvKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,s,n,o;if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(n=e.MsgBody[0])||void 0===n?void 0:n.MsgType,a=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:a,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var s;if(!t)return t;const n=this._core.message.messageFactory.getElementClass(e);return n?null===(s=n.parseServerPushElement(t))||void 0===s?void 0:s.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=M:1===e?t=f:2===e?t=y:3===e&&(t=T),t}_patchTypeAndPayload(e){const{event:t,elements:s=[]}=e.lastMsg||{};return E(t)?{type:s[0]?s[0].type:null,payload:s[0]?this._amendLayersOverLimitProp(s[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:s=0}=e,n=t-s;return n>0?n:0}_updateLocalConvList(e){const{newConvList:t}=this._getTmpConvListMapping(e);this._convMap=new Map(this._sortConvList([...this._convMap])),this._core.store.set("conversation",{conversationMap:this._convMap}),console.log(`${this._name}._updateLocalConvList newConvList: ${t.length}`)}_getTmpConvListMapping(e){const{conversationOptionsList:n,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],u=null==n?void 0:n.length;for(let e=0;e<u;e++){const u=new U(n[e]),{conversationID:d,type:c}=u;if(!this._isNonExistentAccount(d))if(this._convMap.has(d)){const l=this._convMap.get(d);if(o){this._convMap.set(d,u),c===t?u.unreadCount=l.unreadCount:c===s&&(u.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:d,tmpConversation:u,lastMessage:n[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:d,lastMessage:n[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:u.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(u),this._convMap.set(d,u)}return{newConvList:l}}_isNonExistentAccount(e){let s;return e.startsWith(t)&&(s=e.replace(t,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}_mergeConversationInfo(e){var t,s;const{conversationID:n,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(n),u=["unreadCount","allowType","adminForbidType","payload"];!1===r&&u.push("lastMessage"),a&&u.push("isPinned"),E(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);k(l,o,u,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:n,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&n){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===s&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],s=[],n=[],o=[];return e.forEach((e=>{var i,a,r,l;!0===e[1].isPinned?(null===(a=null===(i=this._core)||void 0===i?void 0:i.helper)||void 0===a?void 0:a.isEmpty(e[1].lastMessage.lastTime))?s.push(e):t.push(e):(null===(l=null===(r=this._core)||void 0===r?void 0:r.helper)||void 0===l?void 0:l.isEmpty(e[1].lastMessage.lastTime))?o.push(e):n.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_getLocalConvList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}_isConvNeedShow(e){const t=this._getLocalConversation(e);if(E(t))return!0;const o=t.type===n,i=t.type===s&&t.subType===a,l=t.type===s&&t.subType===r;return!(o||i||l)}_getLocalConversation(e){return this._convMap.get(e)}_updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this._getLocalConversation(e),a=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const r=i.unreadCount,l=null==a?void 0:a.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return r!==l&&(i.unreadCount=l,o=!0,console.log(`${this._name}._updateUnreadCount\n from ${r} to ${l}, conversationID:${e}`),!0===t&&this._onConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_onConversationListUpdate(){var e;const t=this._getLocalConvList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.CONVERSATION_LIST_UPDATED,data:t}),this._onTotalUnreadCountUpdate()}_onTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._onTotalUnreadCountUpdate from ${this._convTotalUnreadCount} to ${t}`),this._convTotalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(E(e))return this._getLocalConvList();if(O(e)){if(0===e.length)return[];return this._getLocalConvList().filter((t=>e.includes(t.conversationID)))}if((e=>{if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let s=t;for(;null!==Object.getPrototypeOf(s);)s=Object.getPrototypeOf(s);return t===s})(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this._getLocalConvList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,n){return n!==t&&n!==s||e.type===n}_filterGroupName(e,t){return!D(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(s=t)||!("number"==typeof s&&!Number.isNaN(s-0)||"object"==typeof s&&s.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var s}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_recoverConversations(){return e(this,void 0,void 0,(function*(){try{yield this.syncConvList(),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.RECOVER_CONVERSATIONS_COMPLETED)}catch(e){console.debug(e)}}))}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}getConversationProfile(n){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(n)?e=this._convMap.get(n):(e=new U({conversationID:n}),(e=>D(e)&&e.slice(0,3)===t)(n)?(e.type=t,e.userProfile={userID:n.replace(t,"")}):(e.type=s,e.groupProfile={groupID:n.replace(s,"")}),this._convMap.set(n,e)),{code:0,data:{conversation:e}}}))}setMessageRead(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}.setMessageRead ok, ${JSON.stringify(t)}`)}))}setConversationDraft(t){return e(this,void 0,void 0,(function*(){return console.log(`${this._name}.setConversationDraft , ${JSON.stringify(t)}`),{code:0,data:{conversation:{}}}}))}getTotalUnreadMessageCount(){const e=this._getLocalConvList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==M||(t+=e.unreadCount))})),t}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.RE_LOGIN,this._recoverConversations,this),e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.NEW_MESSAGE,this._handleNewMessage,this),e.unSubscribeInnerEvent(t.MESSAGE_DELETED,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(t.MESSAGE_REVOKED,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(t.MESSAGE_MODIFIED,this._handleMessageModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const b={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0},F={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!e.startsWith("C2C")&&!e.startsWith("GROUP"))||"conversationID is invalid."}]};var x={install:function(e){A.install(e),e.helper.registerValidateConfig({auth:b,params:F})},handleLoginSuccess:function(){A.handleLoginSuccess()}};export{x as default};
1
+ const e=new class{init(e){this.core=e}};function t(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,3)===n.CONV_C2C},s=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,5)===n.CONV_GROUP},o=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t===n.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{core:{utils:{isString:n}}}=e,s=[];if(!n(t))return s;const o=t.length;if(0===o)return s;for(let e=o-1;e>=0;e--)"1"===t[e]&&s.push(2**(o-e-1));return s}function a(t){const{OuterConstant:n}=e.core;let s="";return 0===t?s=n.MSG_REMIND_ACPT_AND_NOTE:1===t?s=n.MSG_REMIND_DISCARD:2===t?s=n.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(s=n.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function c(t){const{OuterConstant:n}=e.core;let s;return t.startsWith(n.CONV_C2C)&&(s=t.replace(n.CONV_C2C,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}var l,u,d,_,p;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(l||(l={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(u||(u={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(_||(_={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(p||(p={}));var h;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(h||(h={}));class C{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){const{core:{OuterConstant:t,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:n(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:n,utils:{isUndefined:s}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;s(o)||(this.subType!==n.GRP_AVCHATROOM?i&&this.type===n.CONV_GROUP||i&&this.type===n.CONV_TOPIC||r&&this.type===n.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:n}}=e,{sequence:s,time:o}=t;return this.type===n.CONV_C2C&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n.CONV_GROUP&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{OuterConstant:n}}=e;let[...s]=t.groupAtType;s.includes(n.CONV_AT_ME)||s.includes(n.CONV_AT_ALL)||(s=[n.CONV_AT_ALL_AT_ME]);const o={from:t.from,groupID:t.groupID,messageSequence:t.sequence,atTypeArray:s,__random:t.__random,__sequence:t.__sequence};this.groupAtInfoList.push(o)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var g=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:n,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{MESSAGE_PUSH:r,NEW_MESSAGE:a,MESSAGE_DELETED:c,MESSAGE_REVOKED:l,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:d,LOGOUT:_,DESTROY:p}}=e;this._conversationStore=s,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this);const{InnerEventSubType:{GROUP_AT_TIPS:h}}=n;n.subscribeInnerEvent(a,this._handleNewMessage,this),n.subscribeInnerEvent(r,h,this._handleNewGroupAtTips,this),n.subscribeInnerEvent(c,this._handleMessageDeleted,this),n.subscribeInnerEvent(l,this._handleMessageRevoked,this),n.subscribeInnerEvent(u,this._handleMessageModified,this),n.subscribeInnerEvent(d,this._handleConversationUpdated,this),n.subscribeInnerEvent(_,this._reset,this),n.subscribeInnerEvent(p,this._dispose,this),console.log(`${this._name}.init`)}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:n=[],groupTipList:s=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;n.forEach((e=>{const{conversationID:t,unreadCount:n}=e,s=this.getLocalConversation(t);s&&s.unreadCount!==n&&(s.updateUnreadCount({nextUnreadCount:n,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(s)}_handleGroupAtTipsSynced(e){for(let t=0;t<e.length;t++)12===e[t].Event&&this._handleNewGroupAtTips(e[t])}_handleGroupListSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,n=e.result[t.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:s}}=this._core;let o=!1;for(let e=0;e<n.length;e++){const t=n[e],i=`${s}${t.groupID}`;if(!this.hasLocalConversation(i))continue;const r=this.getLocalConversation(i);r.groupProfile=JSON.parse(JSON.stringify(t)),r.lastMessage.lastSequence<t.nextMessageSeq&&(r.lastMessage.lastSequence=t.nextMessageSeq-1),r.subType||(r.subType=t.type),o=!0}o&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e.result||{};if(console.log(`${this._name}._handleNewMessage, conversationUpdateFieldList length:`,t.length,e),0===t.length)return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:n,GroupAtType:s,MsgRandom:o,ClientSeq:i}=e;let r={};t?r=this._convertGroupAtTipsKey(t):n?r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(n)),{sync:!0}):s&&(r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(e)),{sync:!0})),r.__random=o,r.__sequence=i,this._groupAtTipsList.push(r)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:n,MsgSeq:s,GroupAtType:o}=e;return{from:t,groupID:n,sequence:s,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,n=e.getCurrentUserID();let s=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==n){const n=this.getLocalConversation(`${t.CONV_GROUP}${o}`);n&&(n.updateGroupAtInfoList(e),s=!0)}})),s&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,n;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:s},OuterConstant:o}=this._core,i=(null==s?void 0:s.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:n=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this.getLocalConversation(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:n}=e,s=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(s))return;const{lastMessage:r}=s;if(r){const e=(null==n?void 0:n[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(){this.emitConversationListUpdate()}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:n}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(n),console.log(`${this._name}.updateLocalConversationList newConversationList: ${n.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:n,isFromGetConversations:s,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,a=[],l=null==n?void 0:n.length;for(let e=0;e<l;e++){const l=new C(n[e]),{conversationID:u,type:d}=l;if(!c(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(s){this.setLocalConversation(u,l),d===t.CONV_C2C?l.unreadCount=(null==a?void 0:a.unreadCount)||0:d===t.CONV_GROUP&&(l.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:l,lastMessage:n[e].lastMessage,isFromGetConversations:s,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:n[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:l.unreadCount,isFromGetConversations:s,isUnreadC2CMessage:i}))}else a.push(l),this.setLocalConversation(u,l)}return{newConversationList:a}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:n,lastMessage:s,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:u}}=this._core;c(i)&&s&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=s.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);u(r,n,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:n,lastMessage:s,isInstantMessage:o}=e,i=this.getLocalConversation(n);if(i&&s){const{payload:e,nameCard:n,nick:r,cloudCustomData:a=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=n,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],n=[],s=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?s.push(t):n.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],n=[],{OuterConstant:{CONV_GROUP:s,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===s){const e=i.replace(s,"");n.push(e)}})),t.length>0&&this._updateC2CConversation(t),n.length>0&&this._updateGroupConversation(n)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:n},appStore:{userStore:s},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${n}${o}`);if(r){const n=(null===(t=s.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=n,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core;let s=!1;e.forEach((e=>{const o=n.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,s=!0)})),s&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:n}=this._core,s=t.type===n.CONV_TOPIC,o=t.type===n.CONV_GROUP&&t.subType===n.GRP_ROOM,i=t.type===n.CONV_GROUP&&t.subType===n.GRP_LIVE;return!(s||o||i)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),r=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageDataHandler)||void 0===s?void 0:s.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,n=this.getLocalConversationList();this._emitEvent({name:t,data:n}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e}=this._core,t=this.getLocalConversationList();let n=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(n+=t.unreadCount))})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,n]of e)this.setLocalConversation(t,n)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let n=!1;e.forEach((e=>{const s=this.getLocalConversation(e);(null==s?void 0:s.messageRemindType)!==t&&(s.messageRemindType=t,n=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${n}`),n&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:n,lastReadTime:s=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(n);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],n=s&&t.time>s,r=o&&t.sequence>o;if(!n&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],n=t.findIndex((e=>!1===e[1].isPinned));t.splice(n,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:n,MESSAGE_REVOKED:s,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:c}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,c,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(n,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(s,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};function v(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var m=new class{constructor(){this._name="SyncConversationList",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s,constants:o}=e;s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.CONVERSATION_RECOVER,this._syncConversationListOnReOnline,this),s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_LOGIN,o.WORKFLOW_STEP.CONVERSATION_LIST_SYNC,this._syncConversationList,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}isSyncCompleted(){return this._pagingStatus===l.RESOLVED}_syncConversationListOnReOnline(){return t(this,void 0,void 0,(function*(){return this._syncConversationList()}))}_syncConversationList(){return t(this,void 0,void 0,(function*(){yield this._pagingGetConversationList(!0),this._pagingStatus=l.RESOLVED,g.emitConversationListUpdate()}))}_pagingGetConversationList(e){return t(this,void 0,void 0,(function*(){try{this._pagingStatus=l.PENDING;const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:r}=e;return v("recentcontact.page_get",{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:t,StartIndex:o,TimeStamp:s,TopStartIndex:r,TopTimeStamp:i},n)}))}({fromAccount:n.getCurrentUserID(),pagingTimeStamp:e?this._pagingTimeStamp:0,pagingStartIndex:e?this._pagingStartIndex:0,pagingPinnedTimeStamp:e?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:e?this._pagingPinnedStartIndex:0},this._core),{CompleteFlag:o,SessionItem:i=[],TimeStamp:r,StartIndex:a,TopTimeStamp:c,TopStartIndex:u}=s||{};if(i.length>0){const e=this._getConversationOptions(i);g.updateLocalConversationList({conversationUpdateFieldList:e,isFromGetConversations:!0,updateUnreadCount:!0}),g.emitConversationListUpdate()}this._pagingTimeStamp=r,this._pagingStartIndex=a,this._pagingPinnedTimeStamp=c,this._pagingPinnedStartIndex=u,1!==o&&this._pagingGetConversationList(e)}catch(e){throw console.error(`${this._name}._pagingGetConversationList fail:`,e),e}}))}_getConversationOptions(e){const{utils:{isUndefined:t}}=this._core,n=this._convertConversationKey(e);return this._filterValidConversations(n).map((e=>(t(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===u.C2C?this._assembleC2COption(e):this._assembleGroupOption(e))))}_filterValidConversations(e){return e.filter((({type:e,userID:t})=>e===u.C2C&&!c(t)||2===e))}_assembleC2COption(e){var t,n,s,o,i,a;const{OuterConstant:c}=this._core,l=this._createUserprofile(e);return{conversationID:`${c.CONV_C2C}${e.userID}`,type:c.CONV_C2C,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(t=e.lastMsg)||void 0===t?void 0:t.elements[0])?null===(n=e.lastMsg)||void 0===n?void 0:n.elements[0].type:null,payload:(null===(s=e.lastMsg)||void 0===s?void 0:s.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(o=e.lastMsg)||void 0===o?void 0:o.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:this._computeIsPeerRead(e),revoker:(null===(a=null===(i=e.lastMsg)||void 0===i?void 0:i.revokerInfo)||void 0===a?void 0:a.revoker)||null},unreadCount:0,userProfile:l,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}_createUserprofile(e){var t;const{userID:n,nick:s,peerAvatar:o}=e,i=[{tag:"Tag_Profile_IM_Nick",value:s},{tag:"Tag_Profile_IM_Image",value:o}];return null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(n,i)}_computeIsPeerRead(e){const{common:t}=this._core,n=t.getCurrentUserID(),{lastC2CMsgFromAccount:s,time:o,c2cPeerReadTime:i}=e;return s===n&&o<=i}_assembleGroupOption(e){var t,n,s;const{OuterConstant:o}=this._core;return{conversationID:`${o.CONV_GROUP}${e.groupID}`,type:o.CONV_GROUP,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(t=e.lastMsg)||void 0===t?void 0:t.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(s=null===(n=e.lastMsg)||void 0===n?void 0:n.revokerInfo)||void 0===s?void 0:s.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}_convertConversationKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",r=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.MsgType,r=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:r,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(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}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){const{OuterConstant:t}=this._core;let n="";return 0===e?n=t.MSG_REMIND_ACPT_AND_NOTE:1===e?n=t.MSG_REMIND_DISCARD:2===e?n=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(n=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}_patchTypeAndPayload(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core,{event:s,elements:o=[]}=e.lastMsg||{};return n(s)?{type:o[0]?o[0].type:null,payload:o[0]?this._amendLayersOverLimitProp(o[0].content):null}:{type:t.MSG_GRP_TIP,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s:0}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};var f=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:m.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:n,isPlainObject:s}}=this._core;if(t(e))return g.getLocalConversationList();if(n(e)){if(0===e.length)return[];return g.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(s(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return g.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:n}=this._core;return t!==n.CONV_C2C&&t!==n.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:n}}=this._core;return!n(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:n}}=this._core;return!n(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_filterGroupAtInfo(e,t){let n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}};function O(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var M=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:s}=e;return O("openim.get_c2c_peer_mute_notifications",{To_Account:t,Peer_Account:s},n)}))}({toAccount:n.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=s||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:n}=e,s=`${this._core.OuterConstant.CONV_C2C}${t}`,o=a(n);g.patchMessageRemindType([s],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var E=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const n=yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:s}=e;return O("group_open_http_svc.get_group_self_member_info",{GroupIdList:t,ResponseFilter:s},n)}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=n||{};s.forEach((e=>{var t;const{GroupId:n,MemberList:s}=e,o=(null===(t=s[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${n}`;g.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var I=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let l=g.getLocalConversation(e);if(o(e))return c.data.conversation=l,c;let u=!1;const d=n(e)?t:s;if(a(l)&&(u=!0,l=new C({conversationID:e,type:d})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=l,null==l?void 0:l.getProfileCompleted())return c;if(d===t){const n=e.replace(t,"");yield this._handleC2CConversation(l,n),u&&(yield M.get([n]))}if(d===s){const t=e.replace(s,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(l,t),u&&l.groupProfile.type!==i&&(yield E.get([t]))}return c}))}_handleC2CConversation(e,n){return t(this,void 0,void 0,(function*(){var t,s;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,u=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[n]});if(0===(null==u?void 0:u.data.length))throw new i.ChatError({code:h.USER_OR_GRP_NOT_FOUND});e.userProfile=null==u?void 0:u.data[0];const d=null===(s=c.getFriend(n))||void 0===s?void 0:s.remark;r(d)||e.remark===d||(e.remark=d),e.setProfileCompleted();const _=g.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${_}`),_?a.updateConversation(l,e):g.appendToPinnedConversation(e)}))}_handleGroupConversation(e,n){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:s}}=this._core,{conversationID:o}=e,i=yield t({groupID:n});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=g.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?s.updateConversation(o,e):g.appendToPinnedConversation(e)}))}};var T=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return g.getTotalUnreadMessageCount()}};var L=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRead",context:this})}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:s}=e;if(!t(s)){const{UinPairReadArray:e=[]}=s;e.forEach((e=>{const{From_Account:t,LastReadTime:s}=e,o=`${n.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${s}`),g.markMessageAsRead({conversationID:o,lastReadTime:s}),g.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:s}=e.MsgBody;n(s)||s.forEach((e=>{const{GroupId:n,LastReadMsgSeq:s}=e,o=`${t.CONV_GROUP}${n}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${s}`),g.markMessageAsRead({conversationID:o,lastReadSequence:s}),g.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,n;const{OuterConstant:s}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=g.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r.groupAtInfoList));if(r.type===s.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;if(r.type===s.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e)}if(r.type===s.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e)}return r.type===s.CONV_SYSTEM&&(r.unreadCount=0),g.emitConversationListUpdate(),i}))}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const n=g.getLocalConversation(e);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const{common:n}=this._core,o=s.map((e=>({From_Account:e.from,To_Account:n.getCurrentUserID(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,n){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e;return v("openim.deletemsg",{DelMsgList:t},n)}))}({messageListToDelete:o},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=g.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&g.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){return v("openim.msgreaded",e,n)}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${n}`),g.markMessageAsRead({conversationID:e,lastReadTime:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:s}=e;return v("group_open_http_svc.msg_read_report",{GroupId:t,MsgReadedSeq:s},n)}))}({groupID:e.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${n}`),g.markMessageAsRead({conversationID:e,lastReadSequence:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var S=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:n}}=this._core;if(!n(e))return;const{OuterConstant:s}=this._core;let o=!1;e.forEach((e=>{const{Type:n,To_Account:i,GroupId:r}=e;let a;1===n?a=g.getLocalConversation(`${s.CONV_C2C}${i}`):2===n&&(a=g.getLocalConversation(`${s.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&g.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r}=this._core,{conversationID:a,isPinned:c}=e,l={code:0,data:{conversationID:a}},u=g.getLocalConversation(a);if(u&&u.isPinned===c)return l;if(o(a))return u&&(u.isPinned=c),g.emitConversationListUpdate(!0),l;try{let e=null;n(a)?e={Type:1,To_Account:a.replace(i.CONV_C2C,"")}:s(a)&&(e={Type:2,GroupId:a.replace(i.CONV_GROUP,"")});const o=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:s,itemList:o}=e;return v("recentcontact.top",{From_Account:t,OperationType:s,RecentContactItem:o},n)}))}({fromAccount:r.getCurrentUserID(),operationType:!0===c?1:2,itemList:[e]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${a} isPinned:${c}.`),o){if(u)u.isPinned!==c&&(u.isPinned=c);else{const e=new C({conversationID:a,type:n(a)?i.CONV_C2C:i.CONV_GROUP,isPinned:c});g.setLocalConversation(a,e)}g.emitConversationListUpdate(!0)}return l}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var R=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:n}=this._core,s=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&s.push(`${n.CONV_C2C}${o}`),2===t&&s.push(`${n.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return console.log(`${this._name}.deleteConversation conversationID:${e}`),void(yield this._deleteConversation({conversationIDList:[e],flag:_.ONLY_CONVERSATIONID}));const n=Object.assign({},e);n.conversationIDList.length>100&&(n.conversationIDList=n.conversationIDList.slice(0,100)),yield this._deleteConversation(n)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:n=!0,flag:s=0}=e;console.log(`${this._name}._deleteConversation conversationIDList:${t} clearHistoryMessage:${n}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,n)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===_.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var n;if(!g.hasLocalConversation(e))return!1;const s=null===(n=g.getLocalConversation(e))||void 0===n?void 0:n.type;return s!==t.CONV_GROUP||this._hasLocalGroup(e)?s===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,n){return t(this,void 0,void 0,(function*(){const{OuterConstant:s,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:n?1:0};if(e.forEach((e=>{var t;if(g.hasLocalConversation(e)){const n=(null===(t=g.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(n,"");n===s.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):n===s.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:s,clearHistoryMessage:o}=e;return v("recentcontact.batch_delete",{From_Account:t,ContactItem:s,ClearRamble:o},n)}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const n=1===e.type?`${s.CONV_C2C}${e.To_Account}`:`${s.CONV_GROUP}${e.ToGroupid}`;t.push(n)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{g.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&g.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=g.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(g.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&g.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core,s=e.replace(t,"");return!!n.getGroup(s)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var y=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:n}=e;if(console.log(`${this._name} conversationID:${t} draftText:${n}`),!g.hasLocalConversation(t))throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});const s=g.getLocalConversation(t);return null==s||s.setDraftText(n),g.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var D=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(n,s){return t(this,void 0,void 0,(function*(){n.length>30&&(console.warn(`${this._name}.set userIDList length:${n.length} exceeds limit 30`),n.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:s}=e.core.OuterConstant;return{[t]:0,[n]:1,[s]:2}}()[s],i=yield function(e,n){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:s}=e;return O("openim.set_c2c_peer_mute_notifications",{Peer_Account:t,Mute_Notifications:s},n)}))}({userIDList:n,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:s}=e;a.push({userID:t,code:s});const o=n.indexOf(t);o>-1&&n.splice(o,1)}));const c=[],l=[],{OuterConstant:u}=this._core;return n.forEach((e=>{l.push(`${u.CONV_C2C}${e}`),c.push({userID:e})})),g.patchMessageRemindType(l,s),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var N=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,n){return t(this,void 0,void 0,(function*(){const{common:s,OuterConstant:o}=this._core;yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:s,receiveMessageOption:o}=e;return O("group_open_http_svc.modify_group_member_info",{GroupId:t,Member_Account:s,MsgFlag:o},n)}))}({groupID:e,userID:s.getCurrentUserID(),receiveMessageOption:n},this._core);const i=`${o.CONV_GROUP}${e}`;return g.patchMessageRemindType([i],n),{code:0,data:{groupID:e,messageRemindType:n}}}))}};var A=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:s}=e;if(!t(s)){const{To_Account:e,MuteNotifications:t}=s,o=e.map((e=>`${n.CONV_C2C}${e}`)),i=a(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),g.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:n,userIDList:s,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(n)){console.log(`${this._name}.${t} groupID:${n} messageRemindType:${o}`);return yield N.set(n,o)}if(!r(s)){console.log(`${this._name}.${t} userIDList:${s} messageRemindType:${o}`);return yield D.set(s,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{init(e){console.log("ConversationAction.init"),this._core=e,m.init(e),f.init(e),I.init(e),T.init(e),L.init(e),S.init(e),R.init(e),y.init(e),A.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:n,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(n,o,this._onConversationModified,this),t.subscribeInnerEvent(n,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(n,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(n,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(s,this._dispose,this)}handleLoginSuccess(){m.handleLoginSuccess()}_onConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===p.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;R.handleConversationDeleted(t)}if(t===p.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!0)}if(t===p.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;L.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;A.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;L.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:s,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,s,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(n,this._dispose,this)}};var G=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,D.init(e),N.init(e),M.init(e),E.init(e)}};const U=e=>!n(e)&&!s(e)&&!o(e),$={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:n,isObject:s,isString:o}}}=e;if(!o(t)&&!s(t))return"options is String or Object.";if(o(t)&&U(t))return"conversationID is invalid.";if(s(t)){if(!n(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if(U(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!n(e)&&!s(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}},V={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0};var F=new class{install(t){e.init(t),P.init(t),G.init(t),g.init(t),t.helper.registerValidateConfig({auth:V,params:$})}handleLoginSuccess(){P.handleLoginSuccess()}};export{F as default};