@tencentcloud/lite-chat 4.1.1 → 4.1.3

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(){let d=new class{init(e){this.core=e}};function c(e,a,r,l){return new(r=r||Promise)(function(s,t){function n(e){try{i(l.next(e))}catch(e){t(e)}}function o(e){try{i(l.throw(e))}catch(e){t(e)}}function i(e){var t;e.done?s(e.value):((t=e.value)instanceof r?t:new r(function(e){e(t)})).then(n,o)}i((l=l.apply(e,a||[])).next())})}let u=e=>{var{OuterConstant:t,utils:{isString:s}}=d["core"];return s(e)&&e.slice(0,3)===t.CONV_C2C},_=e=>{var{OuterConstant:t,utils:{isString:s}}=d["core"];return s(e)&&e.slice(0,5)===t.CONV_GROUP},t=e=>{var{OuterConstant:t,utils:{isString:s}}=d["core"];return s(e)&&e===t.CONV_SYSTEM},s=e=>({lastTime:(null==e?void 0:e.time)||(null==e?void 0:e.lastTime)||0,lastSequence:(null==e?void 0:e.sequence)||(null==e?void 0:e.lastSequence)||0,fromAccount:(null==e?void 0:e.from)||(null==e?void 0:e.fromAccount)||"",messageForShow:d.core.common.getMessagePreviewText(null==e?void 0:e.type,null==e?void 0:e.payload),payload:(null==e?void 0:e.payload)||null,type:(null==e?void 0:e.type)||"",isRevoked:(null==e?void 0:e.isRevoked)||!1,cloudCustomData:(null==e?void 0:e.cloudCustomData)||"",onlineOnlyFlag:(null==e?void 0:e._onlineOnlyFlag)||!1,nick:(null==e?void 0:e.nick)||"",nameCard:(null==e?void 0:e.nameCard)||"",version:(null==e?void 0:e.version)||0,isPeerRead:(null==e?void 0:e.isPeerRead)||!1,revoker:(null==e?void 0:e.revoker)||null});function r(e){var t=d.core["OuterConstant"];let s="";return 0===e?s=t.MSG_REMIND_ACPT_AND_NOTE:1===e?s=t.MSG_REMIND_DISCARD:2===e?s=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(s=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function h(e){var t=d.core["OuterConstant"];let s;return"@TLS#ERROR"===(s=e.startsWith(t.CONV_C2C)?e.replace(t.CONV_C2C,""):s)||"@TLS#NOT_FOUND"===s}function n(e,t){var s=d.core["helper"],s=new s.ChatError({functionName:e,code:(null==t?void 0:t.errorCode)||(null==t?void 0:t.code),message:(null==t?void 0:t.errorInfo)||(null==t?void 0:t.message)});throw console.error(e+" fail:",s),s}class C{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=s(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){var{OuterConstant:e,utils:{isUndefined:t}}=d["core"];t(this.userProfile)&&this.type===e.CONV_C2C?this.userProfile={}:t(this.groupProfile)&&this.type===e.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===e.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){var{OuterConstant:t,utils:{isUndefined:s}}=d["core"],{nextUnreadCount:e,isFromGetConversations:n,isUnreadC2CMessage:o}=e;s(e)||(this.subType!==t.GRP_AVCHATROOM?n&&this.type===t.CONV_GROUP||o&&this.type===t.CONV_C2C?this.unreadCount=e:this.unreadCount+=e:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=s(e)}reduceUnreadCount(){return 1<=this.unreadCount&&(--this.unreadCount,!0)}isLastMessageRevoked(e){var t=d["core"]["OuterConstant"],{sequence:e,time:s}=e;return this.type===t.CONV_C2C&&e===this.lastMessage.lastSequence&&s===this.lastMessage.lastTime||this.type===t.CONV_GROUP&&e===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(e){var{common:{updateGroupAtInfo:t}}=d["core"];t(e,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var l,p,v,e;(e=l=l||{})[e.OFF=0]="OFF",e[e.ON=1]="ON",p=p||{},p[p.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID",(e=v=v||{})[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE";var g=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){var{helper:t,notificationCenter:s,appStore:{conversationStore:n},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{SYNC_CONVERSATION_LIST:a,MESSAGE_PUSH:r,NEW_MESSAGE:l,MESSAGE_DELETED:d,MESSAGE_REVOKED:c,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:_,LOGOUT:h,DESTROY:C},InnerEventSubType:{C2C_MESSAGE_PEER_READ:p}}=this._core=e,n=(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),s)["InnerEventSubType"]["GROUP_AT_TIPS"];s.subscribeInnerEvent(a,this._handleConversationSynced,this),s.subscribeInnerEvent(l,this._handleNewMessage,this),s.subscribeInnerEvent(r,n,this._handleNewGroupAtTips,this),s.subscribeInnerEvent(d,this._handleMessageDeleted,this),s.subscribeInnerEvent(c,this._handleMessageRevoked,this),s.subscribeInnerEvent(u,this._handleMessageModified,this),s.subscribeInnerEvent(_,this._handleConversationUpdated,this),s.subscribeInnerEvent(r,p,this._handleMessageRead,this),s.subscribeInnerEvent(h,this._reset,this),s.subscribeInnerEvent(C,this._dispose,this),e.ssoLog.debug(this._name+".init")}_handleConversationSynced(e){this.updateLocalConversationList({conversationUpdateFieldList:e.conversationUpdateFieldList||[],isFromGetConversations:!0,updateUnreadCount:!0}),this.emitConversationListUpdate()}_handleUnreadSyncFinished(e){let{WORKFLOW_STEP:t}=this._core["constants"],{conversationUpdateFieldList:s=[],groupTipList:n=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{},i=!1;s.forEach(e=>{var{conversationID:e,unreadCount:t}=e,e=this.getLocalConversation(e);e&&e.unreadCount!==t&&(e.updateUnreadCount({nextUnreadCount:t,isUnreadC2CMessage:o}),i=!0)}),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(n)}_handleGroupAtTipsSynced(t){var s;for(let e=0;e<t.length;e++)if(12===t[e].Event){if(null!=(s=t[e].GroupTips[0].MsgBody)&&s.TopicId)continue;this._handleNewGroupAtTips(t[e])}}_handleGroupListSyncFinished(e){let n,{WORKFLOW_STEP:t}=this._core.constants,o=e.result[t.GROUP_LIST_SYNC]||[],{CONV_GROUP:i}=this._core.OuterConstant,a=!1;for(let s=0;s<o.length;s++){let e=o[s],t=""+i+e.groupID;var r;this.hasLocalConversation(t)&&((r=this.getLocalConversation(t)).groupProfile=JSON.parse(JSON.stringify(e)),r.lastMessage.lastSequence<e.nextMessageSeq&&(r.lastMessage.lastSequence=e.nextMessageSeq-1),r.subType||(r.subType=e.type),0<(null==(n=e._groupAtInfoList)?void 0:n.length)&&this._handleNewGroupAtTips({GroupTips:e._groupAtInfoList}),a=!0)}a&&this.emitConversationListUpdate()}_handleNewMessage(e){var t,{conversationUpdateFieldList:e=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e.result||{};0===e.length||({isTopic:t}=this._core["common"],t(e[0].conversationID))||(this.updateLocalConversationList({conversationUpdateFieldList:e,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o}),0<e.filter(e=>this._isConversationNeedShow(e.conversationID)).length&&this.emitConversationListUpdate())}_handleNewGroupAtTips(e){var{GroupTips:e=[]}=e;e.forEach(e=>{var{GroupAtTips:t,MsgBody:s,MsgRandom:n,ClientSeq:o}=e;let i={};t?i=this._convertGroupAtTipsKey(t):s?i=Object.assign({},this._convertGroupAtTipsKey(s)):e.groupAtType&&(i=Object.assign({},e)),i.__random=n,i.__sequence=o,this._groupAtTipsList.push(i)}),console.log(this._name+"._handleNewGroupAtTips groupAtTipsList: "+JSON.stringify(this._groupAtTipsList)),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){var{From_Account:e,GroupId:t,MsgSeq:s,GroupAtType:n}=e;return{from:e,groupID:t,sequence:s,groupAtType:n}}_updateGroupAtInfoList(){if(0!==this._groupAtTipsList.length){let{common:e,OuterConstant:n}=this._core,o=e.getCurrentUserID(),i=!1;this._groupAtTipsList.forEach(t=>{var{groupID:s,from:e}=t;if(e!==o){let e=this.getLocalConversation(""+n.CONV_GROUP+s);e&&(e.updateGroupAtInfoList(t),i=!0)}}),i&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}}_handleMessageDeleted(t){console.log(this._name+"._handleMessageDeleted, conversationID:",t);var s,{message:{messageDataHandler:n},OuterConstant:o}=this._core,i=(null==n?void 0:n.getLocalMessageList(t))||[];let a={};for(let e=(i.length||0)-1;0<=e;e--)if(!i[e].isDeleted){a=i[e];break}n=this.getLocalConversation(t);if(n){let e=!1;n.lastMessage.lastSequence===a.sequence&&n.lastMessage.lastTime===a.time||(null!=(s=null==(s=this._core)?void 0:s.helper)&&s.isEmpty(a)&&(a=void 0),n.updateLastMessage(a),e=!0),t.startsWith(o.CONV_C2C)&&this.updateUnreadCount(t),e&&(this.emitConversationListUpdate(),console.log(this._name+`._handleMessageDeleted. update conversationID:${t} with lastMessage:`,n.lastMessage))}}_handleMessageRevoked(e){let{messageList:n=[],updateUnreadCount:o=!0}=e;if(console.log(this._name+"._handleMessageRevoked messageList:"+n.length),0!==n.length){let t=null,s=!1;n.forEach(e=>{(t=this.getLocalConversation(e.conversationID))&&(o&&t.reduceUnreadCount()&&(s=!0),t.isLastMessageRevoked({sequence:e.sequence,time:e.time}))&&(t.setLastMessageRevoked(!0),t.setLastMessageRevoker(e.revoker),s=!0)}),s&&this.emitConversationListUpdate()}}_handleMessageModified(e){console.log(this._name+"._handleMessageModified",JSON.stringify(e));var{conversationID:t,messageList:s}=e,e=this.getLocalConversation(t),{utils:{isEmpty:n},common:{getMessagePreviewText:o}}=this._core;if(!n(e)){n=e["lastMessage"];if(n){let e=(null==s?void 0:s[0])||{};n.lastTime===e.time&&n.lastSequence===e.sequence&&n.version!==e.version&&(n.type=e.type,n.payload=e.payload,n.messageForShow=o(e.type,e.payload),n.cloudCustomData=e.cloudCustomData,n.version=e.version,this.emitConversationListUpdate(),console.log(this._name+` conversationID:${t} lastMessage updated`))}}}_handleConversationUpdated(e){this.emitConversationListUpdate(null==e?void 0:e.needSort)}updateLocalConversationList(e){var t=e["isFromGetConversations"],e=this._getTmpConversationListMapping(e)["newConversationList"];this._sortConversationList(),t||this._updateNewConversationProfile(e),this._core.ssoLog.debug("updateLocalConversationList"," newConversationList: "+e.length)}_getTmpConversationListMapping(e){let i=this._core["OuterConstant"],{conversationUpdateFieldList:a,isFromGetConversations:r,isInstantMessage:l,isUnreadC2CMessage:d=!1,updateUnreadCount:c}=e,u=[],t=null==a?void 0:a.length;for(let o=0;o<t;o++){let t=new C(a[o]),{conversationID:s,type:n}=t;if(!h(s))if(this.hasLocalConversation(s)){let e=this.getLocalConversation(s);r?(this.setLocalConversation(s,t),n===i.CONV_C2C?t.unreadCount=(null==e?void 0:e.unreadCount)||0:n===i.CONV_GROUP&&(t.groupProfile=JSON.parse(JSON.stringify(null==e?void 0:e.groupProfile)))):(this._mergeConversationInfo({conversationID:s,tmpConversation:t,lastMessage:a[o].lastMessage,isFromGetConversations:r,isInstantMessage:l}),this._patchLastMessage({conversationID:s,lastMessage:a[o].lastMessage,isInstantMessage:l}),!0===c&&null!=e&&e.updateUnreadCount({nextUnreadCount:t.unreadCount,isFromGetConversations:r,isUnreadC2CMessage:d}))}else u.push(t),this.setLocalConversation(s,t)}return{newConversationList:u}}_mergeConversationInfo(e){var{conversationID:e,tmpConversation:t,lastMessage:s,isFromGetConversations:n,isInstantMessage:o}=e,e=this.getLocalConversation(e),i=["unreadCount","allowType","adminForbidType","payload"],{utils:{isUndefined:n,isEmpty:a},common:{deepMerge:r}}=(!1===o&&i.push("lastMessage"),n&&i.push("isPinned"),this._core);n(o)&&s&&null===(null==e?void 0:e.lastMessage.payload)&&(e.lastMessage.payload=s.payload),a(null==e?void 0:e.lastMessage.revoker)||(e.lastMessage.revoker=null),r(e,t,i,[null,void 0,"",0,NaN])}_patchLastMessage(e){let o=this._core["OuterConstant"],{conversationID:t,lastMessage:i,isInstantMessage:a}=e,r=this.getLocalConversation(t);if(r&&i){let{payload:e,nameCard:t,nick:s,cloudCustomData:n=""}=i;a&&(e&&(r.lastMessage.payload=e),r.type===o.CONV_GROUP)&&(r.lastMessage.nameCard=t,r.lastMessage.nick=s),r.lastMessage.cloudCustomData!==n&&(r.lastMessage.cloudCustomData=n)}}_sortConversationList(){let{isEmpty:t}=this._core["utils"],e=[...this._conversationStore.getConversationMap()],s=[],n=[],o=[],i=[];e.forEach(e=>{(!0===e[1].isPinned?t(e[1].lastMessage.lastTime)?n:s:t(e[1].lastMessage.lastTime)?i:o).push(e)});var a=s.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime).concat(n).concat(o.sort((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(i);this._updateConversationMapFromList(a)}_updateNewConversationProfile(e){if(0!==e.length){let s=[],n=[],{CONV_GROUP:o,CONV_C2C:i}=this._core["OuterConstant"];e.forEach(e=>{var{conversationID:t,type:e}=e;if(e===i){let e=t.replace(i,"");s.push(e)}else if(e===o){let e=t.replace(o,"");n.push(e)}}),0<s.length&&this._updateC2CConversation(s),0<n.length&&this._updateGroupConversation(n)}}_updateC2CConversation(e){let t,{OuterConstant:{CONV_C2C:o},appStore:{userStore:i},user:s}=this._core,a=!1;null!=(t=s.userProfile)&&t.getUserProfile({userIDList:e}).then(e=>{((null==e?void 0:e.data)||[]).forEach(t=>{var s=t["userID"],n=this.getLocalConversation(""+o+s);if(n){let e=(null==(s=i.getFriend(s))?void 0:s.remark)||"";n.remark=e,n.userProfile=t,a=!0}}),a&&this.emitConversationListUpdate()}).catch(e=>{})}_updateGroupConversation(e){let{OuterConstant:{CONV_GROUP:s},appStore:{groupStore:n}}=this._core,o=!1;e.forEach(e=>{var t=n.getGroup(e),e=this.getLocalConversation(""+s+e);t&&e&&(e.groupProfile=t,o=!0)}),o&&this.emitConversationListUpdate()}_handleMessageRead(e){let{CONV_C2C:n}=this._core["OuterConstant"],{C2cNotifyMsgArray:t=[]}=e||{};t.forEach(e=>{let{To_Account:s,UinPairReadArray:t=[]}=(null==e?void 0:e.C2cReadedReceipt)||{};null!=t&&t.forEach(e=>{var e=e["LastReadTime"],t=""+n+s;this._updateConversationReadInfo({conversationID:t,peerReadTime:e}),this._updateMessageListPeerRead({conversationID:t,peerReadTime:e})})})}_updateConversationReadInfo(e){var{appStore:t,utils:{isEmpty:s},common:{getCurrentUserID:n}}=this._core,{conversationID:o,peerReadTime:i}=e,a=t.conversationStore.getConversationMap();if(a.has(o)){let e=a.get(o);e.peerReadTime=i;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){let{notificationCenter:t,OuterEvent:s,message:n}=this._core,{conversationID:o,peerReadTime:i}=e,a=n.messageDataHandler.getLocalMessageList(o),r=n.messageDataHandler.getSparseMessageList(o),l=[];a.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,l.push(e))}),r.forEach(e=>{e.time<=i&&!e.isPeerRead&&"out"===e.flow&&(e.isPeerRead=!0,l.push(e))}),t.emitOuterEvent(s.MESSAGE_READ_BY_PEER,{name:s.MESSAGE_READ_BY_PEER,data:l})}_isConversationNeedShow(e){var{OuterConstant:{CONV_GROUP:t,GRP_ROOM:s,GRP_LIVE:n},utils:{isUndefined:o}}=this._core,e=this.getLocalConversation(e);return!(!o(e)&&(o=e.type===t&&(null==(o=e.groupProfile)?void 0:o.type)===s,t=e.type===t&&(null==(s=e.groupProfile)?void 0:s.type)===n,o||t))}updateUnreadCount(e,t=!0){let s,n,o=!1;var i,a=this.getLocalConversation(e),r=null==(n=null==(s=this._core)?void 0:s.message.messageDataHandler)?void 0:n.getLocalMessageList(e);return a&&(i=a.unreadCount,r=null==r?void 0:r.filter(e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted).length,console.log(this._name+`._updateUnreadCount conversationID:${e} currentUnreadCount:${i} newUnreadCount:`+r),i!==r)&&(a.unreadCount=r,(o=!0)===t)&&this.emitConversationListUpdate(),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();var e=this._core["OuterEvent"]["CONVERSATION_LIST_UPDATED"],t=this.getLocalConversationList();this._emitEvent({name:e,data:t}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e,t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(this._core.ssoLog.debug("_emitTotalUnreadCountUpdate",` from ${this._totalUnreadCount} to `+t),this._totalUnreadCount=t,this._emitEvent({name:null==(e=this._core)?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null!=(t=this._core)&&t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){let{OuterConstant:t,utils:{isEmpty:s}}=this._core,e=this.getLocalConversationList(),n=0;return e.forEach(e=>{e.type===t.CONV_SYSTEM||!s(e.messageRemindType)&&e.messageRemindType!==t.MSG_REMIND_ACPT_AND_NOTE||(n+=e.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(var[t,s]of e)this.setLocalConversation(t,s)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let s=!1;e.forEach(e=>{e=this.getLocalConversation(e);(null==e?void 0:e.messageRemindType)!==t&&(e.messageRemindType=t,s=!0)}),console.log(this._name+`.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:`+s),s&&this.emitConversationListUpdate()}markMessageAsRead(e){let{messageDataHandler:t}=this._core["message"],{conversationID:s,lastReadTime:o=0,lastReadSequence:i=0}=e,a=null==t?void 0:t.getLocalMessageList(s);if(0!==a.length){let e=a["length"];for(let n=e-1;0<=n;n--){let e=a[n],t=o&&e.time>o,s=i&&e.sequence>i;if(!t&&!s){if("in"===e.flow&&e.isRead)break;e.setIsRead(!0)}}}}appendToPinnedConversation(e){var t=[...this._conversationStore.getConversationMap().entries()],s=t.findIndex(e=>!1===e[1].isPinned);t.splice(s,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){var{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:s,MESSAGE_REVOKED:n,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:a,DESTROY:r,SYNC_CONVERSATION_LIST:l}}=this._core,{GROUP_AT_TIPS:d}=e["InnerEventSubType"];e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,d,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(s,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(n,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(l,this._handleConversationSynced,this),e.unSubscribeInnerEvent(a,this._reset,this),e.unSubscribeInnerEvent(r,this._dispose,this)}},m=new class{constructor(){this._name="GetConversationList"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return c(this,void 0,void 0,function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:this._core.conversation.syncConversationHandler.isSyncCompleted()}}})}_getConversationList(a){let{isUndefined:e,isArray:t,isPlainObject:s}=this._core["utils"];if(e(a))return g.getLocalConversationList();if(t(a))return 0===a.length?[]:g.getLocalConversationList().filter(e=>a.includes(e.conversationID));if(s(a)){let{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=a;return g.getLocalConversationList().filter(e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i))}return[]}_filterType(e,t){var s=this._core["OuterConstant"];return t!==s.CONV_C2C&&t!==s.CONV_GROUP||e.type===t}_filterGroupName(e,t){var{isString:s}=this._core["utils"];return!s(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){var{isNumber:s}=this._core["utils"];return!s(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let s=!0;return!0===t?s=1<=e.unreadCount:!1===t&&(s=0===e.unreadCount),s}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=1<=e.groupAtInfoList.length:!1===t&&(s=0===e.groupAtInfoList.length),s}},f=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(n){return c(this,void 0,void 0,function*(){try{var e=this._core["common"],t=yield function(s,n){return c(this,void 0,void 0,function*(){var{toAccount:e,userIDList:t}=s;return n.common.buildAndSendPacket({servcmd:"openim.get_c2c_peer_mute_notifications",data:{To_Account:e,Peer_Account:t}})})}({toAccount:e.getCurrentUserID(),userIDList:n},this._core),{MuteNotificationsList:s=[]}=t||{};s.forEach(e=>{var{Peer_Account:e,MuteNotifications:t}=e,e=""+this._core.OuterConstant.CONV_C2C+e,t=r(t);g.patchMessageRemindType([e],t)})}catch(e){console.error(this._name+".get fail:",e)}})}},M=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(s){return c(this,void 0,void 0,function*(){if(0!==s.length)try{var e=yield function(s,n){return c(this,void 0,void 0,function*(){var{groupIDList:e,responseFilter:t}=s;return n.common.buildAndSendPacket({servcmd:"group_open_http_svc.get_group_self_member_info",data:{GroupIdList:e,ResponseFilter:t}})})}({groupIDList:s,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:t=[]}=e||{};t.forEach(e=>{var{GroupId:e,MemberList:t}=e,t=(null==(t=t[0])?void 0:t.MsgFlag)||"",e=""+this._core.OuterConstant.CONV_GROUP+e;g.patchMessageRemindType([e],t)})}catch(e){console.error(this._name+".get fail:",e)}})}},E=new class{constructor(){this._name="GetConversationProfile"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(d){return c(this,void 0,void 0,function*(){let{OuterConstant:{CONV_C2C:s,CONV_GROUP:n,GRP_AVCHATROOM:o},appStore:{groupStore:i},utils:{isEmpty:e}}=this._core,a={code:0,data:{}},r=g.getLocalConversation(d);if(t(d))a.data.conversation=r;else{let t=!1;var l=u(d)?s:n;if(e(r)&&(t=!0,r=new C({conversationID:d,type:l})),console.log(this._name+`.getConversationProfile conversationID:${d} isNewConversation:`+t),null==(a.data.conversation=r)||!r.getProfileCompleted()){if(l===s){let e=d.replace(s,"");yield this._handleC2CConversation(r,e),t&&(yield f.get([e]))}if(l===n){let e=d.replace(n,"");if(!i.getGroup(e))return a;yield this._handleGroupConversation(r,e),t&&r.groupProfile.type!==o&&(yield M.get([e]))}}}return a})}_handleC2CConversation(a,r){return c(this,void 0,void 0,function*(){var{user:e,helper:t,utils:{isEmpty:s},appStore:{conversationStore:n,userStore:o}}=this._core,i=a["conversationID"],e=yield null==(e=e.userProfile)?void 0:e.getUserProfile({userIDList:[r]});if(0===(null==e?void 0:e.data.length))throw new t.ChatError({code:v.USER_OR_GRP_NOT_FOUND});a.userProfile=null==e?void 0:e.data[0];e=null==(t=o.getFriend(r))?void 0:t.remark,s(e)||a.remark===e||(a.remark=e),a.setProfileCompleted(),o=g.hasLocalConversation(i);console.log(this._name+`._handleC2CConversation conversationID:${i} hasLocalConversation: `+o),o?n.updateConversation(i,a):g.appendToPinnedConversation(a)})}_handleGroupConversation(n,o){return c(this,void 0,void 0,function*(){var{apiMap:{getGroupProfile:e},appStore:{conversationStore:t}}=this._core,s=n["conversationID"],e=yield e({groupID:o}),e=(n.groupProfile=null==e?void 0:e.data.group,n.setProfileCompleted(),g.hasLocalConversation(s));console.log(this._name+`._handleGroupConversation conversationID:${s} hasLocalConversation: `+e),e?t.updateConversation(s,n):g.appendToPinnedConversation(n)})}},R=new class{init(e){e=e.helper;e.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return g.getTotalUnreadMessageCount()}},S=new class{constructor(){this._serverGroupConversationLastReadSeqMap=new Map,this._name="SetMessageRead"}init(e){let{helper:t,common:{isTopic:s},notificationCenter:n,InnerEvent:{MESSAGE_PUSH:o},InnerEventSubType:{ALL_MESSAGE_READ:i}}=this._core=e;t.registerApi({apiName:"setMessageRead",context:this,matcher:e=>!s(e[0].conversationID)}),t.registerApi({apiName:"setAllMessageRead",context:this}),n.subscribeInnerEvent(o,i,this._handleAllMessageRead,this)}handleC2CMessageReadSync(e){let{helper:{isEmpty:s},OuterConstant:n}=this._core;e.forEach(e=>{var t=e["ReadC2cMsgNotify"];if(!s(t)){let{UinPairReadArray:e=[]}=t;e.forEach(e=>{var{From_Account:e,LastReadTime:t}=e,e=""+n.CONV_C2C+e;console.log(this._name+`.handleC2CMessageReadSync conversationID:${e} lastReadTime:`+t),g.markMessageAsRead({conversationID:e,lastReadTime:t}),g.updateUnreadCount(e)})}})}handleGroupMessageReadSync(e){let{OuterConstant:s,utils:{isUndefined:t}}=this._core;e.forEach(e=>{e=e.MsgBody.GroupReadInfoArray;t(e)||e.forEach(e=>{var{GroupId:e,LastReadMsgSeq:t}=e,e=""+s.CONV_GROUP+e;console.log(this._name+`.handleGroupMessageReadSync conversationID:${e} lastReadSequence:`+t),g.markMessageAsRead({conversationID:e,lastReadSequence:t}),g.updateUnreadCount(e),this._clearGroupAtInfoList(e)})})}setMessageRead(l){return c(this,void 0,void 0,function*(){var e,t=this._core["OuterConstant"],s=l["conversationID"],n={code:0,data:{}},o=g.getLocalConversation(s);let i=this._name+`.setMessageRead conversationID:${s} unreadCount:`+((null==o?void 0:o.unreadCount)||0);if(n.successLog={message:i},!o)return n;var a=!(null!=(e=null==(a=this._core)?void 0:a.helper)&&e.isEmpty(o.groupAtInfoList));if(o.type===t.CONV_GROUP&&a&&this._deleteGroupAtTips(s),0===o.unreadCount)return n;var r=this._core["helper"]["ChatError"];try{if(o.type===t.CONV_C2C){let e=this._getLocalMessageMaxTime(o);yield this._setC2CMessageRead(s,e),i+="lastMessageTime:"+e}if(o.type===t.CONV_GROUP){let e=this._getLocalMessageMaxSequence(o);yield this._setGroupMessageRead(s,e),i+="lastMessageSequence:"+e}}catch(e){let{errorCode:t,errorInfo:s}=e;throw new r({functionName:"setMessageRead",code:t,message:s,moreMessage:i})}return o.type===t.CONV_SYSTEM&&(o.unreadCount=0),g.emitConversationListUpdate(),Object.assign(Object.assign({},n),{successLog:{message:i}})})}setAllMessageRead(){return c(this,arguments,void 0,function*(e={}){let{OuterConstant:{READ_ALL_MSG:t},utils:{safeStringify:o}}=this._core,i="scope:"+e.scope;e.scope||(e.scope=t);var e=e["scope"],s=this._generateSetAllMessageReadRequestData(e);if(0===s.allC2CMessageReadStatus&&0===s.groupMessageReadInfoList.length)return{code:0};try{let n=yield function(s){return c(this,void 0,void 0,function*(){var{allC2CMessageReadStatus:e,groupMessageReadInfoList:t}=s,e={C2CReadAllMsg:e,GroupReadInfo:t};return d.core.common.buildAndSendPacket({servcmd:"openim.read_all_unread_msg",data:e})})}(s);if(n){let{GroupReadInfoArray:e,C2CReadAllMsg:t}=n,s=this._parseGroupReadInfo(e);0<this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})&&g.emitConversationListUpdate(),i+="failureGroupInfoList:"+o(s)}return{code:0,successLog:{message:i}}}catch(e){let t=e["errorCode"];throw new this._core.helper.ChatError({functionName:"setAllMessageRead",code:t,moreMessage:i})}})}_handleAllMessageRead(e){var{GroupReadInfoArray:e,C2CReadAllMsg:t}=e;this._parseGroupReadInfo(e),0<this._updateAllConversationReadStatus({allC2CMessageReadStatus:t})&&g.emitConversationListUpdate()}_updateAllConversationReadStatus(e){let{OuterConstant:{CONV_C2C:n,CONV_GROUP:o},appStore:t}=this._core,i=t.conversationStore.getConversationMap(),a=e["allC2CMessageReadStatus"],r=0;for(let[s,t]of i)if(1<=t.unreadCount){if(1===a&&t.type===n){let e=this._getLocalMessageMaxTime(t);g.markMessageAsRead({conversationID:s,lastReadTime:e})}else if(t.type===o){let t=s.replace(o,"");if(this._serverGroupConversationLastReadSeqMap.has(t)){let e=this._serverGroupConversationLastReadSeqMap.get(t);g.markMessageAsRead({conversationID:s,lastReadSequence:e})}}g.updateUnreadCount(s,!1)&&(r+=1)}return r}_generateSetAllMessageReadRequestData(n){let{OuterConstant:{CONV_C2C:o,CONV_GROUP:i,READ_ALL_C2C_MSG:a},appStore:e}=this._core,r={allC2CMessageReadStatus:0,groupMessageReadInfoList:[]},t=e.conversationStore.getConversationMap();for(let[,s]of t){let{type:e,unreadCount:t}=s;if(this._shouldSetAllMessageRead({scope:n,type:e,unreadCount:t}))if(e===o&&0===r.allC2CMessageReadStatus){if(r.allC2CMessageReadStatus=1,n===a)break}else if(e===i){let e=this._getLocalMessageMaxSequence(s),t=s.groupProfile["groupID"];r.groupMessageReadInfoList.push({GroupId:t,MsgSeq:e})}}return r}_parseGroupReadInfo(e){let{isUndefined:o}=this._core["utils"],i=[];return null!=e&&e.forEach(e=>{var{GroupId:e,MsgSeq:t,RetCode:s,LastReadMsgSeq:n}=e;o(s)?this._serverGroupConversationLastReadSeqMap.set(e,n):(this._serverGroupConversationLastReadSeqMap.set(e,t),0!==s&&i.push(e+`-${t}-`+s))}),i}_deleteGroupAtTips(a){return c(this,void 0,void 0,function*(){console.log(this._name+"._deleteGroupAtTips conversationID:"+a);let e=g.getLocalConversation(a);if(e){var i=(null==e?void 0:e.groupAtInfoList)||[];if(0!==i.length)try{let{common:{getCurrentUserID:t,isCommunity:e},OuterConstant:{CONV_GROUP:s,CONV_AT_ALL:n}}=this._core,o=[...i];e({groupID:a.replace(s,"")})&&0===(o=i.filter(e=>!e.atTypeArray.includes(n))).length?this._clearGroupAtInfoList(a,!1):(yield function(t,s){return c(this,void 0,void 0,function*(){var e=t["messageListToDelete"];return s.common.buildAndSendPacket({servcmd:"openim.deletemsg",data:{DelMsgList:e}})})}({messageListToDelete:o.map(e=>({From_Account:e.from,To_Account:t(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID}))},this._core),console.log(this._name+"._deleteGroupAtTips ok. count:"+i.length),this._clearGroupAtInfoList(a))}catch(e){console.error(this._name+"._deleteGroupAtTips fail:",e)}}})}_clearGroupAtInfoList(e,t=!0){var s=g.getLocalConversation(e);s&&(0<s.groupAtInfoList.length&&(s.clearGroupAtInfoList(),console.log(this._name+`._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:`+t)),t)&&g.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t=e["conversationID"],t=this._core.message.messageDataHandler.getLocalMessageList(t),t=Math.max(...t.map(e=>e.time));let s=(null==(e=null==e?void 0:e.lastMessage)?void 0:e.lastTime)||0;return t>s&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${s} to `+t),s=t),s}_getLocalMessageMaxSequence(e){var t=e["conversationID"],t=this._core.message.messageDataHandler.getLocalMessageList(t),t=Math.max(...t.map(e=>e.sequence));let s=(null==(e=null==e?void 0:e.lastMessage)?void 0:e.lastSequence)||0;return t>s&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${s} to `+t),s=t),s}_setC2CMessageRead(e,t){return c(this,void 0,void 0,function*(){try{yield function(e,t){return c(this,void 0,void 0,function*(){return t.common.buildAndSendPacket({servcmd:"openim.msgreaded",data:e})})}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:t,Receipt:1}]}},this._core),console.log(this._name+"._setC2CMessageRead ok, lastReadTime:"+t),g.markMessageAsRead({conversationID:e,lastReadTime:t}),g.updateUnreadCount(e)}catch(e){throw console.warn(this._name+"._setC2CMessageRead fail:",e),e}})}_setGroupMessageRead(e,t){return c(this,void 0,void 0,function*(){try{yield function(s,n){return c(this,void 0,void 0,function*(){var{groupID:e,lastMessageSequence:t}=s;return n.common.buildAndSendPacket({servcmd:"group_open_http_svc.msg_read_report",data:{GroupId:e,MsgReadedSeq:t}})})}({groupID:e.replace("GROUP",""),lastMessageSequence:t},this._core),console.log(this._name+"._setGroupMessageRead ok, lastReadSequence:"+t),g.markMessageAsRead({conversationID:e,lastReadSequence:t}),g.updateUnreadCount(e)}catch(e){throw console.warn(this._name+"._setGroupMessageRead fail:",e),e}})}_shouldSetAllMessageRead(e){var{CONV_C2C:t,CONV_GROUP:s,READ_ALL_MSG:n,READ_ALL_C2C_MSG:o,READ_ALL_GROUP_MSG:i}=this._core["OuterConstant"],{type:e,scope:a,unreadCount:r}=e;return!(r<=0||(e!==t||![n,o].includes(a))&&(e!==s||![n,i].includes(a)))}},I=new class{constructor(){this._name="PinConversation"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,a){var{isArray:t}=this._core["utils"];if(t(e)){let o=this._core["OuterConstant"],i=!1;e.forEach(e=>{var{Type:e,To_Account:t,GroupId:s}=e;let n;1===e?n=g.getLocalConversation(""+o.CONV_C2C+t):2===e&&(n=g.getLocalConversation(""+o.CONV_GROUP+s)),n&&(console.log(`${this._name}.handleConversationPinned conversationID:${n.conversationID} localPinned:${n.isPinned} remotePinned:`+a),a&&!n.isPinned&&(n.isPinned=!0,i=!0),!a)&&n.isPinned&&(n.isPinned=!1,i=!0)}),i&&g.emitConversationListUpdate(!0)}}pinConversation(e){return c(this,void 0,void 0,function*(){var{OuterConstant:s,common:n,helper:{ChatError:o}}=this._core,{conversationID:i,isPinned:a}=e,r={code:0,data:{conversationID:i}},l=g.getLocalConversation(i);if(l&&l.isPinned===a)return r;if(t(i))return l&&(l.isPinned=a),g.emitConversationListUpdate(!0),r;var d=`conversationID:${i} isPinned:`+a;try{let e=null,t=(u(i)?e={Type:1,To_Account:i.replace(s.CONV_C2C,"")}:_(i)&&(e={Type:2,GroupId:i.replace(s.CONV_GROUP,"")}),yield function(n,o){return c(this,void 0,void 0,function*(){var{fromAccount:e,operationType:t,itemList:s}=n;return o.common.buildAndSendPacket({servcmd:"recentcontact.top",data:{From_Account:e,OperationType:t,RecentContactItem:s}})})}({fromAccount:n.getCurrentUserID(),operationType:!0===a?1:2,itemList:[e]},this._core));if(t){if(l)l.isPinned!==a&&(l.isPinned=a);else{let e=new C({conversationID:i,type:u(i)?s.CONV_C2C:s.CONV_GROUP,isPinned:a});g.setLocalConversation(i,e)}g.emitConversationListUpdate(!0)}return Object.assign(Object.assign({},r),{successLog:{message:d}})}catch(e){let{errorCode:t,errorInfo:s}=e;throw new o({functionName:"pinConversation",code:t,message:s,moreMessage:d})}})}},L=new class{constructor(){this._name="DeleteConversation"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){var{isArray:t}=this._core["utils"];if(t(e)){let n=this._core["OuterConstant"],o=[];e.forEach(e=>{var{Type:e,Peer_Account:t,GroupId:s}=e;1===e&&o.push(""+n.CONV_C2C+t),2===e&&o.push(""+n.CONV_GROUP+s)}),console.log(this._name+".handleConversationDeleted conversationIDList:"+o),this._deleteLocalConversationList(o)}}deleteConversation(t){return c(this,void 0,void 0,function*(){var e=this._core["utils"]["isString"];e(t)?yield this._deleteConversation({conversationIDList:[t],flag:p.ONLY_CONVERSATIONID}):(100<(e=Object.assign({},t)).conversationIDList.length&&(e.conversationIDList=e.conversationIDList.slice(0,100)),yield this._deleteConversation(e))})}_deleteConversation(e){return c(this,void 0,void 0,function*(){let{conversationIDList:s,clearHistoryMessage:n=!0,flag:o=0}=e,{ChatError:i}=this._core["helper"],a=`conversationIDList:${s} clearHistoryMessage:`+n;try{let e=yield Promise.all([this._deleteConversationFromLocal(s),this._deleteConversationFromServer(s,n)]),t=[...e[0],...e[1]];if(0===t.length)throw new this._core.helper.ChatError({code:v.CONV_NOT_FOUND});return{code:0,data:o===p.ONLY_CONVERSATIONID?{conversationID:t[0]}:{conversationIDList:t},successLog:{message:a}}}catch(e){let{errorCode:t,errorInfo:s}=e;throw new i({code:t,message:s,moreMessage:a})}})}_deleteConversationFromLocal(e){let s=this._core["OuterConstant"];return e.filter(e=>{var t;return!!g.hasLocalConversation(e)&&((t=null==(t=g.getLocalConversation(e))?void 0:t.type)===s.CONV_GROUP&&!this._hasLocalGroup(e)||t===s.CONV_SYSTEM)&&(this._deleteLocalConversation(e),!0)})}_deleteConversationFromServer(t,i){return c(this,void 0,void 0,function*(){let{OuterConstant:n,common:e}=this._core,o={fromAccount:e.getCurrentUserID(),conversationList:[],clearHistoryMessage:i?1:0};if(t.forEach(e=>{var t,s;g.hasLocalConversation(e)&&(t=(null==(t=g.getLocalConversation(e))?void 0:t.type)||"",s=e.replace(t,""),t===n.CONV_C2C?o.conversationList.push({To_Account:s,Type:1}):t===n.CONV_GROUP&&this._hasLocalGroup(e)&&o.conversationList.push({ToGroupid:s,Type:2}))}),0!==o.conversationList.length){var s=yield function(n,o){return c(this,void 0,void 0,function*(){var{fromAccount:e,conversationList:t,clearHistoryMessage:s}=n;return o.common.buildAndSendPacket({servcmd:"recentcontact.batch_delete",data:{From_Account:e,ContactItem:t,ClearRamble:s}})})}(o,this._core);if(s){let{ResultItem:e=[]}=s,t=[];return 0<e.length&&e.forEach(e=>{0===e.ResultCode&&(e=1===e.Type?""+n.CONV_C2C+e.To_Account:""+n.CONV_GROUP+e.ToGroupid,t.push(e))}),this._deleteLocalConversationList(t),t}}return[]})}_deleteLocalConversationList(e){let t=!1;e.forEach(e=>{g.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)}),console.log(this._name+"._deleteLocalConversationList isUpdate:"+t),t&&g.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){var s=g.hasLocalConversation(e);console.log(this._name+`._deleteLocalConversation conversationID:${e} has:`+s),s&&(g.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t)&&g.emitConversationListUpdate()}_hasLocalGroup(e){var{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:s}}=this._core,e=e.replace(t,"");return!!s.getGroup(e)}_deleteConversationLocalMessage(e){console.log(this._name+"._deleteConversationLocalMessage conversationID:"+e),this._core.message.messageDataHandler.deleteConversationMessageList(e)}},O=new class{constructor(){this._name="SetConversationDraft"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(s){return c(this,void 0,void 0,function*(){var{conversationID:e,draftText:t}=s;if(console.log(this._name+` conversationID:${e} draftText:`+t),g.hasLocalConversation(e))return null!=(e=g.getLocalConversation(e))&&e.setDraftText(t),g.emitConversationListUpdate(),{code:0,data:{conversation:e}};throw new this._core.helper.ChatError({code:v.CONV_NOT_FOUND})})}},T=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(r,l){return c(this,void 0,void 0,function*(){30<r.length&&(console.warn(`${this._name}.set userIDList length:${r.length} exceeds limit 30`),r.splice(30));let e=function(){var{MSG_REMIND_ACPT_AND_NOTE:e,MSG_REMIND_DISCARD:t,MSG_REMIND_ACPT_NOT_NOTE:s}=d.core.OuterConstant;return{[e]:0,[t]:1,[s]:2}}()[l],t=yield function(s,n){return c(this,void 0,void 0,function*(){var{userIDList:e,receiveMessageOption:t}=s;return n.common.buildAndSendPacket({servcmd:"openim.set_c2c_peer_mute_notifications",data:{Peer_Account:e,Mute_Notifications:t}})})}({userIDList:r,receiveMessageOption:e},this._core),{ErrorList:s=[]}=t||{},n=[],o=(s.forEach(e=>{var{Peer_Account:e,ErrorCode:t}=e,t=(n.push({userID:e,code:t}),r.indexOf(e));-1<t&&r.splice(t,1)}),[]),i=[],a=this._core["OuterConstant"];return r.forEach(e=>{i.push(""+a.CONV_C2C+e),o.push({userID:e})}),g.patchMessageRemindType(i,l),{code:0,data:{successUserIDList:o,failureUserIDList:n}}})}},A=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(n,o){return c(this,void 0,void 0,function*(){var{common:{getCurrentUserID:e,isTopic:t},OuterConstant:s}=this._core;if(yield function(n,o){return c(this,void 0,void 0,function*(){var{groupID:e,userID:t,receiveMessageOption:s}=n;return o.common.buildAndSendPacket({servcmd:"group_open_http_svc.modify_group_member_info",data:{GroupId:e,Member_Account:t,MsgFlag:s}})})}({groupID:n,userID:e(),receiveMessageOption:o},this._core),!t(n)){let e=""+s.CONV_GROUP+n;g.patchMessageRemindType([e],o)}return{code:0,data:{groupID:n,messageRemindType:o}}})}},y=new class{constructor(){this._name="SetMessageRemindType"}init(e){e=(this._core=e).helper;e.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){let{helper:{isEmpty:t},OuterConstant:i,ssoLog:a}=this._core;e.forEach(e=>{var o=e["MuteNotificationsSync"];if(!t(o)){let{To_Account:e,MuteNotifications:t}=o,s=e.map(e=>""+i.CONV_C2C+e),n=r(t);a.debug(this._name+`.handleC2CMessageRemindTypeSync conversationIDList:${s} messageRemindType:`+n),g.patchMessageRemindType(s,n)}})}setMessageRemindType(r){return c(this,void 0,void 0,function*(){let s="setMessageRemindType",{groupID:e,userIDList:t,messageRemindType:n}=r,{helper:o,utils:{isUndefined:i},ssoLog:a}=this._core;try{if(!i(e))return a.debug(`${this._name}.${s} groupID:${e} messageRemindType:`+n),yield A.set(e,n);if(i(t))throw new o.ChatError({functionName:s,message:"userIDList or groupID is required"});return a.debug(this._name+`.${s} userIDList:${t} messageRemindType:`+n),yield T.set(t,n)}catch(e){let t=new o.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(this._name+`.${s} fail:`,t),t}})}},o=new class{init(e){e.ssoLog.debug("ConversationAction.init"),this._core=e,m.init(e),E.init(e),R.init(e),S.init(e),I.init(e),L.init(e),O.init(e),y.init(e);var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:a}=e["InnerEventSubType"];e.subscribeInnerEvent(t,n,this._onConversationModified,this),e.subscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.subscribeInnerEvent(t,a,this._onC2CMessageRemindTypeSync,this),e.subscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.subscribeInnerEvent(s,this._dispose,this)}_onConversationModified(e){let{ConvModifyPushType:s}=this._core["constants"],{RecentContactMod:t=[]}=e;t.forEach(t=>{var e=t["PushType"];if(e===s.CONV_DELETED){let e=t.RecentContactDeleteItem["RecentContactList"];L.handleConversationDeleted(e)}if(e===s.CONV_PINED){let e=t.RecentContactTopItem["RecentContactList"];I.handleConversationPinned(e,!0)}if(e===s.CONV_UNPINED){let e=t.RecentContactTopItem["RecentContactList"];I.handleConversationPinned(e,!1)}})}_onC2CMessageReadSync(e){var{C2cNotifyMsgArray:e=[]}=e;S.handleC2CMessageReadSync(e)}_onC2CMessageRemindTypeSync(e){var{C2cNotifyMsgArray:e=[]}=e;y.handleC2CMessageRemindTypeSync(e)}_onGroupMessageReadSync(e){var{GroupTips:e=[]}=e;S.handleGroupMessageReadSync(e)}_dispose(){var{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:s}}=this._core,{CONV_MODIFIED:n,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:a}=e["InnerEventSubType"];e.unSubscribeInnerEvent(t,n,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,a,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(s,this._dispose,this)}},i=new class{init(e){e=(this._core=e).helper;e.registerApi({apiName:"setAllReceiveMessageOpt",context:this})}setAllReceiveMessageOpt(a){return c(this,void 0,void 0,function*(){try{let{MSG_REMIND_ACPT_NOT_NOTE:e}=this._core["OuterConstant"],{messageRemindType:t=e,isRepeated:s=!0}=a,{startTime:n=0,endTime:o=0}=this._calcStartAndEndTime(a),i=yield function(i){return c(this,void 0,void 0,function*(){var e=d.core["common"],{startTime:t,endTime:s,isRepeated:n,messageRemindType:o}=i;return e.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_set_do_not_disturb",data:{StartTime:t,EndTime:s,IsRepeated:n,Level:o}})})}({messageRemindType:this._getType(t),startTime:n,endTime:o,isRepeated:s?l.ON:l.OFF});return{code:0,data:{errorCode:i.ErrorCode,errorInfo:i.ErrorInfo}}}catch(e){n("setAllReceiveMessageOpt",e)}})}_calcStartAndEndTime(e){var{startHour:e=0,startMinute:t=0,startSecond:s=0,duration:n=0,isRepeated:o=!0}=e,i=new Date,i=new Date(i.getFullYear(),i.getMonth(),i.getDate(),e,t,s),e=Math.round(i.getTime()/1e3);let a=o&&86400<=n?e+86400:e+n;return{startTime:e,endTime:a}}_getType(e){var t=this._core["OuterConstant"];return{[t.MSG_REMIND_ACPT_AND_NOTE]:0,[t.MSG_REMIND_DISCARD]:1,[t.MSG_REMIND_ACPT_NOT_NOTE]:2}[e]}},a=new class{init(e){var{helper:e,notificationCenter:t,InnerEvent:s}=this._core=e;e.registerApi({apiName:"getAllReceiveMessageOpt",context:this}),t.subscribeInnerEvent(s.MESSAGE_PUSH,t.InnerEventSubType.ALL_RECEIVE_MESSAGE_OPTION,this.onAllReceiveMsgOptionNotify,this)}onAllReceiveMsgOptionNotify(e){var e=this._handleResult(e),{notificationCenter:t,OuterEvent:{ALL_RECEIVE_MESSAGE_OPT_UPDATED:s}}=this._core;t.emitOuterEvent(s,{name:s,data:e})}getAllReceiveMessageOpt(){return c(this,void 0,void 0,function*(){try{var e=yield function(){return c(this,void 0,void 0,function*(){var e=d.core["common"],t={To_Account:e.getCurrentUserID()};return e.buildAndSendPacket({servcmd:"im_msg_db_logic.ws_get_do_not_disturb",data:t})})}();return{code:0,data:this._handleResult(e)}}catch(e){n("getAllReceiveMessageOpt",e)}})}_handleResult(e){var t=this._core["OuterConstant"],{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:s,MSG_REMIND_ACPT_NOT_NOTE:n}=t,{Level:e,StartTime:o,EndTime:i,IsRepeated:a}=e;return{messageRemindType:{0:t,1:s,2:n}[e]||t,startTime:o,endTime:i,isRepeated:a===l.ON}}},N=new class{init(e){e.ssoLog.debug("ReceiveMessageOptions.init"),this._core=e,T.init(e),A.init(e),f.init(e),M.init(e),i.init(e),a.init(e)}};let D=e=>!u(e)&&!_(e)&&!t(e),G={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!D(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!D(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!D(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:e=>{var{utils:{isArray:t,isObject:s,isString:n}}=d["core"];if(!n(e)&&!s(e))return"options is String or Object.";if(n(e)&&D(e))return"conversationID is invalid.";if(s(e)){if(!t(e.conversationIDList))return"conversationIDList is not Array.";if(0===e.conversationIDList.length)return"conversationIDList is empty.";if(e.conversationIDList.some(e=>{if(D(e))return!0}))return"conversationIDList includes invalid conversationID.";if(e.clearHistoryMessage&&"boolean"!=typeof e.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!u(e)&&!_(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}},setAllReceiveMessageOpt:{messageRemindType:{required:!1,rules:["string"],allowEmpty:!0},startHour:{required:!1,rules:["number"],allowEmpty:!0},startMinute:{required:!1,rules:["number"],allowEmpty:!0},startSecond:{required:!1,rules:["number"],allowEmpty:!0},duration:{required:!1,rules:["number"],allowEmpty:!0},isRepeated:{required:!1,rules:["boolean"],allowEmpty:!0}}},P={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(e){d.init(e),o.init(e),N.init(e),g.init(e),e.helper.registerValidateConfig({auth:P,params:G})}}});
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(){const{core:{OuterConstant:t,utils:{isUndefined:s}}}=e;s(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:s(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:s,utils:{isUndefined:n}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;n(o)||(this.subType!==s.GRP_AVCHATROOM?i&&this.type===s.CONV_GROUP||r&&this.type===s.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:s}}=e,{sequence:n,time:o}=t;return this.type===s.CONV_C2C&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s.CONV_GROUP&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{common:{updateGroupAtInfo:s}}}=e;s(t,this.groupAtInfoList)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var d,u;!function(e){e[e.OFF=0]="OFF",e[e.ON=1]="ON"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(u||(u={}));var _;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(_||(_={}));const h=0,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:{isEmpty:o,safeStringify:i},ssoLog:r,apiMap:{getGroupProfile:a}}=this._core;let c=!1;try{yield Promise.all(e.map(e=>t(this,void 0,void 0,function*(){const t=n.getGroup(e),i=this.getLocalConversation(`${s}${e}`);t&&i&&(i.groupProfile=t,c=!0),o(t)&&i&&"function"==typeof a&&(yield a({groupID:e}))}))),c&&this.emitConversationListUpdate()}catch(e){r.debug("_updateGroupConversation",i(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){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,s=this.getLocalConversationList();this._emitEvent({name:t,data:s}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(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 +1 @@
1
- function o(o,i,s,u){return new(s=s||Promise)(function(t,e){function r(o){try{n(u.next(o))}catch(o){e(o)}}function l(o){try{n(u.throw(o))}catch(o){e(o)}}function n(o){var e;o.done?t(o.value):((e=o.value)instanceof s?e:new s(function(o){o(e)})).then(r,l)}n((u=u.apply(o,i||[])).next())})}let t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(s,u){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={FollowType:s,From_Account:null==(e=e.get("login"))?void 0:e.userId,StartCursor:u,WantNum:f()},{FollowItem:o=[],NextCursor:e,ActionStatus:r,ErrorCode:l,ErrorInfo:n,ErrorDisplay:i}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:r,errorCode:l,errorInfo:n,errorDisplay:i}})}function s(e){return o(this,void 0,void 0,function*(){return i(l.FOLLOWERS,e)})}function u(e){return o(this,void 0,void 0,function*(){return i(l.MUTUAL,e)})}function c(e){return o(this,void 0,void 0,function*(){return i(l.FOLLOWING,e)})}function a(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,FollowItem:i.map(o=>({To_Account:o}))},{ResultItem:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_add",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}function d(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:i},{ResultItem:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_delete",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}function f(){let o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0===e)return 500;{let o=Number(e);return 1e3<o?1e3:o}}let w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{constructor(){this.name="Follow"}install(o){var{helper:e,notificationCenter:r,InnerEvent:l}=this._core=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(l.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})})}getMyFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})})}getMutualFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})})}_getFollowList(e){return o(this,void 0,void 0,function*(){var{functionName:r,protocolFunction:l,nextCursor:n=""}=e;try{this._checkBusinessCapabilityBits(r);let o=yield l(n),{resultList:e=[],nextPageToken:t=""}=o;return{code:0,data:{resultList:this._parseFollowItems(e),nextCursor:t},successLog:{message:r+` nextCursor: ${n} from remote`}}}catch(o){this._handleError(r,o)}})}followUser(e){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:e,protocolFunction:a})})}unfollowUser(e){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:e,protocolFunction:d})})}_handleUserFollowRelation(n){return o(this,void 0,void 0,function*(){var{functionName:e,userIDList:t,protocolFunction:r}=n;try{let o=this._sliceUserIDList(t,20);this._checkBusinessCapabilityBits(e);var{resultList:l=[]}=yield r(o);return{code:0,data:l}}catch(o){this._handleError(e,o)}})}getUserFollowInfo(u){return o(this,void 0,void 0,function*(){var i="getUserFollowInfo";try{this._checkBusinessCapabilityBits(i);var s=u||[this._core.common.getCurrentUserID()];console.log(e+` ${i} userIDList: `+s);let r=yield function(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:i},{FollowInfo:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get_info",data:e});return{followInfoList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}(u),{followInfoList:l=[]}=r,n=[];return l.forEach(o=>{var{followerCount:o,followingCount:e,mutualFollowingCount:t}=o;n.push({followerCount:o,followingCount:e,mutualFollowingCount:t})}),{code:0,data:n}}catch(o){this._handleError(i,o)}})}checkFollowType(i){return o(this,void 0,void 0,function*(){var r="checkFollowType";try{this._checkBusinessCapabilityBits(r),100<i.length&&(i=i.slice(0,100),this._core.ssoLog.warn(r,e+` ${r} the length of userIDList cannot exceed 100`));var l=yield function(i){return o(this,void 0,void 0,function*(){var{common:o,store:e}=t.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:i},{ResultItem:o=[],ActionStatus:e,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_check",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:l,errorDisplay:n}})}(i),{resultList:n=[]}=l;return{code:0,data:n.map(({userID:o,followType:e})=>({userID:o,followType:e}))}}catch(o){this._handleError(r,o)}})}onFollowListUpdated(o){var{ssoLog:t,utils:{safeStringify:r}}=this._core,{FollowChangeList:t=[]}=(t.debug("onFollowListUpdated",e+" onFollowListUpdated "+r(o)),o);t.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){let{From_Account:e,FollowDiffList:t=[]}=o,r=function(o,e){var t={};for(l in o)Object.prototype.hasOwnProperty.call(o,l)&&e.indexOf(l)<0&&(t[l]=o[l]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,l=Object.getOwnPropertySymbols(o);r<l.length;r++)e.indexOf(l[r])<0&&Object.prototype.propertyIsEnumerable.call(o,l[r])&&(t[l[r]]=o[l[r]]);return t}(o,["From_Account","FollowDiffList"]),l={userID:e,avatar:r.FaceUrl,nick:r.NickName};t.forEach(o=>{o=this._updateFollowRelation(o,l);this._notifyFollowChanges(o)})}_updateFollowRelation(o,e){var{IsAdd:o,FollowType:t=0}=o,r=this._initFollowInfo(),t=r[t];return t.isAdd=1===o,t.userInfoList.push(t.isAdd?e:e.userID),r}_notifyFollowChanges(o){let e=this._core["OuterEvent"],t={[l.FOLLOWERS]:e.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:e.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:e.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,e])=>{o=Number(o);0<e.userInfoList.length&&t[o]&&this._emitFollowUpdated(t[o],e)})}_initFollowInfo(){let e={};return Object.values(l).forEach(o=>{o!==l.NONE&&(e[o]={userInfoList:[],isAdd:!1})}),e}_emitFollowUpdated(o,e){var t=this._core["notificationCenter"];t.emitOuterEvent(o,{name:o,data:e})}_sliceUserIDList(o,e){return o.slice(0,e)}_checkBusinessCapabilityBits(o){var{helper:e,store:t}=this._core;if(!(t.get("commercialConfig")||new Map).get(r))throw new e.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,e){throw new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}_parseFollowItems(o){return o.map(o=>{let e,{userID:t,followTime:r,profileItem:l=[]}=o,n=[];l.forEach(o=>{n.push({tag:o.Tag,value:o.Value})});o=null==(e=this._core.user.userProfile)?void 0:e.createProfile(t,n);return{userID:t,followTime:r,nick:null==o?void 0:o.nick,avatar:null==o?void 0:o.avatar,allowType:null==o?void 0:o.allowType,adminForbidType:null==o?void 0:o.adminForbidType}})}};export{p as default};
1
+ function o(o,t,e,r){return new(e||(e=Promise))(function(n,l){function i(o){try{u(r.next(o))}catch(o){l(o)}}function s(o){try{u(r.throw(o))}catch(o){l(o)}}function u(o){var t;o.done?n(o.value):(t=o.value,t instanceof e?t:new e(function(o){o(t)})).then(i,s)}u((r=r.apply(o,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(e,r){return o(this,void 0,void 0,function*(){var o;const{common:n,store:l}=t.core,i={FollowType:e,From_Account:null===(o=l.get("login"))||void 0===o?void 0:o.userId,StartCursor:r,WantNum:f()};return function(o){const{FollowItem:t=[],NextCursor:e,ActionStatus:r,ErrorCode:n,ErrorInfo:l,ErrorDisplay:i}=o;return{resultList:t.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:r,errorCode:n,errorInfo:l,errorDisplay:i}}(yield n.buildAndSendPacket({servcmd:"follow.follow_get",data:i}))})}function s(t){return o(this,void 0,void 0,function*(){return i(l.FOLLOWERS,t)})}function u(t){return o(this,void 0,void 0,function*(){return i(l.MUTUAL,t)})}function c(t){return o(this,void 0,void 0,function*(){return i(l.FOLLOWING,t)})}function a(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,FollowItem:e.map(o=>({To_Account:o}))};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_add",data:l}))})}function d(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_delete",data:l}))})}function f(){const o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0!==e){const o=Number(e);return o>1e3?1e3:o}return 500}const w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{constructor(){this.name="Follow"}install(o){this._core=o;const{helper:e,notificationCenter:r,InnerEvent:n}=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(n.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})})}getMyFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})})}getMutualFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})})}_getFollowList(t){return o(this,void 0,void 0,function*(){const{functionName:o,protocolFunction:e,nextCursor:r=""}=t;try{this._checkBusinessCapabilityBits(o);const t=yield e(r),{resultList:n=[],nextPageToken:l=""}=t;return{code:0,data:{resultList:this._parseFollowItems(n),nextCursor:l},successLog:{message:`${o} nextCursor: ${r} from remote`}}}catch(t){this._handleError(o,t)}})}followUser(t){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:t,protocolFunction:a})})}unfollowUser(t){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:t,protocolFunction:d})})}_handleUserFollowRelation(t){return o(this,void 0,void 0,function*(){const{functionName:o,userIDList:e,protocolFunction:r}=t;try{const t=this._sliceUserIDList(e,20);this._checkBusinessCapabilityBits(o);const{resultList:n=[]}=yield r(t);return{code:0,data:n}}catch(t){this._handleError(o,t)}})}getUserFollowInfo(r){return o(this,void 0,void 0,function*(){const n="getUserFollowInfo";try{this._checkBusinessCapabilityBits(n);const l=r||[this._core.common.getCurrentUserID()];console.log(`${e} ${n} userIDList: ${l}`);const i=yield function(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{FollowInfo:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{followInfoList:t.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_get_info",data:l}))})}(r),{followInfoList:s=[]}=i,u=[];return s.forEach(o=>{const{followerCount:t,followingCount:e,mutualFollowingCount:r}=o;u.push({followerCount:t,followingCount:e,mutualFollowingCount:r})}),{code:0,data:u}}catch(o){this._handleError(n,o)}})}checkFollowType(r){return o(this,void 0,void 0,function*(){const n="checkFollowType";try{this._checkBusinessCapabilityBits(n),r.length>100&&(r=r.slice(0,100),this._core.ssoLog.warn(n,`${e} ${n} the length of userIDList cannot exceed 100`));const l=yield function(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_check",data:l}))})}(r),{resultList:i=[]}=l;return{code:0,data:i.map(({userID:o,followType:t})=>({userID:o,followType:t}))}}catch(o){this._handleError(n,o)}})}onFollowListUpdated(o){const{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("onFollowListUpdated",`${e} onFollowListUpdated ${r(o)}`);const{FollowChangeList:n=[]}=o;n.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){const{From_Account:t,FollowDiffList:e=[]}=o,r=function(o,t){var e={};for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(o);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(o,r[n])&&(e[r[n]]=o[r[n]])}return e}(o,["From_Account","FollowDiffList"]),n={userID:t,avatar:r.FaceUrl,nick:r.NickName};e.forEach(o=>{const t=this._updateFollowRelation(o,n);this._notifyFollowChanges(t)})}_updateFollowRelation(o,t){const{IsAdd:e,FollowType:r=0}=o,n=this._initFollowInfo(),l=n[r];return l.isAdd=1===e,l.userInfoList.push(l.isAdd?t:t.userID),n}_notifyFollowChanges(o){const{OuterEvent:t}=this._core,e={[l.FOLLOWERS]:t.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:t.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:t.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,t])=>{const r=Number(o);t.userInfoList.length>0&&e[r]&&this._emitFollowUpdated(e[r],t)})}_initFollowInfo(){const o={};return Object.values(l).forEach(t=>{t!==l.NONE&&(o[t]={userInfoList:[],isAdd:!1})}),o}_emitFollowUpdated(o,t){const{notificationCenter:e}=this._core;e.emitOuterEvent(o,{name:o,data:t})}_sliceUserIDList(o,t){return o.slice(0,t)}_checkBusinessCapabilityBits(o){const{helper:t,store:e}=this._core;if(!(e.get("commercialConfig")||new Map).get(r))throw new t.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,t){throw new this._core.helper.ChatError({functionName:o,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}_parseFollowItems(o){return o.map(o=>{var t;const{userID:e,followTime:r,profileItem:n=[]}=o,l=[];n.forEach(o=>{l.push({tag:o.Tag,value:o.Value})});const i=null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(e,l);return{userID:e,followTime:r,nick:null==i?void 0:i.nick,avatar:null==i?void 0:i.avatar,allowType:null==i?void 0:i.allowType,adminForbidType:null==i?void 0:i.adminForbidType}})}};export{p as default};
package/plugins/follow.js CHANGED
@@ -1 +1 @@
1
- !function(o,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(o="undefined"!=typeof globalThis?globalThis:o||self).TencentCloudChatFollow=e()}(this,function(){function u(o,i,s,u){return new(s=s||Promise)(function(t,e){function r(o){try{n(u.next(o))}catch(o){e(o)}}function l(o){try{n(u.throw(o))}catch(o){e(o)}}function n(o){var e;o.done?t(o.value):((e=o.value)instanceof s?e:new s(function(o){o(e)})).then(r,l)}n((u=u.apply(o,i||[])).next())})}let a=new class{init(o){this.core=o}},i="Follow",r={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function e(i,s){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={FollowType:i,From_Account:null==(e=e.get("login"))?void 0:e.userId,StartCursor:s,WantNum:function(){let o=a.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0===e)return 500;{let o=Number(e);return 1e3<o?1e3:o}}()},{FollowItem:o=[],NextCursor:e,ActionStatus:t,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:t,errorCode:r,errorInfo:l,errorDisplay:n}})}function t(o){return u(this,void 0,void 0,function*(){return e(r.FOLLOWERS,o)})}function l(o){return u(this,void 0,void 0,function*(){return e(r.MUTUAL,o)})}function n(o){return u(this,void 0,void 0,function*(){return e(r.FOLLOWING,o)})}function s(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,FollowItem:n.map(o=>({To_Account:o}))},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_add",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}function c(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_delete",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}let d={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},f={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0},o=new class{constructor(){this.name="Follow"}install(o){var{helper:e,notificationCenter:t,InnerEvent:r}=this._core=o;a.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:f,params:d}),t.subscribeInnerEvent(r.MESSAGE_PUSH,t.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:n,nextCursor:o})})}getMyFollowersList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:t,nextCursor:o})})}getMutualFollowersList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:l,nextCursor:o})})}_getFollowList(o){return u(this,void 0,void 0,function*(){var{functionName:r,protocolFunction:l,nextCursor:n=""}=o;try{this._checkBusinessCapabilityBits(r);let o=yield l(n),{resultList:e=[],nextPageToken:t=""}=o;return{code:0,data:{resultList:this._parseFollowItems(e),nextCursor:t},successLog:{message:r+` nextCursor: ${n} from remote`}}}catch(o){this._handleError(r,o)}})}followUser(o){return u(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:o,protocolFunction:s})})}unfollowUser(o){return u(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:o,protocolFunction:c})})}_handleUserFollowRelation(o){return u(this,void 0,void 0,function*(){var{functionName:e,userIDList:t,protocolFunction:r}=o;try{let o=this._sliceUserIDList(t,20);this._checkBusinessCapabilityBits(e);var{resultList:l=[]}=yield r(o);return{code:0,data:l}}catch(o){this._handleError(e,o)}})}getUserFollowInfo(n){return u(this,void 0,void 0,function*(){var t="getUserFollowInfo";try{this._checkBusinessCapabilityBits(t);var l=n||[this._core.common.getCurrentUserID()];console.log(i+` ${t} userIDList: `+l);let o=yield function(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{FollowInfo:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get_info",data:e});return{followInfoList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}(n),{followInfoList:e=[]}=o,r=[];return e.forEach(o=>{var{followerCount:o,followingCount:e,mutualFollowingCount:t}=o;r.push({followerCount:o,followingCount:e,mutualFollowingCount:t})}),{code:0,data:r}}catch(o){this._handleError(t,o)}})}checkFollowType(r){return u(this,void 0,void 0,function*(){var e="checkFollowType";try{this._checkBusinessCapabilityBits(e),100<r.length&&(r=r.slice(0,100),this._core.ssoLog.warn(e,i+` ${e} the length of userIDList cannot exceed 100`));var o=yield function(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_check",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}(r),{resultList:t=[]}=o;return{code:0,data:t.map(({userID:o,followType:e})=>({userID:o,followType:e}))}}catch(o){this._handleError(e,o)}})}onFollowListUpdated(o){var{ssoLog:e,utils:{safeStringify:t}}=this._core,{FollowChangeList:e=[]}=(e.debug("onFollowListUpdated",i+" onFollowListUpdated "+t(o)),o);e.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){let{From_Account:e,FollowDiffList:t=[]}=o,r=function(o,e){var t={};for(l in o)Object.prototype.hasOwnProperty.call(o,l)&&e.indexOf(l)<0&&(t[l]=o[l]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,l=Object.getOwnPropertySymbols(o);r<l.length;r++)e.indexOf(l[r])<0&&Object.prototype.propertyIsEnumerable.call(o,l[r])&&(t[l[r]]=o[l[r]]);return t}(o,["From_Account","FollowDiffList"]),l={userID:e,avatar:r.FaceUrl,nick:r.NickName};t.forEach(o=>{o=this._updateFollowRelation(o,l);this._notifyFollowChanges(o)})}_updateFollowRelation(o,e){var{IsAdd:o,FollowType:t=0}=o,r=this._initFollowInfo(),t=r[t];return t.isAdd=1===o,t.userInfoList.push(t.isAdd?e:e.userID),r}_notifyFollowChanges(o){let e=this._core["OuterEvent"],t={[r.FOLLOWERS]:e.MY_FOLLOWERS_LIST_UPDATED,[r.FOLLOWING]:e.MY_FOLLOWING_LIST_UPDATED,[r.MUTUAL]:e.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,e])=>{o=Number(o);0<e.userInfoList.length&&t[o]&&this._emitFollowUpdated(t[o],e)})}_initFollowInfo(){let e={};return Object.values(r).forEach(o=>{o!==r.NONE&&(e[o]={userInfoList:[],isAdd:!1})}),e}_emitFollowUpdated(o,e){var t=this._core["notificationCenter"];t.emitOuterEvent(o,{name:o,data:e})}_sliceUserIDList(o,e){return o.slice(0,e)}_checkBusinessCapabilityBits(o){var{helper:e,store:t}=this._core;if(!(t.get("commercialConfig")||new Map).get("FOLLOW"))throw new e.ChatError({functionName:o,code:3122,replacement1:o})}_handleError(o,e){throw new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}_parseFollowItems(o){return o.map(o=>{let e,{userID:t,followTime:r,profileItem:l=[]}=o,n=[];l.forEach(o=>{n.push({tag:o.Tag,value:o.Value})});o=null==(e=this._core.user.userProfile)?void 0:e.createProfile(t,n);return{userID:t,followTime:r,nick:null==o?void 0:o.nick,avatar:null==o?void 0:o.avatar,allowType:null==o?void 0:o.allowType,adminForbidType:null==o?void 0:o.adminForbidType}})}};return o});
1
+ !function(o,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(o="undefined"!=typeof globalThis?globalThis:o||self).TencentCloudChatFollow=t()}(this,function(){"use strict";function o(o,t,e,r){return new(e||(e=Promise))(function(n,l){function i(o){try{u(r.next(o))}catch(o){l(o)}}function s(o){try{u(r.throw(o))}catch(o){l(o)}}function u(o){var t;o.done?n(o.value):(t=o.value,t instanceof e?t:new e(function(o){o(t)})).then(i,s)}u((r=r.apply(o,t||[])).next())})}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(e,r){return o(this,void 0,void 0,function*(){var o;const{common:n,store:l}=t.core,i={FollowType:e,From_Account:null===(o=l.get("login"))||void 0===o?void 0:o.userId,StartCursor:r,WantNum:f()};return function(o){const{FollowItem:t=[],NextCursor:e,ActionStatus:r,ErrorCode:n,ErrorInfo:l,ErrorDisplay:i}=o;return{resultList:t.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:r,errorCode:n,errorInfo:l,errorDisplay:i}}(yield n.buildAndSendPacket({servcmd:"follow.follow_get",data:i}))})}function s(t){return o(this,void 0,void 0,function*(){return i(l.FOLLOWERS,t)})}function u(t){return o(this,void 0,void 0,function*(){return i(l.MUTUAL,t)})}function c(t){return o(this,void 0,void 0,function*(){return i(l.FOLLOWING,t)})}function a(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,FollowItem:e.map(o=>({To_Account:o}))};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_add",data:l}))})}function d(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_delete",data:l}))})}function f(){const o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0!==e){const o=Number(e);return o>1e3?1e3:o}return 500}const w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{constructor(){this.name="Follow"}install(o){this._core=o;const{helper:e,notificationCenter:r,InnerEvent:n}=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(n.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})})}getMyFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})})}getMutualFollowersList(){return o(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})})}_getFollowList(t){return o(this,void 0,void 0,function*(){const{functionName:o,protocolFunction:e,nextCursor:r=""}=t;try{this._checkBusinessCapabilityBits(o);const t=yield e(r),{resultList:n=[],nextPageToken:l=""}=t;return{code:0,data:{resultList:this._parseFollowItems(n),nextCursor:l},successLog:{message:`${o} nextCursor: ${r} from remote`}}}catch(t){this._handleError(o,t)}})}followUser(t){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:t,protocolFunction:a})})}unfollowUser(t){return o(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:t,protocolFunction:d})})}_handleUserFollowRelation(t){return o(this,void 0,void 0,function*(){const{functionName:o,userIDList:e,protocolFunction:r}=t;try{const t=this._sliceUserIDList(e,20);this._checkBusinessCapabilityBits(o);const{resultList:n=[]}=yield r(t);return{code:0,data:n}}catch(t){this._handleError(o,t)}})}getUserFollowInfo(r){return o(this,void 0,void 0,function*(){const n="getUserFollowInfo";try{this._checkBusinessCapabilityBits(n);const l=r||[this._core.common.getCurrentUserID()];console.log(`${e} ${n} userIDList: ${l}`);const i=yield function(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{FollowInfo:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{followInfoList:t.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_get_info",data:l}))})}(r),{followInfoList:s=[]}=i,u=[];return s.forEach(o=>{const{followerCount:t,followingCount:e,mutualFollowingCount:r}=o;u.push({followerCount:t,followingCount:e,mutualFollowingCount:r})}),{code:0,data:u}}catch(o){this._handleError(n,o)}})}checkFollowType(r){return o(this,void 0,void 0,function*(){const n="checkFollowType";try{this._checkBusinessCapabilityBits(n),r.length>100&&(r=r.slice(0,100),this._core.ssoLog.warn(n,`${e} ${n} the length of userIDList cannot exceed 100`));const l=yield function(e){return o(this,void 0,void 0,function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_check",data:l}))})}(r),{resultList:i=[]}=l;return{code:0,data:i.map(({userID:o,followType:t})=>({userID:o,followType:t}))}}catch(o){this._handleError(n,o)}})}onFollowListUpdated(o){const{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("onFollowListUpdated",`${e} onFollowListUpdated ${r(o)}`);const{FollowChangeList:n=[]}=o;n.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){const{From_Account:t,FollowDiffList:e=[]}=o,r=function(o,t){var e={};for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(o);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(o,r[n])&&(e[r[n]]=o[r[n]])}return e}(o,["From_Account","FollowDiffList"]),n={userID:t,avatar:r.FaceUrl,nick:r.NickName};e.forEach(o=>{const t=this._updateFollowRelation(o,n);this._notifyFollowChanges(t)})}_updateFollowRelation(o,t){const{IsAdd:e,FollowType:r=0}=o,n=this._initFollowInfo(),l=n[r];return l.isAdd=1===e,l.userInfoList.push(l.isAdd?t:t.userID),n}_notifyFollowChanges(o){const{OuterEvent:t}=this._core,e={[l.FOLLOWERS]:t.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:t.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:t.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,t])=>{const r=Number(o);t.userInfoList.length>0&&e[r]&&this._emitFollowUpdated(e[r],t)})}_initFollowInfo(){const o={};return Object.values(l).forEach(t=>{t!==l.NONE&&(o[t]={userInfoList:[],isAdd:!1})}),o}_emitFollowUpdated(o,t){const{notificationCenter:e}=this._core;e.emitOuterEvent(o,{name:o,data:t})}_sliceUserIDList(o,t){return o.slice(0,t)}_checkBusinessCapabilityBits(o){const{helper:t,store:e}=this._core;if(!(e.get("commercialConfig")||new Map).get(r))throw new t.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,t){throw new this._core.helper.ChatError({functionName:o,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}_parseFollowItems(o){return o.map(o=>{var t;const{userID:e,followTime:r,profileItem:n=[]}=o,l=[];n.forEach(o=>{l.push({tag:o.Tag,value:o.Value})});const i=null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(e,l);return{userID:e,followTime:r,nick:null==i?void 0:i.nick,avatar:null==i?void 0:i.avatar,allowType:null==i?void 0:i.allowType,adminForbidType:null==i?void 0:i.adminForbidType}})}};return p});
@@ -1 +1 @@
1
- function e(e,n,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{s(d.next(e))}catch(e){t(e)}}function o(e){try{s(d.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}s((d=d.apply(e,n||[])).next())})}let t="friend",r=100,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 L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function I(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:s}}let 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}},A=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),v[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=v[t];null!=e&&e(this,r)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){var{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,e=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",t+" getFriendListFromCache, data:"+i(e)),{code:0,data:e}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){let u,{ssoLog:c,helper:r}=this._core;try{c.debug("syncFriendListFromServer",t+" syncFriendListFromServer");let r={From_Account:null==(u=this._core.store.get("login"))?void 0:u.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},i=yield function(c,l){return e(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:s,ActionStatus:n,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:s,actionStatus:n,errorCode:a,errorInfo:d,errorDisplay:u}})}(r,this._core),{friendList:o,nextStartIndex:s,standardSequence:n,customSequence:a,completeFlag:d}=i;this._startIndex=s,this._standardSequence=n,this._customSequence=a,this._processFriendList(o),0===d?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),c.debug("syncFriendListFromServer",t+" syncFriendListFromServer ok")}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}getFriendProfile(c){return e(this,void 0,void 0,function*(){var i;try{let t=c["userIDList"];t.length>r&&(t=t.slice(0,r));var o,s,n,{friendUserIdList:a,unFriendUserIdList:d}=this.partitionByIsFriend(t),u=this._createNonFriendErrorList(d);return 0===a.length?{code:0,data:{friendList:[],failureUserIDList:u}}:(o=(yield function(s,n){return e(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield n.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:s});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(i=this._core.store.get("login"))?void 0:i.userId,To_Account:a},this._core))||{},{successProfiles:s,failedProfiles:n}=this._processFriendProfileResponse(o),{code:0,data:{friendList:s,failureUserIDList:[...n,...u]}})}catch(e){let t=(e||{})["errorCode"];throw new this._core.helper.ChatError({code:t})}})}addFriend(v){return e(this,void 0,void 0,function*(){var r,{helper:i,store:o,ssoLog:s}=this._core;try{var{to:n,source:d,type:u,wording:c,remark:l,groupName:p}=v,h=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}({From_Account:null==(r=o.get("login"))?void 0:r.userId,AddFriendItem:[{To_Account:n,AddSource:d,AddWording:c,GroupName:p,Remark:l}],AddType:u},this._core),{resultList:m=[]}=h,{userID:_,resultCode:f}=m[0];if(0===f)return s.debug("addFriend",t+" addFriend ok"),{code:0,data:{userID:_}};if(f===a)return s.debug("addFriend",t+" addFriend wait for the other party to agree"),{code:0,data:{userID:_,code:f,message:"wait for the other party to agree"}};throw new i.ChatError({functionName:"addFriend",code:f})}catch(e){let t=(e||{})["errorCode"];throw new i.ChatError({code:t})}})}deleteFriend(m){return e(this,void 0,void 0,function*(){var s,{store:n,ssoLog:a,helper:i}=this._core;try{let{userIDList:i,type:o}=m;var d,u,c,l=null==(s=n.get("login"))?void 0:s.userId,{friendUserIdList:p,unFriendUserIdList:h}=(1e3<i.length&&(a.info("deleteFriend",t+" deleteFriend the length of userIDList cannot exceed:1000"),i=i.slice(0,r)),this.partitionByIsFriend(i));return 0===p.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(h)}}:(d=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}({From_Account:l,To_Account:p,DeleteType:o},this._core),{successUserIDList:u,failureUserIDList:c}=this._processOperationResult({resultList:d.resultList,includeRelation:!1}),{code:0,data:{successUserIDList:u,failureUserIDList:c}})}catch(e){let t=(e||{})["errorCode"];throw new i.ChatError({code:t})}})}updateFriend(h){return e(this,void 0,void 0,function*(){var t,{helper:r,store:e,appStore:{userStore:o}}=this._core;try{var{userID:s,remark:n,friendCustomField:a}=h,d=null==(t=e.get("login"))?void 0:t.userId;if(!o.getFriendMap().has(s))throw new r.ChatError({functionName:"updateFriend",code:i});var u=(yield F({From_Account:d,UpdateItem:[{To_Account:s,SnsItem:this._buildSnsItemList(n,a)}]},this._core))["resultList"],{to:c,resultCode:l,resultInfo:p}=u[0];if(f(l)||0===l)return{code:0,data:this._updateLocalFriend({userID:c,remark:n,friendCustomField:a})};throw new r.ChatError({functionName:"updateFriend",code:l,message:p})}catch(t){let e=(t||{})["errorCode"];throw new r.ChatError({code:e})}})}checkFriend(c){return e(this,void 0,void 0,function*(){let a,{OuterConstant:d,store:u,helper:t}=this._core;try{let{userIDList:e,type:t}=c,r=null==(a=u.get("login"))?void 0:a.userId,i={From_Account:r,To_Account:e,CheckType:t===d.SNS_CHECK_TYPE_SINGLE?t:d.SNS_CHECK_TYPE_BOTH},o=yield I(i,this._core),{successUserIDList:s=[],failureUserIDList:n=[]}=this._processOperationResult({resultList:o.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:n}}}catch(a){let e=(a||{})["errorCode"];throw new t.ChatError({code:e})}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(n){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core;e.debug("updateFriendList",t+" updateFriendList data:"+r(n));let i=this._core.appStore["userStore"],{addedFriendList:o=[],removedFriendList:s=[]}=n;0<o.length&&(o.forEach(e=>{var t=new A({userID:e,core:this._core});i.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:o}),this._emitFriendListUpdated()),0<s.length&&(s.forEach(e=>{i.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",t+" updateFriendInfo data:"+i(e));let{appStore:{userStore:o,conversationStore:s},utils:{isEmpty:n}}=this._core,{userID:a,tagValueList:d}=e[0]||{},c=o.getFriend(a);if(!n(d)&&c){let i=d.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=s.getConversation("C2C"+a))?void 0:r.remark;e===u.REMARK&&t!==r&&s.updateConversation("C2C"+a,{remark:t}),c.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new A({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){let{appStore:{userStore:s},user:{userProfile:n},ssoLog:e}=this._core,a=(e.debug("_fetchFriendProfile",t+" _fetchFriendProfile"),[...s.getFriendMap().keys()]),r=Math.ceil(a.length/100);for(let o=0;o<r;o++){let e=100*o,t=Math.min(100+e,a.length),r=a.slice(e,t),i=yield null==n?void 0:n.getUserProfile({userIDList:r});i&&i.data&&i.data.forEach(e=>{var t=s.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,r=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:r})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return f(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],s=[],n=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(f(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),s.push(e)}else n.push({userID:t,code:e,message:i})}),{successUserIDList:s,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:t=[]}=e,o=this._core.appStore["userStore"],s=[],n=[];return t.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new A({userID:t,tagValueList:i,core:this._core});s.push(e),o.getFriendMap().set(t,e)}else n.push({userID:t,code:e,message:r})}),{successProfiles:s,failedProfiles:n}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},y=new class{init(e){this.core=e}};function S(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return C(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function E(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function D(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return C(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function C(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){var{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*(){let{ssoLog:i,utils:{safeStringify:o}}=this._core,s="syncFriendApplicationListFromServer";try{let t=yield function(u){return e(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:i}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:u.startTime,LastSequence:u.currentSequence},{PendencyItem:t=[],StartTime:i,UnreadPendencyCount:e,CurrentSequence:o,ActionStatus:s,ErrorCode:n,ErrorInfo:a,ErrorDisplay:d}=t=yield i.buildAndSendPacket({servcmd:"sns.pendency_get",data: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:i,unreadCount:e,currentSequence:o,actionStatus:s,errorCode:n,errorInfo:a,errorDisplay:d}})}({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=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let 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(r){return e(this,void 0,void 0,function*(){var{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:t}=this._core["OuterConstant"];return[e,t].includes(r.type)||(r.type=t),this._operationApplication({functionName:"acceptFriendApplication",options:r,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(r){return e(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,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*(){let{functionName:s,options:n,protocolFunction:a}=r;console.log(t+` ${s} options:`,n);try{let e=yield a(n),{resultList:r=[]}=e,{resultCode:i,resultInfo:o}=r[0];if(0===i)return console.log(t+` ${s} ok`),{code:0,data:{}};throw{errorCode:i,errorInfo:o}}catch(e){let r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${s} error:`,r),r}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay: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){var{from:e,addedApplicationList:t=[],removedApplicationList:r=[]}=e,i=this._core.utils["isEmpty"];i(t)||this.onApplicationAdded(t,e),i(r)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,s=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var 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(){var{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*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return U(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}function N(i){return e(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=y.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return U(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function G(r){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return U(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}function w(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,l),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function P(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,p),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function M(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}function R(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function U(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s,ResultItem:n=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s};return t&&0<n.length?Object.assign(Object.assign({},e),{resultList:n.map(t)}):e}class O{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){var{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*(){var e=this._core["ssoLog"],r="syncFriendGroupListFromServer";try{var i=yield k(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",t+` ${r} ok. count: 0`),o.forEach(e=>{var t=new O(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(n){return e(this,void 0,void 0,function*(){var t="createFriendGroup";try{var e=n["name"],r=(this._checkGroupExist(t,e),yield N(n)),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(r),s=new O({name:e,userIDList:i});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:o}}}catch(e){this._handleError(t,e)}})}deleteFriendGroup(i){return e(this,void 0,void 0,function*(){var t="deleteFriendGroup";try{var e=i["name"],r=(this._checkGroupNotExist(t,e),yield G(i),this._friendGroupMap.get(e));return r&&(this._updateFriendGroup({name:e,userIDList:r.userIDList,action:m}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:r}}catch(e){this._handleError(t,e)}})}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(o){return e(this,void 0,void 0,function*(){var t="renameFriendGroup";try{var{oldName:e,newName:r}=o,i=(this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield M(o),this._updateGroupNameInCache(e,r));return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:_,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(a){return e(this,void 0,void 0,function*(){var{functionName:t,params:r,protocolFunction:i}=a;try{let e=r["name"];this._checkGroupNotExist(t,e);var o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(e,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(t,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{f(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],s=[],n=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===l?this._addFriendToGroup(t,e.userID,i,s):e.updateType===p&&this._removeFriendFromGroup(t,e.userID,i,n)):o.push({userID:e.userID,code:e.resultCode,message:e.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(){var{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){let{name:i,userIDList:t,action:o,newName:s}=e,n=this._core.appStore["userStore"];i&&!this._core.utils.isEmpty(t)&&t.forEach(e=>{var t=n.getFriend(e);if(t){var r=t["groupList"];switch(o){case h:-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case m:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case _:if(s){let e=r.indexOf(i);-1!==e&&(r[e]=s)}}}})}_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){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.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");var i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},this._core),{blackList:o=[],startIndex:s=0}=i;return this._startIndex=s,this._addBlacklistMap(o),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(s){return e(this,void 0,void 0,function*(){let r=this._core["helper"];try{let t=this._preprocessBlacklist(s),r={From_Account:this._core.common.getCurrentUserID(),To_Account:t},i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}(r,this._core),{blackList:o=[]}=i;return this._addBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}removeFromBlacklist(o){return e(this,void 0,void 0,function*(){let r=this._core["helper"];try{let t={From_Account:this._core.common.getCurrentUserID(),To_Account:o.userIDList},r=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}(t,this._core),{blackList:i=[]}=r;return this._deleteBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core,{addedBlacklist:r=[],removedBlacklist:i=[]}=(r.debug("updateBlacklist",t+" updateBlacklist data: "+i(e)),e);let o=!1;0<r.length&&r.some(e=>!this._blacklistMap.has(e))&&(o=!0,this._addBlacklistMap(r.map(e=>({userID:e})))),0<i.length&&i.some(e=>this._blacklistMap.has(e))&&(o=!0,this._deleteBlacklistMap(i.map(e=>({userID:e})))),o&&this._emitBlackListUpdated()}_addBlacklistMap(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",t+" _addBlacklistMap blackList: "+i(e)),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",t+" _deleteBlacklistMap blackList: "+i(e)),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{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})}};let 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=>{var t=y.core["OuterConstant"];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=>{var t=y.core["OuterConstant"];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=>{var t=y.core["OuterConstant"];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");var{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:s,WORKFLOW_STEP:n}}=this._core=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){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:s,removedApplicationList:n,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||q.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(g.updateFriendList({addedFriendList:i,removedFriendList:o}),T.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||g.updateFriendInfo(a),u(s)&&u(n)||T.updateFriendApplicationList({from:e,addedApplicationList:s,removedApplicationList:n}),d&&T.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:s=[],FriendAdd_Account:n=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:s,addedFriendList:n,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){var{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,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=100,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};