@tencentcloud/lite-chat 1.2.1 → 1.4.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.
Files changed (41) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/basic.d.ts +3110 -0
  3. package/basic.es.js +3 -1
  4. package/basic.js +3 -1
  5. package/package.json +3 -3
  6. package/plugins/avchatroom.es.js +1 -1
  7. package/plugins/avchatroom.js +1 -1
  8. package/plugins/cloud-search.es.js +1 -1
  9. package/plugins/cloud-search.js +1 -1
  10. package/plugins/conversation-group.d.ts +8 -0
  11. package/plugins/conversation-group.es.js +1 -0
  12. package/plugins/conversation-group.js +1 -0
  13. package/plugins/conversation.es.js +1 -1
  14. package/plugins/conversation.js +1 -1
  15. package/plugins/follow.es.js +1 -1
  16. package/plugins/follow.js +1 -1
  17. package/plugins/friend.es.js +1 -1
  18. package/plugins/friend.js +1 -1
  19. package/plugins/group.es.js +1 -1
  20. package/plugins/group.js +1 -1
  21. package/plugins/message-enhancer.es.js +3 -1
  22. package/plugins/message-enhancer.js +3 -1
  23. package/plugins/offline-message-synchronizer.d.ts +9 -0
  24. package/plugins/offline-message-synchronizer.es.js +1 -0
  25. package/plugins/offline-message-synchronizer.js +1 -0
  26. package/plugins/rich-media-message.es.js +1 -1
  27. package/plugins/rich-media-message.js +1 -1
  28. package/plugins/signaling.d.ts +8 -0
  29. package/plugins/signaling.es.js +1 -1
  30. package/plugins/signaling.js +1 -1
  31. package/plugins/topic.d.ts +8 -0
  32. package/plugins/topic.es.js +1 -0
  33. package/plugins/topic.js +1 -0
  34. package/professional.d.ts +3110 -0
  35. package/professional.es.js +5 -1
  36. package/professional.js +5 -1
  37. package/standard.es.js +5 -1
  38. package/standard.js +5 -1
  39. package/index.es.js +0 -1
  40. package/index.js +0 -1
  41. package/plugins/user-enhancer.d.ts +0 -8
