@tencentcloud/lite-chat 1.2.0 → 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.2.0",
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",
@@ -1 +1 @@
1
- const e=new class{init(e){this.core=e}};function t(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 i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(s[n[i]]=e[n[i]])}return s}function s(e,t,s,n){return new(s||(s=Promise))((function(i,o){function r(e){try{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=[3,4,5,6,17,20,21,100],i=3,o=4,r=5,a=6,l=17,u=20,c=21,g=100,h=300,_=e=>e===a||e===o,p=e=>e===r;function d(e,t){return s(this,void 0,void 0,(function*(){const{longPollingKey:n,startSequence:i,startBroadcastSeq:o,simplifiedMessage:r}=e;return function(e,t,n){return s(this,void 0,void 0,(function*(){const{helper:s,channel:i}=n,o=s.generateProtocolData({servcmd:e,data:t}),r=`${o.head.seq}${e}`;return yield i.sendPacket(o,{requestId:r})}))}("group_open_long_polling_http_svc.get_msg",{Key:n,StartSeq:i,StartBroadcastSeq:o,DownsizeFlag:r,USP:1,HoldTime:90},t)}))}class M{constructor(e){const{core:t,manager:s,groupID:n,getRequestParams:i,onSuccess:o,onFail:r}=e;this._name="Polling",this._core=t,this._manager=s,this._timeoutID=-1,this._isRunning=!1,this._groupID=n,this._getRequestParams=i,this._onSuccess=o,this._onFail=r}start(){this._isRunning=!0,this._request(),console.log(`${this._name}.start pollingInterval:${this._manager.getPollingInterval()}`)}isRunning(){return this._isRunning}_request(){return s(this,void 0,void 0,(function*(){try{const e=this._getRequestParams(this._groupID),t=yield d(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getPollingInterval();this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}}))}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class m{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()}}function I(s){const n=function(e){const{E:s,MCT:n,MR:i,MP:o,MTS:r,GId:a,MS:l,CCD:u,F_Account:c,IsSys:g,GInf:h,MsgBody:_}=e,p=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:s,MsgClientTime:n,MsgRandom:i,MsgPriority:o,MsgTimeStamp:r,ToGroupId:a,MsgSeq:l,CloudCustomData:u,From_Account:c,IsSystemMsg:g,GroupInfo:f(h),MsgBody:v(_)},p)}(s);return function(t){const{Event:s}=t;(_(s)||p(s))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");n=s,(n===l||(e=>e===i)(s))&&function(t){const{core:{OuterConstant:s}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map((e=>{if(e.MsgType===s.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e}))}(t);var n;_(s)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:s={},MsgMemberExtraInfo:n,Operator_Account:i,List_Account:o,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);n||(e.MsgBody.MsgMemberExtraInfo=o.map((e=>({UserId:e}))));1!==r||n||(e.MsgBody.MsgMemberExtraInfo=[{UserId:s.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:i,ImageUrl:"",NickName:""},s)}(t);p(s)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:s}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:s,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,s)=>Object.assign(Object.assign({},t),{[s]:e.MsgBody[s]})),{})}(t)}(n),n}function f(e){const s=e||{},{GN:n,GT:i,F_Hd:o,F_NN:r}=s,a=t(s,["GN","GT","F_Hd","F_NN"]),l=Object.assign({GroupName:n,GroupType:i},a);return o&&(l.From_AccountHeadurl=o),r&&(l.From_AccountNick=r),l}function v(e){let s=e;Array.isArray(e)||(s=[e]);const n=s.map((e=>{const{O_Account:s,Opt:n,L_Account:i,RT:o,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:s,OpType:n,List_Account:i,ReportType:o,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:s,NN:n}=e,i=t(e,["Img","NN"]);return Object.assign({ImageUrl:s,NickName:n},i)}(a)),u&&(g.MsgMemberExtraInfo=function(e){return e.map((e=>{const{Img:s,NN:n}=e,i=t(e,["Img","NN"]);return Object.assign({ImageUrl:s,NickName:n},i)}))}(u)),l&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:s}=e;return{ExpireTime:t,OnlineMemberNum:s}}(l)),g}));return Array.isArray(e)?n:n[0]}var S=new class{constructor(){this._name="MessageParser",this._sequenceList=new m(200),this._messageIDList=new m(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(e,t,s=!1){this._sortServerMessageList(e,t);const n=this._handleMessageList(e,t);if(0===n.length)return;this._checkMessageStacked(n);const i=n.filter((e=>!0===e.isModified)),o=n.filter((e=>!1===e.isModified)),{OuterEvent:{MESSAGE_RECEIVED:r,MESSAGE_MODIFIED:a}}=this._core;i.length>0&&this._emitEvent({name:a,data:i}),o.length>0&&this._emitEvent({name:r,data:o})}_sortServerMessageList(e,t){t.sort(((e,t)=>e.MsgSeq-t.MsgSeq));const s=t.map((e=>e.MsgSeq));console.log(`${this._name}._sortServerMessageList groupID:${e} count:${s.length} sequenceList:${s}`),s.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:s,messageHelper:n},OuterConstant:i}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),r=[],a=t.length;for(let l=0;l<a;l++){let a=t[l];o&&(a=I(a)),this._patchMessageType(a);const u=n.parseServerGroupMessage(a);if(null===this._filterMessageItem(u,a.Event))continue;const c=this._createMessage(u);null!==this._filterDuplicateMessage(c)&&(s.isMessageSentByCurrentInstance(c)||(1===u.isModified&&(c.isModified=!0),c.conversationType===i.CONV_SYSTEM&&5===c.payload.operationType&&this._onGroupDismissed(e),r.push(c)))}return r}_patchMessageType(e){const{OuterConstant:t}=this._core;_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),p(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e,t){return n.includes(t)?t===a&&this._avChatRoomHandler.isGroupAttributesUpdated(e)?(this._avChatRoomHandler.handleGroupAttributesUpdated(e),null):(e=>e===u)(t)?(this._handleMessageRevoked(e),null):(e=>e===g)(t)?(this._onLiveCustomData(e),null):(e=>e===c)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:s}=this._core;let n=s.CONV_GROUP;e.event===r&&(n=s.CONV_SYSTEM);const i=!!e.isSystemMessage,o=t.createMessage(Object.assign(Object.assign({},e),{conversationType:n,isSystemMessage:i,flow:"in"}));return o.setElement(e.elements),o}_filterDuplicateMessage(e){const{common:t}=this._core;if(!t.isUnlimitedAVChatRoom()){if(this._sequenceList.has(e.sequence))return null;this._sequenceList.set(e.sequence)}const s=this._messageIDList.has(e.ID);return s?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${s}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:s}}=this._core,{groupID:n,elements:{revokeMsgList:i},revokerInfo:o}=e,r=[];i.forEach((e=>{const{tinyID:s,clientTime:i,random:a,sequence:l}=e,u={conversationID:`${t.CONV_GROUP}${n}`,ID:`${s}-${i}-${a}`,revoker:o.revoker,revokeReason:o.reason||"",revokerInfo:{userID:o.revoker,nick:"",avatar:""},sequence:l};r.push(u)})),0!==r.length&&this._emitEvent({name:s,data:r})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{groupID:s,sequence:n,time:i,elements:o}=e,r=(null==o?void 0:o.content)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${s} sequence:${n} time:${i} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;t>=100&&this._reportMessageStackedCount<5&&(this._reportMessageStackedCount+=1)}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:s}}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),o=[],r=e.length;for(let s=0;s<r;s++){let r=e[s];i&&(r=I(r));const a=t.parseServerGroupMessage(r);if(!n.includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const l=this._createMessage(a);l.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(l.ID)||(o.push(l),this._broadcastMessageIDMap.set(l.ID,1))}o.length>0&&this._emitEvent({name:s,data:o})}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};var O=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._pollingInterval=h,this._currentPollingInterval=h,this._pollingIntervalPlus=2e3,this._pollingNoMessageMaxCount=20,this._pollingSimplifiedMessage=0,this._pollingNoMessageCount=0,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,S.init(e,this),console.log("AVChatRoomHandler.init")}getPollingInterval(){return this._currentPollingInterval}isPollingSimplifiedMessage(){return 0!==this._pollingSimplifiedMessage}isGroupAttributesUpdated(e){return!!this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)&&(this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e),!0)}handleJoinGroupResult(e){return s(this,void 0,void 0,(function*(){const{longPollingKey:t,group:s,historyMessageList:n}=e,{groupID:i}=s;return yield this._preCheck(s),this._joinedGroupMap.set(i,s),this._parentPlugin.groupDataHandler.updateLocalGroup([s]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),n.length>0&&S.onMessageReceived(i,n,!0),void 0!==t?this._startMessageLongPolling(e):{status:this._core.OuterConstant.JOIN_STATUS_SUCCESS,group:s}}))}_preCheck(e){return s(this,void 0,void 0,(function*(){const{common:t,OuterConstant:s,apiMap:{quitGroup:n}}=this._core;if(t.isUnlimitedAVChatRoom())return;if(0===this._joinedAVChatRoomCount())return;if(e.type===s.GRP_LIVE)return;const[i,o]=this._joinedGroupMap.entries().next().value;o.selfInfo.role===s.GRP_MBR_ROLE_OWNER?this._parentPlugin.groupDataHandler.deleteLocalGroup(i):yield n(i),this.reset(i)}))}_startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:s,startSequence:n=1,group:i}=e,{groupID:o}=i;return this._pollingRequestInfoMap.set(o,{longPollingKey:s,startSequence:n}),this._startPolling(o),{status:t.JOIN_STATUS_SUCCESS,group:i}}_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 M({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:s}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:s,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:this._pollingSimplifiedMessage}:{longPollingKey:t,startSequence:s,simplifiedMessage:this._pollingSimplifiedMessage}}_handleSuccess(e,t){const{ErrorCode:s}=t;if(0===s)this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t);else{const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${n} errorCode:${s}`)}}_handleResponseData(e,t){const{Key:s,NextSeq:n,NextBroadcastSeq:i,RspMsgList:o=[],RspBroadcastMsgList:r=[]}=t;s&&n&&this._pollingRequestInfoMap.set(e,{longPollingKey:s,startSequence:n}),i&&i>this._startBroadcastSequence&&(this._startBroadcastSequence=i),o.length>0?(0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._currentPollingInterval=this._pollingInterval),S.onMessageReceived(e,o)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===this._pollingNoMessageMaxCount&&(this._currentPollingInterval=this._pollingInterval+this._pollingIntervalPlus)),r.length>0&&S.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 t=this._pollingInstanceMap.get(e);return null==t||t.stop(),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),void this._parentPlugin.groupDataHandler.deleteLocalGroup(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()}reset(e){this._stopPolling(e),this._pollingInterval=h,this._currentPollingInterval=h,this._pollingIntervalPlus=2e3,this._pollingNoMessageMaxCount=20,this._pollingSimplifiedMessage=0,this._pollingNoMessageCount=0,this._startBroadcastSequence=1,S.reset()}};var y=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:s}=e;s.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return s(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,s=yield this._parentPlugin.groupAction.joinGroup(e),{data:{group:n}}=s;return n.type===t.GRP_AVCHATROOM?O.handleJoinGroupResult(s.data):s}))}};var C=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:s}=e;s.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return s(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,s=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:n}}=s;return n===t.GRP_AVCHATROOM&&O.reset(e),s}))}};var R=new class{constructor(){this.name="AVChatRoom"}install(t,s){this._core=t,e.init(t),O.init(t,s),y.init(t,s),C.init(t,s);const{notificationCenter:n,InnerEvent:i}=t;n.subscribeInnerEvent(i.LOGOUT,this._reset,this),n.subscribeInnerEvent(i.DESTROY,this._dispose,this)}_reset(){O.reset()}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};export{R as default};
1
+ const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((s=s.apply(e,t||[])).next())}))}function 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};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,(function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var 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}function s(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{l(n.next(e))}catch(e){i(e)}}function a(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(r,a)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=[3,4,5,6,17,20,21,100],o=3,i=4,r=5,a=6,l=17,u=20,c=21,g=100,h=300,p=e=>e===a||e===i,_=e=>e===r;function d(e,t){return s(this,void 0,void 0,(function*(){const{longPollingKey:n,startSequence:o,startBroadcastSeq:i,simplifiedMessage:r}=e;return function(e,t,n){return s(this,void 0,void 0,(function*(){const{helper:s,channel:o}=n,i=s.generateProtocolData({servcmd:e,data:t}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}("group_open_long_polling_http_svc.get_msg",{Key:n,StartSeq:o,StartBroadcastSeq:i,DownsizeFlag:r,USP:1,HoldTime:90},t)}))}class M{constructor(e){const{core:t,manager:s,groupID:n,getRequestParams:o,onSuccess:i,onFail:r}=e;this._name="Polling",this._core=t,this._manager=s,this._timeoutID=-1,this._isRunning=!1,this._groupID=n,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 s(this,void 0,void 0,(function*(){try{const e=this._getRequestParams(this._groupID),t=yield d(e,this._core);this._onSuccess(this._groupID,t);const s=this._manager.getPollingInterval();this._runNextPolling(s)}catch(e){this._onFail(this._groupID,e),this._runNextPolling(2e3)}}))}_runNextPolling(e){this.isRunning()&&(this._timeoutID>-1&&clearTimeout(this._timeoutID),this._timeoutID=setTimeout(this._request.bind(this),e))}stop(){console.log(`${this._name}.stop`),this._timeoutID>-1&&(clearTimeout(this._timeoutID),this._timeoutID=-1),this._isRunning=!1}}class m{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()}}function I(s){const n=function(e){const{E:s,MCT:n,MR:o,MP:i,MTS:r,GId:a,MS:l,CCD:u,F_Account:c,IsSys:g,GInf:h,MsgBody:p}=e,_=t(e,["E","MCT","MR","MP","MTS","GId","MS","CCD","F_Account","IsSys","GInf","MsgBody"]);return Object.assign({Event:s,MsgClientTime:n,MsgRandom:o,MsgPriority:i,MsgTimeStamp:r,ToGroupId:a,MsgSeq:l,CloudCustomData:u,From_Account:c,IsSystemMsg:g,GroupInfo:f(h),MsgBody:v(p)},_)}(s);return function(t){const{Event:s}=t;(p(s)||_(s))&&(t.From_Account=t.From_Account||"@TIM#SYSTEM");n=s,(n===l||(e=>e===o)(s))&&function(t){const{core:{OuterConstant:s}}=e;t.CloudCustomData=t.CloudCustomData||"",t.MsgBody=t.MsgBody.map((e=>{if(e.MsgType===s.MSG_CUSTOM){const{content:t={}}=e;e.content=Object.assign({Data:"",Desc:"",Ext:""},t)}return e}))}(t);var n;p(s)&&function(e){const{GroupJoinType:t,MsgOperatorMemberExtraInfo:s={},MsgMemberExtraInfo:n,Operator_Account:o,List_Account:i,OpType:r}=e.MsgBody||{};"number"==typeof t||1!==r&&2!==r||(e.MsgBody.GroupJoinType=2===r?0:1);n||(e.MsgBody.MsgMemberExtraInfo=i.map((e=>({UserId:e}))));1!==r||n||(e.MsgBody.MsgMemberExtraInfo=[{UserId:s.UserId}]);e.MsgBody.MsgOperatorMemberExtraInfo=Object.assign({Operator_Account:o,ImageUrl:"",NickName:""},s)}(t);_(s)&&function(e){const{MsgOperatorMemberExtraInfo:t={},Operator_Account:s}=e.MsgBody||{};e.MsgBody.MsgMemberExtraInfo=Object.assign({UserId:s,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,s)=>Object.assign(Object.assign({},t),{[s]:e.MsgBody[s]})),{})}(t)}(n),n}function f(e){const s=e||{},{GN:n,GT:o,F_Hd:i,F_NN:r}=s,a=t(s,["GN","GT","F_Hd","F_NN"]),l=Object.assign({GroupName:n,GroupType:o},a);return i&&(l.From_AccountHeadurl=i),r&&(l.From_AccountNick=r),l}function v(e){let s=e;Array.isArray(e)||(s=[e]);const n=s.map((e=>{const{O_Account:s,Opt:n,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:s,OpType:n,List_Account:o,ReportType:i,UserDefinedField:r},c);return a&&(g.MsgOperatorMemberExtraInfo=function(e){const{Img:s,NN:n}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:s,NickName:n},o)}(a)),u&&(g.MsgMemberExtraInfo=function(e){return e.map((e=>{const{Img:s,NN:n}=e,o=t(e,["Img","NN"]);return Object.assign({ImageUrl:s,NickName:n},o)}))}(u)),l&&(g.OnlineMemberInfo=function(e){const{ET:t,Num:s}=e;return{ExpireTime:t,OnlineMemberNum:s}}(l)),g}));return Array.isArray(e)?n:n[0]}var S=new class{constructor(){this._name="MessageParser",this._sequenceList=new m(200),this._messageIDList=new m(100),this._broadcastMessageIDMap=new Map,this._reportMessageStackedCount=0}init(e,t){this._core=e,this._avChatRoomHandler=t}onMessageReceived(e,t,s=!1){this._sortServerMessageList(e,t);const n=this._handleMessageList(e,t);if(0===n.length)return;this._checkMessageStacked(n);const o=n.filter((e=>!0===e.isModified)),i=n.filter((e=>!1===e.isModified)),{OuterEvent:{MESSAGE_RECEIVED:r,MESSAGE_MODIFIED:a}}=this._core;o.length>0&&this._emitEvent({name:a,data:o}),i.length>0&&this._emitEvent({name:r,data:i})}_sortServerMessageList(e,t){t.sort(((e,t)=>e.MsgSeq-t.MsgSeq));const s=t.map((e=>e.MsgSeq));console.log(`${this._name}._sortServerMessageList groupID:${e} count:${s.length} sequenceList:${s}`),s.length=0}_handleMessageList(e,t){const{message:{messageDataHandler:s,messageHelper:n},OuterConstant:o}=this._core,i=this._avChatRoomHandler.isPollingSimplifiedMessage(),r=[],a=t.length;for(let l=0;l<a;l++){let a=t[l];i&&(a=I(a)),this._patchMessageType(a);const u=n.parseServerGroupMessage(a);if(null===this._filterMessageItem(u,a.Event))continue;const c=this._createMessage(u);null!==this._filterDuplicateMessage(c)&&(s.isMessageSentByCurrentInstance(c)||(1===u.isModified&&(c.isModified=!0),c.conversationType===o.CONV_SYSTEM&&5===c.payload.operationType&&this._onGroupDismissed(e),r.push(c)))}return r}_patchMessageType(e){const{OuterConstant:t}=this._core;p(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_TIP),_(e.Event)&&(e.MsgBody.MsgType=t.MSG_GRP_SYS_NOTICE)}_filterMessageItem(e,t){return n.includes(t)?t===a&&this._avChatRoomHandler.isGroupAttributesUpdated(e)?(this._avChatRoomHandler.handleGroupAttributesUpdated(e),null):(e=>e===u)(t)?(this._handleMessageRevoked(e),null):(e=>e===g)(t)?(this._onLiveCustomData(e),null):(e=>e===c)(t)?null:e:(console.warn(`${this._name}.onMessageReceived unknown event:${t}`),null)}_createMessage(e){const{message:{messageFactory:t},OuterConstant:s}=this._core;let n=s.CONV_GROUP;e.event===r&&(n=s.CONV_SYSTEM);const o=!!e.isSystemMessage,i=t.createMessage(Object.assign(Object.assign({},e),{conversationType:n,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 s=this._messageIDList.has(e.ID);return s?(console.warn(`${this._name}_filterDuplicateMessageItem ID:${e.ID} has:${s}`),null):(this._messageIDList.set(e.ID),e)}_handleMessageRevoked(e){const{OuterConstant:t,OuterEvent:{MESSAGE_REVOKED:s}}=this._core,{groupID:n,elements:{revokeMsgList:o},revokerInfo:i}=e,r=[];o.forEach((e=>{const{tinyID:s,clientTime:o,random:a,sequence:l}=e,u={conversationID:`${t.CONV_GROUP}${n}`,ID:`${s}-${o}-${a}`,revoker:i.revoker,revokeReason:i.reason||"",revokerInfo:{userID:i.revoker,nick:"",avatar:""},sequence:l};r.push(u)})),0!==r.length&&this._emitEvent({name:s,data:r})}_onLiveCustomData(e){const{OuterEvent:{ROOM_CUSTOM_DATA_RECEIVED:t}}=this._core,{groupID:s,sequence:n,time:o,elements:i}=e,r=(null==i?void 0:i.content)||"";this._emitEvent({name:t,data:r}),console.log(`${this._name}._onLiveCustomData groupID:${s} sequence:${n} time:${o} data:${r}`)}_onGroupDismissed(e){this._avChatRoomHandler.reset(e)}_checkMessageStacked(e){const{length:t}=e;t>=100&&this._reportMessageStackedCount<5&&(this._reportMessageStackedCount+=1)}_emitEvent(e){this._core.notificationCenter.emitOuterEvent(e.name,e)}onBroadcastMessageReceived(e){const{message:{messageHelper:t},OuterEvent:{MESSAGE_RECEIVED:s}}=this._core,o=this._avChatRoomHandler.isPollingSimplifiedMessage(),i=[],r=e.length;for(let s=0;s<r;s++){let r=e[s];o&&(r=I(r));const a=t.parseServerGroupMessage(r);if(!n.includes(r.Event)){console.warn(`${this._name}.onBroadcastMessageReceived unknown event:${r.Event}`);continue}const l=this._createMessage(a);l.isBroadcastMessage=!0,this._broadcastMessageIDMap.has(l.ID)||(i.push(l),this._broadcastMessageIDMap.set(l.ID,1))}i.length>0&&this._emitEvent({name:s,data:i})}reset(){this._reportMessageStackedCount=0,this._sequenceList.clear(),this._messageIDList.clear(),this._broadcastMessageIDMap.clear()}};var y=new class{constructor(){this._name="AVChatRoomHandler",this._joinedGroupMap=new Map,this._pollingRequestInfoMap=new Map,this._pollingInstanceMap=new Map,this._pollingInterval=h,this._currentPollingInterval=h,this._pollingIntervalPlus=2e3,this._pollingNoMessageMaxCount=20,this._pollingSimplifiedMessage=0,this._pollingNoMessageCount=0,this._startBroadcastSequence=1}init(e,t){this._core=e,this._parentPlugin=t,S.init(e,this),console.log("AVChatRoomHandler.init")}getPollingInterval(){return this._currentPollingInterval}isPollingSimplifiedMessage(){return 0!==this._pollingSimplifiedMessage}isGroupAttributesUpdated(e){return!!this._parentPlugin.groupAttribute.isGroupAttributesUpdated(e)&&(this._parentPlugin.groupAttribute.handleGroupAttributesUpdated(e),!0)}handleJoinGroupResult(e){return s(this,void 0,void 0,(function*(){const{longPollingKey:t,group:s,historyMessageList:n}=e,{groupID:o}=s;return yield this._preCheck(s),this._joinedGroupMap.set(o,s),this._parentPlugin.groupDataHandler.updateLocalGroup([s]),this._parentPlugin.groupDataHandler.emitGroupListUpdate(),n.length>0&&S.onMessageReceived(o,n,!0),void 0!==t?this._startMessageLongPolling(e):{status:this._core.OuterConstant.JOIN_STATUS_SUCCESS,group:s}}))}_preCheck(e){return s(this,void 0,void 0,(function*(){const{common:t,OuterConstant:s,apiMap:{quitGroup:n}}=this._core;if(t.isUnlimitedAVChatRoom())return;if(0===this._joinedAVChatRoomCount())return;if(e.type===s.GRP_LIVE)return;const[o,i]=this._joinedGroupMap.entries().next().value;i.selfInfo.role===s.GRP_MBR_ROLE_OWNER?this._parentPlugin.groupDataHandler.deleteLocalGroup(o):yield n(o),this.reset(o)}))}_startMessageLongPolling(e){const{OuterConstant:t}=this._core,{longPollingKey:s,startSequence:n=1,group:o}=e,{groupID:i}=o;return this._pollingRequestInfoMap.set(i,{longPollingKey:s,startSequence:n}),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 M({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:s}=this._pollingRequestInfoMap.get(e)||{};return e===[...this._pollingInstanceMap.keys()][0]?{longPollingKey:t,startSequence:s,startBroadcastSeq:this._startBroadcastSequence,simplifiedMessage:this._pollingSimplifiedMessage}:{longPollingKey:t,startSequence:s,simplifiedMessage:this._pollingSimplifiedMessage}}_handleSuccess(e,t){const{ErrorCode:s}=t;if(0===s)this._hasJoinedAVChatRoom(e)&&this._handleResponseData(e,t);else{const{longPollingKey:t,startSequence:n}=this._pollingRequestInfoMap.get(e)||{};console.warn(`${this._name}._handleSuccess groupID:${e} key:${t} startSeq:${n} errorCode:${s}`)}}_handleResponseData(e,t){const{Key:s,NextSeq:n,NextBroadcastSeq:o,RspMsgList:i=[],RspBroadcastMsgList:r=[]}=t;s&&n&&this._pollingRequestInfoMap.set(e,{longPollingKey:s,startSequence:n}),o&&o>this._startBroadcastSequence&&(this._startBroadcastSequence=o),i.length>0?(0!==this._pollingNoMessageCount&&(this._pollingNoMessageCount=0,this._currentPollingInterval=this._pollingInterval),S.onMessageReceived(e,i)):(this._pollingNoMessageCount+=1,this._pollingNoMessageCount===this._pollingNoMessageMaxCount&&(this._currentPollingInterval=this._pollingInterval+this._pollingIntervalPlus)),r.length>0&&S.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 t=this._pollingInstanceMap.get(e);return null==t||t.stop(),this._pollingInstanceMap.delete(e),this._pollingRequestInfoMap.delete(e),this._joinedGroupMap.delete(e),void this._parentPlugin.groupDataHandler.deleteLocalGroup(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()}reset(e){this._stopPolling(e),this._pollingInterval=h,this._currentPollingInterval=h,this._pollingIntervalPlus=2e3,this._pollingNoMessageMaxCount=20,this._pollingSimplifiedMessage=0,this._pollingNoMessageCount=0,this._startBroadcastSequence=1,S.reset()}};var O=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:s}=e;s.registerApi({apiName:"joinGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}joinGroup(e){return s(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,s=yield this._parentPlugin.groupAction.joinGroup(e),{data:{group:n}}=s;return n.type===t.GRP_AVCHATROOM?y.handleJoinGroupResult(s.data):s}))}};var C=new class{init(e,t){this._core=e,this._parentPlugin=t;const{helper:s}=e;s.registerApi({apiName:"quitGroup",context:this,matcher:()=>t.getInstalledSubPlugins().length>0})}quitGroup(e){return s(this,void 0,void 0,(function*(){const{OuterConstant:t}=this._core,s=yield this._parentPlugin.groupAction.quitGroup(e),{data:{type:n}}=s;return n===t.GRP_AVCHATROOM&&y.reset(e),s}))}};return new class{constructor(){this.name="AVChatRoom"}install(t,s){this._core=t,e.init(t),y.init(t,s),O.init(t,s),C.init(t,s);const{notificationCenter:n,InnerEvent:o}=t;n.subscribeInnerEvent(o.LOGOUT,this._reset,this),n.subscribeInnerEvent(o.DESTROY,this._dispose,this)}_reset(){y.reset()}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this._reset,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,(function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}function n(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{l(s.next(e))}catch(e){i(e)}}function a(e){try{l(s.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}l((s=s.apply(e,t||[])).next())}))}function 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)}}}));
@@ -1 +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,a){function n(e){try{c(o.next(e))}catch(e){a(e)}}function i(e){try{c(o.throw(e))}catch(e){a(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(n,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",a={OR:"or",AND:"and"},n={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||(!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5")},i={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||(!![a.OR,a.AND].includes(e)||"keywordListMatchType should be OR or AND")},c={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&e>=1&&e<=100||"count must be a number between 1 and 100"},u={required:!1,rules:["string"],allowEmpty:!0},d={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"}},l=e=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:r=>"number"==typeof r&&r>=0||`${e} should be a number >= 0';`}),h={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"}},m={searchCloudMessages:{keywordList:n,keywordListMatchType:i,cursor:u,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:l("timePosition"),timePeriod:l("timePeriod")},searchCloudUsers:{keywordList:n,keywordListMatchType:i,cursor:u,count:c,miniBirthday:l("miniBirthday"),maxBirthday:l("maxBirthday"),gender:h},searchCloudGroupMembers:{keywordList:n,keywordListMatchType:i,cursor:u,count:c,groupTypeList:d}},y={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0};var p=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.registerValidateConfig({auth:y,params:m})}searchCloudMessages(s){return r(this,void 0,void 0,(function*(){try{const{OuterConstant:o,helper:a,ssoLog:n}=this._core,i=n.createSSOLogData({method:"searchCloudMessages"}),{conversationID:c,timePeriod:u,timePosition:d}=s,l=e(s,["conversationID","timePeriod","timePosition"]),h=Object.assign({count:10},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 m=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,senderUserIDList:a,messageTypeList:n,endTime:i,startTime:c,cursor:u,account:d,groupID:l}=e,h={Count:r,KeywordList:o,MatchType:s,SendUserIDList:a,MsgTypeList:n,EndTime:i,StartTime:c,Cursor:u,PeerAccount:d,GroupID:l};return t.core.common.buildAndSendPacket({servcmd:"message_search.query",data:h})}))}(h);if(!m)return{code:0,data:{}};const{ErrorCode:y,ErrorInfo:p,TotalCount:g,Cursor:C="",ConversationMsgs:f=[]}=m;if(0!==y)throw{errorCode:y,errorInfo:p};const L=`keywordList:${s.keywordList} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} res: totalCount:${g}`;i.setLogInfo({message:L}).end();const M=f.map((e=>{const{MsgList:r,Count:t,GroupID:n,UserID:i}=e,c=n?`${o.CONV_GROUP}${n}`:`${o.CONV_C2C}${i}`;if(this._isSearchingAllConversations(s)&&t>1)return{conversationID:c,messageCount:t,messageList:[]};const u=r.map((e=>a.isEmpty(n)?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:M,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 n;try{const s=this._core.ssoLog.createSSOLogData({method:"searchCloudUsers"}),{keywordListMatchType:i,count:c=20}=o,u=e(o,["keywordListMatchType","count"]),d=Object.assign({count:c,keywordListMatchType:i===a.AND?1:0},u);this._setBirthdayRangeParams(d,o);const l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,miniBirthday:a,maxBirthday:n,cursor:i,gender:c}=e,u={Count:r,Keywords:o,KeywordMatchType:s,Cursor:i,UserBirthStart:a,UserBirthEnd:n,Gender:c};return t.core.common.buildAndSendPacket({servcmd:"user_search.query",data:u})}))}(d);if(!l)return{error:0,data:{}};const{ErrorCode:h,ErrorInfo:m,TotalCount:y,Cursor:p="",Users:g=[]}=l;if(0!==h)throw{errorCode:h,errorInfo:m};const C=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${y}`;s.setLogInfo({message:C}).end();const f=[];for(let e=0,r=g.length;e<r;e++){const{UserID:r,ProfileItems:t}=g[e];if(r===this._core.OuterConstant.USER_NOT_FOUND||""===r)continue;const o=t.map((e=>({tag:e.Tag,value:e.StrValue}))),s=null===(n=this._core.user.userProfile)||void 0===n?void 0:n.createProfile(r,o);f.push(s)}return{code:0,data:{searchResultList:f,cursor:p,totalCount:y}}}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:n=20,keywordListMatchType:i}=o,c=e(o,["count","keywordListMatchType"]),u=Object.assign({count:n,keywordListMatchType:i===a.AND?1:0},c),d=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,groupTypeList:a,cursor:n,groupIDList:i}=e,c={Count:r,Keywords:o,KeywordMatchType:s,Cursor:n,GroupType:a,GroupIdList:i};return t.core.common.buildAndSendPacket({servcmd:"group_member_search.query",data:c})}))}(u);if(!d)return{code:0,data:{}};const{ErrorCode:l,ErrorInfo:h,GroupMembers:m,Cursor:y,TotalCount:p}=d;if(0!==l)throw{errorCode:l,errorInfo:h};const g=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${p}`;s.setLogInfo({message:g}).end();const C=new Map;return m.forEach((e=>{const{GroupID:r,GroupName:t,GroupType:o,GroupFaceUrl:s,GroupMemberUserName:a,GroupMemberUserID:n,GroupMemberNameCard:i}=e,c={groupID:r,name:t,type:o,avatar:s},u={userID:n,nick:a,nameCard:i};if(C.has(r)){const e=C.get(r);e.memberList.push(u),C.set(r,e)}else C.set(r,{groupInfo:c,memberList:[u]})})),{code:0,data:{searchResultList:[...C.values()],cursor:y,totalCount:p}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}}))}_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:a,helper:n}=this._core;let i=e;60020===e?i="SearchUnable":t!==o&&27003===e?i="SearchParamsError":t!==o&&60018===e&&(i="SearchOverLimit");const c=new n.ChatError({code:i,message:r});throw a.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{p as default};
1
+ function e(e,r){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&r.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)r.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(t[o[s]]=e[o[s]])}return t}function r(e,r,t,o){return new(t||(t=Promise))((function(s,n){function a(e){try{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};
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatCloud-search"]=r()}(this,(function(){"use strict";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={required:!1,rules:["array"],allowEmpty:!0,customValidator:e=>!e||(!!(Array.isArray(e)&&e.length<=5)||"keywordList should be an array and length <= 5")},i={required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>!e||(!![n.OR,n.AND].includes(e)||"keywordListMatchType should be OR or AND")},c={required:!1,rules:["number"],allowEmpty:!0,customValidator:e=>"number"==typeof e&&e>=1&&e<=100||"count must be a number between 1 and 100"},u={required:!1,rules:["string"],allowEmpty:!0},d={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"}},l=e=>({required:!1,rules:["number"],allowEmpty:!0,customValidator:r=>"number"==typeof r&&r>=0||`${e} should be a number >= 0';`}),h={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"}},m={searchCloudMessages:{keywordList:a,keywordListMatchType:i,cursor:u,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:l("timePosition"),timePeriod:l("timePeriod")},searchCloudUsers:{keywordList:a,keywordListMatchType:i,cursor:u,count:c,miniBirthday:l("miniBirthday"),maxBirthday:l("maxBirthday"),gender:h},searchCloudGroupMembers:{keywordList:a,keywordListMatchType:i,cursor:u,count:c,groupTypeList:d}},y={searchCloudMessages:!0,searchCloudUsers:!0,searchCloudGroupMembers:!0};return 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.registerValidateConfig({auth:y,params:m})}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:10},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 m=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(!m)return{code:0,data:{}};const{ErrorCode:y,ErrorInfo:p,TotalCount:g,Cursor:C="",ConversationMsgs:f=[]}=m;if(0!==y)throw{errorCode:y,errorInfo:p};const L=`keywordList:${s.keywordList} keywordListMatchType:${s.keywordListMatchType} cursor:${s.cursor} res: totalCount:${g}`;i.setLogInfo({message:L}).end();const M=f.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:M,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:i,count:c=20}=o,u=e(o,["keywordListMatchType","count"]),d=Object.assign({count:c,keywordListMatchType:i===n.AND?1:0},u);this._setBirthdayRangeParams(d,o);const l=yield function(e){return r(this,void 0,void 0,(function*(){const{count:r,keywordList:o,keywordListMatchType:s,miniBirthday:n,maxBirthday:a,cursor:i,gender: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})}))}(d);if(!l)return{error:0,data:{}};const{ErrorCode:h,ErrorInfo:m,TotalCount:y,Cursor:p="",Users:g=[]}=l;if(0!==h)throw{errorCode:h,errorInfo:m};const C=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${y}`;s.setLogInfo({message:C}).end();const f=[];for(let e=0,r=g.length;e<r;e++){const{UserID:r,ProfileItems:t}=g[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:p,totalCount:y}}}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=20,keywordListMatchType:i}=o,c=e(o,["count","keywordListMatchType"]),u=Object.assign({count:a,keywordListMatchType:i===n.AND?1:0},c),d=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})}))}(u);if(!d)return{code:0,data:{}};const{ErrorCode:l,ErrorInfo:h,GroupMembers:m,Cursor:y,TotalCount:p}=d;if(0!==l)throw{errorCode:l,errorInfo:h};const g=`keywordList:${o.keywordList} keywordListMatchType:${o.keywordListMatchType} cursor:${o.cursor} count:${o.count} res: totalCount:${p}`;s.setLogInfo({message:g}).end();const C=new Map;return m.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(C.has(r)){const e=C.get(r);e.memberList.push(u),C.set(r,e)}else C.set(r,{groupInfo:c,memberList:[u]})})),{code:0,data:{searchResultList:[...C.values()],cursor:y,totalCount:p}}}catch(e){const{errorCode:r,errorInfo:t}=e||{};this._handleError({errorCode:r,errorInfo:t,searchType:s,functionName:"searchCloudGroupMembers"})}}))}_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)}}}));
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)}}}));