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