@tencentcloud/lite-chat 4.2.5 → 4.2.6

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.
@@ -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,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(){var t;const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===s.CONV_C2C?this.userProfile={userID:this.conversationID.replace(s.CONV_C2C,"")}:this.type===s.CONV_GROUP&&(!this.subType&&(null===(t=this.groupProfile)||void 0===t?void 0:t.type)&&(this.subType=this.groupProfile.type),n(this.groupProfile)&&(this.groupProfile={groupID:this.conversationID.replace(s.CONV_GROUP,""),selfInfo:{},lastMessage:{},type:this.subType}))}updateUnreadCount(t){var s;const{core:{OuterConstant:n,utils:{isUndefined:o},store:i}}=e,{nextUnreadCount:r,isFromGetConversations:a,isUnreadC2CMessage:c}=t;if(o(r))return;if(this.subType===n.GRP_AVCHATROOM)return void(this.unreadCount=0);if(a&&this.type===n.CONV_GROUP)return void(this.unreadCount=r);if(c&&this.type===n.CONV_C2C)return void(this.unreadCount=r);const l="1"===(null===(s=i.get("cloudConfig"))||void 0===s?void 0:s.support_unread_count_for_meeting);this.subType!==n.GRP_MEETING||l?this.unreadCount+=r: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,p=1;var C=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:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ: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),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,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(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${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),this._core.ssoLog.debug("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){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{safeStringify:o},ssoLog:i,apiMap:{getGroupProfile:r}}=this._core;let a=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),o=this.getLocalConversation(`${s}${e}`);t&&o&&(o.groupProfile=t,a=!0),o&&!o.getProfileCompleted()&&"function"==typeof r&&(yield r({groupID:e}))}))),a&&this.emitConversationListUpdate()}catch(e){i.debug("_updateGroupConversation",o(e))}})}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach(e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach(e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})})})}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}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){var t,s;e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:n},conversation:o}=this._core,i=this.getLocalConversationList();this._emitEvent({name:n,data:i,isSyncCompleted:null===(s=null===(t=null==o?void 0:o.syncConversationHandler)||void 0===t?void 0:t.isSyncCompleted)||void 0===s?void 0:s.call(t)}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_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,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach(s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.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,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 C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter(t=>e.includes(t.conversationID))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.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);C.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}`;C.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=C.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=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.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=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)})}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.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}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.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}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.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=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(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&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;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&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.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===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.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);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.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=p,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=C.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=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.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}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.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}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.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=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.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&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.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===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}})}};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 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,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;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{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}})}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter(e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.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(C.hasLocalConversation(e)){const s=(null===(t=C.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=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.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}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.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})}),C.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}`;C.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,ssoLog:n}=this._core;e.forEach(e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map(e=>`${s.CONV_C2C}${e}`),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}})}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},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${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 y=new class{init(e){e.ssoLog.debug("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 A=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 N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={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}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};return new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}}});
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,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(){var t;const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===s.CONV_C2C?this.userProfile={userID:this.conversationID.replace(s.CONV_C2C,"")}:this.type===s.CONV_GROUP&&(!this.subType&&(null===(t=this.groupProfile)||void 0===t?void 0:t.type)&&(this.subType=this.groupProfile.type),n(this.groupProfile)&&(this.groupProfile={groupID:this.conversationID.replace(s.CONV_GROUP,""),selfInfo:{},lastMessage:{},type:this.subType}))}updateUnreadCount(t){var s;const{core:{OuterConstant:n,utils:{isUndefined:o},store:i}}=e,{nextUnreadCount:r,isFromGetConversations:a,isUnreadC2CMessage:c}=t;if(o(r))return;if(this.subType===n.GRP_AVCHATROOM)return void(this.unreadCount=0);if(a&&this.type===n.CONV_GROUP)return void(this.unreadCount=r);if(c&&this.type===n.CONV_C2C)return void(this.unreadCount=r);const l="1"===(null===(s=i.get("cloudConfig"))||void 0===s?void 0:s.support_unread_count_for_meeting);this.subType!==n.GRP_MEETING||l?this.unreadCount+=r: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,p=1;var C=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:p},InnerEventSubType:{C2C_MESSAGE_PEER_READ: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),t.registerWorkflowStep(o.RECEIVE_GROUP_TIPS_NOTIFICATION,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this);const{InnerEventSubType:{GROUP_AT_TIPS:v}}=s;s.subscribeInnerEvent(r,this._handleConversationSynced,this),s.subscribeInnerEvent(c,this._handleNewMessage,this),s.subscribeInnerEvent(a,v,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(a,C,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(p,this._dispose,this),e.ssoLog.debug(`${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),this._core.ssoLog.debug("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){return t(this,void 0,void 0,function*(){const{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n},utils:{safeStringify:o},ssoLog:i,apiMap:{getGroupProfile:r}}=this._core;let a=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),o=this.getLocalConversation(`${s}${e}`);t&&o&&(o.groupProfile=t,a=!0),o&&!o.getProfileCompleted()&&"function"==typeof r&&(yield r({groupID:e}))}))),a&&this.emitConversationListUpdate()}catch(e){i.debug("_updateGroupConversation",o(e))}})}_handleMessageRead(e){const{OuterConstant:{CONV_C2C:t}}=this._core,{C2cNotifyMsgArray:s=[]}=e||{};s.forEach(e=>{const{To_Account:s,UinPairReadArray:n=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null==n||n.forEach(e=>{const{LastReadTime:n}=e,o=`${t}${s}`;this._updateConversationReadInfo({conversationID:o,peerReadTime:n}),this._updateMessageListPeerRead({conversationID:o,peerReadTime:n})})})}_updateConversationReadInfo(e){const{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,r=t.conversationStore.getConversationMap();if(r.has(o)){const e=r.get(o);e.peerReadTime=i;const a=null==e?void 0:e.lastMessage;s(a)||a.fromAccount===n()&&a.lastTime<=i&&!a.isPeerRead&&(a.isPeerRead=!0,t.conversationStore.updateConversation(o,{lastMessage:a}))}}_updateMessageListPeerRead(e){const{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,r=n.messageDataHandler.getLocalMessageList(o),a=n.messageDataHandler.getSparseMessageList(o),c=[];r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,c.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:c})}_isConversationNeedShow(e){var t,s;const{OuterConstant:{CONV_GROUP:n,GRP_ROOM:o,GRP_LIVE:i},utils:{isUndefined:r}}=this._core,a=this.getLocalConversation(e);if(r(a))return!0;const c=a.type===n&&(null===(t=a.groupProfile)||void 0===t?void 0:t.type)===o,l=a.type===n&&(null===(s=a.groupProfile)||void 0===s?void 0:s.type)===i;return!(c||l)}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){var t,s;e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:n},conversation:o}=this._core,i=this.getLocalConversationList();this._emitEvent({name:n,data:i,isSyncCompleted:null===(s=null===(t=null==o?void 0:o.syncConversationHandler)||void 0===t?void 0:t.isSyncCompleted)||void 0===s?void 0:s.call(t)}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_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,utils:{isEmpty:t}}=this._core,s=this.getLocalConversationList();let n=0;return s.forEach(s=>{s.type!==e.CONV_SYSTEM&&(t(s.messageRemindType)||s.messageRemindType===e.MSG_REMIND_ACPT_AND_NOTE)&&(n+=s.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,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 C.getLocalConversationList();if(s(e)){if(0===e.length)return[];return C.getLocalConversationList().filter(t=>e.includes(t.conversationID))}if(n(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return C.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);C.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}`;C.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=C.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=C.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${h}`),h?a.updateConversation(l,e):C.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=C.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?n.updateConversation(o,e):C.appendToPinnedConversation(e)})}};var M=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return C.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}`),C.markMessageAsRead({conversationID:o,lastReadTime:n}),C.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}`),C.markMessageAsRead({conversationID:o,lastReadSequence:n}),C.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=C.getLocalConversation(o);let a=`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`;if(i.successLog={message:a},!r)return i;const c=!(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&&c&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;const{helper:{ChatError:l}}=this._core;try{if(r.type===n.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e),a+=`lastMessageTime:${e}`}if(r.type===n.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e),a+=`lastMessageSequence:${e}`}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new l({functionName:"setMessageRead",code:t,message:s,moreMessage:a})}return r.type===n.CONV_SYSTEM&&(r.unreadCount=0),C.emitConversationListUpdate(),Object.assign(Object.assign({},i),{successLog:{message:a}})})}setAllMessageRead(){return t(this,arguments,void 0,function*(s={}){const{OuterConstant:{READ_ALL_MSG:n},utils:{safeStringify:o}}=this._core;let i=`scope:${s.scope}`;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&&C.emitConversationListUpdate(),i+=`failureGroupInfoList:${o(n)}`}return{code:0,successLog:{message:i}}}catch(e){const{errorCode:t}=e;throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){const{GroupReadInfoArray:t,C2CReadAllMsg:s}=e;this._parseGroupReadInfo(t);this._updateAllConversationReadStatus({allC2CMessageReadStatus:s})>0&&C.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===p&&n.type===t){const t=this._getLocalMessageMaxTime(n);C.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);C.markMessageAsRead({conversationID:e,lastReadSequence:s})}}C.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=p,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=C.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=C.getLocalConversation(e);s&&(s.groupAtInfoList.length>0&&(s.clearGroupAtInfoList(),console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${t}`)),t&&C.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}`),C.markMessageAsRead({conversationID:e,lastReadTime:s}),C.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}`),C.markMessageAsRead({conversationID:e,lastReadSequence:s}),C.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=C.getLocalConversation(`${n.CONV_C2C}${i}`):2===s&&(a=C.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&&C.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,function*(){const{OuterConstant:i,common:r,helper:{ChatError:a}}=this._core,{conversationID:c,isPinned:d}=e,u={code:0,data:{conversationID:c}},_=C.getLocalConversation(c);if(_&&_.isPinned===d)return u;if(o(c))return _&&(_.isPinned=d),C.emitConversationListUpdate(!0),u;const h=`conversationID:${c} isPinned:${d}`;try{let e=null;s(c)?e={Type:1,To_Account:c.replace(i.CONV_C2C,"")}:n(c)&&(e={Type:2,GroupId:c.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===d?1:2,itemList:[e]},this._core);if(o){if(_)_.isPinned!==d&&(_.isPinned=d);else{const e=new l({conversationID:c,type:s(c)?i.CONV_C2C:i.CONV_GROUP,isPinned:d});C.setLocalConversation(c,e)}C.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},u),{successLog:{message:h}})}catch(e){const{errorCode:t,errorInfo:s}=e;throw new a({functionName:"pinConversation",code:t,message:s,moreMessage:h})}})}};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 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,{helper:{ChatError:o}}=this._core,i=`conversationIDList:${t} clearHistoryMessage:${s}`;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{code:0,data:n===u.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o},successLog:{message:i}}}catch(e){const{errorCode:t,errorInfo:s}=e;throw new o({code:t,message:s,moreMessage:i})}})}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter(e=>{var s;if(!C.hasLocalConversation(e))return!1;const n=null===(s=C.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(C.hasLocalConversation(e)){const s=(null===(t=C.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=>{C.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&C.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const s=C.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${s}`),s&&(C.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&C.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),this._core.message.messageHistory.completedHistoryConversations.delete(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}`),!C.hasLocalConversation(t))throw new this._core.helper.ChatError({code:_.CONV_NOT_FOUND});const n=C.getLocalConversation(t);return null==n||n.setDraftText(s),C.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})}),C.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}`;C.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,ssoLog:n}=this._core;e.forEach(e=>{const{MuteNotificationsSync:o}=e;if(!t(o)){const{To_Account:e,MuteNotifications:t}=o,i=e.map(e=>`${s.CONV_C2C}${e}`),a=r(t);n.debug(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${i} messageRemindType:${a}`),C.patchMessageRemindType(i,a)}})}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},ssoLog:a}=this._core;try{if(!r(s)){a.debug(`${this._name}.${t} groupID:${s} messageRemindType:${o}`);return yield O.set(s,o)}if(!r(n)){a.debug(`${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 y=new class{init(e){e.ssoLog.debug("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 A=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 N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,L.init(e),O.init(e),g.init(e),m.init(e),A.init(e),D.init(e)}};const G=e=>!s(e)&&!n(e)&&!o(e),P={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}}},U={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0,getAllReceiveMessageOpt:!0,setAllReceiveMessageOpt:!0};return new class{constructor(){this.name="Conversation"}install(t){e.init(t),y.init(t),N.init(t),C.init(t),t.helper.registerValidateConfig({auth:U,params:P})}}});
@@ -1 +1 @@
1
- function e(e,t,r,i){return new(r||(r=Promise))(function(o,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,d)}a((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const t="friend",r=1e3,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:`${c}Group`,REMARK:`${c}Remark`,ADDSOURCE:`${c}AddSource`,ADDWORDING:`${c}Wording`,ADDTIME:`${c}AddTime`},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function F(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}))})}function I(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){const{[t]:i=[],ActionStatus:o,ErrorCode:n,ErrorInfo:s,ErrorDisplay:d}=e;return{resultList:i.map(r),actionStatus:o,errorCode:n,errorInfo:s,errorDisplay:d}}const v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}};let A=class{constructor(e){var t;this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];const{userID:r,tagValueList:i=[],core:o}=e,n=null===(t=o.user.userProfile)||void 0===t?void 0:t.createProfile(r,i);this.userID=r,this.profile=n,i.forEach(e=>{const{tag:t,value:r}=e;t.indexOf("Tag_Profile_Custom")>-1&&this.friendCustomField.push({key:t,value:r});const i=v[t];null==i||i(this,r)})}update(e){const t=[];this.friendCustomField.forEach(e=>{t.push(e.key)}),e.forEach(e=>{const{tag:r,value:i}=e;r.indexOf("Tag_Profile_Custom")>-1&&(t.indexOf(r)>-1?this.friendCustomField.forEach(e=>{e.key===r&&(e.value=i)}):this.friendCustomField.push({key:r,value:i}));const o=v[r];null==o||o(this,i)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),t.registerApi({apiName:"getFriendProfile",context:this}),t.registerApi({apiName:"addFriend",context:this}),t.registerApi({apiName:"deleteFriend",context:this}),t.registerApi({apiName:"updateFriend",context:this}),t.registerApi({apiName:"checkFriend",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,o=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",`${t} getFriendListFromCache, data:${i(o)}`),{code:0,data:o}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){var r;const{ssoLog:i,helper:o}=this._core;try{i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer`);const o={From_Account:null===(r=this._core.store.get("login"))||void 0===r?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},n=yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{UserDataItem:t=[],StandardSequence:r,CustomSequence:i,FriendNum:o,CompleteFlag:n,NextStartIndex:s,ActionStatus:d,ErrorCode:a,ErrorInfo:c,ErrorDisplay:u}=e;return{friendList:t.map(e=>{var t;return{userID:e.To_Account,tagValueList:null===(t=e.ValueItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:r,customSequence:i,friendNumber:o,completeFlag:n,nextStartIndex:s,actionStatus:d,errorCode:a,errorInfo:c,errorDisplay:u}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get",data:t}))})}(o,this._core),{friendList:s,nextStartIndex:d,standardSequence:a,customSequence:c,completeFlag:u}=n;this._startIndex=d,this._standardSequence=a,this._customSequence=c,this._processFriendList(s),0===u?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer ok`)}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}getFriendProfile(t){return e(this,void 0,void 0,function*(){var i;try{let{userIDList:o}=t;o.length>r&&(o=o.slice(0,r));const{friendUserIdList:n,unFriendUserIdList:s}=this.partitionByIsFriend(o),d=this._createNonFriendErrorList(s);if(0===n.length)return{code:0,data:{friendList:[],failureUserIDList:d}};const a={From_Account:null===(i=this._core.store.get("login"))||void 0===i?void 0:i.userId,To_Account:n},c=(yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{InfoItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{friendProfileList:t.map(e=>{var t;return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null===(t=e.SnsProfileItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:t}))})}(a,this._core))||{},{successProfiles:u,failedProfiles:l}=this._processFriendProfileResponse(c);return{code:0,data:{friendList:u,failureUserIDList:[...l,...d]}}}catch(e){const{errorCode:t}=e||{};throw new this._core.helper.ChatError({code:t})}})}addFriend(r){return e(this,void 0,void 0,function*(){var i;const{helper:o,store:n,ssoLog:s}=this._core;try{const{to:d,source:c,type:u,wording:l,remark:p,groupName:h}=r,m={From_Account:null===(i=n.get("login"))||void 0===i?void 0:i.userId,AddFriendItem:[{To_Account:d,AddSource:c,AddWording:l,GroupName:h,Remark:p}],AddType:u},_=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}(m,this._core),{resultList:f=[]}=_,{userID:F,resultCode:I}=f[0];if(0===I)return s.debug("addFriend",`${t} addFriend ok`),{code:0,data:{userID:F}};if(I===a)return s.debug("addFriend",`${t} addFriend wait for the other party to agree`),{code:0,data:{userID:F,code:I,message:"wait for the other party to agree"}};throw new o.ChatError({functionName:"addFriend",code:I})}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}deleteFriend(i){return e(this,void 0,void 0,function*(){var o;const{store:n,ssoLog:s,helper:d}=this._core;try{let{userIDList:d,type:a}=i;const c=null===(o=n.get("login"))||void 0===o?void 0:o.userId;d.length>1e3&&(s.info("deleteFriend",`${t} deleteFriend the length of userIDList cannot exceed:1000`),d=d.slice(0,r));const{friendUserIdList:u,unFriendUserIdList:l}=this.partitionByIsFriend(d);if(0===u.length)return{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(l)}};const p={From_Account:c,To_Account:u,DeleteType:a},h=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}(p,this._core),{successUserIDList:m,failureUserIDList:_}=this._processOperationResult({resultList:h.resultList,includeRelation:!1});return{code:0,data:{successUserIDList:m,failureUserIDList:_}}}catch(e){const{errorCode:t}=e||{};throw new d.ChatError({code:t})}})}updateFriend(t){return e(this,void 0,void 0,function*(){var e;const{helper:r,store:o,appStore:{userStore:n}}=this._core;try{const{userID:s,remark:d,friendCustomField:a}=t,c=null===(e=o.get("login"))||void 0===e?void 0:e.userId;if(!n.getFriendMap().has(s))throw new r.ChatError({functionName:"updateFriend",code:i});const u={From_Account:c,UpdateItem:[{To_Account:s,SnsItem:this._buildSnsItemList(d,a)}]},l=yield F(u,this._core),{resultList:p}=l,{to:h,resultCode:m,resultInfo:_}=p[0];if(f(m)||0===m){return{code:0,data:this._updateLocalFriend({userID:h,remark:d,friendCustomField:a})}}throw new r.ChatError({functionName:"updateFriend",code:m,message:_})}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}checkFriend(t){return e(this,void 0,void 0,function*(){var e;const{OuterConstant:r,store:i,helper:o}=this._core;try{const{userIDList:o,type:n}=t,s=null===(e=i.get("login"))||void 0===e?void 0:e.userId,d={From_Account:s,To_Account:o,CheckType:n===r.SNS_CHECK_TYPE_SINGLE?n:r.SNS_CHECK_TYPE_BOTH},a=yield I(d,this._core),{successUserIDList:c=[],failureUserIDList:u=[]}=this._processOperationResult({resultList:a.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:c,failureUserIDList:u}}}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){const{userStore:e}=this._core.appStore;e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(r){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:i}}=this._core;e.debug("updateFriendList",`${t} updateFriendList data:${i(r)}`);const{userStore:o}=this._core.appStore,{addedFriendList:n=[],removedFriendList:s=[]}=r;n.length>0&&(n.forEach(e=>{const t=new A({userID:e,core:this._core});o.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:n}),this._emitFriendListUpdated()),s.length>0&&(s.forEach(e=>{o.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",`${t} updateFriendInfo data:${i(e)}`);const{appStore:{userStore:o,conversationStore:n},utils:{isEmpty:s}}=this._core,{userID:d,tagValueList:a}=e[0]||{},c=o.getFriend(d);if(s(a)||!c)return;const l=a.map(e=>({tag:e.BytesTag,value:e.BytesValue}));l.forEach(e=>{var t;const{tag:r,value:i}=e,o=null===(t=n.getConversation(`C2C${d}`))||void 0===t?void 0:t.remark;r===u.REMARK&&i!==o&&n.updateConversation(`C2C${d}`,{remark:i}),c.update(l)}),this._emitFriendListUpdated()}_processFriendList(e){const{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{const{userID:t,tagValueList:i}=e;if(this._isInvalidFriend(t))return;const o=new A({userID:t,tagValueList:i,core:this._core});r.getFriendMap().set(t,o)})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},user:{userProfile:r},ssoLog:i}=this._core;i.debug("_fetchFriendProfile",`${t} _fetchFriendProfile`);const o=[...e.getFriendMap().keys()],n=Math.ceil(o.length/100);for(let t=0;t<n;t++){const i=100*t,n=Math.min(i+100,o.length),s=o.slice(i,n),d=yield null==r?void 0:r.getUserProfile({userIDList:s});if(d&&d.data){d.data.forEach(t=>{const r=e.getFriend(t.userID);r&&(r.profile=t)})}this._emitFriendListUpdated()}})}_emitFriendListUpdated(){const{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,i=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:i})}_updateCustomField(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let r=!1;return t.forEach(({key:t,value:i})=>{const o=e.find(e=>e.key===t);o?o.value!==i&&(o.value=i,r=!0):(e.push({key:t,value:i}),r=!0)}),r}_updateLocalFriend(e){const{userStore:t}=this._core.appStore,{userID:r,remark:i,friendCustomField:o}=e,n=t.getFriend(r);if(n)return f(i)||(n.remark=i),Array.isArray(o)&&o.length>0&&this._updateCustomField(n.friendCustomField,o),this._emitFriendListUpdated(),n}_processOperationResult(e){const{resultList:t,includeRelation:r=!1}=e,{isEmpty:i}=this._core.utils,o=[],n=[];return Array.isArray(t)&&!i(t)&&t.forEach(e=>{const{userID:t,relation:i,resultCode:s,resultInfo:d}=e;if(f(s)||0===s){const e={userID:t};r&&(e.code=0,e.relation=i),o.push(e)}else n.push({userID:t,code:s,message:d})}),{successUserIDList:o,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){const r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&t.length>0&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){const{friendProfileList:t=[]}=e,{userStore:r}=this._core.appStore,i=[],o=[];return t.forEach(e=>{const{userID:t,resultCode:n,resultInfo:s,profileItem:d}=e;if(0===n){const e=new A({userID:t,tagValueList:d,core:this._core});i.push(e),r.getFriendMap().set(t,e)}else o.push({userID:t,code:n,message:s})}),{successProfiles:i,failedProfiles:o}}partitionByIsFriend(e){const t=[],r=[];return e.forEach(e=>{const{userStore:i}=this._core.appStore;i.getFriendMap().has(e)?t.push(e):r.push(e)}),{friendUserIdList:t,unFriendUserIdList:r}}isMyFriend(e){const{userStore:t}=this._core.appStore;return t.getFriendMap().has(e)}};var y=new class{init(e){this.core=e}};function S(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function E(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function D(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return C(yield i.buildAndSendPacket({servcmd:"sns.pendency_delete",data:o}))})}function C(e){const{ResultItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:t.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),t.registerApi({apiName:"acceptFriendApplication",context:this}),t.registerApi({apiName:"refuseFriendApplication",context:this}),t.registerApi({apiName:"deleteFriendApplication",context:this}),t.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",`${t} getFriendApplicationListFromCache friendApplicationList:${r(i)}`),{code:0,data:{friendApplicationList:i,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:i,utils:{safeStringify:o}}=this._core,n="syncFriendApplicationListFromServer";try{const t=yield function(t){return e(this,void 0,void 0,function*(){var e;const{store:i,OuterConstant:o,common:n}=y.core,s={From_Account:null===(e=i.get("login"))||void 0===e?void 0:e.userId,PendencyType:o.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:t.startTime,LastSequence:t.currentSequence};return function(e){const{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:i,CurrentSequence:o,ActionStatus:n,ErrorCode:s,ErrorInfo:d,ErrorDisplay:a}=e;return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,avatar:e.Image})),startTime:r,unreadCount:i,currentSequence:o,actionStatus:n,errorCode:s,errorInfo:d,errorDisplay:a}}(yield n.buildAndSendPacket({servcmd:"sns.pendency_get",data:s}))})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:n,currentSequence:s}=t;this._startTime=n,this._currentSequence=s,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{const{userID:t,type:r}=e,i=this._createFriendApplication(e);this._friendApplicationMap.set(`${t}_${r}`,i)}),this._emitApplicationListUpdated()}catch(e){const r=new this._core.helper.ChatError({functionName:n,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw i.error("syncFriendApplicationListFromServer",`${t} ${n} error:`,{error:r}),r}})}acceptFriendApplication(t){return e(this,void 0,void 0,function*(){const{OuterConstant:{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:r}}=this._core;return[e,r].includes(t.type)||(t.type=r),this._operationApplication({functionName:"acceptFriendApplication",options:t,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(t){return e(this,void 0,void 0,function*(){const{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(`${e}_${t}`))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,function*(){const{functionName:e,options:i,protocolFunction:o}=r;console.log(`${t} ${e} options:`,i);try{const r=yield o(i),{resultList:n=[]}=r,{resultCode:s,resultInfo:d}=n[0];if(0===s)return console.log(`${t} ${e} ok`),{code:0,data:{}};throw{errorCode:s,errorInfo:d}}catch(r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var e;const{store:t,common:r}=y.core,i={From_Account:null===(e=t.get("login"))||void 0===e?void 0:e.userId,LatestPendencyTimeStamp:(o=Math.floor(Date.now()/1e3),n=0,Math.round(Number(o)*Math.pow(10,n))/Math.pow(10,n))};var o,n;return function(e){const{ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}(yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:i}))})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){const{from:t,addedApplicationList:r=[],removedApplicationList:i=[]}=e,{isEmpty:o}=this._core.utils;o(r)||this.onApplicationAdded(r,t),o(i)||this.onApplicationDeleted()}onApplicationAdded(e,t){var r;const{store:i,OuterConstant:o}=this._core,n=t===(null===(r=i.get("login"))||void 0===r?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{const t=`${e.userID}_${n}`;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function k(){return e(this,void 0,void 0,function*(){const{common:e}=y.core,t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return function(e){return U(e,e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))}(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}))})}function N(t){return e(this,void 0,void 0,function*(){const{name:e,userIDList:r}=t,{common:i}=y.core,o={From_Account:i.getCurrentUserID(),GroupName:[e],To_Account:r};return function(e){return U(e,e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield i.buildAndSendPacket({servcmd:"sns.group_add",data:o}))})}function G(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return function(e){return U(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))})}function w(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=R(i,l),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return U(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))})}function P(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=R(i,p),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return U(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))})}function M(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{oldName:r,newName:i}=t,o={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:i};return function(e){return U(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:o}))})}function R(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function U(e,t){const{CurrentSequence:r,ActionStatus:i,ErrorCode:o,ErrorInfo:n,ErrorDisplay:s,ResultItem:d=[]}=e,a={currentSequence:r,actionStatus:i,errorCode:o,errorInfo:n,errorDisplay:s};return t&&d.length>0?Object.assign(Object.assign({},a),{resultList:d.map(t)}):a}class O{constructor(e){const{name:t="",userIDList:r=[]}=e;this.name=t,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){const t=this.userIDList.indexOf(e);t>-1&&(this.userIDList.splice(t,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),t.registerApi({apiName:"createFriendGroup",context:this}),t.registerApi({apiName:"deleteFriendGroup",context:this}),t.registerApi({apiName:"addToFriendGroup",context:this}),t.registerApi({apiName:"removeFromFriendGroup",context:this}),t.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendGroupMap.values()];return e.debug(`${t} getFriendGroupListFromCache, data:${r(i)}`),{code:0,data:i}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:e}=this._core,r="syncFriendGroupListFromServer";try{const i=yield k(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",`${t} ${r} ok. count: 0`),o.forEach(e=>{const t=new O(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(t){return e(this,void 0,void 0,function*(){const e="createFriendGroup";try{const{name:r}=t;this._checkGroupExist(e,r);const i=yield N(t),{successUserIDList:o,failureUserIDList:n}=this._parseCreateGroupResponse(i),s=new O({name:r,userIDList:o});return this._friendGroupMap.set(r,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(t){this._handleError(e,t)}})}deleteFriendGroup(t){return e(this,void 0,void 0,function*(){const e="deleteFriendGroup";try{const{name:r}=t;this._checkGroupNotExist(e,r),yield G(t);const i=this._friendGroupMap.get(r);return i&&(this._updateFriendGroup({name:r,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(r)),this._emitGroupListUpdated(),{code:0,data:i}}catch(t){this._handleError(e,t)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:w})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:P})})}renameFriendGroup(t){return e(this,void 0,void 0,function*(){const e="renameFriendGroup";try{const{oldName:r,newName:i}=t;this._checkGroupNotExist(e,r),this._checkGroupExist(e,i),yield M(t);const o=this._updateGroupNameInCache(r,i);return o&&this._updateFriendGroup({name:r,userIDList:o.userIDList,action:_,newName:i}),this._emitGroupListUpdated(),{code:0,data:o}}catch(t){this._handleError(e,t)}})}_updateFriendGroupMember(t){return e(this,void 0,void 0,function*(){const{functionName:e,params:r,protocolFunction:i}=t;try{const{name:t}=r;this._checkGroupNotExist(e,t);const o=yield i(r),{friendGroup:n,failureUserIDList:s}=this._parseUpdateFriendGroupResponse(t,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:s}}}catch(t){this._handleError(e,t)}})}_updateGroupNameInCache(e,t){const r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){const{resultList:t=[]}=e,r=[],i=[];return t.forEach(({userID:e,resultCode:t,resultInfo:o})=>{f(t)||0===t?r.push(e):i.push({userID:e,code:t,message:o})}),{successUserIDList:r,failureUserIDList:i}}_parseUpdateFriendGroupResponse(e,t){const{resultList:r=[]}=t,i=this._friendGroupMap.get(e),o=[],n=[],s=[];return r.forEach(t=>{0===t.resultCode?i&&(t.updateType===l?this._addFriendToGroup(e,t.userID,i,n):t.updateType===p&&this._removeFriendFromGroup(e,t.userID,i,s)):o.push({userID:t.userID,code:t.resultCode,message:t.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:n})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){const{name:t,userIDList:r,action:i,newName:o}=e,{userStore:n}=this._core.appStore;t&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{const r=n.getFriend(e);if(!r)return;const{groupList:s}=r;switch(i){case h:-1===s.indexOf(t)&&(s.push(t),r.count=s.length);break;case m:{const e=s.indexOf(t);e>-1&&(s.splice(e,1),r.count=s.length);break}case _:{if(!o)return;const e=s.indexOf(t);-1!==e&&(s[e]=o);break}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var q=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),t.registerApi({apiName:"addToBlacklist",context:this}),t.registerApi({apiName:"removeFromBlacklist",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(`${t} syncBlacklistFromServer`);const i={From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_get",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{BlackListItem:a=[],StartIndex:c=0}=d;return{blackList:B(a),startIndex:c}})}(i,this._core),{blackList:n=[],startIndex:s=0}=o;return this._startIndex=s,this._addBlacklistMap(n),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r=this._preprocessBlacklist(t),i={From_Account:this._core.common.getCurrentUserID(),To_Account:r},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_add",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(i,this._core),{blackList:n=[]}=o;return this._addBlacklistMap(n),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}removeFromBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r={From_Account:this._core.common.getCurrentUserID(),To_Account:t.userIDList},i=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_delete",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(r,this._core),{blackList:o=[]}=i;return this._deleteBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateBlacklist",`${t} updateBlacklist data: ${i(e)}`);const{addedBlacklist:o=[],removedBlacklist:n=[]}=e;let s=!1;if(o.length>0){o.some(e=>!this._blacklistMap.has(e))&&(s=!0,this._addBlacklistMap(o.map(e=>({userID:e}))))}if(n.length>0){n.some(e=>this._blacklistMap.has(e))&&(s=!0,this._deleteBlacklistMap(n.map(e=>({userID:e}))))}s&&this._emitBlackListUpdated()}_addBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",`${t} _addBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t,addBlackTimeStamp:r=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:r})})}_deleteBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",`${t} _deleteBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)})}_preprocessBlacklist(e){let{userIDList:t}=e;const r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t.includes(r)&&(t=e.userIDList.filter(e=>e!==r)),t}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:r,ssoLog:i,utils:{safeStringify:o}}=this._core,n=Array.from(this._blacklistMap.keys());i.debug(`${t} _emitBlackListUpdated blackList:${o(n)}`),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:n})}};const x={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},$={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var V=new class{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(`${t} install`),this._core=e;const{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:s}}=e;y.init(e),g.init(e),T.init(e),b.init(e),q.init(e),r.registerValidateConfig({auth:$,params:x}),r.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,s.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){q.syncBlacklistFromServer(),g.syncFriendListFromServer(),T.syncFriendApplicationListFromServer(),b.syncFriendGroupListFromServer()}onFriendModified(e){const{from:t,addedBlacklist:r,removedBlacklist:i,addedFriendList:o,removedFriendList:n,addedApplicationList:s,removedApplicationList:d,friendUpdateInfo:a,reportTime:c}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),{isEmpty:u}=this._core.utils;u(r)&&u(i)||q.updateBlacklist({addedBlacklist:r,removedBlacklist:i}),u(o)&&u(n)||(g.updateFriendList({addedFriendList:o,removedFriendList:n}),T.updateFriendApplicationList({from:t,removedApplicationList:o})),u(a)||g.updateFriendInfo(a),u(s)&&u(d)||T.updateFriendApplicationList({from:t,addedApplicationList:s,removedApplicationList:d}),c&&T.onApplicationRead()}_parseFriendListModification(e){const{PushType:t,From_Account:r,To_Account:i,ReportTime:o,BlackListAdd_Account:n=[],BlackListDel_Account:s=[],FriendAdd_Account:d=[],FriendDel_Account:a=[],PendencyAdd:c=[],FrienPencydDel_Account:u=[],FriendUpInfo:l=[]}=e,p=l.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:t,from:r,to:i,reportTime:o,addedBlacklist:n,removedBlacklist:s,addedFriendList:d,removedFriendList:a,addedApplicationList:c.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:p,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),q.dispose(),g.dispose(),T.dispose(),b.dispose()}};export{V as default};
1
+ function e(e,t,r,i){return new(r||(r=Promise))(function(o,s){function n(e){try{a(i.next(e))}catch(e){s(e)}}function d(e){try{a(i.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(n,d)}a((i=i.apply(e,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const t="friend",r=1e3,i=2700,o=2710,s=2711,n=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:`${c}Group`,REMARK:`${c}Remark`,ADDSOURCE:`${c}AddSource`,ADDWORDING:`${c}Wording`,ADDTIME:`${c}AddTime`},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function F(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}))})}function I(t,r){return e(this,void 0,void 0,function*(){return function(e){return L(e,"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){const{[t]:i=[],ActionStatus:o,ErrorCode:s,ErrorInfo:n,ErrorDisplay:d}=e;return{resultList:i.map(r),actionStatus:o,errorCode:s,errorInfo:n,errorDisplay:d}}const v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}};let A=class{constructor(e){var t;this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];const{userID:r,tagValueList:i=[],core:o}=e,s=null===(t=o.user.userProfile)||void 0===t?void 0:t.createProfile(r,i);this.userID=r,this.profile=s,i.forEach(e=>{const{tag:t,value:r}=e;t.indexOf("Tag_Profile_Custom")>-1&&this.friendCustomField.push({key:t,value:r});const i=v[t];null==i||i(this,r)})}update(e){const t=[];this.friendCustomField.forEach(e=>{t.push(e.key)}),e.forEach(e=>{const{tag:r,value:i}=e;r.indexOf("Tag_Profile_Custom")>-1&&(t.indexOf(r)>-1?this.friendCustomField.forEach(e=>{e.key===r&&(e.value=i)}):this.friendCustomField.push({key:r,value:i}));const o=v[r];null==o||o(this,i)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),t.registerApi({apiName:"getFriendProfile",context:this}),t.registerApi({apiName:"addFriend",context:this}),t.registerApi({apiName:"deleteFriend",context:this}),t.registerApi({apiName:"updateFriend",context:this}),t.registerApi({apiName:"checkFriend",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,o=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",`${t} getFriendListFromCache, data:${i(o)}`),{code:0,data:o}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){var r;const{ssoLog:i,helper:o}=this._core;try{i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer`);const o={From_Account:null===(r=this._core.store.get("login"))||void 0===r?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},s=yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{UserDataItem:t=[],StandardSequence:r,CustomSequence:i,FriendNum:o,CompleteFlag:s,NextStartIndex:n,ActionStatus:d,ErrorCode:a,ErrorInfo:c,ErrorDisplay:u}=e;return{friendList:t.map(e=>{var t;return{userID:e.To_Account,tagValueList:null===(t=e.ValueItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:r,customSequence:i,friendNumber:o,completeFlag:s,nextStartIndex:n,actionStatus:d,errorCode:a,errorInfo:c,errorDisplay:u}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get",data:t}))})}(o,this._core),{friendList:n,nextStartIndex:d,standardSequence:a,customSequence:c,completeFlag:u}=s;this._startIndex=d,this._standardSequence=a,this._customSequence=c,this._processFriendList(n),0===u?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),i.debug("syncFriendListFromServer",`${t} syncFriendListFromServer ok`)}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}getFriendProfile(t){return e(this,void 0,void 0,function*(){var i;try{let{userIDList:o}=t;o.length>r&&(o=o.slice(0,r));const{friendUserIdList:s,unFriendUserIdList:n}=this.partitionByIsFriend(o),d=this._createNonFriendErrorList(n);if(0===s.length)return{code:0,data:{friendList:[],failureUserIDList:d}};const a={From_Account:null===(i=this._core.store.get("login"))||void 0===i?void 0:i.userId,To_Account:s},c=(yield function(t,r){return e(this,void 0,void 0,function*(){return function(e){const{InfoItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{friendProfileList:t.map(e=>{var t;return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null===(t=e.SnsProfileItem)||void 0===t?void 0:t.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:t}))})}(a,this._core))||{},{successProfiles:u,failedProfiles:l}=this._processFriendProfileResponse(c);return{code:0,data:{friendList:u,failureUserIDList:[...l,...d]}}}catch(e){const{errorCode:t}=e||{};throw new this._core.helper.ChatError({code:t})}})}addFriend(r){return e(this,void 0,void 0,function*(){var i;const{helper:o,store:s,ssoLog:n}=this._core;try{const{to:d,source:c,type:u,wording:l,remark:p,groupName:h}=r,m={From_Account:null===(i=s.get("login"))||void 0===i?void 0:i.userId,AddFriendItem:[{To_Account:d,AddSource:c,AddWording:l,GroupName:h,Remark:p}],AddType:u},_=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}(m,this._core),{resultList:f=[]}=_,{userID:F,resultCode:I}=f[0];if(0===I)return n.debug("addFriend",`${t} addFriend ok`),{code:0,data:{userID:F}};if(I===a)return n.debug("addFriend",`${t} addFriend wait for the other party to agree`),{code:0,data:{userID:F,code:I,message:"wait for the other party to agree"}};throw new o.ChatError({functionName:"addFriend",code:I})}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}deleteFriend(i){return e(this,void 0,void 0,function*(){var o;const{store:s,ssoLog:n,helper:d}=this._core;try{let{userIDList:d,type:a}=i;const c=null===(o=s.get("login"))||void 0===o?void 0:o.userId;d.length>1e3&&(n.info("deleteFriend",`${t} deleteFriend the length of userIDList cannot exceed:1000`),d=d.slice(0,r));const{friendUserIdList:u,unFriendUserIdList:l}=this.partitionByIsFriend(d);if(0===u.length)return{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(l)}};const p={From_Account:c,To_Account:u,DeleteType:a},h=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}(p,this._core),{successUserIDList:m,failureUserIDList:_}=this._processOperationResult({resultList:h.resultList,includeRelation:!1});return{code:0,data:{successUserIDList:m,failureUserIDList:_}}}catch(e){const{errorCode:t}=e||{};throw new d.ChatError({code:t})}})}updateFriend(t){return e(this,void 0,void 0,function*(){var e;const{helper:r,store:o,appStore:{userStore:s}}=this._core;try{const{userID:n,remark:d,friendCustomField:a}=t,c=null===(e=o.get("login"))||void 0===e?void 0:e.userId;if(!s.getFriendMap().has(n))throw new r.ChatError({functionName:"updateFriend",code:i});const u={From_Account:c,UpdateItem:[{To_Account:n,SnsItem:this._buildSnsItemList(d,a)}]},l=yield F(u,this._core),{resultList:p}=l,{to:h,resultCode:m,resultInfo:_}=p[0];if(f(m)||0===m){return{code:0,data:this._updateLocalFriend({userID:h,remark:d,friendCustomField:a})}}throw new r.ChatError({functionName:"updateFriend",code:m,message:_})}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}checkFriend(t){return e(this,void 0,void 0,function*(){var e;const{OuterConstant:r,store:i,helper:o}=this._core;try{const{userIDList:o,type:s}=t,n=null===(e=i.get("login"))||void 0===e?void 0:e.userId,d={From_Account:n,To_Account:o,CheckType:s===r.SNS_CHECK_TYPE_SINGLE?s:r.SNS_CHECK_TYPE_BOTH},a=yield I(d,this._core),{successUserIDList:c=[],failureUserIDList:u=[]}=this._processOperationResult({resultList:a.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:c,failureUserIDList:u}}}catch(e){const{errorCode:t}=e||{};throw new o.ChatError({code:t})}})}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){const{userStore:e}=this._core.appStore;e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(r){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:i}}=this._core;e.debug("updateFriendList",`${t} updateFriendList data:${i(r)}`);const{userStore:o}=this._core.appStore,{addedFriendList:s=[],removedFriendList:n=[]}=r;s.length>0&&(s.forEach(e=>{const t=new A({userID:e,core:this._core});o.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:s}),this._emitFriendListUpdated()),n.length>0&&(n.forEach(e=>{o.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",`${t} updateFriendInfo data:${i(e)}`);const{appStore:{userStore:o,conversationStore:s},utils:{isEmpty:n}}=this._core,{userID:d,tagValueList:a}=e[0]||{},c=o.getFriend(d);if(n(a)||!c)return;const l=a.map(e=>({tag:e.BytesTag,value:e.BytesValue}));l.forEach(e=>{var t;const{tag:r,value:i}=e,o=null===(t=s.getConversation(`C2C${d}`))||void 0===t?void 0:t.remark;r===u.REMARK&&i!==o&&s.updateConversation(`C2C${d}`,{remark:i}),c.update(l)}),this._emitFriendListUpdated()}_processFriendList(e){const{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{const{userID:t,tagValueList:i}=e;if(this._isInvalidFriend(t))return;const o=new A({userID:t,tagValueList:i,core:this._core});r.getFriendMap().set(t,o)})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){const{appStore:{userStore:e},user:{userProfile:r},ssoLog:i}=this._core;i.debug("_fetchFriendProfile",`${t} _fetchFriendProfile`);const o=[...e.getFriendMap().keys()],s=Math.ceil(o.length/100);for(let t=0;t<s;t++){const i=100*t,s=Math.min(i+100,o.length),n=o.slice(i,s),d=yield null==r?void 0:r.getUserProfile({userIDList:n});if(d&&d.data){d.data.forEach(t=>{const r=e.getFriend(t.userID);r&&(r.profile=t)})}this._emitFriendListUpdated()}})}_emitFriendListUpdated(){const{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,i=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:i})}_updateCustomField(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let r=!1;return t.forEach(({key:t,value:i})=>{const o=e.find(e=>e.key===t);o?o.value!==i&&(o.value=i,r=!0):(e.push({key:t,value:i}),r=!0)}),r}_updateLocalFriend(e){const{userStore:t}=this._core.appStore,{userID:r,remark:i,friendCustomField:o}=e,s=t.getFriend(r);if(s)return f(i)||(s.remark=i),Array.isArray(o)&&o.length>0&&this._updateCustomField(s.friendCustomField,o),this._emitFriendListUpdated(),s}_processOperationResult(e){const{resultList:t,includeRelation:r=!1}=e,{isEmpty:i}=this._core.utils,o=[],s=[];return Array.isArray(t)&&!i(t)&&t.forEach(e=>{const{userID:t,relation:i,resultCode:n,resultInfo:d}=e;if(f(n)||0===n){const e={userID:t};r&&(e.code=0,e.relation=i),o.push(e)}else s.push({userID:t,code:n,message:d})}),{successUserIDList:o,failureUserIDList:s}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){const r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&t.length>0&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){const{friendProfileList:t=[]}=e,{userStore:r}=this._core.appStore,i=[],o=[];return t.forEach(e=>{const{userID:t,resultCode:s,resultInfo:n,profileItem:d}=e;if(0===s){const e=new A({userID:t,tagValueList:d,core:this._core});i.push(e),r.getFriendMap().set(t,e)}else o.push({userID:t,code:s,message:n})}),{successProfiles:i,failedProfiles:o}}partitionByIsFriend(e){const t=[],r=[];return e.forEach(e=>{const{userStore:i}=this._core.appStore;i.getFriendMap().has(e)?t.push(e):r.push(e)}),{friendUserIdList:t,unFriendUserIdList:r}}isMyFriend(e){const{userStore:t}=this._core.appStore;return t.getFriendMap().has(e)}};var y=new class{init(e){this.core=e}};function S(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function E(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))})}function D(t){return e(this,void 0,void 0,function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return C(yield i.buildAndSendPacket({servcmd:"sns.pendency_delete",data:o}))})}function C(e){const{ResultItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:t.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){this._core=e;const{helper:t,constants:{WORKFLOW_NAME:r,WORKFLOW_STEP:i}}=e;t.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),t.registerApi({apiName:"acceptFriendApplication",context:this}),t.registerApi({apiName:"refuseFriendApplication",context:this}),t.registerApi({apiName:"deleteFriendApplication",context:this}),t.registerApi({apiName:"setFriendApplicationRead",context:this}),t.registerWorkflowStep(r.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.FRIEND_APPLICATION_LIST_RECOVER,this.syncFriendApplicationListFromServer,this)}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",`${t} getFriendApplicationListFromCache friendApplicationList:${r(i)}`),{code:0,data:{friendApplicationList:i,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:i,utils:{safeStringify:o}}=this._core,s="syncFriendApplicationListFromServer";try{const t=yield function(t){return e(this,void 0,void 0,function*(){var e;const{store:i,OuterConstant:o,common:s}=y.core,n={From_Account:null===(e=i.get("login"))||void 0===e?void 0:e.userId,PendencyType:o.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:t.startTime,LastSequence:t.currentSequence};return function(e){const{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:i,CurrentSequence:o,ActionStatus:s,ErrorCode:n,ErrorInfo:d,ErrorDisplay:a}=e;return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,avatar:e.Image})),startTime:r,unreadCount:i,currentSequence:o,actionStatus:s,errorCode:n,errorInfo:d,errorDisplay:a}}(yield s.buildAndSendPacket({servcmd:"sns.pendency_get",data:n}))})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:s,currentSequence:n}=t;this._startTime=s,this._currentSequence=n,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{const{userID:t,type:r}=e,i=this._createFriendApplication(e);this._friendApplicationMap.set(`${t}_${r}`,i)}),this._emitApplicationListUpdated()}catch(e){const r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw i.error("syncFriendApplicationListFromServer",`${t} ${s} error:`,{error:r}),r}})}acceptFriendApplication(t){return e(this,void 0,void 0,function*(){const{OuterConstant:{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:r}}=this._core;return[e,r].includes(t.type)||(t.type=r),this._operationApplication({functionName:"acceptFriendApplication",options:t,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(t){return e(this,void 0,void 0,function*(){const{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(`${e}_${t}`))throw new this._core.helper.ChatError({functionName:r,code:n})}_operationApplication(r){return e(this,void 0,void 0,function*(){const{functionName:e,options:i,protocolFunction:o}=r;console.log(`${t} ${e} options:`,i);try{const r=yield o(i),{resultList:s=[]}=r,{resultCode:n,resultInfo:d}=s[0];if(0===n)return console.log(`${t} ${e} ok`),{code:0,data:{}};throw{errorCode:n,errorInfo:d}}catch(r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var e;const{store:t,common:r}=y.core,i={From_Account:null===(e=t.get("login"))||void 0===e?void 0:e.userId,LatestPendencyTimeStamp:(o=Math.floor(Date.now()/1e3),s=0,Math.round(Number(o)*Math.pow(10,s))/Math.pow(10,s))};var o,s;return function(e){const{ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}(yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:i}))})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){const{from:t,addedApplicationList:r=[],removedApplicationList:i=[]}=e,{isEmpty:o}=this._core.utils;o(r)||this.onApplicationAdded(r,t),o(i)||this.onApplicationDeleted()}onApplicationAdded(e,t){var r;const{store:i,OuterConstant:o}=this._core,s=t===(null===(r=i.get("login"))||void 0===r?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{const t=`${e.userID}_${s}`;s!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:s})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function N(){return e(this,void 0,void 0,function*(){const{common:e}=y.core,t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return function(e){return M(e,e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))}(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}))})}function k(t){return e(this,void 0,void 0,function*(){const{name:e,userIDList:r}=t,{common:i}=y.core,o={From_Account:i.getCurrentUserID(),GroupName:[e],To_Account:r};return function(e){return M(e,e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield i.buildAndSendPacket({servcmd:"sns.group_add",data:o}))})}function P(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))})}function w(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=O(i,l),s={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:s}))})}function G(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=O(i,p),s={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:s}))})}function R(t){return e(this,void 0,void 0,function*(){const{common:e}=y.core,{oldName:r,newName:i}=t,o={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:i};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:o}))})}function O(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function M(e,t){const{CurrentSequence:r,ActionStatus:i,ErrorCode:o,ErrorInfo:s,ErrorDisplay:n,ResultItem:d=[]}=e,a={currentSequence:r,actionStatus:i,errorCode:o,errorInfo:s,errorDisplay:n};return t&&d.length>0?Object.assign(Object.assign({},a),{resultList:d.map(t)}):a}class U{constructor(e){const{name:t="",userIDList:r=[]}=e;this.name=t,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){const t=this.userIDList.indexOf(e);t>-1&&(this.userIDList.splice(t,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),t.registerApi({apiName:"createFriendGroup",context:this}),t.registerApi({apiName:"deleteFriendGroup",context:this}),t.registerApi({apiName:"addToFriendGroup",context:this}),t.registerApi({apiName:"removeFromFriendGroup",context:this}),t.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){const{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendGroupMap.values()];return e.debug(`${t} getFriendGroupListFromCache, data:${r(i)}`),{code:0,data:i}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){const{ssoLog:e}=this._core,r="syncFriendGroupListFromServer";try{const i=yield N(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",`${t} ${r} ok. count: 0`),o.forEach(e=>{const t=new U(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(t){return e(this,void 0,void 0,function*(){const e="createFriendGroup";try{const{name:r}=t;this._checkGroupExist(e,r);const i=yield k(t),{successUserIDList:o,failureUserIDList:s}=this._parseCreateGroupResponse(i),n=new U({name:r,userIDList:o});return this._friendGroupMap.set(r,n),this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:s}}}catch(t){this._handleError(e,t)}})}deleteFriendGroup(t){return e(this,void 0,void 0,function*(){const e="deleteFriendGroup";try{const{name:r}=t;this._checkGroupNotExist(e,r),yield P(t);const i=this._friendGroupMap.get(r);return i&&(this._updateFriendGroup({name:r,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(r)),this._emitGroupListUpdated(),{code:0,data:i}}catch(t){this._handleError(e,t)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:w})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:G})})}renameFriendGroup(t){return e(this,void 0,void 0,function*(){const e="renameFriendGroup";try{const{oldName:r,newName:i}=t;this._checkGroupNotExist(e,r),this._checkGroupExist(e,i),yield R(t);const o=this._updateGroupNameInCache(r,i);return o&&this._updateFriendGroup({name:r,userIDList:o.userIDList,action:_,newName:i}),this._emitGroupListUpdated(),{code:0,data:o}}catch(t){this._handleError(e,t)}})}_updateFriendGroupMember(t){return e(this,void 0,void 0,function*(){const{functionName:e,params:r,protocolFunction:i}=t;try{const{name:t}=r;this._checkGroupNotExist(e,t);const o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(t,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(t){this._handleError(e,t)}})}_updateGroupNameInCache(e,t){const r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){const{resultList:t=[]}=e,r=[],i=[];return t.forEach(({userID:e,resultCode:t,resultInfo:o})=>{f(t)||0===t?r.push(e):i.push({userID:e,code:t,message:o})}),{successUserIDList:r,failureUserIDList:i}}_parseUpdateFriendGroupResponse(e,t){const{resultList:r=[]}=t,i=this._friendGroupMap.get(e),o=[],s=[],n=[];return r.forEach(t=>{0===t.resultCode?i&&(t.updateType===l?this._addFriendToGroup(e,t.userID,i,s):t.updateType===p&&this._removeFriendFromGroup(e,t.userID,i,n)):o.push({userID:t.userID,code:t.resultCode,message:t.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){const{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:s})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){const{name:t,userIDList:r,action:i,newName:o}=e,{userStore:s}=this._core.appStore;t&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{const r=s.getFriend(e);if(!r)return;const{groupList:n}=r;switch(i){case h:-1===n.indexOf(t)&&(n.push(t),r.count=n.length);break;case m:{const e=n.indexOf(t);e>-1&&(n.splice(e,1),r.count=n.length);break}case _:{if(!o)return;const e=n.indexOf(t);-1!==e&&(n[e]=o);break}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var q=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),t.registerApi({apiName:"addToBlacklist",context:this}),t.registerApi({apiName:"removeFromBlacklist",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(`${t} syncBlacklistFromServer`);const i={From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_get",s=e.generateProtocolData({servcmd:o,data:t}),n=`${s.head.seq}${o}`,d=yield i.sendPacket(s,{requestId:n}),{BlackListItem:a=[],StartIndex:c=0}=d;return{blackList:B(a),startIndex:c}})}(i,this._core),{blackList:s=[],startIndex:n=0}=o;return this._startIndex=n,this._addBlacklistMap(s),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r=this._preprocessBlacklist(t),i={From_Account:this._core.common.getCurrentUserID(),To_Account:r},o=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_add",s=e.generateProtocolData({servcmd:o,data:t}),n=`${s.head.seq}${o}`,d=yield i.sendPacket(s,{requestId:n}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(i,this._core),{blackList:s=[]}=o;return this._addBlacklistMap(s),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}removeFromBlacklist(t){return e(this,void 0,void 0,function*(){const{helper:r}=this._core;try{const r={From_Account:this._core.common.getCurrentUserID(),To_Account:t.userIDList},i=yield function(t,r){return e(this,void 0,void 0,function*(){const{helper:e,channel:i}=r,o="sns.black_list_delete",s=e.generateProtocolData({servcmd:o,data:t}),n=`${s.head.seq}${o}`,d=yield i.sendPacket(s,{requestId:n}),{ResultItem:a=[]}=d;return{blackList:B(a)}})}(r,this._core),{blackList:o=[]}=i;return this._deleteBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){const{errorCode:t}=e||{};throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateBlacklist",`${t} updateBlacklist data: ${i(e)}`);const{addedBlacklist:o=[],removedBlacklist:s=[]}=e;let n=!1;if(o.length>0){o.some(e=>!this._blacklistMap.has(e))&&(n=!0,this._addBlacklistMap(o.map(e=>({userID:e}))))}if(s.length>0){s.some(e=>this._blacklistMap.has(e))&&(n=!0,this._deleteBlacklistMap(s.map(e=>({userID:e}))))}n&&this._emitBlackListUpdated()}_addBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",`${t} _addBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t,addBlackTimeStamp:r=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:r})})}_deleteBlacklistMap(e){const{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",`${t} _deleteBlacklistMap blackList: ${i(e)}`),e.forEach(e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)})}_preprocessBlacklist(e){let{userIDList:t}=e;const r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t.includes(r)&&(t=e.userIDList.filter(e=>e!==r)),t}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:r,ssoLog:i,utils:{safeStringify:o}}=this._core,s=Array.from(this._blacklistMap.keys());i.debug(`${t} _emitBlackListUpdated blackList:${o(s)}`),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:s})}};const x={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},$={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var W=new class{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(`${t} install`),this._core=e;const{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:s,WORKFLOW_STEP:n}}=e;y.init(e),g.init(e),T.init(e),b.init(e),q.init(e),r.registerValidateConfig({auth:$,params:x}),r.registerWorkflowStep(s.SYNC_SERVER_INFO_AFTER_LOGIN,n.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){q.syncBlacklistFromServer(),g.syncFriendListFromServer(),T.syncFriendApplicationListFromServer(),b.syncFriendGroupListFromServer()}onFriendModified(e){const{from:t,addedBlacklist:r,removedBlacklist:i,addedFriendList:o,removedFriendList:s,addedApplicationList:n,removedApplicationList:d,friendUpdateInfo:a,reportTime:c}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),{isEmpty:u}=this._core.utils;u(r)&&u(i)||q.updateBlacklist({addedBlacklist:r,removedBlacklist:i}),u(o)&&u(s)||(g.updateFriendList({addedFriendList:o,removedFriendList:s}),T.updateFriendApplicationList({from:t,removedApplicationList:o})),u(a)||g.updateFriendInfo(a),u(n)&&u(d)||T.updateFriendApplicationList({from:t,addedApplicationList:n,removedApplicationList:d}),c&&T.onApplicationRead()}_parseFriendListModification(e){const{PushType:t,From_Account:r,To_Account:i,ReportTime:o,BlackListAdd_Account:s=[],BlackListDel_Account:n=[],FriendAdd_Account:d=[],FriendDel_Account:a=[],PendencyAdd:c=[],FrienPencydDel_Account:u=[],FriendUpInfo:l=[]}=e,p=l.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:t,from:r,to:i,reportTime:o,addedBlacklist:s,removedBlacklist:n,addedFriendList:d,removedFriendList:a,addedApplicationList:c.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:p,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),q.dispose(),g.dispose(),T.dispose(),b.dispose()}};export{W as default};