@tencentcloud/lite-chat 1.1.1-beta.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tencentcloud/lite-chat",
3
- "version": "1.1.1-beta.1",
3
+ "version": "1.2.0",
4
4
  "description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
5
5
  "main": "index.js",
6
6
  "module": "index.es.js",
@@ -0,0 +1,8 @@
1
+ declare const avChatRoomPlugin: {
2
+ [key: string]: any;
3
+ };
4
+
5
+ export default avChatRoomPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/avchatroom' {
7
+ export default avChatRoomPlugin;
8
+ }
@@ -0,0 +1 @@
1
+ const e=new class{init(e){this.core=e}};function t(e,t){var 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};
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatAvchatroom=t()}(this,(function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t){var 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)}}}));
@@ -0,0 +1,9 @@
1
+ declare const cloudSearchPlugin: {
2
+ [key: string]: any;
3
+ };
4
+
5
+ export default cloudSearchPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/cloud-search' {
7
+ export default cloudSearchPlugin;
8
+ }
9
+
@@ -0,0 +1 @@
1
+ function e(e,r){var t={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&r.indexOf(o)<0&&(t[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(o=Object.getOwnPropertySymbols(e);s<o.length;s++)r.indexOf(o[s])<0&&Object.prototype.propertyIsEnumerable.call(e,o[s])&&(t[o[s]]=e[o[s]])}return t}function r(e,r,t,o){return new(t||(t=Promise))((function(s,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};
@@ -0,0 +1 @@
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self)["TencentCloudChatCloud-search"]=r()}(this,(function(){"use strict";function e(e,r){var 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 +1 @@
1
- function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function r(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,r)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",s="GROUP",n="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",u="TIMImageElem",d="TIMSoundElem",c="TIMFileElem",g="TIMFaceElem",p="TIMVideoFileElem",v="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",C="TIMCustomElem",_="TIMRelayElem",M="AcceptAndNotify",y="AcceptNotNotify",f="Discard",T="AcceptNotNotifyExceptAt";var I,L,S;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(I||(I={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(L||(L={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(S||(S={}));const E=e=>void 0===e,D=e=>"string"==typeof e,O=e=>"function"==typeof Array.isArray?Array.isArray(e):"array"===(e=>{var t;return null===(t=Object.prototype.toString.call(e).match(/^\[object (.*)\]$/))||void 0===t?void 0:t[1].toLowerCase()})(e),R=e=>O(e)||(e=>null!==e&&"object"==typeof e)(e),k=(e,t,s,n)=>{if(!R(e)||!R(t))return 0;let o=0;const i=Object.keys(t);let a;for(let r=0,l=i.length;r<l;r++)if(a=i[r],!(E(t[a])||s&&s.includes(a)))if(R(e[a])&&R(t[a]))o+=k(e[a],t[a],s,n);else{if(n&&n.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},P=(e,t)=>{if(E(t))return"";switch(e){case l:return t.text||"";case u:return"[Image]";case v:return"[Location]";case d:return"[Voice]";case p:return"[Video]";case c:return"[File]";case C:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case g:return"[Animated Sticker]";case _:return"[Chat Record]";default:return""}},G=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:P(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function N(e){const t=[];if(!D(e))return t;const s=e.length;if(0===s)return t;for(let n=s-1;n>=0;n--)"1"===e[n]&&t.push(2**(s-n-1));return t}class U{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=G(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark="",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){E(this.userProfile)&&this.type===t?this.userProfile={}:E(this.groupProfile)&&this.type===s&&(this.groupProfile={}),this.subType&&this.type===s&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;E(o)||(this.subType!==i?a&&this.type===s||a&&this.type===n||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=G(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:n,time:o}=e;return this.type===t&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}}var A=new class{constructor(){this._name="ConversationFactory",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0,this._pagingConvIDMap=new Map,this._convMap=new Map,this._convTotalUnreadCount=0}install(e){this._core=e;const{notificationCenter:t,InnerEvent:s,helper:n}=e;n.registerApi("getConversationList",this),n.registerApi("getConversationProfile",this),n.registerApi("setMessageRead",this),n.registerApi("getTotalUnreadMessageCount",this),n.registerApi("setConversationDraft",this),t.subscribeInnerEvent(s.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(s.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(s.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(s.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(s.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(s.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(s.DESTROY,this._dispose,this),console.log(`${this._name}.install`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this._onConversationListUpdate()}_handleMessageDeleted(e){var s,n,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(a.length||0)-1;e>=0;e--)if(!a[e].isDeleted){r=a[e];break}const l=this._convMap.get(e);if(!l)return;let u=!1;l.lastMessage.lastSequence===r.sequence&&l.lastMessage.lastTime===r.time||((null===(i=null===(o=this._core)||void 0===o?void 0:o.helper)||void 0===i?void 0:i.isEmpty(r))&&(r=void 0),l.updateLastMessage(r),u=!0),e.startsWith(t)&&this._updateUnreadCount(e),u&&(this._onConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. \n update conversationID:${e} with lastMessage:`,l.lastMessage))}_handleMessageRevoked(e){console.log(`${this._name}._handleMessageRevoked`,JSON.stringify(e));const{messageList:t=[],updateUnreadCount:s=!0}=e;if(0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this._convMap.get(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))})),o&&this._onConversationListUpdate()}_handleMessageModified(e){var t,s;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:n,message:o}=e,i=this._convMap.get(n);if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(i))return;const{lastMessage:a}=i;a&&a.lastTime===o.time&&a.lastSequence===o.sequence&&a.version!==o.version&&(a.type=o.type,a.payload=o.payload,a.messageForShow=P(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this._onConversationListUpdate(),console.log(`${this._name} conversationID:${n} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this._onConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){try{this._pagingStatus=I.PENDING;const s=yield function(t,s){return e(this,void 0,void 0,(function*(){const{pagingTimeStamp:e,pagingStartIndex:n,pagingPinnedTimeStamp:o,pagingPinnedStartIndex:i}=t;try{const t="recentcontact.page_get",a=null==s?void 0:s.helper.generateProtocolData({servcmd:t,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:null==s?void 0:s.store.get("login").userId,StartIndex:n,TimeStamp:e,TopStartIndex:i,TopTimeStamp:o}}),r=`${a.head.seq}${t}`;return yield s.channel.sendPacket(a,{requestId:r})}catch(e){throw console.warn(`ConversationService.pagingGetConvList error: ${e}`),e}}))}({pagingTimeStamp:t?this._pagingTimeStamp:0,pagingStartIndex:t?this._pagingStartIndex:0,pagingPinnedTimeStamp:t?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:t?this._pagingPinnedStartIndex:0},this._core);if(s){const{CompleteFlag:e,SessionItem:n=[],TimeStamp:o,StartIndex:i,TopTimeStamp:a,TopStartIndex:r}=s;if(n.length>0){const e=this._getConvOptions(n);this._pagingConvIDMap=new Map([...this._pagingConvIDMap,...e.map((e=>[e.conversationID,1]))]),this._updateLocalConvList({conversationOptionsList:e,isFromGetConversations:!0,updateUnreadCount:!0}),this._onConversationListUpdate()}this._pagingTimeStamp=o,this._pagingStartIndex=i,this._pagingPinnedTimeStamp=a,this._pagingPinnedStartIndex=r,1!==e&&this._pagingGetConvList(t)}}catch(e){throw console.error(`${this._name}._pagingGetConvList fail:`,e),e}}))}_getConvOptions(e){const n=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return n.map((e=>{var n,i,a,r,l,u,d,c,g,p,v,h;if(E(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===L.C2C){const s={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},p=null===(a=null===(i=null===(n=this._core)||void 0===n?void 0:n.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[s]);return{conversationID:`${t}${e.userID}`,type:t,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(r=e.lastMsg)||void 0===r?void 0:r.elements[0])?null===(l=e.lastMsg)||void 0===l?void 0:l.elements[0].type:null,payload:(null===(u=e.lastMsg)||void 0===u?void 0:u.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(d=e.lastMsg)||void 0===d?void 0:d.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(g=null===(c=e.lastMsg)||void 0===c?void 0:c.revokerInfo)||void 0===g?void 0:g.revoker)||null},unreadCount:0,userProfile:p,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${s}${e.groupID}`,type:s,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(p=e.lastMsg)||void 0===p?void 0:p.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(v=e.lastMsg)||void 0===v?void 0:v.revokerInfo)||void 0===h?void 0:h.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}))}_convertConvKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,s,n,o;if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(n=e.MsgBody[0])||void 0===n?void 0:n.MsgType,a=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:a,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var s;if(!t)return t;const n=this._core.message.messageFactory.getElementClass(e);return n?null===(s=n.parseServerPushElement(t))||void 0===s?void 0:s.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=M:1===e?t=f:2===e?t=y:3===e&&(t=T),t}_patchTypeAndPayload(e){const{event:t,elements:s=[]}=e.lastMsg||{};return E(t)?{type:s[0]?s[0].type:null,payload:s[0]?this._amendLayersOverLimitProp(s[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:s=0}=e,n=t-s;return n>0?n:0}_updateLocalConvList(e){const{newConvList:t}=this._getTmpConvListMapping(e);this._convMap=new Map(this._sortConvList([...this._convMap])),this._core.store.set("conversation",{conversationMap:this._convMap}),console.log(`${this._name}._updateLocalConvList newConvList: ${t.length}`)}_getTmpConvListMapping(e){const{conversationOptionsList:n,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],u=null==n?void 0:n.length;for(let e=0;e<u;e++){const u=new U(n[e]),{conversationID:d,type:c}=u;if(!this._isNonExistentAccount(d))if(this._convMap.has(d)){const l=this._convMap.get(d);if(o){this._convMap.set(d,u),c===t?u.unreadCount=l.unreadCount:c===s&&(u.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:d,tmpConversation:u,lastMessage:n[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:d,lastMessage:n[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:u.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(u),this._convMap.set(d,u)}return{newConvList:l}}_isNonExistentAccount(e){let s;return e.startsWith(t)&&(s=e.replace(t,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}_mergeConversationInfo(e){var t,s;const{conversationID:n,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(n),u=["unreadCount","allowType","adminForbidType","payload"];!1===r&&u.push("lastMessage"),a&&u.push("isPinned"),E(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);k(l,o,u,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:n,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&n){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===s&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],s=[],n=[],o=[];return e.forEach((e=>{var i,a,r,l;!0===e[1].isPinned?(null===(a=null===(i=this._core)||void 0===i?void 0:i.helper)||void 0===a?void 0:a.isEmpty(e[1].lastMessage.lastTime))?s.push(e):t.push(e):(null===(l=null===(r=this._core)||void 0===r?void 0:r.helper)||void 0===l?void 0:l.isEmpty(e[1].lastMessage.lastTime))?o.push(e):n.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_getLocalConvList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}_isConvNeedShow(e){const t=this._getLocalConversation(e);if(E(t))return!0;const o=t.type===n,i=t.type===s&&t.subType===a,l=t.type===s&&t.subType===r;return!(o||i||l)}_getLocalConversation(e){return this._convMap.get(e)}_updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this._getLocalConversation(e),a=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const r=i.unreadCount,l=null==a?void 0:a.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return r!==l&&(i.unreadCount=l,o=!0,console.log(`${this._name}._updateUnreadCount\n from ${r} to ${l}, conversationID:${e}`),!0===t&&this._onConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_onConversationListUpdate(){var e;const t=this._getLocalConvList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.CONVERSATION_LIST_UPDATED,data:t}),this._onTotalUnreadCountUpdate()}_onTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._onTotalUnreadCountUpdate from ${this._convTotalUnreadCount} to ${t}`),this._convTotalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(E(e))return this._getLocalConvList();if(O(e)){if(0===e.length)return[];return this._getLocalConvList().filter((t=>e.includes(t.conversationID)))}if((e=>{if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let s=t;for(;null!==Object.getPrototypeOf(s);)s=Object.getPrototypeOf(s);return t===s})(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this._getLocalConvList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,n){return n!==t&&n!==s||e.type===n}_filterGroupName(e,t){return!D(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(s=t)||!("number"==typeof s&&!Number.isNaN(s-0)||"object"==typeof s&&s.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var s}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_recoverConversations(){return e(this,void 0,void 0,(function*(){try{yield this.syncConvList(),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.RECOVER_CONVERSATIONS_COMPLETED)}catch(e){console.debug(e)}}))}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}getConversationProfile(n){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(n)?e=this._convMap.get(n):(e=new U({conversationID:n}),(e=>D(e)&&e.slice(0,3)===t)(n)?(e.type=t,e.userProfile={userID:n.replace(t,"")}):(e.type=s,e.groupProfile={groupID:n.replace(s,"")}),this._convMap.set(n,e)),{code:0,data:{conversation:e}}}))}setMessageRead(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}.setMessageRead ok, ${JSON.stringify(t)}`)}))}setConversationDraft(t){return e(this,void 0,void 0,(function*(){return console.log(`${this._name}.setConversationDraft , ${JSON.stringify(t)}`),{code:0,data:{conversation:{}}}}))}getTotalUnreadMessageCount(){const e=this._getLocalConvList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==M||(t+=e.unreadCount))})),t}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.RE_LOGIN,this._recoverConversations,this),e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.NEW_MESSAGE,this._handleNewMessage,this),e.unSubscribeInnerEvent(t.MESSAGE_DELETED,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(t.MESSAGE_REVOKED,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(t.MESSAGE_MODIFIED,this._handleMessageModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const b={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0},F={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!e.startsWith("C2C")&&!e.startsWith("GROUP"))||"conversationID is invalid."}]};var x={install:function(e){A.install(e),e.helper.registerValidateConfig({auth:b,params:F})},handleLoginSuccess:function(){A.handleLoginSuccess()}};export{x as default};
1
+ const e=new class{init(e){this.core=e}};function t(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,3)===n.CONV_C2C},s=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,5)===n.CONV_GROUP},o=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t===n.CONV_SYSTEM},i=(t,n)=>{const{core:{utils:{isUndefined:s}}}=e;if(s(n))return"";const{core:{OuterConstant:o}}=e;switch(t){case o.MSG_TEXT:return n.text||"";case o.MSG_IMAGE:return"[Image]";case o.MSG_LOCATION:return"[Location]";case o.MSG_AUDIO:return"[Voice]";case o.MSG_VIDEO:return"[Video]";case o.MSG_FILE:return"[File]";case o.MSG_CUSTOM:return"[Custom Messages]";case o.MSG_GRP_TIP:return"[Group Notification]";case o.MSG_GRP_SYS_NOTICE:return"[Group System Message]";case o.MSG_FACE:return"[Animated Sticker]";case o.MSG_MERGER:return"[Chat Record]";default:return""}},r=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:i(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function a(t){const{core:{utils:{isString:n}}}=e,s=[];if(!n(t))return s;const o=t.length;if(0===o)return s;for(let e=o-1;e>=0;e--)"1"===t[e]&&s.push(2**(o-e-1));return s}function c(t){const{OuterConstant:n}=e.core;let s="";return 0===t?s=n.MSG_REMIND_ACPT_AND_NOTE:1===t?s=n.MSG_REMIND_DISCARD:2===t?s=n.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(s=n.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function l(t){const{OuterConstant:n}=e.core;let s;return t.startsWith(n.CONV_C2C)&&(s=t.replace(n.CONV_C2C,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}var u,d,_,p,C;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(u||(u={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(d||(d={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(_||(_={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(p||(p={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(C||(C={}));var h;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(h||(h={}));class g{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=r(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){const{core:{OuterConstant:t,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:n(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:n,utils:{isUndefined:s}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;s(o)||(this.subType!==n.GRP_AVCHATROOM?i&&this.type===n.CONV_GROUP||i&&this.type===n.CONV_TOPIC||r&&this.type===n.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=r(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:n}}=e,{sequence:s,time:o}=t;return this.type===n.CONV_C2C&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n.CONV_GROUP&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{OuterConstant:n}}=e;let[...s]=t.groupAtType;s.includes(n.CONV_AT_ME)||s.includes(n.CONV_AT_ALL)||(s=[n.CONV_AT_ALL_AT_ME]);const o={from:t.from,groupID:t.groupID,messageSequence:t.sequence,atTypeArray:s,__random:t.__random,__sequence:t.__sequence};this.groupAtInfoList.push(o)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var v=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:n,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{MESSAGE_PUSH:r,NEW_MESSAGE:a,MESSAGE_DELETED:c,MESSAGE_REVOKED:l,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:d,LOGOUT:_,DESTROY:p}}=e;this._conversationStore=s,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this);const{InnerEventSubType:{GROUP_AT_TIPS:C}}=n;n.subscribeInnerEvent(a,this._handleNewMessage,this),n.subscribeInnerEvent(r,C,this._handleNewGroupAtTips,this),n.subscribeInnerEvent(c,this._handleMessageDeleted,this),n.subscribeInnerEvent(l,this._handleMessageRevoked,this),n.subscribeInnerEvent(u,this._handleMessageModified,this),n.subscribeInnerEvent(d,this._handleConversationUpdated,this),n.subscribeInnerEvent(_,this._reset,this),n.subscribeInnerEvent(p,this._dispose,this),console.log(`${this._name}.init`)}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:n=[],groupTipList:s=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;n.forEach((e=>{const{conversationID:t,unreadCount:n}=e,s=this.getLocalConversation(t);s&&s.unreadCount!==n&&(s.updateUnreadCount({nextUnreadCount:n,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(s)}_handleGroupAtTipsSynced(e){for(let t=0;t<e.length;t++)12===e[t].Event&&this._handleNewGroupAtTips(e[t])}_handleGroupListSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,n=e.result[t.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:s}}=this._core;let o=!1;for(let e=0;e<n.length;e++){const t=n[e],i=`${s}${t.groupID}`;if(!this.hasLocalConversation(i))continue;const r=this.getLocalConversation(i);r.groupProfile=JSON.parse(JSON.stringify(t)),r.lastMessage.lastSequence<t.nextMessageSeq&&(r.lastMessage.lastSequence=t.nextMessageSeq-1),r.subType||(r.subType=t.type),o=!0}o&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e.result||{};if(console.log(`${this._name}._handleNewMessage, conversationUpdateFieldList length:`,t.length,e),0===t.length)return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:n,GroupAtType:s,MsgRandom:o,ClientSeq:i}=e;let r={};t?r=this._convertGroupAtTipsKey(t):n?r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(n)),{sync:!0}):s&&(r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(e)),{sync:!0})),r.__random=o,r.__sequence=i,this._groupAtTipsList.push(r)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:n,MsgSeq:s,GroupAtType:o}=e;return{from:t,groupID:n,sequence:s,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,n=e.getCurrentUserID();let s=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==n){const n=this.getLocalConversation(`${t.CONV_GROUP}${o}`);n&&(n.updateGroupAtInfoList(e),s=!0)}})),s&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,n;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:s},OuterConstant:o}=this._core,i=(null==s?void 0:s.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:n=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this.getLocalConversation(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:n}=e,s=this.getLocalConversation(t),{utils:{isEmpty:o}}=this._core;if(o(s))return;const{lastMessage:r}=s;if(r){const e=(null==n?void 0:n[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(){this.emitConversationListUpdate()}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:n}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(n),console.log(`${this._name}.updateLocalConversationList newConversationList: ${n.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:n,isFromGetConversations:s,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,a=[],c=null==n?void 0:n.length;for(let e=0;e<c;e++){const c=new g(n[e]),{conversationID:u,type:d}=c;if(!l(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(s){this.setLocalConversation(u,c),d===t.CONV_C2C?c.unreadCount=(null==a?void 0:a.unreadCount)||0:d===t.CONV_GROUP&&(c.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:c,lastMessage:n[e].lastMessage,isFromGetConversations:s,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:n[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:c.unreadCount,isFromGetConversations:s,isUnreadC2CMessage:i}))}else a.push(c),this.setLocalConversation(u,c)}return{newConversationList:a}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:n,lastMessage:s,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:u}}=this._core;c(i)&&s&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=s.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);u(r,n,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:n,lastMessage:s,isInstantMessage:o}=e,i=this.getLocalConversation(n);if(i&&s){const{payload:e,nameCard:n,nick:r,cloudCustomData:a=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=n,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],n=[],s=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?s.push(t):n.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],n=[],{OuterConstant:{CONV_GROUP:s,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===s){const e=i.replace(s,"");n.push(e)}})),t.length>0&&this._updateC2CConversation(t),n.length>0&&this._updateGroupConversation(n)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:n},appStore:{userStore:s},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${n}${o}`);if(r){const n=(null===(t=s.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=n,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core;let s=!1;e.forEach((e=>{const o=n.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,s=!0)})),s&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:n}=this._core,s=t.type===n.CONV_TOPIC,o=t.type===n.CONV_GROUP&&t.subType===n.GRP_ROOM,i=t.type===n.CONV_GROUP&&t.subType===n.GRP_LIVE;return!(s||o||i)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),r=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageDataHandler)||void 0===s?void 0:s.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,n=this.getLocalConversationList();this._emitEvent({name:t,data:n}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e}=this._core,t=this.getLocalConversationList();let n=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(n+=t.unreadCount))})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,n]of e)this.setLocalConversation(t,n)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let n=!1;e.forEach((e=>{const s=this.getLocalConversation(e);(null==s?void 0:s.messageRemindType)!==t&&(s.messageRemindType=t,n=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${n}`),n&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:n,lastReadTime:s=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(n);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],n=s&&t.time>s,r=o&&t.sequence>o;if(!n&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],n=t.findIndex((e=>!1===e[1].isPinned));t.splice(n,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:n,MESSAGE_REVOKED:s,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:c}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,c,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(n,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(s,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};function m(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var f=new class{constructor(){this._name="SyncConversationList",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s,constants:o}=e;s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.CONVERSATION_RECOVER,this._syncConversationListOnReOnline,this),s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_LOGIN,o.WORKFLOW_STEP.CONVERSATION_LIST_SYNC,this._syncConversationList,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}isSyncCompleted(){return this._pagingStatus===u.RESOLVED}_syncConversationListOnReOnline(){return t(this,void 0,void 0,(function*(){return this._syncConversationList()}))}_syncConversationList(){return t(this,void 0,void 0,(function*(){yield this._pagingGetConversationList(!0),this._pagingStatus=u.RESOLVED,v.emitConversationListUpdate()}))}_pagingGetConversationList(e){return t(this,void 0,void 0,(function*(){try{this._pagingStatus=u.PENDING;const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:r}=e;return m("recentcontact.page_get",{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:t,StartIndex:o,TimeStamp:s,TopStartIndex:r,TopTimeStamp:i},n)}))}({fromAccount:n.getCurrentUserID(),pagingTimeStamp:e?this._pagingTimeStamp:0,pagingStartIndex:e?this._pagingStartIndex:0,pagingPinnedTimeStamp:e?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:e?this._pagingPinnedStartIndex:0},this._core),{CompleteFlag:o,SessionItem:i=[],TimeStamp:r,StartIndex:a,TopTimeStamp:c,TopStartIndex:l}=s||{};if(i.length>0){const e=this._getConversationOptions(i);v.updateLocalConversationList({conversationUpdateFieldList:e,isFromGetConversations:!0,updateUnreadCount:!0}),v.emitConversationListUpdate()}this._pagingTimeStamp=r,this._pagingStartIndex=a,this._pagingPinnedTimeStamp=c,this._pagingPinnedStartIndex=l,1!==o&&this._pagingGetConversationList(e)}catch(e){throw console.error(`${this._name}._pagingGetConversationList fail:`,e),e}}))}_getConversationOptions(e){const{utils:{isUndefined:t}}=this._core,n=this._convertConversationKey(e);return this._filterValidConversations(n).map((e=>(t(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===d.C2C?this._assembleC2COption(e):this._assembleGroupOption(e))))}_filterValidConversations(e){return e.filter((({type:e,userID:t})=>e===d.C2C&&!l(t)||2===e))}_assembleC2COption(e){var t,n,s,o,i,r;const{OuterConstant:c}=this._core,l=this._createUserprofile(e);return{conversationID:`${c.CONV_C2C}${e.userID}`,type:c.CONV_C2C,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(t=e.lastMsg)||void 0===t?void 0:t.elements[0])?null===(n=e.lastMsg)||void 0===n?void 0:n.elements[0].type:null,payload:(null===(s=e.lastMsg)||void 0===s?void 0:s.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(o=e.lastMsg)||void 0===o?void 0:o.cloudCustomData)||"",isRevoked:e.lastMessageFlag===_.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:this._computeIsPeerRead(e),revoker:(null===(r=null===(i=e.lastMsg)||void 0===i?void 0:i.revokerInfo)||void 0===r?void 0:r.revoker)||null},unreadCount:0,userProfile:l,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:a(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}_createUserprofile(e){var t;const{userID:n,nick:s,peerAvatar:o}=e,i=[{tag:"Tag_Profile_IM_Nick",value:s},{tag:"Tag_Profile_IM_Image",value:o}];return null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(n,i)}_computeIsPeerRead(e){const{common:t}=this._core,n=t.getCurrentUserID(),{lastC2CMsgFromAccount:s,time:o,c2cPeerReadTime:i}=e;return s===n&&o<=i}_assembleGroupOption(e){var t,n,s;const{OuterConstant:o}=this._core;return{conversationID:`${o.CONV_GROUP}${e.groupID}`,type:o.CONV_GROUP,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(t=e.lastMsg)||void 0===t?void 0:t.cloudCustomData)||"",isRevoked:e.lastMessageFlag===_.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(s=null===(n=e.lastMsg)||void 0===n?void 0:n.revokerInfo)||void 0===s?void 0:s.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:a(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}_convertConversationKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",r=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.MsgType,r=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:r,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){const{OuterConstant:t}=this._core;let n="";return 0===e?n=t.MSG_REMIND_ACPT_AND_NOTE:1===e?n=t.MSG_REMIND_DISCARD:2===e?n=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(n=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}_patchTypeAndPayload(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core,{event:s,elements:o=[]}=e.lastMsg||{};return n(s)?{type:o[0]?o[0].type:null,payload:o[0]?this._amendLayersOverLimitProp(o[0].content):null}:{type:t.MSG_GRP_TIP,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s:0}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};var M=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:f.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:n,isPlainObject:s}}=this._core;if(t(e))return v.getLocalConversationList();if(n(e)){if(0===e.length)return[];return v.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(s(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return v.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:n}=this._core;return t!==n.CONV_C2C&&t!==n.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:n}}=this._core;return!n(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:n}}=this._core;return!n(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_filterGroupAtInfo(e,t){let n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}};function O(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var E=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:s}=e;return O("openim.get_c2c_peer_mute_notifications",{To_Account:t,Peer_Account:s},n)}))}({toAccount:n.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=s||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:n}=e,s=`${this._core.OuterConstant.CONV_C2C}${t}`,o=c(n);v.patchMessageRemindType([s],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var I=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const n=yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:s}=e;return O("group_open_http_svc.get_group_self_member_info",{GroupIdList:t,ResponseFilter:s},n)}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=n||{};s.forEach((e=>{var t;const{GroupId:n,MemberList:s}=e,o=(null===(t=s[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${n}`;v.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var S=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:{groupStore:i},utils:{isEmpty:r}}=this._core,a={code:0,data:null};let c=v.getLocalConversation(e);if(o(e))return a.data=c,a;let l=!1;const u=n(e)?t:s;if(r(c)&&(l=!0,c=new g({conversationID:e,type:u})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${l}`),a.data=c,null==c?void 0:c.getProfileCompleted())return a;if(u===t){const n=e.replace(t,"");yield this._handleC2CConversation(c,n),l&&(yield E.get([n]))}if(u===s){const t=e.replace(s,"");if(!i.getGroup(t))return a;yield this._handleGroupConversation(c,t),l&&(yield I.get([t]))}return a}))}_handleC2CConversation(e,n){return t(this,void 0,void 0,(function*(){var t,s;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,u=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[n]});if(0===(null==u?void 0:u.data.length))throw new i.ChatError({code:h.USER_OR_GRP_NOT_FOUND});e.userProfile=null==u?void 0:u.data[0];const d=null===(s=c.getFriend(n))||void 0===s?void 0:s.remark;r(d)||e.remark===d||(e.remark=d),e.setProfileCompleted();const _=v.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${_}`),_?a.updateConversation(l,e):v.appendToPinnedConversation(e)}))}_handleGroupConversation(e,n){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:s}}=this._core,{conversationID:o}=e,i=yield t({groupID:n});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=v.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?s.updateConversation(o,e):v.appendToPinnedConversation(e)}))}};var T=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return v.getTotalUnreadMessageCount()}};var L=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRead",context:this})}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:s}=e;if(!t(s)){const{UinPairReadArray:e=[]}=s;e.forEach((e=>{const{From_Account:t,LastReadTime:s}=e,o=`${n.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${s}`),v.markMessageAsRead({conversationID:o,lastReadTime:s}),v.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:s}=e.MsgBody;n(s)||s.forEach((e=>{const{GroupId:n,LastReadMsgSeq:s}=e,o=`${t.CONV_GROUP}${n}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${s}`),v.markMessageAsRead({conversationID:o,lastReadSequence:s}),v.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,n;const{OuterConstant:s}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=v.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r.groupAtInfoList));if(r.type===s.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;if(r.type===s.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e)}if(r.type===s.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e)}return r.type===s.CONV_SYSTEM&&(r.unreadCount=0),v.emitConversationListUpdate(),i}))}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const n=v.getLocalConversation(e);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const{common:n}=this._core,o=s.map((e=>({From_Account:e.from,To_Account:n.getCurrentUserID(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,n){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e;return m("openim.deletemsg",{DelMsgList:t},n)}))}({messageListToDelete:o},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=v.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&v.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){return m("openim.msgreaded",e,n)}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${n}`),v.markMessageAsRead({conversationID:e,lastReadTime:n}),v.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:s}=e;return m("group_open_http_svc.msg_read_report",{GroupId:t,MsgReadedSeq:s},n)}))}({groupID:e.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${n}`),v.markMessageAsRead({conversationID:e,lastReadSequence:n}),v.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:n}}=this._core;if(!n(e))return;const{OuterConstant:s}=this._core;let o=!1;e.forEach((e=>{const{Type:n,To_Account:i,GroupId:r}=e;let a;1===n?a=v.getLocalConversation(`${s.CONV_C2C}${i}`):2===n&&(a=v.getLocalConversation(`${s.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&v.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r}=this._core,{conversationID:a,isPinned:c}=e,l={code:0,data:{conversationID:a}},u=v.getLocalConversation(a);if(u&&u.isPinned===c)return l;if(o(a))return u&&(u.isPinned=c),v.emitConversationListUpdate(!0),l;try{let e=null;n(a)?e={Type:1,To_Account:a.replace(i.CONV_C2C,"")}:s(a)&&(e={Type:2,GroupId:a.replace(i.CONV_GROUP,"")});const o=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:s,itemList:o}=e;return m("recentcontact.top",{From_Account:t,OperationType:s,RecentContactItem:o},n)}))}({fromAccount:r.getCurrentUserID(),operationType:!0===c?1:2,itemList:[e]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${a} isPinned:${c}.`),o){if(u)u.isPinned!==c&&(u.isPinned=c);else{const e=new g({conversationID:a,type:n(a)?i.CONV_C2C:i.CONV_GROUP,isPinned:c});v.setLocalConversation(a,e)}v.emitConversationListUpdate(!0)}return l}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var y=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:n}=this._core,s=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&s.push(`${n.CONV_C2C}${o}`),2===t&&s.push(`${n.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return console.log(`${this._name}.deleteConversation conversationID:${e}`),void(yield this._deleteConversation({conversationIDList:[e],flag:p.ONLY_CONVERSATIONID}));const n=Object.assign({},e);n.conversationIDList.length>100&&(n.conversationIDList=n.conversationIDList.slice(0,100)),yield this._deleteConversation(n)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:n=!0,flag:s=0}=e;console.log(`${this._name}._deleteConversation conversationIDList:${t} clearHistoryMessage:${n}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,n)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===p.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var n;if(!v.hasLocalConversation(e))return!1;const s=null===(n=v.getLocalConversation(e))||void 0===n?void 0:n.type;return s!==t.CONV_GROUP||this._hasLocalGroup(e)?s===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,n){return t(this,void 0,void 0,(function*(){const{OuterConstant:s,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:n?1:0};if(e.forEach((e=>{var t;if(v.hasLocalConversation(e)){const n=(null===(t=v.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(n,"");n===s.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):n===s.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:s,clearHistoryMessage:o}=e;return m("recentcontact.batch_delete",{From_Account:t,ContactItem:s,ClearRamble:o},n)}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const n=1===e.type?`${s.CONV_C2C}${e.To_Account}`:`${s.CONV_GROUP}${e.ToGroupid}`;t.push(n)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{v.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&v.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=v.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(v.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&v.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core,s=e.replace(t,"");return!!n.getGroup(s)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var N=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:n}=e;if(console.log(`${this._name} conversationID:${t} draftText:${n}`),!v.hasLocalConversation(t))throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});const s=v.getLocalConversation(t);return null==s||s.setDraftText(n),v.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var D=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(n,s){return t(this,void 0,void 0,(function*(){n.length>30&&(console.warn(`${this._name}.set userIDList length:${n.length} exceeds limit 30`),n.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:s}=e.core.OuterConstant;return{[t]:0,[n]:1,[s]:2}}()[s],i=yield function(e,n){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:s}=e;return O("openim.set_c2c_peer_mute_notifications",{Peer_Account:t,Mute_Notifications:s},n)}))}({userIDList:n,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:s}=e;a.push({userID:t,code:s});const o=n.indexOf(t);o>-1&&n.splice(o,1)}));const c=[],l=[],{OuterConstant:u}=this._core;return n.forEach((e=>{l.push(`${u.CONV_C2C}${e}`),c.push({userID:e})})),v.patchMessageRemindType(l,s),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var A=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,n){return t(this,void 0,void 0,(function*(){const{common:s,OuterConstant:o}=this._core;yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:s,receiveMessageOption:o}=e;return O("group_open_http_svc.modify_group_member_info",{GroupId:t,Member_Account:s,MsgFlag:o},n)}))}({groupID:e,userID:s.getCurrentUserID(),receiveMessageOption:n},this._core);const i=`${o.CONV_GROUP}${e}`;return v.patchMessageRemindType([i],n),{code:0,data:{groupID:e,messageRemindType:n}}}))}};var G=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:s}=e;if(!t(s)){const{To_Account:e,MuteNotifications:t}=s,o=e.map((e=>`${n.CONV_C2C}${e}`)),i=c(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),v.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:n,userIDList:s,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(n)){console.log(`${this._name}.${t} groupID:${n} messageRemindType:${o}`);return yield A.set(n,o)}if(!r(s)){console.log(`${this._name}.${t} userIDList:${s} messageRemindType:${o}`);return yield D.set(s,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{init(e){console.log("ConversationAction.init"),this._core=e,f.init(e),M.init(e),S.init(e),T.init(e),L.init(e),R.init(e),y.init(e),N.init(e),G.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:n,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(n,o,this._onConversationModified,this),t.subscribeInnerEvent(n,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(n,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(n,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(s,this._dispose,this)}handleLoginSuccess(){f.handleLoginSuccess()}_onConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===C.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;y.handleConversationDeleted(t)}if(t===C.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(t===C.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;L.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;G.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;L.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:s,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,s,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(n,this._dispose,this)}};var U=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,D.init(e),A.init(e),E.init(e),I.init(e)}};const $=e=>!n(e)&&!s(e)&&!o(e),V={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!$(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!$(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!$(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:n,isObject:s,isString:o}}}=e;if(!o(t)&&!s(t))return"options is String or Object.";if(o(t)&&$(t))return"conversationID is invalid.";if(s(t)){if(!n(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if($(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!n(e)&&!s(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}},F={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0};var b=new class{install(t){e.init(t),P.init(t),U.init(t),v.init(t),t.helper.registerValidateConfig({auth:F,params:V})}handleLoginSuccess(){P.handleLoginSuccess()}};export{b 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).TencentCloudChatConversation=t()}(this,(function(){"use strict";function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function r(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,r)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",s="GROUP",n="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",u="TIMImageElem",d="TIMSoundElem",c="TIMFileElem",p="TIMFaceElem",g="TIMVideoFileElem",v="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",C="TIMCustomElem",_="TIMRelayElem",M="AcceptAndNotify",f="AcceptNotNotify",y="Discard",T="AcceptNotNotifyExceptAt";var I,L,S;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(I||(I={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(L||(L={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(S||(S={}));const E=e=>void 0===e,D=e=>"string"==typeof e,O=e=>"function"==typeof Array.isArray?Array.isArray(e):"array"===(e=>{var t;return null===(t=Object.prototype.toString.call(e).match(/^\[object (.*)\]$/))||void 0===t?void 0:t[1].toLowerCase()})(e),R=e=>O(e)||(e=>null!==e&&"object"==typeof e)(e),k=(e,t,s,n)=>{if(!R(e)||!R(t))return 0;let o=0;const i=Object.keys(t);let a;for(let r=0,l=i.length;r<l;r++)if(a=i[r],!(E(t[a])||s&&s.includes(a)))if(R(e[a])&&R(t[a]))o+=k(e[a],t[a],s,n);else{if(n&&n.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},P=(e,t)=>{if(E(t))return"";switch(e){case l:return t.text||"";case u:return"[Image]";case v:return"[Location]";case d:return"[Voice]";case g:return"[Video]";case c:return"[File]";case C:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case p:return"[Animated Sticker]";case _:return"[Chat Record]";default:return""}},G=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:P(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function N(e){const t=[];if(!D(e))return t;const s=e.length;if(0===s)return t;for(let n=s-1;n>=0;n--)"1"===e[n]&&t.push(2**(s-n-1));return t}class b{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=G(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark="",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){E(this.userProfile)&&this.type===t?this.userProfile={}:E(this.groupProfile)&&this.type===s&&(this.groupProfile={}),this.subType&&this.type===s&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;E(o)||(this.subType!==i?a&&this.type===s||a&&this.type===n||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=G(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:n,time:o}=e;return this.type===t&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}}var U=new class{constructor(){this._name="ConversationFactory",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0,this._pagingConvIDMap=new Map,this._convMap=new Map,this._convTotalUnreadCount=0}install(e){this._core=e;const{notificationCenter:t,InnerEvent:s,helper:n}=e;n.registerApi("getConversationList",this),n.registerApi("getConversationProfile",this),n.registerApi("setMessageRead",this),n.registerApi("getTotalUnreadMessageCount",this),n.registerApi("setConversationDraft",this),t.subscribeInnerEvent(s.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(s.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(s.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(s.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(s.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(s.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(s.DESTROY,this._dispose,this),console.log(`${this._name}.install`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this._onConversationListUpdate()}_handleMessageDeleted(e){var s,n,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(a.length||0)-1;e>=0;e--)if(!a[e].isDeleted){r=a[e];break}const l=this._convMap.get(e);if(!l)return;let u=!1;l.lastMessage.lastSequence===r.sequence&&l.lastMessage.lastTime===r.time||((null===(i=null===(o=this._core)||void 0===o?void 0:o.helper)||void 0===i?void 0:i.isEmpty(r))&&(r=void 0),l.updateLastMessage(r),u=!0),e.startsWith(t)&&this._updateUnreadCount(e),u&&(this._onConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. \n update conversationID:${e} with lastMessage:`,l.lastMessage))}_handleMessageRevoked(e){console.log(`${this._name}._handleMessageRevoked`,JSON.stringify(e));const{messageList:t=[],updateUnreadCount:s=!0}=e;if(0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this._convMap.get(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))})),o&&this._onConversationListUpdate()}_handleMessageModified(e){var t,s;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:n,message:o}=e,i=this._convMap.get(n);if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(i))return;const{lastMessage:a}=i;a&&a.lastTime===o.time&&a.lastSequence===o.sequence&&a.version!==o.version&&(a.type=o.type,a.payload=o.payload,a.messageForShow=P(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this._onConversationListUpdate(),console.log(`${this._name} conversationID:${n} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this._onConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){try{this._pagingStatus=I.PENDING;const s=yield function(t,s){return e(this,void 0,void 0,(function*(){const{pagingTimeStamp:e,pagingStartIndex:n,pagingPinnedTimeStamp:o,pagingPinnedStartIndex:i}=t;try{const t="recentcontact.page_get",a=null==s?void 0:s.helper.generateProtocolData({servcmd:t,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:null==s?void 0:s.store.get("login").userId,StartIndex:n,TimeStamp:e,TopStartIndex:i,TopTimeStamp:o}}),r=`${a.head.seq}${t}`;return yield s.channel.sendPacket(a,{requestId:r})}catch(e){throw console.warn(`ConversationService.pagingGetConvList error: ${e}`),e}}))}({pagingTimeStamp:t?this._pagingTimeStamp:0,pagingStartIndex:t?this._pagingStartIndex:0,pagingPinnedTimeStamp:t?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:t?this._pagingPinnedStartIndex:0},this._core);if(s){const{CompleteFlag:e,SessionItem:n=[],TimeStamp:o,StartIndex:i,TopTimeStamp:a,TopStartIndex:r}=s;if(n.length>0){const e=this._getConvOptions(n);this._pagingConvIDMap=new Map([...this._pagingConvIDMap,...e.map((e=>[e.conversationID,1]))]),this._updateLocalConvList({conversationOptionsList:e,isFromGetConversations:!0,updateUnreadCount:!0}),this._onConversationListUpdate()}this._pagingTimeStamp=o,this._pagingStartIndex=i,this._pagingPinnedTimeStamp=a,this._pagingPinnedStartIndex=r,1!==e&&this._pagingGetConvList(t)}}catch(e){throw console.error(`${this._name}._pagingGetConvList fail:`,e),e}}))}_getConvOptions(e){const n=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return n.map((e=>{var n,i,a,r,l,u,d,c,p,g,v,h;if(E(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===L.C2C){const s={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},g=null===(a=null===(i=null===(n=this._core)||void 0===n?void 0:n.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[s]);return{conversationID:`${t}${e.userID}`,type:t,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(r=e.lastMsg)||void 0===r?void 0:r.elements[0])?null===(l=e.lastMsg)||void 0===l?void 0:l.elements[0].type:null,payload:(null===(u=e.lastMsg)||void 0===u?void 0:u.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(d=e.lastMsg)||void 0===d?void 0:d.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(p=null===(c=e.lastMsg)||void 0===c?void 0:c.revokerInfo)||void 0===p?void 0:p.revoker)||null},unreadCount:0,userProfile:g,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${s}${e.groupID}`,type:s,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(g=e.lastMsg)||void 0===g?void 0:g.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(v=e.lastMsg)||void 0===v?void 0:v.revokerInfo)||void 0===h?void 0:h.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}))}_convertConvKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,s,n,o;if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(n=e.MsgBody[0])||void 0===n?void 0:n.MsgType,a=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:a,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var s;if(!t)return t;const n=this._core.message.messageFactory.getElementClass(e);return n?null===(s=n.parseServerPushElement(t))||void 0===s?void 0:s.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=M:1===e?t=y:2===e?t=f:3===e&&(t=T),t}_patchTypeAndPayload(e){const{event:t,elements:s=[]}=e.lastMsg||{};return E(t)?{type:s[0]?s[0].type:null,payload:s[0]?this._amendLayersOverLimitProp(s[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:s=0}=e,n=t-s;return n>0?n:0}_updateLocalConvList(e){const{newConvList:t}=this._getTmpConvListMapping(e);this._convMap=new Map(this._sortConvList([...this._convMap])),this._core.store.set("conversation",{conversationMap:this._convMap}),console.log(`${this._name}._updateLocalConvList newConvList: ${t.length}`)}_getTmpConvListMapping(e){const{conversationOptionsList:n,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],u=null==n?void 0:n.length;for(let e=0;e<u;e++){const u=new b(n[e]),{conversationID:d,type:c}=u;if(!this._isNonExistentAccount(d))if(this._convMap.has(d)){const l=this._convMap.get(d);if(o){this._convMap.set(d,u),c===t?u.unreadCount=l.unreadCount:c===s&&(u.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:d,tmpConversation:u,lastMessage:n[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:d,lastMessage:n[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:u.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(u),this._convMap.set(d,u)}return{newConvList:l}}_isNonExistentAccount(e){let s;return e.startsWith(t)&&(s=e.replace(t,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}_mergeConversationInfo(e){var t,s;const{conversationID:n,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(n),u=["unreadCount","allowType","adminForbidType","payload"];!1===r&&u.push("lastMessage"),a&&u.push("isPinned"),E(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);k(l,o,u,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:n,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&n){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===s&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],s=[],n=[],o=[];return e.forEach((e=>{var i,a,r,l;!0===e[1].isPinned?(null===(a=null===(i=this._core)||void 0===i?void 0:i.helper)||void 0===a?void 0:a.isEmpty(e[1].lastMessage.lastTime))?s.push(e):t.push(e):(null===(l=null===(r=this._core)||void 0===r?void 0:r.helper)||void 0===l?void 0:l.isEmpty(e[1].lastMessage.lastTime))?o.push(e):n.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_getLocalConvList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}_isConvNeedShow(e){const t=this._getLocalConversation(e);if(E(t))return!0;const o=t.type===n,i=t.type===s&&t.subType===a,l=t.type===s&&t.subType===r;return!(o||i||l)}_getLocalConversation(e){return this._convMap.get(e)}_updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this._getLocalConversation(e),a=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const r=i.unreadCount,l=null==a?void 0:a.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return r!==l&&(i.unreadCount=l,o=!0,console.log(`${this._name}._updateUnreadCount\n from ${r} to ${l}, conversationID:${e}`),!0===t&&this._onConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_onConversationListUpdate(){var e;const t=this._getLocalConvList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.CONVERSATION_LIST_UPDATED,data:t}),this._onTotalUnreadCountUpdate()}_onTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._onTotalUnreadCountUpdate from ${this._convTotalUnreadCount} to ${t}`),this._convTotalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(E(e))return this._getLocalConvList();if(O(e)){if(0===e.length)return[];return this._getLocalConvList().filter((t=>e.includes(t.conversationID)))}if((e=>{if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let s=t;for(;null!==Object.getPrototypeOf(s);)s=Object.getPrototypeOf(s);return t===s})(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this._getLocalConvList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,n){return n!==t&&n!==s||e.type===n}_filterGroupName(e,t){return!D(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(s=t)||!("number"==typeof s&&!Number.isNaN(s-0)||"object"==typeof s&&s.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var s}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_recoverConversations(){return e(this,void 0,void 0,(function*(){try{yield this.syncConvList(),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.RECOVER_CONVERSATIONS_COMPLETED)}catch(e){console.debug(e)}}))}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}getConversationProfile(n){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(n)?e=this._convMap.get(n):(e=new b({conversationID:n}),(e=>D(e)&&e.slice(0,3)===t)(n)?(e.type=t,e.userProfile={userID:n.replace(t,"")}):(e.type=s,e.groupProfile={groupID:n.replace(s,"")}),this._convMap.set(n,e)),{code:0,data:{conversation:e}}}))}setMessageRead(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}.setMessageRead ok, ${JSON.stringify(t)}`)}))}setConversationDraft(t){return e(this,void 0,void 0,(function*(){return console.log(`${this._name}.setConversationDraft , ${JSON.stringify(t)}`),{code:0,data:{conversation:{}}}}))}getTotalUnreadMessageCount(){const e=this._getLocalConvList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==M||(t+=e.unreadCount))})),t}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.RE_LOGIN,this._recoverConversations,this),e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.NEW_MESSAGE,this._handleNewMessage,this),e.unSubscribeInnerEvent(t.MESSAGE_DELETED,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(t.MESSAGE_REVOKED,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(t.MESSAGE_MODIFIED,this._handleMessageModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const A={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0},F={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!e.startsWith("C2C")&&!e.startsWith("GROUP"))||"conversationID is invalid."}]};return{install:function(e){U.install(e),e.helper.registerValidateConfig({auth:A,params:F})},handleLoginSuccess:function(){U.handleLoginSuccess()}}}));
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).TencentCloudChatConversation=t()}(this,(function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,3)===n.CONV_C2C},s=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,5)===n.CONV_GROUP},o=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t===n.CONV_SYSTEM},i=(t,n)=>{const{core:{utils:{isUndefined:s}}}=e;if(s(n))return"";const{core:{OuterConstant:o}}=e;switch(t){case o.MSG_TEXT:return n.text||"";case o.MSG_IMAGE:return"[Image]";case o.MSG_LOCATION:return"[Location]";case o.MSG_AUDIO:return"[Voice]";case o.MSG_VIDEO:return"[Video]";case o.MSG_FILE:return"[File]";case o.MSG_CUSTOM:return"[Custom Messages]";case o.MSG_GRP_TIP:return"[Group Notification]";case o.MSG_GRP_SYS_NOTICE:return"[Group System Message]";case o.MSG_FACE:return"[Animated Sticker]";case o.MSG_MERGER:return"[Chat Record]";default:return""}},r=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:i(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function a(t){const{core:{utils:{isString:n}}}=e,s=[];if(!n(t))return s;const o=t.length;if(0===o)return s;for(let e=o-1;e>=0;e--)"1"===t[e]&&s.push(2**(o-e-1));return s}function c(t){const{OuterConstant:n}=e.core;let s="";return 0===t?s=n.MSG_REMIND_ACPT_AND_NOTE:1===t?s=n.MSG_REMIND_DISCARD:2===t?s=n.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(s=n.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function l(t){const{OuterConstant:n}=e.core;let s;return t.startsWith(n.CONV_C2C)&&(s=t.replace(n.CONV_C2C,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}var u,d,_,p,h;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(u||(u={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(d||(d={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(_||(_={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(p||(p={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(h||(h={}));var C;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(C||(C={}));class g{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=r(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){const{core:{OuterConstant:t,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:n(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:n,utils:{isUndefined:s}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;s(o)||(this.subType!==n.GRP_AVCHATROOM?i&&this.type===n.CONV_GROUP||i&&this.type===n.CONV_TOPIC||r&&this.type===n.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=r(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:n}}=e,{sequence:s,time:o}=t;return this.type===n.CONV_C2C&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n.CONV_GROUP&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{OuterConstant:n}}=e;let[...s]=t.groupAtType;s.includes(n.CONV_AT_ME)||s.includes(n.CONV_AT_ALL)||(s=[n.CONV_AT_ALL_AT_ME]);const o={from:t.from,groupID:t.groupID,messageSequence:t.sequence,atTypeArray:s,__random:t.__random,__sequence:t.__sequence};this.groupAtInfoList.push(o)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var v=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:n,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{MESSAGE_PUSH:r,NEW_MESSAGE:a,MESSAGE_DELETED:c,MESSAGE_REVOKED:l,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:d,LOGOUT:_,DESTROY:p}}=e;this._conversationStore=s,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this);const{InnerEventSubType:{GROUP_AT_TIPS:h}}=n;n.subscribeInnerEvent(a,this._handleNewMessage,this),n.subscribeInnerEvent(r,h,this._handleNewGroupAtTips,this),n.subscribeInnerEvent(c,this._handleMessageDeleted,this),n.subscribeInnerEvent(l,this._handleMessageRevoked,this),n.subscribeInnerEvent(u,this._handleMessageModified,this),n.subscribeInnerEvent(d,this._handleConversationUpdated,this),n.subscribeInnerEvent(_,this._reset,this),n.subscribeInnerEvent(p,this._dispose,this),console.log(`${this._name}.init`)}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:n=[],groupTipList:s=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;n.forEach((e=>{const{conversationID:t,unreadCount:n}=e,s=this.getLocalConversation(t);s&&s.unreadCount!==n&&(s.updateUnreadCount({nextUnreadCount:n,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(s)}_handleGroupAtTipsSynced(e){for(let t=0;t<e.length;t++)12===e[t].Event&&this._handleNewGroupAtTips(e[t])}_handleGroupListSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,n=e.result[t.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:s}}=this._core;let o=!1;for(let e=0;e<n.length;e++){const t=n[e],i=`${s}${t.groupID}`;if(!this.hasLocalConversation(i))continue;const r=this.getLocalConversation(i);r.groupProfile=JSON.parse(JSON.stringify(t)),r.lastMessage.lastSequence<t.nextMessageSeq&&(r.lastMessage.lastSequence=t.nextMessageSeq-1),r.subType||(r.subType=t.type),o=!0}o&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e.result||{};if(console.log(`${this._name}._handleNewMessage, conversationUpdateFieldList length:`,t.length,e),0===t.length)return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:n,GroupAtType:s,MsgRandom:o,ClientSeq:i}=e;let r={};t?r=this._convertGroupAtTipsKey(t):n?r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(n)),{sync:!0}):s&&(r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(e)),{sync:!0})),r.__random=o,r.__sequence=i,this._groupAtTipsList.push(r)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:n,MsgSeq:s,GroupAtType:o}=e;return{from:t,groupID:n,sequence:s,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,n=e.getCurrentUserID();let s=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==n){const n=this.getLocalConversation(`${t.CONV_GROUP}${o}`);n&&(n.updateGroupAtInfoList(e),s=!0)}})),s&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,n;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:s},OuterConstant:o}=this._core,i=(null==s?void 0:s.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:n=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this.getLocalConversation(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:n}=e,s=this.getLocalConversation(t),{utils:{isEmpty:o}}=this._core;if(o(s))return;const{lastMessage:r}=s;if(r){const e=(null==n?void 0:n[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(){this.emitConversationListUpdate()}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:n}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(n),console.log(`${this._name}.updateLocalConversationList newConversationList: ${n.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:n,isFromGetConversations:s,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,a=[],c=null==n?void 0:n.length;for(let e=0;e<c;e++){const c=new g(n[e]),{conversationID:u,type:d}=c;if(!l(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(s){this.setLocalConversation(u,c),d===t.CONV_C2C?c.unreadCount=(null==a?void 0:a.unreadCount)||0:d===t.CONV_GROUP&&(c.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:c,lastMessage:n[e].lastMessage,isFromGetConversations:s,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:n[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:c.unreadCount,isFromGetConversations:s,isUnreadC2CMessage:i}))}else a.push(c),this.setLocalConversation(u,c)}return{newConversationList:a}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:n,lastMessage:s,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:u}}=this._core;c(i)&&s&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=s.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);u(r,n,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:n,lastMessage:s,isInstantMessage:o}=e,i=this.getLocalConversation(n);if(i&&s){const{payload:e,nameCard:n,nick:r,cloudCustomData:a=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=n,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],n=[],s=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?s.push(t):n.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],n=[],{OuterConstant:{CONV_GROUP:s,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===s){const e=i.replace(s,"");n.push(e)}})),t.length>0&&this._updateC2CConversation(t),n.length>0&&this._updateGroupConversation(n)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:n},appStore:{userStore:s},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${n}${o}`);if(r){const n=(null===(t=s.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=n,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core;let s=!1;e.forEach((e=>{const o=n.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,s=!0)})),s&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:n}=this._core,s=t.type===n.CONV_TOPIC,o=t.type===n.CONV_GROUP&&t.subType===n.GRP_ROOM,i=t.type===n.CONV_GROUP&&t.subType===n.GRP_LIVE;return!(s||o||i)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),r=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageDataHandler)||void 0===s?void 0:s.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,n=this.getLocalConversationList();this._emitEvent({name:t,data:n}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e}=this._core,t=this.getLocalConversationList();let n=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(n+=t.unreadCount))})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,n]of e)this.setLocalConversation(t,n)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let n=!1;e.forEach((e=>{const s=this.getLocalConversation(e);(null==s?void 0:s.messageRemindType)!==t&&(s.messageRemindType=t,n=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${n}`),n&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:n,lastReadTime:s=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(n);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],n=s&&t.time>s,r=o&&t.sequence>o;if(!n&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],n=t.findIndex((e=>!1===e[1].isPinned));t.splice(n,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:n,MESSAGE_REVOKED:s,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:c}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,c,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(n,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(s,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};function m(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var f=new class{constructor(){this._name="SyncConversationList",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s,constants:o}=e;s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.CONVERSATION_RECOVER,this._syncConversationListOnReOnline,this),s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_LOGIN,o.WORKFLOW_STEP.CONVERSATION_LIST_SYNC,this._syncConversationList,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}isSyncCompleted(){return this._pagingStatus===u.RESOLVED}_syncConversationListOnReOnline(){return t(this,void 0,void 0,(function*(){return this._syncConversationList()}))}_syncConversationList(){return t(this,void 0,void 0,(function*(){yield this._pagingGetConversationList(!0),this._pagingStatus=u.RESOLVED,v.emitConversationListUpdate()}))}_pagingGetConversationList(e){return t(this,void 0,void 0,(function*(){try{this._pagingStatus=u.PENDING;const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:r}=e;return m("recentcontact.page_get",{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:t,StartIndex:o,TimeStamp:s,TopStartIndex:r,TopTimeStamp:i},n)}))}({fromAccount:n.getCurrentUserID(),pagingTimeStamp:e?this._pagingTimeStamp:0,pagingStartIndex:e?this._pagingStartIndex:0,pagingPinnedTimeStamp:e?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:e?this._pagingPinnedStartIndex:0},this._core),{CompleteFlag:o,SessionItem:i=[],TimeStamp:r,StartIndex:a,TopTimeStamp:c,TopStartIndex:l}=s||{};if(i.length>0){const e=this._getConversationOptions(i);v.updateLocalConversationList({conversationUpdateFieldList:e,isFromGetConversations:!0,updateUnreadCount:!0}),v.emitConversationListUpdate()}this._pagingTimeStamp=r,this._pagingStartIndex=a,this._pagingPinnedTimeStamp=c,this._pagingPinnedStartIndex=l,1!==o&&this._pagingGetConversationList(e)}catch(e){throw console.error(`${this._name}._pagingGetConversationList fail:`,e),e}}))}_getConversationOptions(e){const{utils:{isUndefined:t}}=this._core,n=this._convertConversationKey(e);return this._filterValidConversations(n).map((e=>(t(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===d.C2C?this._assembleC2COption(e):this._assembleGroupOption(e))))}_filterValidConversations(e){return e.filter((({type:e,userID:t})=>e===d.C2C&&!l(t)||2===e))}_assembleC2COption(e){var t,n,s,o,i,r;const{OuterConstant:c}=this._core,l=this._createUserprofile(e);return{conversationID:`${c.CONV_C2C}${e.userID}`,type:c.CONV_C2C,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(t=e.lastMsg)||void 0===t?void 0:t.elements[0])?null===(n=e.lastMsg)||void 0===n?void 0:n.elements[0].type:null,payload:(null===(s=e.lastMsg)||void 0===s?void 0:s.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(o=e.lastMsg)||void 0===o?void 0:o.cloudCustomData)||"",isRevoked:e.lastMessageFlag===_.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:this._computeIsPeerRead(e),revoker:(null===(r=null===(i=e.lastMsg)||void 0===i?void 0:i.revokerInfo)||void 0===r?void 0:r.revoker)||null},unreadCount:0,userProfile:l,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:a(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}_createUserprofile(e){var t;const{userID:n,nick:s,peerAvatar:o}=e,i=[{tag:"Tag_Profile_IM_Nick",value:s},{tag:"Tag_Profile_IM_Image",value:o}];return null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(n,i)}_computeIsPeerRead(e){const{common:t}=this._core,n=t.getCurrentUserID(),{lastC2CMsgFromAccount:s,time:o,c2cPeerReadTime:i}=e;return s===n&&o<=i}_assembleGroupOption(e){var t,n,s;const{OuterConstant:o}=this._core;return{conversationID:`${o.CONV_GROUP}${e.groupID}`,type:o.CONV_GROUP,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(t=e.lastMsg)||void 0===t?void 0:t.cloudCustomData)||"",isRevoked:e.lastMessageFlag===_.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(s=null===(n=e.lastMsg)||void 0===n?void 0:n.revokerInfo)||void 0===s?void 0:s.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:a(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}_convertConversationKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",r=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.MsgType,r=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:r,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){const{OuterConstant:t}=this._core;let n="";return 0===e?n=t.MSG_REMIND_ACPT_AND_NOTE:1===e?n=t.MSG_REMIND_DISCARD:2===e?n=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(n=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}_patchTypeAndPayload(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core,{event:s,elements:o=[]}=e.lastMsg||{};return n(s)?{type:o[0]?o[0].type:null,payload:o[0]?this._amendLayersOverLimitProp(o[0].content):null}:{type:t.MSG_GRP_TIP,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s:0}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};var M=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:f.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:n,isPlainObject:s}}=this._core;if(t(e))return v.getLocalConversationList();if(n(e)){if(0===e.length)return[];return v.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(s(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return v.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:n}=this._core;return t!==n.CONV_C2C&&t!==n.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:n}}=this._core;return!n(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:n}}=this._core;return!n(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_filterGroupAtInfo(e,t){let n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}};function O(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var E=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:s}=e;return O("openim.get_c2c_peer_mute_notifications",{To_Account:t,Peer_Account:s},n)}))}({toAccount:n.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=s||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:n}=e,s=`${this._core.OuterConstant.CONV_C2C}${t}`,o=c(n);v.patchMessageRemindType([s],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var I=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const n=yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:s}=e;return O("group_open_http_svc.get_group_self_member_info",{GroupIdList:t,ResponseFilter:s},n)}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=n||{};s.forEach((e=>{var t;const{GroupId:n,MemberList:s}=e,o=(null===(t=s[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${n}`;v.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var S=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:{groupStore:i},utils:{isEmpty:r}}=this._core,a={code:0,data:null};let c=v.getLocalConversation(e);if(o(e))return a.data=c,a;let l=!1;const u=n(e)?t:s;if(r(c)&&(l=!0,c=new g({conversationID:e,type:u})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${l}`),a.data=c,null==c?void 0:c.getProfileCompleted())return a;if(u===t){const n=e.replace(t,"");yield this._handleC2CConversation(c,n),l&&(yield E.get([n]))}if(u===s){const t=e.replace(s,"");if(!i.getGroup(t))return a;yield this._handleGroupConversation(c,t),l&&(yield I.get([t]))}return a}))}_handleC2CConversation(e,n){return t(this,void 0,void 0,(function*(){var t,s;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,u=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[n]});if(0===(null==u?void 0:u.data.length))throw new i.ChatError({code:C.USER_OR_GRP_NOT_FOUND});e.userProfile=null==u?void 0:u.data[0];const d=null===(s=c.getFriend(n))||void 0===s?void 0:s.remark;r(d)||e.remark===d||(e.remark=d),e.setProfileCompleted();const _=v.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${_}`),_?a.updateConversation(l,e):v.appendToPinnedConversation(e)}))}_handleGroupConversation(e,n){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:s}}=this._core,{conversationID:o}=e,i=yield t({groupID:n});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=v.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?s.updateConversation(o,e):v.appendToPinnedConversation(e)}))}};var T=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return v.getTotalUnreadMessageCount()}};var L=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRead",context:this})}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:s}=e;if(!t(s)){const{UinPairReadArray:e=[]}=s;e.forEach((e=>{const{From_Account:t,LastReadTime:s}=e,o=`${n.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${s}`),v.markMessageAsRead({conversationID:o,lastReadTime:s}),v.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:s}=e.MsgBody;n(s)||s.forEach((e=>{const{GroupId:n,LastReadMsgSeq:s}=e,o=`${t.CONV_GROUP}${n}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${s}`),v.markMessageAsRead({conversationID:o,lastReadSequence:s}),v.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,n;const{OuterConstant:s}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=v.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r.groupAtInfoList));if(r.type===s.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;if(r.type===s.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e)}if(r.type===s.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e)}return r.type===s.CONV_SYSTEM&&(r.unreadCount=0),v.emitConversationListUpdate(),i}))}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const n=v.getLocalConversation(e);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const{common:n}=this._core,o=s.map((e=>({From_Account:e.from,To_Account:n.getCurrentUserID(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,n){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e;return m("openim.deletemsg",{DelMsgList:t},n)}))}({messageListToDelete:o},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=v.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&v.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){return m("openim.msgreaded",e,n)}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${n}`),v.markMessageAsRead({conversationID:e,lastReadTime:n}),v.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:s}=e;return m("group_open_http_svc.msg_read_report",{GroupId:t,MsgReadedSeq:s},n)}))}({groupID:e.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${n}`),v.markMessageAsRead({conversationID:e,lastReadSequence:n}),v.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:n}}=this._core;if(!n(e))return;const{OuterConstant:s}=this._core;let o=!1;e.forEach((e=>{const{Type:n,To_Account:i,GroupId:r}=e;let a;1===n?a=v.getLocalConversation(`${s.CONV_C2C}${i}`):2===n&&(a=v.getLocalConversation(`${s.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&v.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r}=this._core,{conversationID:a,isPinned:c}=e,l={code:0,data:{conversationID:a}},u=v.getLocalConversation(a);if(u&&u.isPinned===c)return l;if(o(a))return u&&(u.isPinned=c),v.emitConversationListUpdate(!0),l;try{let e=null;n(a)?e={Type:1,To_Account:a.replace(i.CONV_C2C,"")}:s(a)&&(e={Type:2,GroupId:a.replace(i.CONV_GROUP,"")});const o=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:s,itemList:o}=e;return m("recentcontact.top",{From_Account:t,OperationType:s,RecentContactItem:o},n)}))}({fromAccount:r.getCurrentUserID(),operationType:!0===c?1:2,itemList:[e]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${a} isPinned:${c}.`),o){if(u)u.isPinned!==c&&(u.isPinned=c);else{const e=new g({conversationID:a,type:n(a)?i.CONV_C2C:i.CONV_GROUP,isPinned:c});v.setLocalConversation(a,e)}v.emitConversationListUpdate(!0)}return l}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var y=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:n}=this._core,s=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&s.push(`${n.CONV_C2C}${o}`),2===t&&s.push(`${n.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return console.log(`${this._name}.deleteConversation conversationID:${e}`),void(yield this._deleteConversation({conversationIDList:[e],flag:p.ONLY_CONVERSATIONID}));const n=Object.assign({},e);n.conversationIDList.length>100&&(n.conversationIDList=n.conversationIDList.slice(0,100)),yield this._deleteConversation(n)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:n=!0,flag:s=0}=e;console.log(`${this._name}._deleteConversation conversationIDList:${t} clearHistoryMessage:${n}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,n)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:C.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===p.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var n;if(!v.hasLocalConversation(e))return!1;const s=null===(n=v.getLocalConversation(e))||void 0===n?void 0:n.type;return s!==t.CONV_GROUP||this._hasLocalGroup(e)?s===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,n){return t(this,void 0,void 0,(function*(){const{OuterConstant:s,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:n?1:0};if(e.forEach((e=>{var t;if(v.hasLocalConversation(e)){const n=(null===(t=v.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(n,"");n===s.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):n===s.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:s,clearHistoryMessage:o}=e;return m("recentcontact.batch_delete",{From_Account:t,ContactItem:s,ClearRamble:o},n)}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const n=1===e.type?`${s.CONV_C2C}${e.To_Account}`:`${s.CONV_GROUP}${e.ToGroupid}`;t.push(n)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{v.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&v.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=v.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(v.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&v.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core,s=e.replace(t,"");return!!n.getGroup(s)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var N=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:n}=e;if(console.log(`${this._name} conversationID:${t} draftText:${n}`),!v.hasLocalConversation(t))throw new this._core.helper.ChatError({code:C.CONV_NOT_FOUND});const s=v.getLocalConversation(t);return null==s||s.setDraftText(n),v.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var D=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(n,s){return t(this,void 0,void 0,(function*(){n.length>30&&(console.warn(`${this._name}.set userIDList length:${n.length} exceeds limit 30`),n.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:s}=e.core.OuterConstant;return{[t]:0,[n]:1,[s]:2}}()[s],i=yield function(e,n){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:s}=e;return O("openim.set_c2c_peer_mute_notifications",{Peer_Account:t,Mute_Notifications:s},n)}))}({userIDList:n,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:s}=e;a.push({userID:t,code:s});const o=n.indexOf(t);o>-1&&n.splice(o,1)}));const c=[],l=[],{OuterConstant:u}=this._core;return n.forEach((e=>{l.push(`${u.CONV_C2C}${e}`),c.push({userID:e})})),v.patchMessageRemindType(l,s),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var A=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,n){return t(this,void 0,void 0,(function*(){const{common:s,OuterConstant:o}=this._core;yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:s,receiveMessageOption:o}=e;return O("group_open_http_svc.modify_group_member_info",{GroupId:t,Member_Account:s,MsgFlag:o},n)}))}({groupID:e,userID:s.getCurrentUserID(),receiveMessageOption:n},this._core);const i=`${o.CONV_GROUP}${e}`;return v.patchMessageRemindType([i],n),{code:0,data:{groupID:e,messageRemindType:n}}}))}};var G=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:s}=e;if(!t(s)){const{To_Account:e,MuteNotifications:t}=s,o=e.map((e=>`${n.CONV_C2C}${e}`)),i=c(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),v.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:n,userIDList:s,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(n)){console.log(`${this._name}.${t} groupID:${n} messageRemindType:${o}`);return yield A.set(n,o)}if(!r(s)){console.log(`${this._name}.${t} userIDList:${s} messageRemindType:${o}`);return yield D.set(s,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{init(e){console.log("ConversationAction.init"),this._core=e,f.init(e),M.init(e),S.init(e),T.init(e),L.init(e),R.init(e),y.init(e),N.init(e),G.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:n,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(n,o,this._onConversationModified,this),t.subscribeInnerEvent(n,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(n,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(n,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(s,this._dispose,this)}handleLoginSuccess(){f.handleLoginSuccess()}_onConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===h.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;y.handleConversationDeleted(t)}if(t===h.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(t===h.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;L.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;G.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;L.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:s,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,s,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(n,this._dispose,this)}};var U=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,D.init(e),A.init(e),E.init(e),I.init(e)}};const $=e=>!n(e)&&!s(e)&&!o(e),V={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!$(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!$(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!$(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:n,isObject:s,isString:o}}}=e;if(!o(t)&&!s(t))return"options is String or Object.";if(o(t)&&$(t))return"conversationID is invalid.";if(s(t)){if(!n(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if($(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!n(e)&&!s(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}},F={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0};return new class{install(t){e.init(t),P.init(t),U.init(t),v.init(t),t.helper.registerValidateConfig({auth:F,params:V})}handleLoginSuccess(){P.handleLoginSuccess()}}}));