UNPKG

@tencentcloud/lite-chat

Version:

Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut

2 lines (1 loc) 48.9 kB
const e=new class{init(e){this.core=e}};function t(e,t,s,n){return new(s||(s=Promise))((function(o,i){function r(e){try{c(n.next(e))}catch(e){i(e)}}function a(e){try{c(n.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,a)}c((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const s=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,3)===s.CONV_C2C},n=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;return n(t)&&t.slice(0,5)===s.CONV_GROUP},o=t=>{const{core:{OuterConstant:s,utils:{isString:n}}}=e;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){const{OuterConstant:s}=e.core;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){const{OuterConstant:s}=e.core;let n;return t.startsWith(s.CONV_C2C)&&(n=t.replace(s.CONV_C2C,"")),"@TLS#ERROR"===n||"@TLS#NOT_FOUND"===n}function c(t,s){const{helper:n}=e.core,o=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:`,o),o}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(){const{core:{OuterConstant:t,utils:{isUndefined:s}}}=e;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){const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;n(o)||(this.subType!==s.GRP_AVCHATROOM?i&&this.type===s.CONV_GROUP||r&&this.type===s.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:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;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={}));var _;!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"}(_||(_={}));const h=0,C=1;var p=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:r,MESSAGE_PUSH:a,NEW_MESSAGE:c,MESSAGE_DELETED:l,MESSAGE_REVOKED:d,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:C}}=e;this._conversationStore=n,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:p}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,p,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(l,this._handleMessageDeleted,this),s.subscribeInnerEvent(d,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(C,this._dispose,this),console.log(`${this._name}.init`)}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;s.forEach((e=>{const{conversationID:t,unreadCount:s}=e,n=this.getLocalConversation(t);n&&n.unreadCount!==s&&(n.updateUnreadCount({nextUnreadCount:s,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(e){var t;for(let s=0;s<e.length;s++)if(12===e[s].Event){if(null===(t=e[s].GroupTips[0].MsgBody)||void 0===t?void 0:t.TopicId)continue;this._handleNewGroupAtTips(e[s])}}_handleGroupListSyncFinished(e){var t;const{constants:{WORKFLOW_STEP:s}}=this._core,n=e.result[s.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:o}}=this._core;let i=!1;for(let e=0;e<n.length;e++){const s=n[e],r=`${o}${s.groupID}`;if(!this.hasLocalConversation(r))continue;const a=this.getLocalConversation(r);a.groupProfile=JSON.parse(JSON.stringify(s)),a.lastMessage.lastSequence<s.nextMessageSeq&&(a.lastMessage.lastSequence=s.nextMessageSeq-1),a.subType||(a.subType=s.type),(null===(t=s._groupAtInfoList)||void 0===t?void 0:t.length)>0&&this._handleNewGroupAtTips({GroupTips:s._groupAtInfoList}),i=!0}i&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};if(0===t.length)return;const{common:{isTopic:i}}=this._core;if(i(t[0].conversationID))return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:s,isUnreadC2CMessage:n,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: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){const{From_Account:t,GroupId:s,MsgSeq:n,GroupAtType:o}=e;return{from:t,groupID:s,sequence:n,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,s=e.getCurrentUserID();let n=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==s){const s=this.getLocalConversation(`${t.CONV_GROUP}${o}`);s&&(s.updateGroupAtInfoList(e),n=!0)}})),n&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,s;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.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===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.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:s=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this.getLocalConversation(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:s}=e,n=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(n))return;const{lastMessage:r}=n;if(r){const e=(null==s?void 0:s[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(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:s}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(s),console.log(`${this._name}.updateLocalConversationList newConversationList: ${s.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:s,isFromGetConversations:n,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,c=[],d=null==s?void 0:s.length;for(let e=0;e<d;e++){const d=new l(s[e]),{conversationID:u,type:_}=d;if(!a(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(n){this.setLocalConversation(u,d),_===t.CONV_C2C?d.unreadCount=(null==a?void 0:a.unreadCount)||0:_===t.CONV_GROUP&&(d.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:d,lastMessage:s[e].lastMessage,isFromGetConversations:n,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:s[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:d.unreadCount,isFromGetConversations:n,isUnreadC2CMessage:i}))}else c.push(d),this.setLocalConversation(u,d)}return{newConversationList:c}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:s,lastMessage:n,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:d}}=this._core;c(i)&&n&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=n.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);d(r,s,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:s,lastMessage:n,isInstantMessage:o}=e,i=this.getLocalConversation(s);if(i&&n){const{payload:e,nameCard:s,nick:r,cloudCustomData:a=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=s,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?n.push(t):s.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=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(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],s=[],{OuterConstant:{CONV_GROUP:n,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===n){const e=i.replace(n,"");s.push(e)}})),t.length>0&&this._updateC2CConversation(t),s.length>0&&this._updateGroupConversation(s)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:s},appStore:{userStore:n},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(`${s}${o}`);if(r){const s=(null===(t=n.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=s,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core;let n=!1;e.forEach((e=>{const o=s.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,n=!0)})),n&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:s}=this._core,n=t.type===s.CONV_TOPIC,o=t.type===s.CONV_GROUP&&t.subType===s.GRP_ROOM,i=t.type===s.CONV_GROUP&&t.subType===s.GRP_LIVE;return!(n||o||i)}updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this.getLocalConversation(e),r=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageDataHandler)||void 0===n?void 0:n.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,s=this.getLocalConversationList();this._emitEvent({name:t,data:s}),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 s=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(s+=t.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(const[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach((e=>{const n=this.getLocalConversation(e);(null==n?void 0:n.messageRemindType)!==t&&(n.messageRemindType=t,s=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${s}`),s&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:s,lastReadTime:n=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(s);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],s=n&&t.time>n,r=o&&t.sequence>o;if(!s&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const 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(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a,SYNC_CONVERSATION_LIST:c}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:l}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,l,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(c,this._handleConversationSynced,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};var v=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:this._core.conversation.syncConversationHandler.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:s,isPlainObject:n}}=this._core;if(t(e))return p.getLocalConversationList();if(s(e)){if(0===e.length)return[];return p.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;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){const{OuterConstant:s}=this._core;return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:s}}=this._core;return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:s}}=this._core;return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}};var g=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:s}=this._core,n=yield function(e,s){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:n}=e,o={To_Account:t,Peer_Account:n};return s.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:o})}))}({toAccount:s.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=n||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:s}=e,n=`${this._core.OuterConstant.CONV_C2C}${t}`,o=r(s);p.patchMessageRemindType([n],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var m=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 s=yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:n}=e,o={GroupIdList:t,ResponseFilter:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:o})}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:n=[]}=s||{};n.forEach((e=>{var t;const{GroupId:s,MemberList:n}=e,o=(null===(t=n[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${s}`;p.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var f=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:n,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let d=p.getLocalConversation(e);if(o(e))return c.data.conversation=d,c;let u=!1;const _=s(e)?t:n;if(a(d)&&(u=!0,d=new l({conversationID:e,type:_})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=d,null==d?void 0:d.getProfileCompleted())return c;if(_===t){const s=e.replace(t,"");yield this._handleC2CConversation(d,s),u&&(yield g.get([s]))}if(_===n){const t=e.replace(n,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(d,t),u&&d.groupProfile.type!==i&&(yield m.get([t]))}return c}))}_handleC2CConversation(e,s){return t(this,void 0,void 0,(function*(){var t,n;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,d=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[s]});if(0===(null==d?void 0:d.data.length))throw new i.ChatError({code:_.USER_OR_GRP_NOT_FOUND});e.userProfile=null==d?void 0:d.data[0];const u=null===(n=c.getFriend(s))||void 0===n?void 0:n.remark;r(u)||e.remark===u||(e.remark=u),e.setProfileCompleted();const h=p.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):p.appendToPinnedConversation(e)}))}_handleGroupConversation(e,s){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:n}}=this._core,{conversationID:o}=e,i=yield t({groupID:s});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=p.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):p.appendToPinnedConversation(e)}))}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return p.getTotalUnreadMessageCount()}};var E=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){this._core=e;const{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=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){const{helper:{isEmpty:t},OuterConstant:s}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:n}=e;if(!t(n)){const{UinPairReadArray:e=[]}=n;e.forEach((e=>{const{From_Account:t,LastReadTime:n}=e,o=`${s.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${n}`),p.markMessageAsRead({conversationID:o,lastReadTime:n}),p.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:s}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:n}=e.MsgBody;s(n)||n.forEach((e=>{const{GroupId:s,LastReadMsgSeq:n}=e,o=`${t.CONV_GROUP}${s}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${n}`),p.markMessageAsRead({conversationID:o,lastReadSequence:n}),p.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,s;const{OuterConstant:n}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=p.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(r.groupAtInfoList));if(r.type===n.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{ssoLog:c,helper:{ChatError:l}}=this._core,d=c.createSSOLogData({method:"setMessageRead"});d.setLogInfo({message:`conversationID:${o}`});try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),d.setLogInfo({moreMessage:`lastMessageTime:${e}`}).end()}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),d.setLogInfo({moreMessage:`lastMessageSequence:${e}`}).end()}}catch(e){const{errorCode:t,errorInfo:s}=e,n=new l({functionName:"setMessageRead",code:t,message:s});throw d.setError(n).end(),n}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),p.emitConversationListUpdate(),i}))}setAllMessageRead(){return t(this,arguments,void 0,(function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},ssoLog:o}=this._core,i=o.createSSOLogData({method:"setAllMessageRead"});s.scope||(s.scope=n);const{scope:r}=s,a=this._generateSetAllMessageReadRequestData(r);if(a.allC2CMessageReadStatus===h&&0===a.groupMessageReadInfoList.length)return{code:0};try{const s=yield function(s){return t(this,void 0,void 0,(function*(){const{allC2CMessageReadStatus:t,groupMessageReadInfoList:n}=s,o={C2CReadAllMsg:t,GroupReadInfo:n};return e.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:o})}))}(a);if(s){const{GroupReadInfoArray:e,C2CReadAllMsg:t}=s,n=this._parseGroupReadInfo(e);this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})>0&&p.emitConversationListUpdate(),i.setLogInfo({message:`scope:${r} failureGroups:${JSON.stringify(n)}`}).end()}return{code:0}}catch(e){const{errorCode:t}=e,s=new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t});throw i.setError(s).end(),s}}))}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&p.emitConversationListUpdate()}_updateAllConversationReadStatus(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s},appStore:n}=this._core,o=n.conversationStore.getConversationMap(),{allC2CMessageReadStatus:i}=e;let r=0;for(const[e,n]of o)if(n.unreadCount>=1){if(i===C&&n.type===t){const t=this._getLocalMessageMaxTime(n);p.markMessageAsRead({conversationID:e,lastReadTime:t})}else if(n.type===s){const t=e.replace(s,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){const s=this._serverGroupConversationLastReadSeqMap.get(t);p.markMessageAsRead({conversationID:e,lastReadSequence:s})}}p.updateUnreadCount(e,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(e){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_C2C_MSG:n},appStore:o}=this._core,i={allC2CMessageReadStatus:h,groupMessageReadInfoList:[]},r=o.conversationStore.getConversationMap();for(const[,o]of r){const{type:r,unreadCount:a}=o;if(this._shouldSetAllMessageRead({scope:e,type:r,unreadCount:a}))if(r===t&&i.allC2CMessageReadStatus===h){if(i.allC2CMessageReadStatus=C,e===n)break}else if(r===s){const e=this._getLocalMessageMaxSequence(o),{groupID:t}=o.groupProfile;i.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return i}_parseGroupReadInfo(e){const{utils:{isUndefined:t}}=this._core,s=[];return null==e||e.forEach((e=>{const{GroupId:n,MsgSeq:o,RetCode:i,LastReadMsgSeq:r}=e;t(i)?this._serverGroupConversationLastReadSeqMap.set(n,r):(this._serverGroupConversationLastReadSeqMap.set(n,o),0!==i&&s.push(`${n}-${o}-${i}`))})),s}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const s=p.getLocalConversation(e);if(!s)return;const n=(null==s?void 0:s.groupAtInfoList)||[];if(0!==n.length)try{const{common:{getCurrentUserID:s,isCommunity:o},OuterConstant:{CONV_GROUP:i,CONV_AT_ALL:r}}=this._core;let a=[...n];if(o({groupID:e.replace(i,"")})&&(a=n.filter((e=>!e.atTypeArray.includes(r))),0===a.length))return void this._clearGroupAtInfoList(e,!1);const c=a.map((e=>({From_Account:e.from,To_Account:s(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,s){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e,n={DelMsgList:t};return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:n})}))}({messageListToDelete:c},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${n.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e,t=!0){const s=p.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&p.emitConversationListUpdate())}_getLocalMessageMaxTime(e){var t;const{conversationID:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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:s}=e,n=this._core.message.messageDataHandler.getLocalMessageList(s),o=Math.max(...n.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,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(e,s){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:n}=e,o={GroupId:t,MsgReadedSeq:n};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:o})}))}({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){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}}=this._core,{type:r,scope:a,unreadCount:c}=e;return!(c<=0)&&(!(r!==t||![n,o].includes(a))||!(r!==s||![n,i].includes(a)))}};var R=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:s}}=this._core;if(!s(e))return;const{OuterConstant:n}=this._core;let o=!1;e.forEach((e=>{const{Type:s,To_Account:i,GroupId:r}=e;let a;1===s?a=p.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=p.getLocalConversation(`${n.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&&p.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r,ssoLog:a,helper:{ChatError:c}}=this._core,{conversationID:d,isPinned:u}=e,_={code:0,data:{conversationID:d}},h=p.getLocalConversation(d);if(h&&h.isPinned===u)return _;if(o(d))return h&&(h.isPinned=u),p.emitConversationListUpdate(!0),_;const C=a.createSSOLogData({method:"pinConversation"});C.setLogInfo({message:`conversationID:${d} isPinned:${u}`});try{let e=null;s(d)?e={Type:1,To_Account:d.replace(i.CONV_C2C,"")}:n(d)&&(e={Type:2,GroupId:d.replace(i.CONV_GROUP,"")});const o=yield function(e,s){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:n,itemList:o}=e,i={From_Account:t,OperationType:n,RecentContactItem:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.top",data:i})}))}({fromAccount:r.getCurrentUserID(),operationType:!0===u?1:2,itemList:[e]},this._core);if(C.end(),console.log(`${this._name}.pinConversation ok, conversationID:${d} isPinned:${u}.`),o){if(h)h.isPinned!==u&&(h.isPinned=u);else{const e=new l({conversationID:d,type:s(d)?i.CONV_C2C:i.CONV_GROUP,isPinned:u});p.setLocalConversation(d,e)}p.emitConversationListUpdate(!0)}return _}catch(e){const{errorCode:t,errorInfo:s}=e,n=new c({functionName:"pinConversation",code:t,message:s});throw C.setError(n).end(),console.error(`${this._name}.pinConversation fail:`,n),n}}))}};var S=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:s}=this._core,n=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&n.push(`${s.CONV_C2C}${o}`),2===t&&n.push(`${s.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${n}`),this._deleteLocalConversationList(n)}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:u.ONLY_CONVERSATIONID}));const s=Object.assign({},e);s.conversationIDList.length>100&&(s.conversationIDList=s.conversationIDList.slice(0,100)),yield this._deleteConversation(s)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:s=!0,flag:n=0}=e,{ssoLog:o,helper:{ChatError:i}}=this._core,r=`conversationIDList:${t} clearHistoryMessage:${s}`,a=o.createSSOLogData({method:"deleteConversation"});a.setLogInfo({message:r}),console.log(`${this._name}._deleteConversation ${r}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,s)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});return a.end(),console.log(`${this._name}._deleteConversation ok.`),{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){const{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){const{OuterConstant:t}=this._core;return e.filter((e=>{var s;if(!p.hasLocalConversation(e))return!1;const n=null===(s=p.getLocalConversation(e))||void 0===s?void 0:s.type;return n!==t.CONV_GROUP||this._hasLocalGroup(e)?n===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,s){return t(this,void 0,void 0,(function*(){const{OuterConstant:n,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:s?1:0};if(e.forEach((e=>{var t;if(p.hasLocalConversation(e)){const s=(null===(t=p.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(s,"");s===n.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):s===n.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,s){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:n,clearHistoryMessage:o}=e,i={From_Account:t,ContactItem:n,ClearRamble:o};return s.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:i})}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const s=1===e.type?`${n.CONV_C2C}${e.To_Account}`:`${n.CONV_GROUP}${e.ToGroupid}`;t.push(s)}})),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){const 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){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,n=e.replace(t,"");return!!s.getGroup(n)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var I=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:s}=e;if(console.log(`${this._name} conversationID:${t} draftText:${s}`),!p.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=p.getLocalConversation(t);return null==n||n.setDraftText(s),p.emitConversationListUpdate(),{code:0,data:{conversation:n}}}))}};var L=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(s,n){return t(this,void 0,void 0,(function*(){s.length>30&&(console.warn(`${this._name}.set userIDList length:${s.length} exceeds limit 30`),s.splice(30));const o=function(){const{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}}()[n],i=yield function(e,s){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:n}=e,o={Peer_Account:t,Mute_Notifications:n};return s.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:o})}))}({userIDList:s,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:n}=e;a.push({userID:t,code:n});const o=s.indexOf(t);o>-1&&s.splice(o,1)}));const c=[],l=[],{OuterConstant:d}=this._core;return s.forEach((e=>{l.push(`${d.CONV_C2C}${e}`),c.push({userID:e})})),p.patchMessageRemindType(l,n),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var O=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,s){return t(this,void 0,void 0,(function*(){const{common:{getCurrentUserID:n,isTopic:o},OuterConstant:i}=this._core;if(yield function(e,s){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:n,receiveMessageOption:o}=e,i={GroupId:t,Member_Account:n,MsgFlag:o};return s.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:i})}))}({groupID:e,userID:n(),receiveMessageOption:s},this._core),!o(e)){const t=`${i.CONV_GROUP}${e}`;p.patchMessageRemindType([t],s)}return{code:0,data:{groupID:e,messageRemindType:s}}}))}};var T=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:s}=this._core;e.forEach((e=>{const{MuteNotificationsSync:n}=e;if(!t(n)){const{To_Account:e,MuteNotifications:t}=n,o=e.map((e=>`${s.CONV_C2C}${e}`)),i=r(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),p.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:s,userIDList:n,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(s)){console.log(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){console.log(`${this._name}.${t} userIDList:${n} messageRemindType:${o}`);return yield L.set(n,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const s=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:`,s),s}}))}};var 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);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:s,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(s,o,this._onConversationModified,this),t.subscribeInnerEvent(s,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(s,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(s,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(n,this._dispose,this)}_onConversationModified(e){const{constants:{ConvModifyPushType:t}}=this._core,{RecentContactMod:s=[]}=e;s.forEach((e=>{const{PushType:s}=e;if(s===t.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;S.handleConversationDeleted(t)}if(s===t.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!0)}if(s===t.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;R.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;E.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;T.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;E.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,n,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(s,this._dispose,this)}};var y=new class{init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(s){return t(this,void 0,void 0,(function*(){try{const{OuterConstant:{MSG_REMIND_ACPT_NOT_NOTE:n}}=this._core,{messageRemindType:o=n,isRepeated:i=!0}=s,{startTime:r=0,endTime:a=0}=this._calcStartAndEndTime(s),c=yield function(s){return t(this,void 0,void 0,(function*(){const{common:t}=e.core,{startTime:n,endTime:o,isRepeated:i,messageRemindType:r}=s,a={StartTime:n,EndTime:o,IsRepeated:i,Level:r};return t.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:a})}))}({messageRemindType:this._getType(o),startTime:r,endTime:a,isRepeated:i?d.ON:d.OFF});return{code:0,data:{errorCode:c.ErrorCode,errorInfo:c.ErrorInfo}}}catch(e){c("setAllReceiveMessageOpt",e)}}))}_calcStartAndEndTime(e){const{startHour:t=0,startMinute:s=0,startSecond:n=0,duration:o=0,isRepeated:i=!0}=e,r=new Date,a=new Date(r.getFullYear(),r.getMonth(),r.getDate(),t,s,n),c=Math.round(a.getTime()/1e3);let l=c+o;return i&&o>=86400&&(l=c+86400),{startTime:c,endTime:l}}_getType(e){const{OuterConstant:t}=this._core;return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}};var D=new class{init(e){this._core=e;const{helper:t,notificationCenter:s,InnerEvent:n}=e;t.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),s.subscribeInnerEvent(n.MESSAGE_PUSH,s.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){const t=this._handleResult(e),{notificationCenter:s,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:n}}=this._core;s.emitOuterEvent(n,{name:n,data:t})}getAllReceiveMessageOpt(){return t(this,void 0,void 0,(function*(){try{const s=yield function(){return t(this,void 0,void 0,(function*(){const{common:t}=e.core,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){const{OuterConstant:t}=this._core,{MSG_REMIND_ACPT_AND_NOTE:s,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:o}=t,i={0:s,1:n,2:o},{Level:r,StartTime:a,EndTime:c,IsRepeated:l}=e;return{messageRemindType:i[r]||s,startTime:a,endTime:c,isRepeated:l===d.ON}}};var 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)}};const 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=>{const{core:{utils:{isArray:s,isObject:n,isString:o}}}=e;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{constructor(){this.name="Conversation"}install(t){e.init(t),N.init(t),A.init(t),p.init(t),t.helper.registerValidateConfig({auth:P,params:U})}};export{$ as default};