@@ -1 +1 @@
1
- const e=new class{init(e){this.core=e}};function t(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,3)===n.CONV_C2C},s=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,5)===n.CONV_GROUP},o=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t===n.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{core:{utils:{isString:n}}}=e,s=[];if(!n(t))return s;const o=t.length;if(0===o)return s;for(let e=o-1;e>=0;e--)"1"===t[e]&&s.push(2**(o-e-1));return s}function a(t){const{OuterConstant:n}=e.core;let s="";return 0===t?s=n.MSG_REMIND_ACPT_AND_NOTE:1===t?s=n.MSG_REMIND_DISCARD:2===t?s=n.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(s=n.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function c(t){const{OuterConstant:n}=e.core;let s;return t.startsWith(n.CONV_C2C)&&(s=t.replace(n.CONV_C2C,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}var l,u,d,_,p;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(l||(l={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(u||(u={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(_||(_={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(p||(p={}));var h;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(h||(h={}));class C{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){const{core:{OuterConstant:t,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:n(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:n,utils:{isUndefined:s}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;s(o)||(this.subType!==n.GRP_AVCHATROOM?i&&this.type===n.CONV_GROUP||i&&this.type===n.CONV_TOPIC||r&&this.type===n.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:n}}=e,{sequence:s,time:o}=t;return this.type===n.CONV_C2C&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n.CONV_GROUP&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{OuterConstant:n}}=e;let[...s]=t.groupAtType;s.includes(n.CONV_AT_ME)||s.includes(n.CONV_AT_ALL)||(s=[n.CONV_AT_ALL_AT_ME]);const o={from:t.from,groupID:t.groupID,messageSequence:t.sequence,atTypeArray:s,__random:t.__random,__sequence:t.__sequence};this.groupAtInfoList.push(o)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var g=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:n,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{MESSAGE_PUSH:r,NEW_MESSAGE:a,MESSAGE_DELETED:c,MESSAGE_REVOKED:l,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:d,LOGOUT:_,DESTROY:p}}=e;this._conversationStore=s,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this);const{InnerEventSubType:{GROUP_AT_TIPS:h}}=n;n.subscribeInnerEvent(a,this._handleNewMessage,this),n.subscribeInnerEvent(r,h,this._handleNewGroupAtTips,this),n.subscribeInnerEvent(c,this._handleMessageDeleted,this),n.subscribeInnerEvent(l,this._handleMessageRevoked,this),n.subscribeInnerEvent(u,this._handleMessageModified,this),n.subscribeInnerEvent(d,this._handleConversationUpdated,this),n.subscribeInnerEvent(_,this._reset,this),n.subscribeInnerEvent(p,this._dispose,this),console.log(`${this._name}.init`)}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:n=[],groupTipList:s=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;n.forEach((e=>{const{conversationID:t,unreadCount:n}=e,s=this.getLocalConversation(t);s&&s.unreadCount!==n&&(s.updateUnreadCount({nextUnreadCount:n,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(s)}_handleGroupAtTipsSynced(e){for(let t=0;t<e.length;t++)12===e[t].Event&&this._handleNewGroupAtTips(e[t])}_handleGroupListSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,n=e.result[t.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:s}}=this._core;let o=!1;for(let e=0;e<n.length;e++){const t=n[e],i=`${s}${t.groupID}`;if(!this.hasLocalConversation(i))continue;const r=this.getLocalConversation(i);r.groupProfile=JSON.parse(JSON.stringify(t)),r.lastMessage.lastSequence<t.nextMessageSeq&&(r.lastMessage.lastSequence=t.nextMessageSeq-1),r.subType||(r.subType=t.type),o=!0}o&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e.result||{};if(console.log(`${this._name}._handleNewMessage, conversationUpdateFieldList length:`,t.length,e),0===t.length)return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:n,GroupAtType:s,MsgRandom:o,ClientSeq:i}=e;let r={};t?r=this._convertGroupAtTipsKey(t):n?r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(n)),{sync:!0}):s&&(r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(e)),{sync:!0})),r.__random=o,r.__sequence=i,this._groupAtTipsList.push(r)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:n,MsgSeq:s,GroupAtType:o}=e;return{from:t,groupID:n,sequence:s,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,n=e.getCurrentUserID();let s=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==n){const n=this.getLocalConversation(`${t.CONV_GROUP}${o}`);n&&(n.updateGroupAtInfoList(e),s=!0)}})),s&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,n;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:s},OuterConstant:o}=this._core,i=(null==s?void 0:s.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:n=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this.getLocalConversation(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:n}=e,s=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(s))return;const{lastMessage:r}=s;if(r){const e=(null==n?void 0:n[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(){this.emitConversationListUpdate()}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:n}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(n),console.log(`${this._name}.updateLocalConversationList newConversationList: ${n.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:n,isFromGetConversations:s,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,a=[],l=null==n?void 0:n.length;for(let e=0;e<l;e++){const l=new C(n[e]),{conversationID:u,type:d}=l;if(!c(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(s){this.setLocalConversation(u,l),d===t.CONV_C2C?l.unreadCount=(null==a?void 0:a.unreadCount)||0:d===t.CONV_GROUP&&(l.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:l,lastMessage:n[e].lastMessage,isFromGetConversations:s,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:n[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:l.unreadCount,isFromGetConversations:s,isUnreadC2CMessage:i}))}else a.push(l),this.setLocalConversation(u,l)}return{newConversationList:a}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:n,lastMessage:s,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:u}}=this._core;c(i)&&s&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=s.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);u(r,n,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:n,lastMessage:s,isInstantMessage:o}=e,i=this.getLocalConversation(n);if(i&&s){const{payload:e,nameCard:n,nick:r,cloudCustomData:a=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=n,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],n=[],s=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?s.push(t):n.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],n=[],{OuterConstant:{CONV_GROUP:s,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===s){const e=i.replace(s,"");n.push(e)}})),t.length>0&&this._updateC2CConversation(t),n.length>0&&this._updateGroupConversation(n)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:n},appStore:{userStore:s},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${n}${o}`);if(r){const n=(null===(t=s.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=n,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core;let s=!1;e.forEach((e=>{const o=n.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,s=!0)})),s&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:n}=this._core,s=t.type===n.CONV_TOPIC,o=t.type===n.CONV_GROUP&&t.subType===n.GRP_ROOM,i=t.type===n.CONV_GROUP&&t.subType===n.GRP_LIVE;return!(s||o||i)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),r=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageDataHandler)||void 0===s?void 0:s.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,n=this.getLocalConversationList();this._emitEvent({name:t,data:n}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e}=this._core,t=this.getLocalConversationList();let n=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(n+=t.unreadCount))})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,n]of e)this.setLocalConversation(t,n)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let n=!1;e.forEach((e=>{const s=this.getLocalConversation(e);(null==s?void 0:s.messageRemindType)!==t&&(s.messageRemindType=t,n=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${n}`),n&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:n,lastReadTime:s=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(n);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],n=s&&t.time>s,r=o&&t.sequence>o;if(!n&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],n=t.findIndex((e=>!1===e[1].isPinned));t.splice(n,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:n,MESSAGE_REVOKED:s,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:c}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,c,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(n,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(s,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};function v(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var m=new class{constructor(){this._name="SyncConversationList",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s,constants:o}=e;s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.CONVERSATION_RECOVER,this._syncConversationListOnReOnline,this),s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_LOGIN,o.WORKFLOW_STEP.CONVERSATION_LIST_SYNC,this._syncConversationList,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}isSyncCompleted(){return this._pagingStatus===l.RESOLVED}_syncConversationListOnReOnline(){return t(this,void 0,void 0,(function*(){return this._syncConversationList()}))}_syncConversationList(){return t(this,void 0,void 0,(function*(){yield this._pagingGetConversationList(!0),this._pagingStatus=l.RESOLVED,g.emitConversationListUpdate()}))}_pagingGetConversationList(e){return t(this,void 0,void 0,(function*(){try{this._pagingStatus=l.PENDING;const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:r}=e;return v("recentcontact.page_get",{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:t,StartIndex:o,TimeStamp:s,TopStartIndex:r,TopTimeStamp:i},n)}))}({fromAccount:n.getCurrentUserID(),pagingTimeStamp:e?this._pagingTimeStamp:0,pagingStartIndex:e?this._pagingStartIndex:0,pagingPinnedTimeStamp:e?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:e?this._pagingPinnedStartIndex:0},this._core),{CompleteFlag:o,SessionItem:i=[],TimeStamp:r,StartIndex:a,TopTimeStamp:c,TopStartIndex:u}=s||{};if(i.length>0){const e=this._getConversationOptions(i);g.updateLocalConversationList({conversationUpdateFieldList:e,isFromGetConversations:!0,updateUnreadCount:!0}),g.emitConversationListUpdate()}this._pagingTimeStamp=r,this._pagingStartIndex=a,this._pagingPinnedTimeStamp=c,this._pagingPinnedStartIndex=u,1!==o&&this._pagingGetConversationList(e)}catch(e){throw console.error(`${this._name}._pagingGetConversationList fail:`,e),e}}))}_getConversationOptions(e){const{utils:{isUndefined:t}}=this._core,n=this._convertConversationKey(e);return this._filterValidConversations(n).map((e=>(t(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===u.C2C?this._assembleC2COption(e):this._assembleGroupOption(e))))}_filterValidConversations(e){return e.filter((({type:e,userID:t})=>e===u.C2C&&!c(t)||2===e))}_assembleC2COption(e){var t,n,s,o,i,a;const{OuterConstant:c}=this._core,l=this._createUserprofile(e);return{conversationID:`${c.CONV_C2C}${e.userID}`,type:c.CONV_C2C,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(t=e.lastMsg)||void 0===t?void 0:t.elements[0])?null===(n=e.lastMsg)||void 0===n?void 0:n.elements[0].type:null,payload:(null===(s=e.lastMsg)||void 0===s?void 0:s.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(o=e.lastMsg)||void 0===o?void 0:o.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:this._computeIsPeerRead(e),revoker:(null===(a=null===(i=e.lastMsg)||void 0===i?void 0:i.revokerInfo)||void 0===a?void 0:a.revoker)||null},unreadCount:0,userProfile:l,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}_createUserprofile(e){var t;const{userID:n,nick:s,peerAvatar:o}=e,i=[{tag:"Tag_Profile_IM_Nick",value:s},{tag:"Tag_Profile_IM_Image",value:o}];return null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(n,i)}_computeIsPeerRead(e){const{common:t}=this._core,n=t.getCurrentUserID(),{lastC2CMsgFromAccount:s,time:o,c2cPeerReadTime:i}=e;return s===n&&o<=i}_assembleGroupOption(e){var t,n,s;const{OuterConstant:o}=this._core;return{conversationID:`${o.CONV_GROUP}${e.groupID}`,type:o.CONV_GROUP,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(t=e.lastMsg)||void 0===t?void 0:t.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(s=null===(n=e.lastMsg)||void 0===n?void 0:n.revokerInfo)||void 0===s?void 0:s.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}_convertConversationKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",r=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.MsgType,r=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:r,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){const{OuterConstant:t}=this._core;let n="";return 0===e?n=t.MSG_REMIND_ACPT_AND_NOTE:1===e?n=t.MSG_REMIND_DISCARD:2===e?n=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(n=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}_patchTypeAndPayload(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core,{event:s,elements:o=[]}=e.lastMsg||{};return n(s)?{type:o[0]?o[0].type:null,payload:o[0]?this._amendLayersOverLimitProp(o[0].content):null}:{type:t.MSG_GRP_TIP,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s:0}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};var f=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:m.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:n,isPlainObject:s}}=this._core;if(t(e))return g.getLocalConversationList();if(n(e)){if(0===e.length)return[];return g.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(s(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return g.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:n}=this._core;return t!==n.CONV_C2C&&t!==n.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:n}}=this._core;return!n(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:n}}=this._core;return!n(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_filterGroupAtInfo(e,t){let n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}};function O(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var M=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:s}=e;return O("openim.get_c2c_peer_mute_notifications",{To_Account:t,Peer_Account:s},n)}))}({toAccount:n.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=s||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:n}=e,s=`${this._core.OuterConstant.CONV_C2C}${t}`,o=a(n);g.patchMessageRemindType([s],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var E=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const n=yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:s}=e;return O("group_open_http_svc.get_group_self_member_info",{GroupIdList:t,ResponseFilter:s},n)}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=n||{};s.forEach((e=>{var t;const{GroupId:n,MemberList:s}=e,o=(null===(t=s[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${n}`;g.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var I=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let l=g.getLocalConversation(e);if(o(e))return c.data.conversation=l,c;let u=!1;const d=n(e)?t:s;if(a(l)&&(u=!0,l=new C({conversationID:e,type:d})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=l,null==l?void 0:l.getProfileCompleted())return c;if(d===t){const n=e.replace(t,"");yield this._handleC2CConversation(l,n),u&&(yield M.get([n]))}if(d===s){const t=e.replace(s,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(l,t),u&&l.groupProfile.type!==i&&(yield E.get([t]))}return c}))}_handleC2CConversation(e,n){return t(this,void 0,void 0,(function*(){var t,s;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,u=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[n]});if(0===(null==u?void 0:u.data.length))throw new i.ChatError({code:h.USER_OR_GRP_NOT_FOUND});e.userProfile=null==u?void 0:u.data[0];const d=null===(s=c.getFriend(n))||void 0===s?void 0:s.remark;r(d)||e.remark===d||(e.remark=d),e.setProfileCompleted();const _=g.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${_}`),_?a.updateConversation(l,e):g.appendToPinnedConversation(e)}))}_handleGroupConversation(e,n){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:s}}=this._core,{conversationID:o}=e,i=yield t({groupID:n});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=g.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?s.updateConversation(o,e):g.appendToPinnedConversation(e)}))}};var T=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return g.getTotalUnreadMessageCount()}};var L=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRead",context:this})}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:s}=e;if(!t(s)){const{UinPairReadArray:e=[]}=s;e.forEach((e=>{const{From_Account:t,LastReadTime:s}=e,o=`${n.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${s}`),g.markMessageAsRead({conversationID:o,lastReadTime:s}),g.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:s}=e.MsgBody;n(s)||s.forEach((e=>{const{GroupId:n,LastReadMsgSeq:s}=e,o=`${t.CONV_GROUP}${n}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${s}`),g.markMessageAsRead({conversationID:o,lastReadSequence:s}),g.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,n;const{OuterConstant:s}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=g.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r.groupAtInfoList));if(r.type===s.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;if(r.type===s.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e)}if(r.type===s.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e)}return r.type===s.CONV_SYSTEM&&(r.unreadCount=0),g.emitConversationListUpdate(),i}))}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const n=g.getLocalConversation(e);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const{common:n}=this._core,o=s.map((e=>({From_Account:e.from,To_Account:n.getCurrentUserID(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,n){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e;return v("openim.deletemsg",{DelMsgList:t},n)}))}({messageListToDelete:o},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=g.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&g.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){return v("openim.msgreaded",e,n)}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${n}`),g.markMessageAsRead({conversationID:e,lastReadTime:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:s}=e;return v("group_open_http_svc.msg_read_report",{GroupId:t,MsgReadedSeq:s},n)}))}({groupID:e.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${n}`),g.markMessageAsRead({conversationID:e,lastReadSequence:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var S=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:n}}=this._core;if(!n(e))return;const{OuterConstant:s}=this._core;let o=!1;e.forEach((e=>{const{Type:n,To_Account:i,GroupId:r}=e;let a;1===n?a=g.getLocalConversation(`${s.CONV_C2C}${i}`):2===n&&(a=g.getLocalConversation(`${s.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&g.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r}=this._core,{conversationID:a,isPinned:c}=e,l={code:0,data:{conversationID:a}},u=g.getLocalConversation(a);if(u&&u.isPinned===c)return l;if(o(a))return u&&(u.isPinned=c),g.emitConversationListUpdate(!0),l;try{let e=null;n(a)?e={Type:1,To_Account:a.replace(i.CONV_C2C,"")}:s(a)&&(e={Type:2,GroupId:a.replace(i.CONV_GROUP,"")});const o=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:s,itemList:o}=e;return v("recentcontact.top",{From_Account:t,OperationType:s,RecentContactItem:o},n)}))}({fromAccount:r.getCurrentUserID(),operationType:!0===c?1:2,itemList:[e]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${a} isPinned:${c}.`),o){if(u)u.isPinned!==c&&(u.isPinned=c);else{const e=new C({conversationID:a,type:n(a)?i.CONV_C2C:i.CONV_GROUP,isPinned:c});g.setLocalConversation(a,e)}g.emitConversationListUpdate(!0)}return l}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var R=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:n}=this._core,s=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&s.push(`${n.CONV_C2C}${o}`),2===t&&s.push(`${n.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return console.log(`${this._name}.deleteConversation conversationID:${e}`),void(yield this._deleteConversation({conversationIDList:[e],flag:_.ONLY_CONVERSATIONID}));const n=Object.assign({},e);n.conversationIDList.length>100&&(n.conversationIDList=n.conversationIDList.slice(0,100)),yield this._deleteConversation(n)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:n=!0,flag:s=0}=e;console.log(`${this._name}._deleteConversation conversationIDList:${t} clearHistoryMessage:${n}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,n)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===_.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var n;if(!g.hasLocalConversation(e))return!1;const s=null===(n=g.getLocalConversation(e))||void 0===n?void 0:n.type;return s!==t.CONV_GROUP||this._hasLocalGroup(e)?s===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,n){return t(this,void 0,void 0,(function*(){const{OuterConstant:s,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:n?1:0};if(e.forEach((e=>{var t;if(g.hasLocalConversation(e)){const n=(null===(t=g.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(n,"");n===s.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):n===s.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:s,clearHistoryMessage:o}=e;return v("recentcontact.batch_delete",{From_Account:t,ContactItem:s,ClearRamble:o},n)}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const n=1===e.type?`${s.CONV_C2C}${e.To_Account}`:`${s.CONV_GROUP}${e.ToGroupid}`;t.push(n)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{g.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&g.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=g.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(g.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&g.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core,s=e.replace(t,"");return!!n.getGroup(s)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var y=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:n}=e;if(console.log(`${this._name} conversationID:${t} draftText:${n}`),!g.hasLocalConversation(t))throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});const s=g.getLocalConversation(t);return null==s||s.setDraftText(n),g.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var D=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(n,s){return t(this,void 0,void 0,(function*(){n.length>30&&(console.warn(`${this._name}.set userIDList length:${n.length} exceeds limit 30`),n.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:s}=e.core.OuterConstant;return{[t]:0,[n]:1,[s]:2}}()[s],i=yield function(e,n){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:s}=e;return O("openim.set_c2c_peer_mute_notifications",{Peer_Account:t,Mute_Notifications:s},n)}))}({userIDList:n,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:s}=e;a.push({userID:t,code:s});const o=n.indexOf(t);o>-1&&n.splice(o,1)}));const c=[],l=[],{OuterConstant:u}=this._core;return n.forEach((e=>{l.push(`${u.CONV_C2C}${e}`),c.push({userID:e})})),g.patchMessageRemindType(l,s),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var N=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,n){return t(this,void 0,void 0,(function*(){const{common:s,OuterConstant:o}=this._core;yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:s,receiveMessageOption:o}=e;return O("group_open_http_svc.modify_group_member_info",{GroupId:t,Member_Account:s,MsgFlag:o},n)}))}({groupID:e,userID:s.getCurrentUserID(),receiveMessageOption:n},this._core);const i=`${o.CONV_GROUP}${e}`;return g.patchMessageRemindType([i],n),{code:0,data:{groupID:e,messageRemindType:n}}}))}};var A=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:s}=e;if(!t(s)){const{To_Account:e,MuteNotifications:t}=s,o=e.map((e=>`${n.CONV_C2C}${e}`)),i=a(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),g.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:n,userIDList:s,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(n)){console.log(`${this._name}.${t} groupID:${n} messageRemindType:${o}`);return yield N.set(n,o)}if(!r(s)){console.log(`${this._name}.${t} userIDList:${s} messageRemindType:${o}`);return yield D.set(s,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{init(e){console.log("ConversationAction.init"),this._core=e,m.init(e),f.init(e),I.init(e),T.init(e),L.init(e),S.init(e),R.init(e),y.init(e),A.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:n,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(n,o,this._onConversationModified,this),t.subscribeInnerEvent(n,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(n,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(n,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(s,this._dispose,this)}handleLoginSuccess(){m.handleLoginSuccess()}_onConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===p.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;R.handleConversationDeleted(t)}if(t===p.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!0)}if(t===p.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;L.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;A.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;L.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:s,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,s,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(n,this._dispose,this)}};var G=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,D.init(e),N.init(e),M.init(e),E.init(e)}};const U=e=>!n(e)&&!s(e)&&!o(e),$={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:n,isObject:s,isString:o}}}=e;if(!o(t)&&!s(t))return"options is String or Object.";if(o(t)&&U(t))return"conversationID is invalid.";if(s(t)){if(!n(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if(U(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!n(e)&&!s(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}},V={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0};var F=new class{install(t){e.init(t),P.init(t),G.init(t),g.init(t),t.helper.registerValidateConfig({auth:V,params:$})}handleLoginSuccess(){P.handleLoginSuccess()}};export{F as default};
1
+ let e=new class{init(e){this.core=e}};function t(e,a,r,l){return new(r=r||Promise)(function(s,t){function n(e){try{i(l.next(e))}catch(e){t(e)}}function o(e){try{i(l.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?s(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(n,o)}i((l=l.apply(e,a||[])).next())})}let s=t=>{var{OuterConstant:s,utils:{isString:n}}=e["core"];return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{var{OuterConstant:s,utils:{isString:n}}=e["core"];return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{var{OuterConstant:s,utils:{isString:n}}=e["core"];return n(t)&&t===s.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){var s=e.core["OuterConstant"];let n="";return 0===t?n=s.MSG_REMIND_ACPT_AND_NOTE:1===t?n=s.MSG_REMIND_DISCARD:2===t?n=s.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(n=s.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}function a(t){var s=e.core["OuterConstant"];let n;return"@TLS#ERROR"===(n=t.startsWith(s.CONV_C2C)?t.replace(s.CONV_C2C,""):n)||"@TLS#NOT_FOUND"===n}function c(t,s){var n=e.core["helper"],n=new n.ChatError({functionName:t,code:(null==s?void 0:s.errorCode)||(null==s?void 0:s.code),message:(null==s?void 0:s.errorInfo)||(null==s?void 0:s.message)});throw console.error(t+" fail:",n),n}class l{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){var{OuterConstant:t,utils:{isUndefined:s}}=e["core"];s(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:s(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){var{OuterConstant:s,utils:{isUndefined:n}}=e["core"],{nextUnreadCount:t,isFromGetConversations:o,isUnreadC2CMessage:i}=t;n(t)||(this.subType!==s.GRP_AVCHATROOM?o&&this.type===s.CONV_GROUP||i&&this.type===s.CONV_C2C?this.unreadCount=t:this.unreadCount+=t:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return 1<=this.unreadCount&&(--this.unreadCount,!0)}isLastMessageRevoked(t){var s=e["core"]["OuterConstant"],{sequence:t,time:n}=t;return this.type===s.CONV_C2C&&t===this.lastMessage.lastSequence&&n===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&t===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){var{common:{updateGroupAtInfo:s}}=e["core"];s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u,_;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d=d||{}),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u=u||{}),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"}(_=_||{});let h=0,C=1;var p=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){var{helper:e,notificationCenter:t,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:o},InnerEvent:{SYNC_CONVERSATION_LIST:i,MESSAGE_PUSH:a,NEW_MESSAGE:r,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:c,CONVERSATION_UPDATED:u,LOGOUT:_,DESTROY:p}}=this._core=e,s=(this._conversationStore=s,e.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,o.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),e.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,o.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),e.registerWorkflowStep(n.RECEIVE_C2C_NEW_MESSAGE,o.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),e.registerWorkflowStep(n.RECEIVE_C2C_NEW_MESSAGE,o.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),e.registerWorkflowStep(n.RECEIVE_GROUP_NEW_MESSAGE,o.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),e.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t)["InnerEventSubType"]["GROUP_AT_TIPS"];t.subscribeInnerEvent(i,this._handleConversationSynced,this),t.subscribeInnerEvent(r,this._handleNewMessage,this),t.subscribeInnerEvent(a,s,this._handleNewGroupAtTips,this),t.subscribeInnerEvent(l,this._handleMessageDeleted,this),t.subscribeInnerEvent(d,this._handleMessageRevoked,this),t.subscribeInnerEvent(c,this._handleMessageModified,this),t.subscribeInnerEvent(u,this._handleConversationUpdated,this),t.subscribeInnerEvent(_,this._reset,this),t.subscribeInnerEvent(p,this._dispose,this),console.log(this._name+".init")}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){let{WORKFLOW_STEP:t}=this._core["constants"],{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{},i=!1;s.forEach(e=>{var{conversationID:e,unreadCount:t}=e,e=this.getLocalConversation(e);e&&e.unreadCount!==t&&(e.updateUnreadCount({nextUnreadCount:t,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(t){var s;for(let e=0;e<t.length;e++)if(12===t[e].Event){if(null!=(s=t[e].GroupTips[0].MsgBody)&&s.TopicId)continue;this._handleNewGroupAtTips(t[e])}}_handleGroupListSyncFinished(e){let n,{WORKFLOW_STEP:t}=this._core.constants,o=e.result[t.GROUP_LIST_SYNC]||[],{CONV_GROUP:i}=this._core.OuterConstant,a=!1;for(let s=0;s<o.length;s++){let e=o[s],t=""+i+e.groupID;var r;this.hasLocalConversation(t)&&((r=this.getLocalConversation(t)).groupProfile=JSON.parse(JSON.stringify(e)),r.lastMessage.lastSequence<e.nextMessageSeq&&(r.lastMessage.lastSequence=e.nextMessageSeq-1),r.subType||(r.subType=e.type),0<(null==(n=e._groupAtInfoList)?void 0:n.length)&&this._handleNewGroupAtTips({GroupTips:e._groupAtInfoList}),a=!0)}a&&this.emitConversationListUpdate()}_handleNewMessage(e){var t,{conversationUpdateFieldList:e=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};0===e.length||({isTopic:t}=this._core["common"],t(e[0].conversationID))||(this.updateLocalConversationList({conversationUpdateFieldList:e,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o}),0<e.filter(e=>this._isConversationNeedShow(e.conversationID)).length&&this.emitConversationListUpdate())}_handleNewGroupAtTips(e){var{GroupTips:e=[]}=e;e.forEach(e=>{var{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(this._name+"._handleNewGroupAtTips groupAtTipsList: "+JSON.stringify(this._groupAtTipsList)),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){var{From_Account:e,GroupId:t,MsgSeq:s,GroupAtType:n}=e;return{from:e,groupID:t,sequence:s,groupAtType:n}}_updateGroupAtInfoList(){if(0!==this._groupAtTipsList.length){let{common:e,OuterConstant:n}=this._core,o=e.getCurrentUserID(),i=!1;this._groupAtTipsList.forEach(t=>{var{groupID:s,from:e}=t;if(e!==o){let e=this.getLocalConversation(""+n.CONV_GROUP+s);e&&(e.updateGroupAtInfoList(t),i=!0)}}),i&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}}_handleMessageDeleted(t){console.log(this._name+"._handleMessageDeleted, conversationID:",t);var s,{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(t))||[];let a={};for(let e=(i.length||0)-1;0<=e;e--)if(!i[e].isDeleted){a=i[e];break}n=this.getLocalConversation(t);if(n){let e=!1;n.lastMessage.lastSequence===a.sequence&&n.lastMessage.lastTime===a.time||(null!=(s=null==(s=this._core)?void 0:s.helper)&&s.isEmpty(a)&&(a=void 0),n.updateLastMessage(a),e=!0),t.startsWith(o.CONV_C2C)&&this.updateUnreadCount(t),e&&(this.emitConversationListUpdate(),console.log(this._name+`._handleMessageDeleted. update conversationID:${t} with lastMessage:`,n.lastMessage))}}_handleMessageRevoked(e){let{messageList:n=[],updateUnreadCount:o=!0}=e;if(console.log(this._name+"._handleMessageRevoked messageList:"+n.length),0!==n.length){let t=null,s=!1;n.forEach(e=>{(t=this.getLocalConversation(e.conversationID))&&(o&&t.reduceUnreadCount()&&(s=!0),t.isLastMessageRevoked({sequence:e.sequence,time:e.time}))&&(t.setLastMessageRevoked(!0),t.setLastMessageRevoker(e.revoker),s=!0)}),s&&this.emitConversationListUpdate()}}_handleMessageModified(e){console.log(this._name+"._handleMessageModified",JSON.stringify(e));var{conversationID:t,messageList:s}=e,e=this.getLocalConversation(t),{utils:{isEmpty:n},common:{getMessagePreviewText:o}}=this._core;if(!n(e)){n=e["lastMessage"];if(n){let e=(null==s?void 0:s[0])||{};n.lastTime===e.time&&n.lastSequence===e.sequence&&n.version!==e.version&&(n.type=e.type,n.payload=e.payload,n.messageForShow=o(e.type,e.payload),n.cloudCustomData=e.cloudCustomData,n.version=e.version,this.emitConversationListUpdate(),console.log(this._name+` conversationID:${t} lastMessage updated`))}}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){var t=e["isFromGetConversations"],e=this._getTmpConversationListMapping(e)["newConversationList"];this._sortConversationList(),t||this._updateNewConversationProfile(e),console.log(this._name+".updateLocalConversationList newConversationList: "+e.length)}_getTmpConversationListMapping(e){let i=this._core["OuterConstant"],{conversationUpdateFieldList:r,isFromGetConversations:d,isInstantMessage:c,isUnreadC2CMessage:u=!1,updateUnreadCount:_}=e,p=[],t=null==r?void 0:r.length;for(let o=0;o<t;o++){let t=new l(r[o]),{conversationID:s,type:n}=t;if(!a(s))if(this.hasLocalConversation(s)){let e=this.getLocalConversation(s);d?(this.setLocalConversation(s,t),n===i.CONV_C2C?t.unreadCount=(null==e?void 0:e.unreadCount)||0:n===i.CONV_GROUP&&(t.groupProfile=JSON.parse(JSON.stringify(null==e?void 0:e.groupProfile)))):(this._mergeConversationInfo({conversationID:s,tmpConversation:t,lastMessage:r[o].lastMessage,isFromGetConversations:d,isInstantMessage:c}),this._patchLastMessage({conversationID:s,lastMessage:r[o].lastMessage,isInstantMessage:c}),!0===_&&null!=e&&e.updateUnreadCount({nextUnreadCount:t.unreadCount,isFromGetConversations:d,isUnreadC2CMessage:u}))}else p.push(t),this.setLocalConversation(s,t)}return{newConversationList:p}}_mergeConversationInfo(e){var{conversationID:e,tmpConversation:t,lastMessage:s,isFromGetConversations:n,isInstantMessage:o}=e,e=this.getLocalConversation(e),i=["unreadCount","allowType","adminForbidType","payload"],{utils:{isUndefined:n,isEmpty:a},common:{deepMerge:r}}=(!1===o&&i.push("lastMessage"),n&&i.push("isPinned"),this._core);n(o)&&s&&null===(null==e?void 0:e.lastMessage.payload)&&(e.lastMessage.payload=s.payload),a(null==e?void 0:e.lastMessage.revoker)||(e.lastMessage.revoker=null),r(e,t,i,[null,void 0,"",0,NaN])}_patchLastMessage(e){let o=this._core["OuterConstant"],{conversationID:t,lastMessage:i,isInstantMessage:a}=e,r=this.getLocalConversation(t);if(r&&i){let{payload:e,nameCard:t,nick:s,cloudCustomData:n=""}=i;a&&(e&&(r.lastMessage.payload=e),r.type===o.CONV_GROUP)&&(r.lastMessage.nameCard=t,r.lastMessage.nick=s),r.lastMessage.cloudCustomData!==n&&(r.lastMessage.cloudCustomData=n)}}_sortConversationList(){let{isEmpty:t}=this._core["utils"],e=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];e.forEach(e=>{(!0===e[1].isPinned?t(e[1].lastMessage.lastTime)?n:s:t(e[1].lastMessage.lastTime)?i:o).push(e)});var a=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(a)}_updateNewConversationProfile(e){if(0!==e.length){let s=[],n=[],{CONV_GROUP:o,CONV_C2C:i}=this._core["OuterConstant"];e.forEach(e=>{var{conversationID:t,type:e}=e;if(e===i){let e=t.replace(i,"");s.push(e)}else if(e===o){let e=t.replace(o,"");n.push(e)}}),0<s.length&&this._updateC2CConversation(s),0<n.length&&this._updateGroupConversation(n)}}_updateC2CConversation(e){let t,{OuterConstant:{CONV_C2C:o},appStore:{userStore:i},user:s}=this._core,a=!1;null!=(t=s.userProfile)&&t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(t=>{var s=t["userID"],n=this.getLocalConversation(""+o+s);if(n){let e=(null==(s=i.getFriend(s))?void 0:s.remark)||"";n.remark=e,n.userProfile=t,a=!0}}),a&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){let{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n}}=this._core,o=!1;e.forEach(e=>{var t=n.getGroup(e),e=this.getLocalConversation(""+s+e);t&&e&&(e.groupProfile=t,o=!0)}),o&&this.emitConversationListUpdate()}_isConversationNeedShow(e){var t,s,n,e=this.getLocalConversation(e);return!(!this._core.utils.isUndefined(e)&&(t=this._core.OuterConstant,s=e.type===t.CONV_TOPIC,n=e.type===t.CONV_GROUP&&e.subType===t.GRP_ROOM,e=e.type===t.CONV_GROUP&&e.subType===t.GRP_LIVE,s||n||e))}updateUnreadCount(e,t=!0){let s,n,o=!1;var i,a=this.getLocalConversation(e),r=null==(n=null==(s=this._core)?void 0:s.message.messageDataHandler)?void 0:n.getLocalMessageList(e);return a&&(i=a.unreadCount,r=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length,console.log(this._name+`._updateUnreadCount conversationID:${e} currentUnreadCount:${i} newUnreadCount:`+r),i!==r)&&(a.unreadCount=r,(o=!0)===t)&&this.emitConversationListUpdate(),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();var e=this._core["OuterEvent"]["CONVERSATION_LIST_UPDATED"],t=this.getLocalConversationList();this._emitEvent({name:e,data:t}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e,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.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null!=(t=this._core)&&t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){let t=this._core["OuterConstant"],e=this.getLocalConversationList(),s=0;return e.forEach(e=>{e.type===t.CONV_SYSTEM||""!==e.messageRemindType&&e.messageRemindType!==t.MSG_REMIND_ACPT_AND_NOTE||(s+=e.unreadCount)}),s}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(var[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{e=this.getLocalConversation(e);(null==e?void 0:e.messageRemindType)!==t&&(e.messageRemindType=t,s=!0)}),console.log(this._name+`.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:`+s),s&&this.emitConversationListUpdate()}markMessageAsRead(e){let{messageDataHandler:t}=this._core["message"],{conversationID:s,lastReadTime:o=0,lastReadSequence:i=0}=e,a=null==t?void 0:t.getLocalMessageList(s);if(0!==a.length){let e=a["length"];for(let n=e-1;0<=n;n--){let e=a[n],t=o&&e.time>o,s=i&&e.sequence>i;if(!t&&!s){if("in"===e.flow&&e.isRead)break;e.setIsRead(!0)}}}}appendToPinnedConversation(e){var t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){var{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:a,DESTROY:r,SYNC_CONVERSATION_LIST:l}}=this._core,{GROUP_AT_TIPS:d}=e["InnerEventSubType"];e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,d,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(l,this._handleConversationSynced,this),e.unSubscribeInnerEvent(a,this._reset,this),e.unSubscribeInnerEvent(r,this._dispose,this)}},v=new class{constructor(){this._name="GetConversationList"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(a){let{isUndefined:e,isArray:t,isPlainObject:s}=this._core["utils"];if(e(a))return p.getLocalConversationList();if(t(a))return 0===a.length?[]:p.getLocalConversationList().filter(e=>a.includes(e.conversationID));if(s(a)){let{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=a;return p.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){var s=this._core["OuterConstant"];return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){var{isString:s}=this._core["utils"];return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){var{isNumber:s}=this._core["utils"];return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=1<=e.unreadCount:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=1<=e.groupAtInfoList.length:!1===t&&(s=0===e.groupAtInfoList.length),s}},g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(o){return t(this,void 0,void 0,function*(){try{var e=this._core["common"],s=yield function(s,n){return t(this,void 0,void 0,function*(){var{toAccount:e,userIDList:t}=s;return n.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:{To_Account:e,Peer_Account:t}})})}({toAccount:e.getCurrentUserID(),userIDList:o},this._core),{MuteNotificationsList:n=[]}=s||{};n.forEach(e=>{var{Peer_Account:e,MuteNotifications:t}=e,e=""+this._core.OuterConstant.CONV_C2C+e,t=r(t);p.patchMessageRemindType([e],t)})}catch(e){console.error(this._name+".get fail:",e)}})}},m=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(n){return t(this,void 0,void 0,function*(){if(0!==n.length)try{var e=yield function(s,n){return t(this,void 0,void 0,function*(){var{groupIDList:e,responseFilter:t}=s;return n.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:{GroupIdList:e,ResponseFilter:t}})})}({groupIDList:n,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=e||{};s.forEach(e=>{var{GroupId:e,MemberList:t}=e,t=(null==(t=t[0])?void 0:t.MsgFlag)||"",e=""+this._core.OuterConstant.CONV_GROUP+e;p.patchMessageRemindType([e],t)})}catch(e){console.error(this._name+".get fail:",e)}})}},f=new class{constructor(){this._name="GetConversationProfile"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(_){return t(this,void 0,void 0,function*(){let{OuterConstant:{CONV_C2C:n,CONV_GROUP:i,GRP_AVCHATROOM:a},appStore:{groupStore:r},utils:{isEmpty:e}}=this._core,d={code:0,data:{}},c=p.getLocalConversation(_);if(o(_))d.data.conversation=c;else{let t=!1;var u=s(_)?n:i;if(e(c)&&(t=!0,c=new l({conversationID:_,type:u})),console.log(this._name+`.getConversationProfile conversationID:${_} isNewConversation:`+t),null==(d.data.conversation=c)||!c.getProfileCompleted()){if(u===n){let e=_.replace(n,"");yield this._handleC2CConversation(c,e),t&&(yield g.get([e]))}if(u===i){let e=_.replace(i,"");if(!r.getGroup(e))return d;yield this._handleGroupConversation(c,e),t&&c.groupProfile.type!==a&&(yield m.get([e]))}}}return d})}_handleC2CConversation(a,r){return t(this,void 0,void 0,function*(){var{user:e,helper:t,utils:{isEmpty:s},appStore:{conversationStore:n,userStore:o}}=this._core,i=a["conversationID"],e=yield null==(e=e.userProfile)?void 0:e.getUserProfile({userIDList:[r]});if(0===(null==e?void 0:e.data.length))throw new t.ChatError({code:_.USER_OR_GRP_NOT_FOUND});a.userProfile=null==e?void 0:e.data[0];e=null==(t=o.getFriend(r))?void 0:t.remark,s(e)||a.remark===e||(a.remark=e),a.setProfileCompleted(),o=p.hasLocalConversation(i);console.log(this._name+`._handleC2CConversation conversationID:${i} hasLocalConversation: `+o),o?n.updateConversation(i,a):p.appendToPinnedConversation(a)})}_handleGroupConversation(n,o){return t(this,void 0,void 0,function*(){var{apiMap:{getGroupProfile:e},appStore:{conversationStore:t}}=this._core,s=n["conversationID"],e=yield e({groupID:o}),e=(n.groupProfile=null==e?void 0:e.data.group,n.setProfileCompleted(),p.hasLocalConversation(s));console.log(this._name+`._handleGroupConversation conversationID:${s} hasLocalConversation: `+e),e?t.updateConversation(s,n):p.appendToPinnedConversation(n)})}},M=new class{init(e){e=e.helper;e.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return p.getTotalUnreadMessageCount()}},E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){let{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=this._core=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){let{helper:{isEmpty:s},OuterConstant:n}=this._core;e.forEach(e=>{var t=e["ReadC2cMsgNotify"];if(!s(t)){let{UinPairReadArray:e=[]}=t;e.forEach(e=>{var{From_Account:e,LastReadTime:t}=e,e=""+n.CONV_C2C+e;console.log(this._name+`.handleC2CMessageReadSync conversationID:${e} lastReadTime:`+t),p.markMessageAsRead({conversationID:e,lastReadTime:t}),p.updateUnreadCount(e)})}})}handleGroupMessageReadSync(e){let{OuterConstant:s,utils:{isUndefined:t}}=this._core;e.forEach(e=>{e=e.MsgBody.GroupReadInfoArray;t(e)||e.forEach(e=>{var{GroupId:e,LastReadMsgSeq:t}=e,e=""+s.CONV_GROUP+e;console.log(this._name+`.handleGroupMessageReadSync conversationID:${e} lastReadSequence:`+t),p.markMessageAsRead({conversationID:e,lastReadSequence:t}),p.updateUnreadCount(e),this._clearGroupAtInfoList(e)})})}setMessageRead(l){return t(this,void 0,void 0,function*(){let e=this._core["OuterConstant"],t=l["conversationID"],s={code:0,data:{}},n=p.getLocalConversation(t);if(console.log(this._name+`.setMessageRead conversationID:${t} unreadCount:`+((null==n?void 0:n.unreadCount)||0)),n){var o=!(null!=(i=null==(o=this._core)?void 0:o.helper)&&i.isEmpty(n.groupAtInfoList));if(n.type===e.CONV_GROUP&&o&&this._deleteGroupAtTips(t),0!==n.unreadCount){var{ssoLog:i,helper:{ChatError:a}}=this._core,r=i.createSSOLogData({method:"setMessageRead"});r.setLogInfo({message:"conversationID:"+t});try{if(n.type===e.CONV_C2C){let e=this._getLocalMessageMaxTime(n);yield this._setC2CMessageRead(t,e),r.setLogInfo({moreMessage:"lastMessageTime:"+e}).end()}if(n.type===e.CONV_GROUP){let e=this._getLocalMessageMaxSequence(n);yield this._setGroupMessageRead(t,e),r.setLogInfo({moreMessage:"lastMessageSequence:"+e}).end()}}catch(e){let{errorCode:t,errorInfo:s}=e,n=new a({functionName:"setMessageRead",code:t,message:s});throw r.setError(n).end(),n}n.type===e.CONV_SYSTEM&&(n.unreadCount=0),p.emitConversationListUpdate()}}return s})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){let{OuterConstant:{READ_ALL_MSG:n},ssoLog:o}=this._core,i=o.createSSOLogData({method:"setAllMessageRead"});s.scope||(s.scope=n);var a=s["scope"],r=this._generateSetAllMessageReadRequestData(a);if(r.allC2CMessageReadStatus===h&&0===r.groupMessageReadInfoList.length)return{code:0};try{let n=yield function(n){return t(this,void 0,void 0,function*(){var{allC2CMessageReadStatus:t,groupMessageReadInfoList:s}=n,t={C2CReadAllMsg:t,GroupReadInfo:s};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:t})})}(r);if(n){let{GroupReadInfoArray:e,C2CReadAllMsg:t}=n,s=this._parseGroupReadInfo(e);0<this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})&&p.emitConversationListUpdate(),i.setLogInfo({message:`scope:${a} failureGroups:`+JSON.stringify(s)}).end()}return{code:0}}catch(e){let t=e["errorCode"],s=new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t});throw i.setError(s).end(),s}})}_handleAllMessageRead(e){var{GroupReadInfoArray:e,C2CReadAllMsg:t}=e;this._parseGroupReadInfo(e),0<this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})&&p.emitConversationListUpdate()}_updateAllConversationReadStatus(e){let{OuterConstant:{CONV_C2C:n,CONV_GROUP:o},appStore:t}=this._core,i=t.conversationStore.getConversationMap(),a=e["allC2CMessageReadStatus"],r=0;for(let[s,t]of i)if(1<=t.unreadCount){if(a===C&&t.type===n){let e=this._getLocalMessageMaxTime(t);p.markMessageAsRead({conversationID:s,lastReadTime:e})}else if(t.type===o){let t=s.replace(o,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){let e=this._serverGroupConversationLastReadSeqMap.get(t);p.markMessageAsRead({conversationID:s,lastReadSequence:e})}}p.updateUnreadCount(s,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(n){let{OuterConstant:{CONV_C2C:o,CONV_GROUP:i,READ_ALL_C2C_MSG:a},appStore:e}=this._core,r={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},t=e.conversationStore.getConversationMap();for(let[,s]of t){let{type:e,unreadCount:t}=s;if(this._shouldSetAllMessageRead({scope:n,type:e,unreadCount:t}))if(e===o&&r.allC2CMessageReadStatus===h){if(r.allC2CMessageReadStatus=C,n===a)break}else if(e===i){let e=this._getLocalMessageMaxSequence(s),t=s.groupProfile["groupID"];r.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return r}_parseGroupReadInfo(e){let{isUndefined:o}=this._core["utils"],i=[];return null!=e&&e.forEach(e=>{var{GroupId:e,MsgSeq:t,RetCode:s,LastReadMsgSeq:n}=e;o(s)?this._serverGroupConversationLastReadSeqMap.set(e,n):(this._serverGroupConversationLastReadSeqMap.set(e,t),0!==s&&i.push(e+`-${t}-`+s))}),i}_deleteGroupAtTips(r){return t(this,void 0,void 0,function*(){console.log(this._name+"._deleteGroupAtTips conversationID:"+r);let e=p.getLocalConversation(r);if(e){var a=(null==e?void 0:e.groupAtInfoList)||[];if(0!==a.length)try{let{common:{getCurrentUserID:s,isCommunity:e},OuterConstant:{CONV_GROUP:n,CONV_AT_ALL:o}}=this._core,i=[...a];e({groupID:r.replace(n,"")})&&0===(i=a.filter(e=>!e.atTypeArray.includes(o))).length?this._clearGroupAtInfoList(r,!1):(yield function(s,n){return t(this,void 0,void 0,function*(){var e=s["messageListToDelete"];return n.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:{DelMsgList:e}})})}({messageListToDelete:i.map(e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}))},this._core),console.log(this._name+"._deleteGroupAtTips ok. count:"+a.length),this._clearGroupAtInfoList(r))}catch(e){console.error(this._name+"._deleteGroupAtTips fail:",e)}}})}_clearGroupAtInfoList(e,t=!0){var s=p.getLocalConversation(e);s&&(0<s.groupAtInfoList.length&&(s.clearGroupAtInfoList(),console.log(this._name+`._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:`+t)),t)&&p.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t=e["conversationID"],t=this._core.message.messageDataHandler.getLocalMessageList(t),t=Math.max(...t.map(e=>e.time));let s=(null==(e=null==e?void 0:e.lastMessage)?void 0:e.lastTime)||0;return t>s&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${s} to `+t),s=t),s}_getLocalMessageMaxSequence(e){var t=e["conversationID"],t=this._core.message.messageDataHandler.getLocalMessageList(t),t=Math.max(...t.map(e=>e.sequence));let s=(null==(e=null==e?void 0:e.lastMessage)?void 0:e.lastSequence)||0;return t>s&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${s} to `+t),s=t),s}_setC2CMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(e,s){return t(this,void 0,void 0,function*(){return s.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:s,Receipt:1}]}},this._core),console.log(this._name+"._setC2CMessageRead ok, lastReadTime:"+s),p.markMessageAsRead({conversationID:e,lastReadTime:s}),p.updateUnreadCount(e)}catch(e){throw console.warn(this._name+"._setC2CMessageRead fail:",e),e}})}_setGroupMessageRead(e,s){return t(this,void 0,void 0,function*(){try{yield function(s,n){return t(this,void 0,void 0,function*(){var{groupID:e,lastMessageSequence:t}=s;return n.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:{GroupId:e,MsgReadedSeq:t}})})}({groupID:e.replace("GROUP",""),lastMessageSequence:s},this._core),console.log(this._name+"._setGroupMessageRead ok, lastReadSequence:"+s),p.markMessageAsRead({conversationID:e,lastReadSequence:s}),p.updateUnreadCount(e)}catch(e){throw console.warn(this._name+"._setGroupMessageRead fail:",e),e}})}_shouldSetAllMessageRead(e){var{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}=this._core["OuterConstant"],{type:e,scope:a,unreadCount:r}=e;return!(r<=0||(e!==t||![n,o].includes(a))&&(e!==s||![n,i].includes(a)))}},R=new class{constructor(){this._name="PinConversation"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,a){var{isArray:t}=this._core["utils"];if(t(e)){let o=this._core["OuterConstant"],i=!1;e.forEach(e=>{var{Type:e,To_Account:t,GroupId:s}=e;let n;1===e?n=p.getLocalConversation(""+o.CONV_C2C+t):2===e&&(n=p.getLocalConversation(""+o.CONV_GROUP+s)),n&&(console.log(`${this._name}.handleConversationPinned conversationID:${n.conversationID} localPinned:${n.isPinned} remotePinned:`+a),a&&!n.isPinned&&(n.isPinned=!0,i=!0),!a)&&n.isPinned&&(n.isPinned=!1,i=!0)}),i&&p.emitConversationListUpdate(!0)}}pinConversation(e){return t(this,void 0,void 0,function*(){var{OuterConstant:i,common:a,ssoLog:r,helper:{ChatError:d}}=this._core,{conversationID:c,isPinned:u}=e,_={code:0,data:{conversationID:c}},h=p.getLocalConversation(c);if(h&&h.isPinned===u)return _;if(o(c))return h&&(h.isPinned=u),p.emitConversationListUpdate(!0),_;r=r.createSSOLogData({method:"pinConversation"});r.setLogInfo({message:`conversationID:${c} isPinned:`+u});try{let e=null,o=(s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.replace(i.CONV_GROUP,"")}),yield function(n,o){return t(this,void 0,void 0,function*(){var{fromAccount:e,operationType:t,itemList:s}=n;return o.common.buildAndSendPacket({servcmd:"recentcontact.top",data:{From_Account:e,OperationType:t,RecentContactItem:s}})})}({fromAccount:a.getCurrentUserID(),operationType:!0===u?1:2,itemList:[e]},this._core));if(r.end(),console.log(this._name+`.pinConversation ok, conversationID:${c} isPinned:${u}.`),o){if(h)h.isPinned!==u&&(h.isPinned=u);else{let e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:u});p.setLocalConversation(c,e)}p.emitConversationListUpdate(!0)}return _}catch(e){let{errorCode:t,errorInfo:s}=e,n=new d({functionName:"pinConversation",code:t,message:s});throw r.setError(n).end(),console.error(this._name+".pinConversation fail:",n),n}})}},S=new class{constructor(){this._name="DeleteConversation"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){var{isArray:t}=this._core["utils"];if(t(e)){let n=this._core["OuterConstant"],o=[];e.forEach(e=>{var{Type:e,Peer_Account:t,GroupId:s}=e;1===e&&o.push(""+n.CONV_C2C+t),2===e&&o.push(""+n.CONV_GROUP+s)}),console.log(this._name+".handleConversationDeleted conversationIDList:"+o),this._deleteLocalConversationList(o)}}deleteConversation(s){return t(this,void 0,void 0,function*(){var e=this._core["utils"]["isString"];e(s)?(console.log(this._name+".deleteConversation conversationID:"+s),yield this._deleteConversation({conversationIDList:[s],flag:u.ONLY_CONVERSATIONID})):(100<(e=Object.assign({},s)).conversationIDList.length&&(e.conversationIDList=e.conversationIDList.slice(0,100)),yield this._deleteConversation(e))})}_deleteConversation(r){return t(this,void 0,void 0,function*(){let{conversationIDList:s,clearHistoryMessage:n=!0,flag:o=0}=r,{ssoLog:e,helper:{ChatError:i}}=this._core,t=`conversationIDList:${s} clearHistoryMessage:`+n,a=e.createSSOLogData({method:"deleteConversation"});a.setLogInfo({message:t}),console.log(this._name+"._deleteConversation "+t);try{let e=yield Promise.all([this._deleteConversationFromLocal(s),this._deleteConversationFromServer(s,n)]),t=[...e[0],...e[1]];if(0===t.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return a.end(),console.log(this._name+"._deleteConversation ok."),{code:0,data:o===u.ONLY_CONVERSATIONID?{conversationID:t[0]}:{conversationIDList:t}}}catch(e){let{errorCode:t,errorInfo:s}=e,n=new i({functionName:"deleteConversation",code:t,message:s});throw a.setError(n).end(),console.error(this._name+"._deleteConversation fail:",n),n}})}_deleteConversationFromLocal(e){let s=this._core["OuterConstant"];return e.filter(e=>{var t;return!!p.hasLocalConversation(e)&&((t=null==(t=p.getLocalConversation(e))?void 0:t.type)===s.CONV_GROUP&&!this._hasLocalGroup(e)||t===s.CONV_SYSTEM)&&(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(i,a){return t(this,void 0,void 0,function*(){let{OuterConstant:n,common:e}=this._core,o={fromAccount:e.getCurrentUserID(),conversationList:[],clearHistoryMessage:a?1:0};if(i.forEach(e=>{var t,s;p.hasLocalConversation(e)&&(t=(null==(t=p.getLocalConversation(e))?void 0:t.type)||"",s=e.replace(t,""),t===n.CONV_C2C?o.conversationList.push({To_Account:s,Type:1}):t===n.CONV_GROUP&&this._hasLocalGroup(e)&&o.conversationList.push({ToGroupid:s,Type:2}))}),0!==o.conversationList.length){var s=yield function(n,o){return t(this,void 0,void 0,function*(){var{fromAccount:e,conversationList:t,clearHistoryMessage:s}=n;return o.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:{From_Account:e,ContactItem:t,ClearRamble:s}})})}(o,this._core);if(s){let{ResultItem:e=[]}=s,t=[];return 0<e.length&&e.forEach(e=>{0===e.ResultCode&&(e=1===e.type?""+n.CONV_C2C+e.To_Account:""+n.CONV_GROUP+e.ToGroupid,t.push(e))}),this._deleteLocalConversationList(t),t}}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{p.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(this._name+"._deleteLocalConversationList isUpdate:"+t),t&&p.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){var s=p.hasLocalConversation(e);console.log(this._name+`._deleteLocalConversation conversationID:${e} has:`+s),s&&(p.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t)&&p.emitConversationListUpdate()}_hasLocalGroup(e){var{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,e=e.replace(t,"");return!!s.getGroup(e)}_deleteConversationLocalMessage(e){console.log(this._name+"._deleteConversationLocalMessage conversationID:"+e),this._core.message.messageDataHandler.deleteConversationMessageList(e)}},I=new class{constructor(){this._name="SetConversationDraft"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(s){return t(this,void 0,void 0,function*(){var{conversationID:e,draftText:t}=s;if(console.log(this._name+` conversationID:${e} draftText:`+t),p.hasLocalConversation(e))return null!=(e=p.getLocalConversation(e))&&e.setDraftText(t),p.emitConversationListUpdate(),{code:0,data:{conversation:e}};throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND})})}},L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(d,c){return t(this,void 0,void 0,function*(){30<d.length&&(console.warn(`${this._name}.set userIDList length:${d.length} exceeds limit 30`),d.splice(30));let s=function(){var{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=e.core.OuterConstant;return{[t]:0,[s]:1,[n]:2}}()[c],n=yield function(s,n){return t(this,void 0,void 0,function*(){var{userIDList:e,receiveMessageOption:t}=s;return n.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:{Peer_Account:e,Mute_Notifications:t}})})}({userIDList:d,receiveMessageOption:s},this._core),{ErrorList:o=[]}=n||{},i=[],a=(o.forEach(e=>{var{Peer_Account:e,ErrorCode:t}=e,t=(i.push({userID:e,code:t}),d.indexOf(e));-1<t&&d.splice(t,1)}),[]),r=[],l=this._core["OuterConstant"];return d.forEach(e=>{r.push(""+l.CONV_C2C+e),a.push({userID:e})}),p.patchMessageRemindType(r,c),{code:0,data:{successUserIDList:a,failureUserIDList:i}}})}},O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(o,i){return t(this,void 0,void 0,function*(){var{common:{getCurrentUserID:e,isTopic:s},OuterConstant:n}=this._core;if(yield function(n,o){return t(this,void 0,void 0,function*(){var{groupID:e,userID:t,receiveMessageOption:s}=n;return o.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:{GroupId:e,Member_Account:t,MsgFlag:s}})})}({groupID:o,userID:e(),receiveMessageOption:i},this._core),!s(o)){let e=""+n.CONV_GROUP+o;p.patchMessageRemindType([e],i)}return{code:0,data:{groupID:o,messageRemindType:i}}})}},T=new class{constructor(){this._name="SetMessageRemindType"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){let{helper:{isEmpty:t},OuterConstant:i}=this._core;e.forEach(e=>{var o=e["MuteNotificationsSync"];if(!t(o)){let{To_Account:e,MuteNotifications:t}=o,s=e.map(e=>""+i.CONV_C2C+e),n=r(t);console.log(this._name+`.handleC2CMessageRemindTypeSync conversationIDList:${s} messageRemindType:`+n),p.patchMessageRemindType(s,n)}})}setMessageRemindType(a){return t(this,void 0,void 0,function*(){let s="setMessageRemindType",{groupID:e,userIDList:t,messageRemindType:n}=a,{helper:o,utils:{isUndefined:i}}=this._core;try{if(!i(e))return console.log(`${this._name}.${s} groupID:${e} messageRemindType:`+n),yield O.set(e,n);if(i(t))throw new o.ChatError({functionName:s,message:"userIDList or groupID is required"});return console.log(this._name+`.${s} userIDList:${t} messageRemindType:`+n),yield L.set(t,n)}catch(e){let t=new o.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(this._name+`.${s} fail:`,t),t}})}},N=new class{init(e){console.log("ConversationAction.init"),this._core=e,v.init(e),f.init(e),M.init(e),E.init(e),R.init(e),S.init(e),I.init(e),T.init(e);var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:a}=e["InnerEventSubType"];e.subscribeInnerEvent(t,n,this._onConversationModified,this),e.subscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.subscribeInnerEvent(t,a,this._onC2CMessageRemindTypeSync,this),e.subscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.subscribeInnerEvent(s,this._dispose,this)}_onConversationModified(e){let{ConvModifyPushType:s}=this._core["constants"],{RecentContactMod:t=[]}=e;t.forEach(t=>{var e=t["PushType"];if(e===s.CONV_DELETED){let e=t.RecentContactDeleteItem["RecentContactList"];S.handleConversationDeleted(e)}if(e===s.CONV_PINED){let e=t.RecentContactTopItem["RecentContactList"];R.handleConversationPinned(e,!0)}if(e===s.CONV_UNPINED){let e=t.RecentContactTopItem["RecentContactList"];R.handleConversationPinned(e,!1)}})}_onC2CMessageReadSync(e){var{C2cNotifyMsgArray:e=[]}=e;E.handleC2CMessageReadSync(e)}_onC2CMessageRemindTypeSync(e){var{C2cNotifyMsgArray:e=[]}=e;T.handleC2CMessageRemindTypeSync(e)}_onGroupMessageReadSync(e){var{GroupTips:e=[]}=e;E.handleGroupMessageReadSync(e)}_dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:a}=e["InnerEventSubType"];e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,a,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}},y=new class{init(e){e=(this._core=e).helper;e.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(l){return t(this,void 0,void 0,function*(){try{let{MSG_REMIND_ACPT_NOT_NOTE:s}=this._core["OuterConstant"],{messageRemindType:n=s,isRepeated:o=!0}=l,{startTime:i=0,endTime:a=0}=this._calcStartAndEndTime(l),r=yield function(a){return t(this,void 0,void 0,function*(){var t=e.core["common"],{startTime:s,endTime:n,isRepeated:o,messageRemindType:i}=a;return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:{StartTime:s,EndTime:n,IsRepeated:o,Level:i}})})}({messageRemindType:this._getType(n),startTime:i,endTime:a,isRepeated:o?d.ON:d.OFF});return{code:0,data:{errorCode:r.ErrorCode,errorInfo:r.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){var{startHour:e=0,startMinute:t=0,startSecond:s=0,duration:n=0,isRepeated:o=!0}=e,i=new Date,i=new Date(i.getFullYear(),i.getMonth(),i.getDate(),e,t,s),e=Math.round(i.getTime()/1e3);let a=o&&86400<=n?e+86400:e+n;return{startTime:e,endTime:a}}_getType(e){var t=this._core["OuterConstant"];return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}},D=new class{init(e){var{helper:e,notificationCenter:t,InnerEvent:s}=this._core=e;e.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),t.subscribeInnerEvent(s.MESSAGE_PUSH,t.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){var e=this._handleResult(e),{notificationCenter:t,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:s}}=this._core;t.emitOuterEvent(s,{name:s,data:e})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,function*(){try{var s=yield function(){return t(this,void 0,void 0,function*(){var t=e.core["common"],s={To_Account:t.getCurrentUserID()};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:s})})}();return{code:0,data:this._handleResult(s)}}catch(e){c("getAllReceiveMessageOpt",e)}})}_handleResult(e){var t=this._core["OuterConstant"],{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=t,{Level:e,StartTime:o,EndTime:i,IsRepeated:a}=e;return{messageRemindType:{0:t,1:s,2:n}[e]||t,startTime:o,endTime:i,isRepeated:a===d.ON}}},A=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),y.init(e),D.init(e)}};let G=e=>!s(e)&&!n(e)&&!o(e),U={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!G(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{var{utils:{isArray:s,isObject:n,isString:o}}=e["core"];if(!o(t)&&!n(t))return"options is String or Object.";if(o(t)&&G(t))return"conversationID is invalid.";if(n(t)){if(!s(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some(e=>{if(G(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=>!(!s(e)&&!n(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},P={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};var $=new class{install(t){e.init(t),N.init(t),A.init(t),p.init(t),t.helper.registerValidateConfig({auth:P,params:U})}};export{$ as default};
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).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=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{core:{utils:{isString:n}}}=e,s=[];if(!n(t))return s;const o=t.length;if(0===o)return s;for(let e=o-1;e>=0;e--)"1"===t[e]&&s.push(2**(o-e-1));return s}function a(t){const{OuterConstant:n}=e.core;let s="";return 0===t?s=n.MSG_REMIND_ACPT_AND_NOTE:1===t?s=n.MSG_REMIND_DISCARD:2===t?s=n.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(s=n.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function c(t){const{OuterConstant:n}=e.core;let s;return t.startsWith(n.CONV_C2C)&&(s=t.replace(n.CONV_C2C,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}var l,u,d,_,p;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(l||(l={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(u||(u={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(_||(_={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(p||(p={}));var h;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(h||(h={}));class C{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){const{core:{OuterConstant:t,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:n(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:n,utils:{isUndefined:s}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;s(o)||(this.subType!==n.GRP_AVCHATROOM?i&&this.type===n.CONV_GROUP||i&&this.type===n.CONV_TOPIC||r&&this.type===n.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:n}}=e,{sequence:s,time:o}=t;return this.type===n.CONV_C2C&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n.CONV_GROUP&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{OuterConstant:n}}=e;let[...s]=t.groupAtType;s.includes(n.CONV_AT_ME)||s.includes(n.CONV_AT_ALL)||(s=[n.CONV_AT_ALL_AT_ME]);const o={from:t.from,groupID:t.groupID,messageSequence:t.sequence,atTypeArray:s,__random:t.__random,__sequence:t.__sequence};this.groupAtInfoList.push(o)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var g=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:n,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{MESSAGE_PUSH:r,NEW_MESSAGE:a,MESSAGE_DELETED:c,MESSAGE_REVOKED:l,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:d,LOGOUT:_,DESTROY:p}}=e;this._conversationStore=s,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this);const{InnerEventSubType:{GROUP_AT_TIPS:h}}=n;n.subscribeInnerEvent(a,this._handleNewMessage,this),n.subscribeInnerEvent(r,h,this._handleNewGroupAtTips,this),n.subscribeInnerEvent(c,this._handleMessageDeleted,this),n.subscribeInnerEvent(l,this._handleMessageRevoked,this),n.subscribeInnerEvent(u,this._handleMessageModified,this),n.subscribeInnerEvent(d,this._handleConversationUpdated,this),n.subscribeInnerEvent(_,this._reset,this),n.subscribeInnerEvent(p,this._dispose,this),console.log(`${this._name}.init`)}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:n=[],groupTipList:s=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;n.forEach((e=>{const{conversationID:t,unreadCount:n}=e,s=this.getLocalConversation(t);s&&s.unreadCount!==n&&(s.updateUnreadCount({nextUnreadCount:n,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(s)}_handleGroupAtTipsSynced(e){for(let t=0;t<e.length;t++)12===e[t].Event&&this._handleNewGroupAtTips(e[t])}_handleGroupListSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,n=e.result[t.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:s}}=this._core;let o=!1;for(let e=0;e<n.length;e++){const t=n[e],i=`${s}${t.groupID}`;if(!this.hasLocalConversation(i))continue;const r=this.getLocalConversation(i);r.groupProfile=JSON.parse(JSON.stringify(t)),r.lastMessage.lastSequence<t.nextMessageSeq&&(r.lastMessage.lastSequence=t.nextMessageSeq-1),r.subType||(r.subType=t.type),o=!0}o&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e.result||{};if(console.log(`${this._name}._handleNewMessage, conversationUpdateFieldList length:`,t.length,e),0===t.length)return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:n,GroupAtType:s,MsgRandom:o,ClientSeq:i}=e;let r={};t?r=this._convertGroupAtTipsKey(t):n?r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(n)),{sync:!0}):s&&(r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(e)),{sync:!0})),r.__random=o,r.__sequence=i,this._groupAtTipsList.push(r)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:n,MsgSeq:s,GroupAtType:o}=e;return{from:t,groupID:n,sequence:s,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,n=e.getCurrentUserID();let s=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==n){const n=this.getLocalConversation(`${t.CONV_GROUP}${o}`);n&&(n.updateGroupAtInfoList(e),s=!0)}})),s&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,n;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:s},OuterConstant:o}=this._core,i=(null==s?void 0:s.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:n=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this.getLocalConversation(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:n}=e,s=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(s))return;const{lastMessage:r}=s;if(r){const e=(null==n?void 0:n[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(){this.emitConversationListUpdate()}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:n}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(n),console.log(`${this._name}.updateLocalConversationList newConversationList: ${n.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:n,isFromGetConversations:s,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,a=[],l=null==n?void 0:n.length;for(let e=0;e<l;e++){const l=new C(n[e]),{conversationID:u,type:d}=l;if(!c(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(s){this.setLocalConversation(u,l),d===t.CONV_C2C?l.unreadCount=(null==a?void 0:a.unreadCount)||0:d===t.CONV_GROUP&&(l.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:l,lastMessage:n[e].lastMessage,isFromGetConversations:s,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:n[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:l.unreadCount,isFromGetConversations:s,isUnreadC2CMessage:i}))}else a.push(l),this.setLocalConversation(u,l)}return{newConversationList:a}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:n,lastMessage:s,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:u}}=this._core;c(i)&&s&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=s.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);u(r,n,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:n,lastMessage:s,isInstantMessage:o}=e,i=this.getLocalConversation(n);if(i&&s){const{payload:e,nameCard:n,nick:r,cloudCustomData:a=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=n,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],n=[],s=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?s.push(t):n.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],n=[],{OuterConstant:{CONV_GROUP:s,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===s){const e=i.replace(s,"");n.push(e)}})),t.length>0&&this._updateC2CConversation(t),n.length>0&&this._updateGroupConversation(n)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:n},appStore:{userStore:s},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${n}${o}`);if(r){const n=(null===(t=s.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=n,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core;let s=!1;e.forEach((e=>{const o=n.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,s=!0)})),s&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:n}=this._core,s=t.type===n.CONV_TOPIC,o=t.type===n.CONV_GROUP&&t.subType===n.GRP_ROOM,i=t.type===n.CONV_GROUP&&t.subType===n.GRP_LIVE;return!(s||o||i)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),r=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageDataHandler)||void 0===s?void 0:s.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,n=this.getLocalConversationList();this._emitEvent({name:t,data:n}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e}=this._core,t=this.getLocalConversationList();let n=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(n+=t.unreadCount))})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,n]of e)this.setLocalConversation(t,n)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let n=!1;e.forEach((e=>{const s=this.getLocalConversation(e);(null==s?void 0:s.messageRemindType)!==t&&(s.messageRemindType=t,n=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${n}`),n&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:n,lastReadTime:s=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(n);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],n=s&&t.time>s,r=o&&t.sequence>o;if(!n&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],n=t.findIndex((e=>!1===e[1].isPinned));t.splice(n,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:n,MESSAGE_REVOKED:s,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:c}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,c,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(n,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(s,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};function v(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var m=new class{constructor(){this._name="SyncConversationList",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s,constants:o}=e;s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.CONVERSATION_RECOVER,this._syncConversationListOnReOnline,this),s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_LOGIN,o.WORKFLOW_STEP.CONVERSATION_LIST_SYNC,this._syncConversationList,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}isSyncCompleted(){return this._pagingStatus===l.RESOLVED}_syncConversationListOnReOnline(){return t(this,void 0,void 0,(function*(){return this._syncConversationList()}))}_syncConversationList(){return t(this,void 0,void 0,(function*(){yield this._pagingGetConversationList(!0),this._pagingStatus=l.RESOLVED,g.emitConversationListUpdate()}))}_pagingGetConversationList(e){return t(this,void 0,void 0,(function*(){try{this._pagingStatus=l.PENDING;const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:r}=e;return v("recentcontact.page_get",{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:t,StartIndex:o,TimeStamp:s,TopStartIndex:r,TopTimeStamp:i},n)}))}({fromAccount:n.getCurrentUserID(),pagingTimeStamp:e?this._pagingTimeStamp:0,pagingStartIndex:e?this._pagingStartIndex:0,pagingPinnedTimeStamp:e?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:e?this._pagingPinnedStartIndex:0},this._core),{CompleteFlag:o,SessionItem:i=[],TimeStamp:r,StartIndex:a,TopTimeStamp:c,TopStartIndex:u}=s||{};if(i.length>0){const e=this._getConversationOptions(i);g.updateLocalConversationList({conversationUpdateFieldList:e,isFromGetConversations:!0,updateUnreadCount:!0}),g.emitConversationListUpdate()}this._pagingTimeStamp=r,this._pagingStartIndex=a,this._pagingPinnedTimeStamp=c,this._pagingPinnedStartIndex=u,1!==o&&this._pagingGetConversationList(e)}catch(e){throw console.error(`${this._name}._pagingGetConversationList fail:`,e),e}}))}_getConversationOptions(e){const{utils:{isUndefined:t}}=this._core,n=this._convertConversationKey(e);return this._filterValidConversations(n).map((e=>(t(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===u.C2C?this._assembleC2COption(e):this._assembleGroupOption(e))))}_filterValidConversations(e){return e.filter((({type:e,userID:t})=>e===u.C2C&&!c(t)||2===e))}_assembleC2COption(e){var t,n,s,o,i,a;const{OuterConstant:c}=this._core,l=this._createUserprofile(e);return{conversationID:`${c.CONV_C2C}${e.userID}`,type:c.CONV_C2C,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(t=e.lastMsg)||void 0===t?void 0:t.elements[0])?null===(n=e.lastMsg)||void 0===n?void 0:n.elements[0].type:null,payload:(null===(s=e.lastMsg)||void 0===s?void 0:s.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(o=e.lastMsg)||void 0===o?void 0:o.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:this._computeIsPeerRead(e),revoker:(null===(a=null===(i=e.lastMsg)||void 0===i?void 0:i.revokerInfo)||void 0===a?void 0:a.revoker)||null},unreadCount:0,userProfile:l,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}_createUserprofile(e){var t;const{userID:n,nick:s,peerAvatar:o}=e,i=[{tag:"Tag_Profile_IM_Nick",value:s},{tag:"Tag_Profile_IM_Image",value:o}];return null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(n,i)}_computeIsPeerRead(e){const{common:t}=this._core,n=t.getCurrentUserID(),{lastC2CMsgFromAccount:s,time:o,c2cPeerReadTime:i}=e;return s===n&&o<=i}_assembleGroupOption(e){var t,n,s;const{OuterConstant:o}=this._core;return{conversationID:`${o.CONV_GROUP}${e.groupID}`,type:o.CONV_GROUP,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(t=e.lastMsg)||void 0===t?void 0:t.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(s=null===(n=e.lastMsg)||void 0===n?void 0:n.revokerInfo)||void 0===s?void 0:s.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}_convertConversationKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",r=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.MsgType,r=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:r,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){const{OuterConstant:t}=this._core;let n="";return 0===e?n=t.MSG_REMIND_ACPT_AND_NOTE:1===e?n=t.MSG_REMIND_DISCARD:2===e?n=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(n=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}_patchTypeAndPayload(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core,{event:s,elements:o=[]}=e.lastMsg||{};return n(s)?{type:o[0]?o[0].type:null,payload:o[0]?this._amendLayersOverLimitProp(o[0].content):null}:{type:t.MSG_GRP_TIP,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s:0}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};var f=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:m.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:n,isPlainObject:s}}=this._core;if(t(e))return g.getLocalConversationList();if(n(e)){if(0===e.length)return[];return g.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(s(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return g.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:n}=this._core;return t!==n.CONV_C2C&&t!==n.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:n}}=this._core;return!n(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:n}}=this._core;return!n(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_filterGroupAtInfo(e,t){let n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}};function O(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var M=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:s}=e;return O("openim.get_c2c_peer_mute_notifications",{To_Account:t,Peer_Account:s},n)}))}({toAccount:n.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=s||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:n}=e,s=`${this._core.OuterConstant.CONV_C2C}${t}`,o=a(n);g.patchMessageRemindType([s],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var E=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const n=yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:s}=e;return O("group_open_http_svc.get_group_self_member_info",{GroupIdList:t,ResponseFilter:s},n)}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=n||{};s.forEach((e=>{var t;const{GroupId:n,MemberList:s}=e,o=(null===(t=s[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${n}`;g.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var I=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let l=g.getLocalConversation(e);if(o(e))return c.data.conversation=l,c;let u=!1;const d=n(e)?t:s;if(a(l)&&(u=!0,l=new C({conversationID:e,type:d})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=l,null==l?void 0:l.getProfileCompleted())return c;if(d===t){const n=e.replace(t,"");yield this._handleC2CConversation(l,n),u&&(yield M.get([n]))}if(d===s){const t=e.replace(s,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(l,t),u&&l.groupProfile.type!==i&&(yield E.get([t]))}return c}))}_handleC2CConversation(e,n){return t(this,void 0,void 0,(function*(){var t,s;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,u=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[n]});if(0===(null==u?void 0:u.data.length))throw new i.ChatError({code:h.USER_OR_GRP_NOT_FOUND});e.userProfile=null==u?void 0:u.data[0];const d=null===(s=c.getFriend(n))||void 0===s?void 0:s.remark;r(d)||e.remark===d||(e.remark=d),e.setProfileCompleted();const _=g.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${_}`),_?a.updateConversation(l,e):g.appendToPinnedConversation(e)}))}_handleGroupConversation(e,n){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:s}}=this._core,{conversationID:o}=e,i=yield t({groupID:n});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=g.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?s.updateConversation(o,e):g.appendToPinnedConversation(e)}))}};var T=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return g.getTotalUnreadMessageCount()}};var L=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRead",context:this})}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:s}=e;if(!t(s)){const{UinPairReadArray:e=[]}=s;e.forEach((e=>{const{From_Account:t,LastReadTime:s}=e,o=`${n.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${s}`),g.markMessageAsRead({conversationID:o,lastReadTime:s}),g.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:s}=e.MsgBody;n(s)||s.forEach((e=>{const{GroupId:n,LastReadMsgSeq:s}=e,o=`${t.CONV_GROUP}${n}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${s}`),g.markMessageAsRead({conversationID:o,lastReadSequence:s}),g.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,n;const{OuterConstant:s}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=g.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r.groupAtInfoList));if(r.type===s.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;if(r.type===s.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e)}if(r.type===s.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e)}return r.type===s.CONV_SYSTEM&&(r.unreadCount=0),g.emitConversationListUpdate(),i}))}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const n=g.getLocalConversation(e);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const{common:n}=this._core,o=s.map((e=>({From_Account:e.from,To_Account:n.getCurrentUserID(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,n){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e;return v("openim.deletemsg",{DelMsgList:t},n)}))}({messageListToDelete:o},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=g.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&g.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){return v("openim.msgreaded",e,n)}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${n}`),g.markMessageAsRead({conversationID:e,lastReadTime:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:s}=e;return v("group_open_http_svc.msg_read_report",{GroupId:t,MsgReadedSeq:s},n)}))}({groupID:e.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${n}`),g.markMessageAsRead({conversationID:e,lastReadSequence:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var S=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:n}}=this._core;if(!n(e))return;const{OuterConstant:s}=this._core;let o=!1;e.forEach((e=>{const{Type:n,To_Account:i,GroupId:r}=e;let a;1===n?a=g.getLocalConversation(`${s.CONV_C2C}${i}`):2===n&&(a=g.getLocalConversation(`${s.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&g.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r}=this._core,{conversationID:a,isPinned:c}=e,l={code:0,data:{conversationID:a}},u=g.getLocalConversation(a);if(u&&u.isPinned===c)return l;if(o(a))return u&&(u.isPinned=c),g.emitConversationListUpdate(!0),l;try{let e=null;n(a)?e={Type:1,To_Account:a.replace(i.CONV_C2C,"")}:s(a)&&(e={Type:2,GroupId:a.replace(i.CONV_GROUP,"")});const o=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:s,itemList:o}=e;return v("recentcontact.top",{From_Account:t,OperationType:s,RecentContactItem:o},n)}))}({fromAccount:r.getCurrentUserID(),operationType:!0===c?1:2,itemList:[e]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${a} isPinned:${c}.`),o){if(u)u.isPinned!==c&&(u.isPinned=c);else{const e=new C({conversationID:a,type:n(a)?i.CONV_C2C:i.CONV_GROUP,isPinned:c});g.setLocalConversation(a,e)}g.emitConversationListUpdate(!0)}return l}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var R=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:n}=this._core,s=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&s.push(`${n.CONV_C2C}${o}`),2===t&&s.push(`${n.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return console.log(`${this._name}.deleteConversation conversationID:${e}`),void(yield this._deleteConversation({conversationIDList:[e],flag:_.ONLY_CONVERSATIONID}));const n=Object.assign({},e);n.conversationIDList.length>100&&(n.conversationIDList=n.conversationIDList.slice(0,100)),yield this._deleteConversation(n)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:n=!0,flag:s=0}=e;console.log(`${this._name}._deleteConversation conversationIDList:${t} clearHistoryMessage:${n}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,n)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===_.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var n;if(!g.hasLocalConversation(e))return!1;const s=null===(n=g.getLocalConversation(e))||void 0===n?void 0:n.type;return s!==t.CONV_GROUP||this._hasLocalGroup(e)?s===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,n){return t(this,void 0,void 0,(function*(){const{OuterConstant:s,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:n?1:0};if(e.forEach((e=>{var t;if(g.hasLocalConversation(e)){const n=(null===(t=g.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(n,"");n===s.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):n===s.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:s,clearHistoryMessage:o}=e;return v("recentcontact.batch_delete",{From_Account:t,ContactItem:s,ClearRamble:o},n)}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const n=1===e.type?`${s.CONV_C2C}${e.To_Account}`:`${s.CONV_GROUP}${e.ToGroupid}`;t.push(n)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{g.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&g.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=g.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(g.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&g.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core,s=e.replace(t,"");return!!n.getGroup(s)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var y=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:n}=e;if(console.log(`${this._name} conversationID:${t} draftText:${n}`),!g.hasLocalConversation(t))throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});const s=g.getLocalConversation(t);return null==s||s.setDraftText(n),g.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var D=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(n,s){return t(this,void 0,void 0,(function*(){n.length>30&&(console.warn(`${this._name}.set userIDList length:${n.length} exceeds limit 30`),n.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:s}=e.core.OuterConstant;return{[t]:0,[n]:1,[s]:2}}()[s],i=yield function(e,n){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:s}=e;return O("openim.set_c2c_peer_mute_notifications",{Peer_Account:t,Mute_Notifications:s},n)}))}({userIDList:n,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:s}=e;a.push({userID:t,code:s});const o=n.indexOf(t);o>-1&&n.splice(o,1)}));const c=[],l=[],{OuterConstant:u}=this._core;return n.forEach((e=>{l.push(`${u.CONV_C2C}${e}`),c.push({userID:e})})),g.patchMessageRemindType(l,s),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var N=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,n){return t(this,void 0,void 0,(function*(){const{common:s,OuterConstant:o}=this._core;yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:s,receiveMessageOption:o}=e;return O("group_open_http_svc.modify_group_member_info",{GroupId:t,Member_Account:s,MsgFlag:o},n)}))}({groupID:e,userID:s.getCurrentUserID(),receiveMessageOption:n},this._core);const i=`${o.CONV_GROUP}${e}`;return g.patchMessageRemindType([i],n),{code:0,data:{groupID:e,messageRemindType:n}}}))}};var A=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:s}=e;if(!t(s)){const{To_Account:e,MuteNotifications:t}=s,o=e.map((e=>`${n.CONV_C2C}${e}`)),i=a(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),g.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:n,userIDList:s,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(n)){console.log(`${this._name}.${t} groupID:${n} messageRemindType:${o}`);return yield N.set(n,o)}if(!r(s)){console.log(`${this._name}.${t} userIDList:${s} messageRemindType:${o}`);return yield D.set(s,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{init(e){console.log("ConversationAction.init"),this._core=e,m.init(e),f.init(e),I.init(e),T.init(e),L.init(e),S.init(e),R.init(e),y.init(e),A.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:n,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(n,o,this._onConversationModified,this),t.subscribeInnerEvent(n,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(n,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(n,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(s,this._dispose,this)}handleLoginSuccess(){m.handleLoginSuccess()}_onConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===p.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;R.handleConversationDeleted(t)}if(t===p.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!0)}if(t===p.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;L.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;A.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;L.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:s,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,s,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(n,this._dispose,this)}};var G=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,D.init(e),N.init(e),M.init(e),E.init(e)}};const U=e=>!n(e)&&!s(e)&&!o(e),$={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:n,isObject:s,isString:o}}}=e;if(!o(t)&&!s(t))return"options is String or Object.";if(o(t)&&U(t))return"conversationID is invalid.";if(s(t)){if(!n(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if(U(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!n(e)&&!s(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}},V={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0};return new class{install(t){e.init(t),P.init(t),G.init(t),g.init(t),t.helper.registerValidateConfig({auth:V,params:$})}handleLoginSuccess(){P.handleLoginSuccess()}}}));
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(){let d=new class{init(e){this.core=e}};function c(e,a,r,l){return new(r=r||Promise)(function(s,t){function n(e){try{i(l.next(e))}catch(e){t(e)}}function o(e){try{i(l.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?s(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(n,o)}i((l=l.apply(e,a||[])).next())})}let u=e=>{var{OuterConstant:t,utils:{isString:s}}=d["core"];return s(e)&&e.slice(0,3)===t.CONV_C2C},_=e=>{var{OuterConstant:t,utils:{isString:s}}=d["core"];return s(e)&&e.slice(0,5)===t.CONV_GROUP},t=e=>{var{OuterConstant:t,utils:{isString:s}}=d["core"];return s(e)&&e===t.CONV_SYSTEM},s=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:d.core.common.getMessagePreviewText(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(e){var t=d.core["OuterConstant"];let s="";return 0===e?s=t.MSG_REMIND_ACPT_AND_NOTE:1===e?s=t.MSG_REMIND_DISCARD:2===e?s=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(s=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function h(e){var t=d.core["OuterConstant"];let s;return"@TLS#ERROR"===(s=e.startsWith(t.CONV_C2C)?e.replace(t.CONV_C2C,""):s)||"@TLS#NOT_FOUND"===s}function n(e,t){var s=d.core["helper"],s=new s.ChatError({functionName:e,code:(null==t?void 0:t.errorCode)||(null==t?void 0:t.code),message:(null==t?void 0:t.errorInfo)||(null==t?void 0:t.message)});throw console.error(e+" fail:",s),s}class C{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=s(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(){var{OuterConstant:e,utils:{isUndefined:t}}=d["core"];t(this.userProfile)&&this.type===e.CONV_C2C?this.userProfile={}:t(this.groupProfile)&&this.type===e.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===e.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){var{OuterConstant:t,utils:{isUndefined:s}}=d["core"],{nextUnreadCount:e,isFromGetConversations:n,isUnreadC2CMessage:o}=e;s(e)||(this.subType!==t.GRP_AVCHATROOM?n&&this.type===t.CONV_GROUP||o&&this.type===t.CONV_C2C?this.unreadCount=e:this.unreadCount+=e:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=s(e)}reduceUnreadCount(){return 1<=this.unreadCount&&(--this.unreadCount,!0)}isLastMessageRevoked(e){var t=d["core"]["OuterConstant"],{sequence:e,time:s}=e;return this.type===t.CONV_C2C&&e===this.lastMessage.lastSequence&&s===this.lastMessage.lastTime||this.type===t.CONV_GROUP&&e===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(e){var{common:{updateGroupAtInfo:t}}=d["core"];t(e,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var r,l,v,e;(e=r=r||{})[e.OFF=0]="OFF",e[e.ON=1]="ON",l=l||{},l[l.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID",(e=v=v||{})[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";var p=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){var{helper:e,notificationCenter:t,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:o},InnerEvent:{SYNC_CONVERSATION_LIST:i,MESSAGE_PUSH:a,NEW_MESSAGE:r,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:c,CONVERSATION_UPDATED:u,LOGOUT:_,DESTROY:h}}=this._core=e,s=(this._conversationStore=s,e.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,o.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),e.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,o.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),e.registerWorkflowStep(n.RECEIVE_C2C_NEW_MESSAGE,o.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),e.registerWorkflowStep(n.RECEIVE_C2C_NEW_MESSAGE,o.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),e.registerWorkflowStep(n.RECEIVE_GROUP_NEW_MESSAGE,o.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),e.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t)["InnerEventSubType"]["GROUP_AT_TIPS"];t.subscribeInnerEvent(i,this._handleConversationSynced,this),t.subscribeInnerEvent(r,this._handleNewMessage,this),t.subscribeInnerEvent(a,s,this._handleNewGroupAtTips,this),t.subscribeInnerEvent(l,this._handleMessageDeleted,this),t.subscribeInnerEvent(d,this._handleMessageRevoked,this),t.subscribeInnerEvent(c,this._handleMessageModified,this),t.subscribeInnerEvent(u,this._handleConversationUpdated,this),t.subscribeInnerEvent(_,this._reset,this),t.subscribeInnerEvent(h,this._dispose,this),console.log(this._name+".init")}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){let{WORKFLOW_STEP:t}=this._core["constants"],{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{},i=!1;s.forEach(e=>{var{conversationID:e,unreadCount:t}=e,e=this.getLocalConversation(e);e&&e.unreadCount!==t&&(e.updateUnreadCount({nextUnreadCount:t,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(t){var s;for(let e=0;e<t.length;e++)if(12===t[e].Event){if(null!=(s=t[e].GroupTips[0].MsgBody)&&s.TopicId)continue;this._handleNewGroupAtTips(t[e])}}_handleGroupListSyncFinished(e){let n,{WORKFLOW_STEP:t}=this._core.constants,o=e.result[t.GROUP_LIST_SYNC]||[],{CONV_GROUP:i}=this._core.OuterConstant,a=!1;for(let s=0;s<o.length;s++){let e=o[s],t=""+i+e.groupID;var r;this.hasLocalConversation(t)&&((r=this.getLocalConversation(t)).groupProfile=JSON.parse(JSON.stringify(e)),r.lastMessage.lastSequence<e.nextMessageSeq&&(r.lastMessage.lastSequence=e.nextMessageSeq-1),r.subType||(r.subType=e.type),0<(null==(n=e._groupAtInfoList)?void 0:n.length)&&this._handleNewGroupAtTips({GroupTips:e._groupAtInfoList}),a=!0)}a&&this.emitConversationListUpdate()}_handleNewMessage(e){var t,{conversationUpdateFieldList:e=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};0===e.length||({isTopic:t}=this._core["common"],t(e[0].conversationID))||(this.updateLocalConversationList({conversationUpdateFieldList:e,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o}),0<e.filter(e=>this._isConversationNeedShow(e.conversationID)).length&&this.emitConversationListUpdate())}_handleNewGroupAtTips(e){var{GroupTips:e=[]}=e;e.forEach(e=>{var{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(this._name+"._handleNewGroupAtTips groupAtTipsList: "+JSON.stringify(this._groupAtTipsList)),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){var{From_Account:e,GroupId:t,MsgSeq:s,GroupAtType:n}=e;return{from:e,groupID:t,sequence:s,groupAtType:n}}_updateGroupAtInfoList(){if(0!==this._groupAtTipsList.length){let{common:e,OuterConstant:n}=this._core,o=e.getCurrentUserID(),i=!1;this._groupAtTipsList.forEach(t=>{var{groupID:s,from:e}=t;if(e!==o){let e=this.getLocalConversation(""+n.CONV_GROUP+s);e&&(e.updateGroupAtInfoList(t),i=!0)}}),i&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}}_handleMessageDeleted(t){console.log(this._name+"._handleMessageDeleted, conversationID:",t);var s,{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(t))||[];let a={};for(let e=(i.length||0)-1;0<=e;e--)if(!i[e].isDeleted){a=i[e];break}n=this.getLocalConversation(t);if(n){let e=!1;n.lastMessage.lastSequence===a.sequence&&n.lastMessage.lastTime===a.time||(null!=(s=null==(s=this._core)?void 0:s.helper)&&s.isEmpty(a)&&(a=void 0),n.updateLastMessage(a),e=!0),t.startsWith(o.CONV_C2C)&&this.updateUnreadCount(t),e&&(this.emitConversationListUpdate(),console.log(this._name+`._handleMessageDeleted. update conversationID:${t} with lastMessage:`,n.lastMessage))}}_handleMessageRevoked(e){let{messageList:n=[],updateUnreadCount:o=!0}=e;if(console.log(this._name+"._handleMessageRevoked messageList:"+n.length),0!==n.length){let t=null,s=!1;n.forEach(e=>{(t=this.getLocalConversation(e.conversationID))&&(o&&t.reduceUnreadCount()&&(s=!0),t.isLastMessageRevoked({sequence:e.sequence,time:e.time}))&&(t.setLastMessageRevoked(!0),t.setLastMessageRevoker(e.revoker),s=!0)}),s&&this.emitConversationListUpdate()}}_handleMessageModified(e){console.log(this._name+"._handleMessageModified",JSON.stringify(e));var{conversationID:t,messageList:s}=e,e=this.getLocalConversation(t),{utils:{isEmpty:n},common:{getMessagePreviewText:o}}=this._core;if(!n(e)){n=e["lastMessage"];if(n){let e=(null==s?void 0:s[0])||{};n.lastTime===e.time&&n.lastSequence===e.sequence&&n.version!==e.version&&(n.type=e.type,n.payload=e.payload,n.messageForShow=o(e.type,e.payload),n.cloudCustomData=e.cloudCustomData,n.version=e.version,this.emitConversationListUpdate(),console.log(this._name+` conversationID:${t} lastMessage updated`))}}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){var t=e["isFromGetConversations"],e=this._getTmpConversationListMapping(e)["newConversationList"];this._sortConversationList(),t||this._updateNewConversationProfile(e),console.log(this._name+".updateLocalConversationList newConversationList: "+e.length)}_getTmpConversationListMapping(e){let i=this._core["OuterConstant"],{conversationUpdateFieldList:a,isFromGetConversations:r,isInstantMessage:l,isUnreadC2CMessage:d=!1,updateUnreadCount:c}=e,u=[],t=null==a?void 0:a.length;for(let o=0;o<t;o++){let t=new C(a[o]),{conversationID:s,type:n}=t;if(!h(s))if(this.hasLocalConversation(s)){let e=this.getLocalConversation(s);r?(this.setLocalConversation(s,t),n===i.CONV_C2C?t.unreadCount=(null==e?void 0:e.unreadCount)||0:n===i.CONV_GROUP&&(t.groupProfile=JSON.parse(JSON.stringify(null==e?void 0:e.groupProfile)))):(this._mergeConversationInfo({conversationID:s,tmpConversation:t,lastMessage:a[o].lastMessage,isFromGetConversations:r,isInstantMessage:l}),this._patchLastMessage({conversationID:s,lastMessage:a[o].lastMessage,isInstantMessage:l}),!0===c&&null!=e&&e.updateUnreadCount({nextUnreadCount:t.unreadCount,isFromGetConversations:r,isUnreadC2CMessage:d}))}else u.push(t),this.setLocalConversation(s,t)}return{newConversationList:u}}_mergeConversationInfo(e){var{conversationID:e,tmpConversation:t,lastMessage:s,isFromGetConversations:n,isInstantMessage:o}=e,e=this.getLocalConversation(e),i=["unreadCount","allowType","adminForbidType","payload"],{utils:{isUndefined:n,isEmpty:a},common:{deepMerge:r}}=(!1===o&&i.push("lastMessage"),n&&i.push("isPinned"),this._core);n(o)&&s&&null===(null==e?void 0:e.lastMessage.payload)&&(e.lastMessage.payload=s.payload),a(null==e?void 0:e.lastMessage.revoker)||(e.lastMessage.revoker=null),r(e,t,i,[null,void 0,"",0,NaN])}_patchLastMessage(e){let o=this._core["OuterConstant"],{conversationID:t,lastMessage:i,isInstantMessage:a}=e,r=this.getLocalConversation(t);if(r&&i){let{payload:e,nameCard:t,nick:s,cloudCustomData:n=""}=i;a&&(e&&(r.lastMessage.payload=e),r.type===o.CONV_GROUP)&&(r.lastMessage.nameCard=t,r.lastMessage.nick=s),r.lastMessage.cloudCustomData!==n&&(r.lastMessage.cloudCustomData=n)}}_sortConversationList(){let{isEmpty:t}=this._core["utils"],e=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];e.forEach(e=>{(!0===e[1].isPinned?t(e[1].lastMessage.lastTime)?n:s:t(e[1].lastMessage.lastTime)?i:o).push(e)});var a=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(a)}_updateNewConversationProfile(e){if(0!==e.length){let s=[],n=[],{CONV_GROUP:o,CONV_C2C:i}=this._core["OuterConstant"];e.forEach(e=>{var{conversationID:t,type:e}=e;if(e===i){let e=t.replace(i,"");s.push(e)}else if(e===o){let e=t.replace(o,"");n.push(e)}}),0<s.length&&this._updateC2CConversation(s),0<n.length&&this._updateGroupConversation(n)}}_updateC2CConversation(e){let t,{OuterConstant:{CONV_C2C:o},appStore:{userStore:i},user:s}=this._core,a=!1;null!=(t=s.userProfile)&&t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(t=>{var s=t["userID"],n=this.getLocalConversation(""+o+s);if(n){let e=(null==(s=i.getFriend(s))?void 0:s.remark)||"";n.remark=e,n.userProfile=t,a=!0}}),a&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){let{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n}}=this._core,o=!1;e.forEach(e=>{var t=n.getGroup(e),e=this.getLocalConversation(""+s+e);t&&e&&(e.groupProfile=t,o=!0)}),o&&this.emitConversationListUpdate()}_isConversationNeedShow(e){var t,s,n,e=this.getLocalConversation(e);return!(!this._core.utils.isUndefined(e)&&(t=this._core.OuterConstant,s=e.type===t.CONV_TOPIC,n=e.type===t.CONV_GROUP&&e.subType===t.GRP_ROOM,e=e.type===t.CONV_GROUP&&e.subType===t.GRP_LIVE,s||n||e))}updateUnreadCount(e,t=!0){let s,n,o=!1;var i,a=this.getLocalConversation(e),r=null==(n=null==(s=this._core)?void 0:s.message.messageDataHandler)?void 0:n.getLocalMessageList(e);return a&&(i=a.unreadCount,r=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length,console.log(this._name+`._updateUnreadCount conversationID:${e} currentUnreadCount:${i} newUnreadCount:`+r),i!==r)&&(a.unreadCount=r,(o=!0)===t)&&this.emitConversationListUpdate(),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();var e=this._core["OuterEvent"]["CONVERSATION_LIST_UPDATED"],t=this.getLocalConversationList();this._emitEvent({name:e,data:t}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e,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.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null!=(t=this._core)&&t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){let t=this._core["OuterConstant"],e=this.getLocalConversationList(),s=0;return e.forEach(e=>{e.type===t.CONV_SYSTEM||""!==e.messageRemindType&&e.messageRemindType!==t.MSG_REMIND_ACPT_AND_NOTE||(s+=e.unreadCount)}),s}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(var[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{e=this.getLocalConversation(e);(null==e?void 0:e.messageRemindType)!==t&&(e.messageRemindType=t,s=!0)}),console.log(this._name+`.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:`+s),s&&this.emitConversationListUpdate()}markMessageAsRead(e){let{messageDataHandler:t}=this._core["message"],{conversationID:s,lastReadTime:o=0,lastReadSequence:i=0}=e,a=null==t?void 0:t.getLocalMessageList(s);if(0!==a.length){let e=a["length"];for(let n=e-1;0<=n;n--){let e=a[n],t=o&&e.time>o,s=i&&e.sequence>i;if(!t&&!s){if("in"===e.flow&&e.isRead)break;e.setIsRead(!0)}}}}appendToPinnedConversation(e){var t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){var{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:a,DESTROY:r,SYNC_CONVERSATION_LIST:l}}=this._core,{GROUP_AT_TIPS:d}=e["InnerEventSubType"];e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,d,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(l,this._handleConversationSynced,this),e.unSubscribeInnerEvent(a,this._reset,this),e.unSubscribeInnerEvent(r,this._dispose,this)}},g=new class{constructor(){this._name="GetConversationList"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return c(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(a){let{isUndefined:e,isArray:t,isPlainObject:s}=this._core["utils"];if(e(a))return p.getLocalConversationList();if(t(a))return 0===a.length?[]:p.getLocalConversationList().filter(e=>a.includes(e.conversationID));if(s(a)){let{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=a;return p.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){var s=this._core["OuterConstant"];return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){var{isString:s}=this._core["utils"];return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){var{isNumber:s}=this._core["utils"];return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=1<=e.unreadCount:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=1<=e.groupAtInfoList.length:!1===t&&(s=0===e.groupAtInfoList.length),s}},m=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(n){return c(this,void 0,void 0,function*(){try{var e=this._core["common"],t=yield function(s,n){return c(this,void 0,void 0,function*(){var{toAccount:e,userIDList:t}=s;return n.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:{To_Account:e,Peer_Account:t}})})}({toAccount:e.getCurrentUserID(),userIDList:n},this._core),{MuteNotificationsList:s=[]}=t||{};s.forEach(e=>{var{Peer_Account:e,MuteNotifications:t}=e,e=""+this._core.OuterConstant.CONV_C2C+e,t=a(t);p.patchMessageRemindType([e],t)})}catch(e){console.error(this._name+".get fail:",e)}})}},f=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(s){return c(this,void 0,void 0,function*(){if(0!==s.length)try{var e=yield function(s,n){return c(this,void 0,void 0,function*(){var{groupIDList:e,responseFilter:t}=s;return n.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:{GroupIdList:e,ResponseFilter:t}})})}({groupIDList:s,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:t=[]}=e||{};t.forEach(e=>{var{GroupId:e,MemberList:t}=e,t=(null==(t=t[0])?void 0:t.MsgFlag)||"",e=""+this._core.OuterConstant.CONV_GROUP+e;p.patchMessageRemindType([e],t)})}catch(e){console.error(this._name+".get fail:",e)}})}},M=new class{constructor(){this._name="GetConversationProfile"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(d){return c(this,void 0,void 0,function*(){let{OuterConstant:{CONV_C2C:s,CONV_GROUP:n,GRP_AVCHATROOM:o},appStore:{groupStore:i},utils:{isEmpty:e}}=this._core,a={code:0,data:{}},r=p.getLocalConversation(d);if(t(d))a.data.conversation=r;else{let t=!1;var l=u(d)?s:n;if(e(r)&&(t=!0,r=new C({conversationID:d,type:l})),console.log(this._name+`.getConversationProfile conversationID:${d} isNewConversation:`+t),null==(a.data.conversation=r)||!r.getProfileCompleted()){if(l===s){let e=d.replace(s,"");yield this._handleC2CConversation(r,e),t&&(yield m.get([e]))}if(l===n){let e=d.replace(n,"");if(!i.getGroup(e))return a;yield this._handleGroupConversation(r,e),t&&r.groupProfile.type!==o&&(yield f.get([e]))}}}return a})}_handleC2CConversation(a,r){return c(this,void 0,void 0,function*(){var{user:e,helper:t,utils:{isEmpty:s},appStore:{conversationStore:n,userStore:o}}=this._core,i=a["conversationID"],e=yield null==(e=e.userProfile)?void 0:e.getUserProfile({userIDList:[r]});if(0===(null==e?void 0:e.data.length))throw new t.ChatError({code:v.USER_OR_GRP_NOT_FOUND});a.userProfile=null==e?void 0:e.data[0];e=null==(t=o.getFriend(r))?void 0:t.remark,s(e)||a.remark===e||(a.remark=e),a.setProfileCompleted(),o=p.hasLocalConversation(i);console.log(this._name+`._handleC2CConversation conversationID:${i} hasLocalConversation: `+o),o?n.updateConversation(i,a):p.appendToPinnedConversation(a)})}_handleGroupConversation(n,o){return c(this,void 0,void 0,function*(){var{apiMap:{getGroupProfile:e},appStore:{conversationStore:t}}=this._core,s=n["conversationID"],e=yield e({groupID:o}),e=(n.groupProfile=null==e?void 0:e.data.group,n.setProfileCompleted(),p.hasLocalConversation(s));console.log(this._name+`._handleGroupConversation conversationID:${s} hasLocalConversation: `+e),e?t.updateConversation(s,n):p.appendToPinnedConversation(n)})}},R=new class{init(e){e=e.helper;e.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return p.getTotalUnreadMessageCount()}},E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){let{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=this._core=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){let{helper:{isEmpty:s},OuterConstant:n}=this._core;e.forEach(e=>{var t=e["ReadC2cMsgNotify"];if(!s(t)){let{UinPairReadArray:e=[]}=t;e.forEach(e=>{var{From_Account:e,LastReadTime:t}=e,e=""+n.CONV_C2C+e;console.log(this._name+`.handleC2CMessageReadSync conversationID:${e} lastReadTime:`+t),p.markMessageAsRead({conversationID:e,lastReadTime:t}),p.updateUnreadCount(e)})}})}handleGroupMessageReadSync(e){let{OuterConstant:s,utils:{isUndefined:t}}=this._core;e.forEach(e=>{e=e.MsgBody.GroupReadInfoArray;t(e)||e.forEach(e=>{var{GroupId:e,LastReadMsgSeq:t}=e,e=""+s.CONV_GROUP+e;console.log(this._name+`.handleGroupMessageReadSync conversationID:${e} lastReadSequence:`+t),p.markMessageAsRead({conversationID:e,lastReadSequence:t}),p.updateUnreadCount(e),this._clearGroupAtInfoList(e)})})}setMessageRead(l){return c(this,void 0,void 0,function*(){let e=this._core["OuterConstant"],t=l["conversationID"],s={code:0,data:{}},n=p.getLocalConversation(t);if(console.log(this._name+`.setMessageRead conversationID:${t} unreadCount:`+((null==n?void 0:n.unreadCount)||0)),n){var o=!(null!=(i=null==(o=this._core)?void 0:o.helper)&&i.isEmpty(n.groupAtInfoList));if(n.type===e.CONV_GROUP&&o&&this._deleteGroupAtTips(t),0!==n.unreadCount){var{ssoLog:i,helper:{ChatError:a}}=this._core,r=i.createSSOLogData({method:"setMessageRead"});r.setLogInfo({message:"conversationID:"+t});try{if(n.type===e.CONV_C2C){let e=this._getLocalMessageMaxTime(n);yield this._setC2CMessageRead(t,e),r.setLogInfo({moreMessage:"lastMessageTime:"+e}).end()}if(n.type===e.CONV_GROUP){let e=this._getLocalMessageMaxSequence(n);yield this._setGroupMessageRead(t,e),r.setLogInfo({moreMessage:"lastMessageSequence:"+e}).end()}}catch(e){let{errorCode:t,errorInfo:s}=e,n=new a({functionName:"setMessageRead",code:t,message:s});throw r.setError(n).end(),n}n.type===e.CONV_SYSTEM&&(n.unreadCount=0),p.emitConversationListUpdate()}}return s})}setAllMessageRead(){return c(this,arguments,void 0,function*(e={}){let{OuterConstant:{READ_ALL_MSG:t},ssoLog:s}=this._core,o=s.createSSOLogData({method:"setAllMessageRead"});e.scope||(e.scope=t);var i=e["scope"],a=this._generateSetAllMessageReadRequestData(i);if(0===a.allC2CMessageReadStatus&&0===a.groupMessageReadInfoList.length)return{code:0};try{let n=yield function(s){return c(this,void 0,void 0,function*(){var{allC2CMessageReadStatus:e,groupMessageReadInfoList:t}=s,e={C2CReadAllMsg:e,GroupReadInfo:t};return d.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:e})})}(a);if(n){let{GroupReadInfoArray:e,C2CReadAllMsg:t}=n,s=this._parseGroupReadInfo(e);0<this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})&&p.emitConversationListUpdate(),o.setLogInfo({message:`scope:${i} failureGroups:`+JSON.stringify(s)}).end()}return{code:0}}catch(e){let t=e["errorCode"],s=new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t});throw o.setError(s).end(),s}})}_handleAllMessageRead(e){var{GroupReadInfoArray:e,C2CReadAllMsg:t}=e;this._parseGroupReadInfo(e),0<this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})&&p.emitConversationListUpdate()}_updateAllConversationReadStatus(e){let{OuterConstant:{CONV_C2C:n,CONV_GROUP:o},appStore:t}=this._core,i=t.conversationStore.getConversationMap(),a=e["allC2CMessageReadStatus"],r=0;for(let[s,t]of i)if(1<=t.unreadCount){if(1===a&&t.type===n){let e=this._getLocalMessageMaxTime(t);p.markMessageAsRead({conversationID:s,lastReadTime:e})}else if(t.type===o){let t=s.replace(o,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){let e=this._serverGroupConversationLastReadSeqMap.get(t);p.markMessageAsRead({conversationID:s,lastReadSequence:e})}}p.updateUnreadCount(s,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(n){let{OuterConstant:{CONV_C2C:o,CONV_GROUP:i,READ_ALL_C2C_MSG:a},appStore:e}=this._core,r={allC2CMessageReadStatus:0,groupMessageReadInfoList:[]},t=e.conversationStore.getConversationMap();for(let[,s]of t){let{type:e,unreadCount:t}=s;if(this._shouldSetAllMessageRead({scope:n,type:e,unreadCount:t}))if(e===o&&0===r.allC2CMessageReadStatus){if(r.allC2CMessageReadStatus=1,n===a)break}else if(e===i){let e=this._getLocalMessageMaxSequence(s),t=s.groupProfile["groupID"];r.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return r}_parseGroupReadInfo(e){let{isUndefined:o}=this._core["utils"],i=[];return null!=e&&e.forEach(e=>{var{GroupId:e,MsgSeq:t,RetCode:s,LastReadMsgSeq:n}=e;o(s)?this._serverGroupConversationLastReadSeqMap.set(e,n):(this._serverGroupConversationLastReadSeqMap.set(e,t),0!==s&&i.push(e+`-${t}-`+s))}),i}_deleteGroupAtTips(a){return c(this,void 0,void 0,function*(){console.log(this._name+"._deleteGroupAtTips conversationID:"+a);let e=p.getLocalConversation(a);if(e){var i=(null==e?void 0:e.groupAtInfoList)||[];if(0!==i.length)try{let{common:{getCurrentUserID:t,isCommunity:e},OuterConstant:{CONV_GROUP:s,CONV_AT_ALL:n}}=this._core,o=[...i];e({groupID:a.replace(s,"")})&&0===(o=i.filter(e=>!e.atTypeArray.includes(n))).length?this._clearGroupAtInfoList(a,!1):(yield function(t,s){return c(this,void 0,void 0,function*(){var e=t["messageListToDelete"];return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:{DelMsgList:e}})})}({messageListToDelete:o.map(e=>({From_Account:e.from,To_Account:t(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}))},this._core),console.log(this._name+"._deleteGroupAtTips ok. count:"+i.length),this._clearGroupAtInfoList(a))}catch(e){console.error(this._name+"._deleteGroupAtTips fail:",e)}}})}_clearGroupAtInfoList(e,t=!0){var s=p.getLocalConversation(e);s&&(0<s.groupAtInfoList.length&&(s.clearGroupAtInfoList(),console.log(this._name+`._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:`+t)),t)&&p.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t=e["conversationID"],t=this._core.message.messageDataHandler.getLocalMessageList(t),t=Math.max(...t.map(e=>e.time));let s=(null==(e=null==e?void 0:e.lastMessage)?void 0:e.lastTime)||0;return t>s&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${s} to `+t),s=t),s}_getLocalMessageMaxSequence(e){var t=e["conversationID"],t=this._core.message.messageDataHandler.getLocalMessageList(t),t=Math.max(...t.map(e=>e.sequence));let s=(null==(e=null==e?void 0:e.lastMessage)?void 0:e.lastSequence)||0;return t>s&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${s} to `+t),s=t),s}_setC2CMessageRead(e,t){return c(this,void 0,void 0,function*(){try{yield function(e,t){return c(this,void 0,void 0,function*(){return t.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:t,Receipt:1}]}},this._core),console.log(this._name+"._setC2CMessageRead ok, lastReadTime:"+t),p.markMessageAsRead({conversationID:e,lastReadTime:t}),p.updateUnreadCount(e)}catch(e){throw console.warn(this._name+"._setC2CMessageRead fail:",e),e}})}_setGroupMessageRead(e,t){return c(this,void 0,void 0,function*(){try{yield function(s,n){return c(this,void 0,void 0,function*(){var{groupID:e,lastMessageSequence:t}=s;return n.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:{GroupId:e,MsgReadedSeq:t}})})}({groupID:e.replace("GROUP",""),lastMessageSequence:t},this._core),console.log(this._name+"._setGroupMessageRead ok, lastReadSequence:"+t),p.markMessageAsRead({conversationID:e,lastReadSequence:t}),p.updateUnreadCount(e)}catch(e){throw console.warn(this._name+"._setGroupMessageRead fail:",e),e}})}_shouldSetAllMessageRead(e){var{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}=this._core["OuterConstant"],{type:e,scope:a,unreadCount:r}=e;return!(r<=0||(e!==t||![n,o].includes(a))&&(e!==s||![n,i].includes(a)))}},S=new class{constructor(){this._name="PinConversation"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,a){var{isArray:t}=this._core["utils"];if(t(e)){let o=this._core["OuterConstant"],i=!1;e.forEach(e=>{var{Type:e,To_Account:t,GroupId:s}=e;let n;1===e?n=p.getLocalConversation(""+o.CONV_C2C+t):2===e&&(n=p.getLocalConversation(""+o.CONV_GROUP+s)),n&&(console.log(`${this._name}.handleConversationPinned conversationID:${n.conversationID} localPinned:${n.isPinned} remotePinned:`+a),a&&!n.isPinned&&(n.isPinned=!0,i=!0),!a)&&n.isPinned&&(n.isPinned=!1,i=!0)}),i&&p.emitConversationListUpdate(!0)}}pinConversation(e){return c(this,void 0,void 0,function*(){var{OuterConstant:s,common:n,ssoLog:o,helper:{ChatError:i}}=this._core,{conversationID:a,isPinned:r}=e,l={code:0,data:{conversationID:a}},d=p.getLocalConversation(a);if(d&&d.isPinned===r)return l;if(t(a))return d&&(d.isPinned=r),p.emitConversationListUpdate(!0),l;o=o.createSSOLogData({method:"pinConversation"});o.setLogInfo({message:`conversationID:${a} isPinned:`+r});try{let e=null,t=(u(a)?e={Type:1,To_Account:a.replace(s.CONV_C2C,"")}:_(a)&&(e={Type:2,GroupId:a.replace(s.CONV_GROUP,"")}),yield function(n,o){return c(this,void 0,void 0,function*(){var{fromAccount:e,operationType:t,itemList:s}=n;return o.common.buildAndSendPacket({servcmd:"recentcontact.top",data:{From_Account:e,OperationType:t,RecentContactItem:s}})})}({fromAccount:n.getCurrentUserID(),operationType:!0===r?1:2,itemList:[e]},this._core));if(o.end(),console.log(this._name+`.pinConversation ok, conversationID:${a} isPinned:${r}.`),t){if(d)d.isPinned!==r&&(d.isPinned=r);else{let e=new C({conversationID:a,type:u(a)?s.CONV_C2C:s.CONV_GROUP,isPinned:r});p.setLocalConversation(a,e)}p.emitConversationListUpdate(!0)}return l}catch(e){let{errorCode:t,errorInfo:s}=e,n=new i({functionName:"pinConversation",code:t,message:s});throw o.setError(n).end(),console.error(this._name+".pinConversation fail:",n),n}})}},I=new class{constructor(){this._name="DeleteConversation"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){var{isArray:t}=this._core["utils"];if(t(e)){let n=this._core["OuterConstant"],o=[];e.forEach(e=>{var{Type:e,Peer_Account:t,GroupId:s}=e;1===e&&o.push(""+n.CONV_C2C+t),2===e&&o.push(""+n.CONV_GROUP+s)}),console.log(this._name+".handleConversationDeleted conversationIDList:"+o),this._deleteLocalConversationList(o)}}deleteConversation(t){return c(this,void 0,void 0,function*(){var e=this._core["utils"]["isString"];e(t)?(console.log(this._name+".deleteConversation conversationID:"+t),yield this._deleteConversation({conversationIDList:[t],flag:l.ONLY_CONVERSATIONID})):(100<(e=Object.assign({},t)).conversationIDList.length&&(e.conversationIDList=e.conversationIDList.slice(0,100)),yield this._deleteConversation(e))})}_deleteConversation(r){return c(this,void 0,void 0,function*(){let{conversationIDList:s,clearHistoryMessage:n=!0,flag:o=0}=r,{ssoLog:e,helper:{ChatError:i}}=this._core,t=`conversationIDList:${s} clearHistoryMessage:`+n,a=e.createSSOLogData({method:"deleteConversation"});a.setLogInfo({message:t}),console.log(this._name+"._deleteConversation "+t);try{let e=yield Promise.all([this._deleteConversationFromLocal(s),this._deleteConversationFromServer(s,n)]),t=[...e[0],...e[1]];if(0===t.length)throw new this._core.helper.ChatError({code:v.CONV_NOT_FOUND});return a.end(),console.log(this._name+"._deleteConversation ok."),{code:0,data:o===l.ONLY_CONVERSATIONID?{conversationID:t[0]}:{conversationIDList:t}}}catch(e){let{errorCode:t,errorInfo:s}=e,n=new i({functionName:"deleteConversation",code:t,message:s});throw a.setError(n).end(),console.error(this._name+"._deleteConversation fail:",n),n}})}_deleteConversationFromLocal(e){let s=this._core["OuterConstant"];return e.filter(e=>{var t;return!!p.hasLocalConversation(e)&&((t=null==(t=p.getLocalConversation(e))?void 0:t.type)===s.CONV_GROUP&&!this._hasLocalGroup(e)||t===s.CONV_SYSTEM)&&(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(t,i){return c(this,void 0,void 0,function*(){let{OuterConstant:n,common:e}=this._core,o={fromAccount:e.getCurrentUserID(),conversationList:[],clearHistoryMessage:i?1:0};if(t.forEach(e=>{var t,s;p.hasLocalConversation(e)&&(t=(null==(t=p.getLocalConversation(e))?void 0:t.type)||"",s=e.replace(t,""),t===n.CONV_C2C?o.conversationList.push({To_Account:s,Type:1}):t===n.CONV_GROUP&&this._hasLocalGroup(e)&&o.conversationList.push({ToGroupid:s,Type:2}))}),0!==o.conversationList.length){var s=yield function(n,o){return c(this,void 0,void 0,function*(){var{fromAccount:e,conversationList:t,clearHistoryMessage:s}=n;return o.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:{From_Account:e,ContactItem:t,ClearRamble:s}})})}(o,this._core);if(s){let{ResultItem:e=[]}=s,t=[];return 0<e.length&&e.forEach(e=>{0===e.ResultCode&&(e=1===e.type?""+n.CONV_C2C+e.To_Account:""+n.CONV_GROUP+e.ToGroupid,t.push(e))}),this._deleteLocalConversationList(t),t}}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{p.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(this._name+"._deleteLocalConversationList isUpdate:"+t),t&&p.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){var s=p.hasLocalConversation(e);console.log(this._name+`._deleteLocalConversation conversationID:${e} has:`+s),s&&(p.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t)&&p.emitConversationListUpdate()}_hasLocalGroup(e){var{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,e=e.replace(t,"");return!!s.getGroup(e)}_deleteConversationLocalMessage(e){console.log(this._name+"._deleteConversationLocalMessage conversationID:"+e),this._core.message.messageDataHandler.deleteConversationMessageList(e)}},L=new class{constructor(){this._name="SetConversationDraft"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(s){return c(this,void 0,void 0,function*(){var{conversationID:e,draftText:t}=s;if(console.log(this._name+` conversationID:${e} draftText:`+t),p.hasLocalConversation(e))return null!=(e=p.getLocalConversation(e))&&e.setDraftText(t),p.emitConversationListUpdate(),{code:0,data:{conversation:e}};throw new this._core.helper.ChatError({code:v.CONV_NOT_FOUND})})}},O=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(r,l){return c(this,void 0,void 0,function*(){30<r.length&&(console.warn(`${this._name}.set userIDList length:${r.length} exceeds limit 30`),r.splice(30));let e=function(){var{MSG_REMIND_ACPT_AND_NOTE:e,MSG_REMIND_DISCARD:t,MSG_REMIND_ACPT_NOT_NOTE:s}=d.core.OuterConstant;return{[e]:0,[t]:1,[s]:2}}()[l],t=yield function(s,n){return c(this,void 0,void 0,function*(){var{userIDList:e,receiveMessageOption:t}=s;return n.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:{Peer_Account:e,Mute_Notifications:t}})})}({userIDList:r,receiveMessageOption:e},this._core),{ErrorList:s=[]}=t||{},n=[],o=(s.forEach(e=>{var{Peer_Account:e,ErrorCode:t}=e,t=(n.push({userID:e,code:t}),r.indexOf(e));-1<t&&r.splice(t,1)}),[]),i=[],a=this._core["OuterConstant"];return r.forEach(e=>{i.push(""+a.CONV_C2C+e),o.push({userID:e})}),p.patchMessageRemindType(i,l),{code:0,data:{successUserIDList:o,failureUserIDList:n}}})}},T=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(n,o){return c(this,void 0,void 0,function*(){var{common:{getCurrentUserID:e,isTopic:t},OuterConstant:s}=this._core;if(yield function(n,o){return c(this,void 0,void 0,function*(){var{groupID:e,userID:t,receiveMessageOption:s}=n;return o.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:{GroupId:e,Member_Account:t,MsgFlag:s}})})}({groupID:n,userID:e(),receiveMessageOption:o},this._core),!t(n)){let e=""+s.CONV_GROUP+n;p.patchMessageRemindType([e],o)}return{code:0,data:{groupID:n,messageRemindType:o}}})}},y=new class{constructor(){this._name="SetMessageRemindType"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){let{helper:{isEmpty:t},OuterConstant:i}=this._core;e.forEach(e=>{var o=e["MuteNotificationsSync"];if(!t(o)){let{To_Account:e,MuteNotifications:t}=o,s=e.map(e=>""+i.CONV_C2C+e),n=a(t);console.log(this._name+`.handleC2CMessageRemindTypeSync conversationIDList:${s} messageRemindType:`+n),p.patchMessageRemindType(s,n)}})}setMessageRemindType(a){return c(this,void 0,void 0,function*(){let s="setMessageRemindType",{groupID:e,userIDList:t,messageRemindType:n}=a,{helper:o,utils:{isUndefined:i}}=this._core;try{if(!i(e))return console.log(`${this._name}.${s} groupID:${e} messageRemindType:`+n),yield T.set(e,n);if(i(t))throw new o.ChatError({functionName:s,message:"userIDList or groupID is required"});return console.log(this._name+`.${s} userIDList:${t} messageRemindType:`+n),yield O.set(t,n)}catch(e){let t=new o.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(this._name+`.${s} fail:`,t),t}})}},o=new class{init(e){console.log("ConversationAction.init"),this._core=e,g.init(e),M.init(e),R.init(e),E.init(e),S.init(e),I.init(e),L.init(e),y.init(e);var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:a}=e["InnerEventSubType"];e.subscribeInnerEvent(t,n,this._onConversationModified,this),e.subscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.subscribeInnerEvent(t,a,this._onC2CMessageRemindTypeSync,this),e.subscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.subscribeInnerEvent(s,this._dispose,this)}_onConversationModified(e){let{ConvModifyPushType:s}=this._core["constants"],{RecentContactMod:t=[]}=e;t.forEach(t=>{var e=t["PushType"];if(e===s.CONV_DELETED){let e=t.RecentContactDeleteItem["RecentContactList"];I.handleConversationDeleted(e)}if(e===s.CONV_PINED){let e=t.RecentContactTopItem["RecentContactList"];S.handleConversationPinned(e,!0)}if(e===s.CONV_UNPINED){let e=t.RecentContactTopItem["RecentContactList"];S.handleConversationPinned(e,!1)}})}_onC2CMessageReadSync(e){var{C2cNotifyMsgArray:e=[]}=e;E.handleC2CMessageReadSync(e)}_onC2CMessageRemindTypeSync(e){var{C2cNotifyMsgArray:e=[]}=e;y.handleC2CMessageRemindTypeSync(e)}_onGroupMessageReadSync(e){var{GroupTips:e=[]}=e;E.handleGroupMessageReadSync(e)}_dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:a}=e["InnerEventSubType"];e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,a,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}},i=new class{init(e){e=(this._core=e).helper;e.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(a){return c(this,void 0,void 0,function*(){try{let{MSG_REMIND_ACPT_NOT_NOTE:e}=this._core["OuterConstant"],{messageRemindType:t=e,isRepeated:s=!0}=a,{startTime:n=0,endTime:o=0}=this._calcStartAndEndTime(a),i=yield function(i){return c(this,void 0,void 0,function*(){var e=d.core["common"],{startTime:t,endTime:s,isRepeated:n,messageRemindType:o}=i;return e.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:{StartTime:t,EndTime:s,IsRepeated:n,Level:o}})})}({messageRemindType:this._getType(t),startTime:n,endTime:o,isRepeated:s?r.ON:r.OFF});return{code:0,data:{errorCode:i.ErrorCode,errorInfo:i.ErrorInfo}}}catch(e){n("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){var{startHour:e=0,startMinute:t=0,startSecond:s=0,duration:n=0,isRepeated:o=!0}=e,i=new Date,i=new Date(i.getFullYear(),i.getMonth(),i.getDate(),e,t,s),e=Math.round(i.getTime()/1e3);let a=o&&86400<=n?e+86400:e+n;return{startTime:e,endTime:a}}_getType(e){var t=this._core["OuterConstant"];return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}},N=new class{init(e){var{helper:e,notificationCenter:t,InnerEvent:s}=this._core=e;e.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),t.subscribeInnerEvent(s.MESSAGE_PUSH,t.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){var e=this._handleResult(e),{notificationCenter:t,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:s}}=this._core;t.emitOuterEvent(s,{name:s,data:e})}getAllReceiveMessageOpt(){return c(this,void 0,void 0,function*(){try{var e=yield function(){return c(this,void 0,void 0,function*(){var e=d.core["common"],t={To_Account:e.getCurrentUserID()};return e.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:t})})}();return{code:0,data:this._handleResult(e)}}catch(e){n("getAllReceiveMessageOpt",e)}})}_handleResult(e){var t=this._core["OuterConstant"],{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=t,{Level:e,StartTime:o,EndTime:i,IsRepeated:a}=e;return{messageRemindType:{0:t,1:s,2:n}[e]||t,startTime:o,endTime:i,isRepeated:a===r.ON}}},D=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,O.init(e),T.init(e),m.init(e),f.init(e),i.init(e),N.init(e)}};let A=e=>!u(e)&&!_(e)&&!t(e),G={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!A(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!A(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!A(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:e=>{var{utils:{isArray:t,isObject:s,isString:n}}=d["core"];if(!n(e)&&!s(e))return"options is String or Object.";if(n(e)&&A(e))return"conversationID is invalid.";if(s(e)){if(!t(e.conversationIDList))return"conversationIDList is not Array.";if(0===e.conversationIDList.length)return"conversationIDList is empty.";if(e.conversationIDList.some(e=>{if(A(e))return!0}))return"conversationIDList includes invalid conversationID.";if(e.clearHistoryMessage&&"boolean"!=typeof e.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!u(e)&&!_(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};return new class{install(e){d.init(e),o.init(e),D.init(e),p.init(e),e.helper.registerValidateConfig({auth:U,params:G})}}});
@@ -1 +1 @@
1
- function o(o,t,e,r){return new(e||(e=Promise))((function(n,l){function i(o){try{u(r.next(o))}catch(o){l(o)}}function s(o){try{u(r.throw(o))}catch(o){l(o)}}function u(o){var t;o.done?n(o.value):(t=o.value,t instanceof e?t:new e((function(o){o(t)}))).then(i,s)}u((r=r.apply(o,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(e,r){return o(this,void 0,void 0,(function*(){var o;const{common:n,store:l}=t.core,i={FollowType:e,From_Account:null===(o=l.get("login"))||void 0===o?void 0:o.userId,StartCursor:r,WantNum:f()};return function(o){const{FollowItem:t=[],NextCursor:e,ActionStatus:r,ErrorCode:n,ErrorInfo:l,ErrorDisplay:i}=o;return{resultList:t.map((o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence}))),nextPageToken:e,actionStatus:r,errorCode:n,errorInfo:l,errorDisplay:i}}(yield n.buildAndSendPacket({servcmd:"follow.follow_get",data:i}))}))}function s(t){return o(this,void 0,void 0,(function*(){return i(l.FOLLOWERS,t)}))}function u(t){return o(this,void 0,void 0,(function*(){return i(l.MUTUAL,t)}))}function c(t){return o(this,void 0,void 0,(function*(){return i(l.FOLLOWING,t)}))}function a(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,FollowItem:e.map((o=>({To_Account:o})))};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_add",data:l}))}))}function d(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_delete",data:l}))}))}function f(){const o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0!==e){const o=Number(e);return o>1e3?1e3:o}return 500}const w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{install(o){this._core=o;const{helper:e,notificationCenter:r,InnerEvent:n}=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(n.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})}))}getMyFollowersList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})}))}getMutualFollowersList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})}))}_getFollowList(t){return o(this,void 0,void 0,(function*(){const{functionName:o,protocolFunction:r,nextCursor:n=""}=t;console.log(`${e} ${o} nextCursor:`,n);try{this._checkBusinessCapabilityBits(o);const t=yield r(n),{resultList:l=[],nextPageToken:i=""}=t,s=this._parseFollowItems(l);return console.log(`${e}.${o} nextCursor: ${n} from remote.`),{code:0,data:{resultList:s,nextCursor:i}}}catch(t){console.error(`${e}.${o} fail:`,t),this._handleError(o,t)}}))}followUser(t){return o(this,void 0,void 0,(function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:t,protocolFunction:a})}))}unfollowUser(t){return o(this,void 0,void 0,(function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:t,protocolFunction:d})}))}_handleUserFollowRelation(t){return o(this,void 0,void 0,(function*(){const{functionName:o,userIDList:e,protocolFunction:r}=t;try{const t=this._sliceUserIDList(e,20);this._checkBusinessCapabilityBits(o);const{resultList:n=[]}=yield r(t);return{code:0,data:n}}catch(t){this._handleError(o,t)}}))}getUserFollowInfo(r){return o(this,void 0,void 0,(function*(){const n="getUserFollowInfo";console.log(`${e} ${n} userIDList:`,r);try{this._checkBusinessCapabilityBits(n);const l=r||[this._core.common.getCurrentUserID()];console.log(`${e} ${n} userIDList: ${l}`);const i=yield function(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{FollowInfo:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{followInfoList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_get_info",data:l}))}))}(r),{followInfoList:s=[]}=i,u=[];return s.forEach((o=>{const{followerCount:t,followingCount:e,mutualFollowingCount:r}=o;u.push({followerCount:t,followingCount:e,mutualFollowingCount:r})})),{code:0,data:u}}catch(o){this._handleError(n,o)}}))}checkFollowType(r){return o(this,void 0,void 0,(function*(){const n="checkFollowType";console.log(`${e} ${n} userIDList:`,r);try{this._checkBusinessCapabilityBits(n),r.length>100&&(r=r.slice(0,100),console.warn(`${e} ${n} the length of userIDList cannot exceed 100`));const l=yield function(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_check",data:l}))}))}(r),{resultList:i=[]}=l;return{code:0,data:i.map((({userID:o,followType:t})=>({userID:o,followType:t})))}}catch(o){this._handleError(n,o)}}))}onFollowListUpdated(o){console.log(`${e} onFollowListUpdated`,o);const{FollowChangeList:t=[]}=o;t.forEach((o=>this._processFollowChangeItem(o)))}_processFollowChangeItem(o){const{From_Account:t,FollowDiffList:e=[]}=o,r=function(o,t){var e={};for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(o);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(o,r[n])&&(e[r[n]]=o[r[n]])}return e}(o,["From_Account","FollowDiffList"]),n={userID:t,avatar:r.FaceUrl,nick:r.NickName};e.forEach((o=>{const t=this._updateFollowRelation(o,n);this._notifyFollowChanges(t)}))}_updateFollowRelation(o,t){const{IsAdd:e,FollowType:r=0}=o,n=this._initFollowInfo(),l=n[r];return l.isAdd=1===e,l.userInfoList.push(l.isAdd?t:t.userID),n}_notifyFollowChanges(o){const{OuterEvent:t}=this._core,e={[l.FOLLOWERS]:t.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:t.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:t.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach((([o,t])=>{const r=Number(o);t.userInfoList.length>0&&e[r]&&this._emitFollowUpdated(e[r],t)}))}_initFollowInfo(){const o={};return Object.values(l).forEach((t=>{t!==l.NONE&&(o[t]={userInfoList:[],isAdd:!1})})),o}_emitFollowUpdated(o,t){console.log(`${e} _emitFollowUpdated`);const{notificationCenter:r}=this._core;r.emitOuterEvent(o,{name:o,data:t})}_sliceUserIDList(o,t){return o.slice(0,t)}_checkBusinessCapabilityBits(o){const{helper:t,store:e}=this._core;if(!(e.get("commercialConfig")||new Map).get(r))throw new t.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,t){const r=new this._core.helper.ChatError({functionName:o,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo});throw console.error(`${e} ${o} fail:`,r),r}_parseFollowItems(o){return o.map((o=>{var t;const{userID:e,followTime:r,profileItem:n=[]}=o,l=[];n.forEach((o=>{l.push({tag:o.Tag,value:o.Value})}));const i=null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(e,l);return{userID:e,followTime:r,nick:null==i?void 0:i.nick,avatar:null==i?void 0:i.avatar,allowType:null==i?void 0:i.allowType,adminForbidType:null==i?void 0:i.adminForbidType}}))}};export{p as default};
1
+ function o(o,i,s,u){return new(s=s||Promise)(function(t,e){function r(o){try{n(u.next(o))}catch(o){e(o)}}function l(o){try{n(u.throw(o))}catch(o){e(o)}}function n(o){var e;o.done?t(o.value):((e=o.value)instanceof s?e:new s(function(o){o(e)})).then(r,l)}n((u=u.apply(o,i||[])).next())})}let t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(s,u){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={FollowType:s,From_Account:null==(e=e.get("login"))?void 0:e.userId,StartCursor:u,WantNum:f()},{FollowItem:o=[],NextCursor:e,ActionStatus:r,ErrorCode:l,ErrorInfo:n,ErrorDisplay:i}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:r,errorCode:l,errorInfo:n,errorDisplay:i}})}function s(e){return o(this,void 0,void 0,function*(){return i(l.FOLLOWERS,e)})}function u(e){return o(this,void 0,void 0,function*(){return i(l.MUTUAL,e)})}function c(e){return o(this,void 0,void 0,function*(){return i(l.FOLLOWING,e)})}function a(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,FollowItem:i.map(o=>({To_Account:o}))},{ResultItem:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_add",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}function d(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:i},{ResultItem:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_delete",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}function f(){let o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0===e)return 500;{let o=Number(e);return 1e3<o?1e3:o}}let w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{install(o){var{helper:e,notificationCenter:r,InnerEvent:l}=this._core=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(l.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})})}getMyFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})})}getMutualFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})})}_getFollowList(t){return o(this,void 0,void 0,function*(){var{functionName:n,protocolFunction:i,nextCursor:s=""}=t;console.log(e+` ${n} nextCursor:`,s);try{this._checkBusinessCapabilityBits(n);let o=yield i(s),{resultList:t=[],nextPageToken:r=""}=o,l=this._parseFollowItems(t);return console.log(e+`.${n} nextCursor: ${s} from remote.`),{code:0,data:{resultList:l,nextCursor:r}}}catch(o){console.error(e+`.${n} fail:`,o),this._handleError(n,o)}})}followUser(e){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:e,protocolFunction:a})})}unfollowUser(e){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:e,protocolFunction:d})})}_handleUserFollowRelation(n){return o(this,void 0,void 0,function*(){var{functionName:e,userIDList:t,protocolFunction:r}=n;try{let o=this._sliceUserIDList(t,20);this._checkBusinessCapabilityBits(e);var{resultList:l=[]}=yield r(o);return{code:0,data:l}}catch(o){this._handleError(e,o)}})}getUserFollowInfo(u){return o(this,void 0,void 0,function*(){var i="getUserFollowInfo";console.log(e+` ${i} userIDList:`,u);try{this._checkBusinessCapabilityBits(i);var s=u||[this._core.common.getCurrentUserID()];console.log(e+` ${i} userIDList: `+s);let r=yield function(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:i},{FollowInfo:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get_info",data:e});return{followInfoList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}(u),{followInfoList:l=[]}=r,n=[];return l.forEach(o=>{var{followerCount:o,followingCount:e,mutualFollowingCount:t}=o;n.push({followerCount:o,followingCount:e,mutualFollowingCount:t})}),{code:0,data:n}}catch(o){this._handleError(i,o)}})}checkFollowType(i){return o(this,void 0,void 0,function*(){var r="checkFollowType";console.log(e+` ${r} userIDList:`,i);try{this._checkBusinessCapabilityBits(r),100<i.length&&(i=i.slice(0,100),console.warn(e+` ${r} the length of userIDList cannot exceed 100`));var l=yield function(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:i},{ResultItem:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_check",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}(i),{resultList:n=[]}=l;return{code:0,data:n.map(({userID:o,followType:e})=>({userID:o,followType:e}))}}catch(o){this._handleError(r,o)}})}onFollowListUpdated(o){console.log(e+" onFollowListUpdated",o);var{FollowChangeList:o=[]}=o;o.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){let{From_Account:e,FollowDiffList:t=[]}=o,r=function(o,e){var t={};for(l in o)Object.prototype.hasOwnProperty.call(o,l)&&e.indexOf(l)<0&&(t[l]=o[l]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,l=Object.getOwnPropertySymbols(o);r<l.length;r++)e.indexOf(l[r])<0&&Object.prototype.propertyIsEnumerable.call(o,l[r])&&(t[l[r]]=o[l[r]]);return t}(o,["From_Account","FollowDiffList"]),l={userID:e,avatar:r.FaceUrl,nick:r.NickName};t.forEach(o=>{o=this._updateFollowRelation(o,l);this._notifyFollowChanges(o)})}_updateFollowRelation(o,e){var{IsAdd:o,FollowType:t=0}=o,r=this._initFollowInfo(),t=r[t];return t.isAdd=1===o,t.userInfoList.push(t.isAdd?e:e.userID),r}_notifyFollowChanges(o){let e=this._core["OuterEvent"],t={[l.FOLLOWERS]:e.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:e.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:e.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,e])=>{o=Number(o);0<e.userInfoList.length&&t[o]&&this._emitFollowUpdated(t[o],e)})}_initFollowInfo(){let e={};return Object.values(l).forEach(o=>{o!==l.NONE&&(e[o]={userInfoList:[],isAdd:!1})}),e}_emitFollowUpdated(o,t){console.log(e+" _emitFollowUpdated");var r=this._core["notificationCenter"];r.emitOuterEvent(o,{name:o,data:t})}_sliceUserIDList(o,e){return o.slice(0,e)}_checkBusinessCapabilityBits(o){var{helper:e,store:t}=this._core;if(!(t.get("commercialConfig")||new Map).get(r))throw new e.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,t){t=new this._core.helper.ChatError({functionName:o,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo});throw console.error(e+` ${o} fail:`,t),t}_parseFollowItems(o){return o.map(o=>{let e,{userID:t,followTime:r,profileItem:l=[]}=o,n=[];l.forEach(o=>{n.push({tag:o.Tag,value:o.Value})});o=null==(e=this._core.user.userProfile)?void 0:e.createProfile(t,n);return{userID:t,followTime:r,nick:null==o?void 0:o.nick,avatar:null==o?void 0:o.avatar,allowType:null==o?void 0:o.allowType,adminForbidType:null==o?void 0:o.adminForbidType}})}};export{p as default};