@tencentcloud/lite-chat 1.1.1 → 1.2.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.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatConversation=t()}(this,(function(){"use strict";function e(e,t,s,n){return new(s||(s=Promise))((function(o,i){function a(e){try{l(n.next(e))}catch(e){i(e)}}function r(e){try{l(n.throw(e))}catch(e){i(e)}}function l(e){var t;e.done?o(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(a,r)}l((n=n.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="C2C",s="GROUP",n="TOPIC",o="@TIM#SYSTEM",i="AVChatRoom",a="Room",r="Live",l="TIMTextElem",u="TIMImageElem",d="TIMSoundElem",c="TIMFileElem",p="TIMFaceElem",g="TIMVideoFileElem",v="TIMLocationElem",h="TIMGroupTipElem",m="TIMGroupSystemNoticeElem",C="TIMCustomElem",_="TIMRelayElem",M="AcceptAndNotify",f="AcceptNotNotify",y="Discard",T="AcceptNotNotifyExceptAt";var I,L,S;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(I||(I={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(L||(L={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(S||(S={}));const E=e=>void 0===e,D=e=>"string"==typeof e,O=e=>"function"==typeof Array.isArray?Array.isArray(e):"array"===(e=>{var t;return null===(t=Object.prototype.toString.call(e).match(/^\[object (.*)\]$/))||void 0===t?void 0:t[1].toLowerCase()})(e),R=e=>O(e)||(e=>null!==e&&"object"==typeof e)(e),k=(e,t,s,n)=>{if(!R(e)||!R(t))return 0;let o=0;const i=Object.keys(t);let a;for(let r=0,l=i.length;r<l;r++)if(a=i[r],!(E(t[a])||s&&s.includes(a)))if(R(e[a])&&R(t[a]))o+=k(e[a],t[a],s,n);else{if(n&&n.includes(t[a]))continue;e[a]!==t[a]&&(e[a]=t[a],o+=1)}return o},P=(e,t)=>{if(E(t))return"";switch(e){case l:return t.text||"";case u:return"[Image]";case v:return"[Location]";case d:return"[Voice]";case g:return"[Video]";case c:return"[File]";case C:return"[Custom Messages]";case h:return"[Group Notification]";case m:return"[Group System Message]";case p:return"[Animated Sticker]";case _:return"[Chat Record]";default:return""}},G=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:P(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 N(e){const t=[];if(!D(e))return t;const s=e.length;if(0===s)return t;for(let n=s-1;n>=0;n--)"1"===e[n]&&t.push(2**(s-n-1));return t}class b{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=G(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.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(){E(this.userProfile)&&this.type===t?this.userProfile={}:E(this.groupProfile)&&this.type===s&&(this.groupProfile={}),this.subType&&this.type===s&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(e){const{nextUnreadCount:o,isFromGetConversations:a,isUnreadC2CMessage:r}=e;E(o)||(this.subType!==i?a&&this.type===s||a&&this.type===n||r&&this.type===t?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=G(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(e){const{sequence:n,time:o}=e;return this.type===t&&n===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===s&&n===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}}var U=new class{constructor(){this._name="ConversationFactory",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0,this._pagingConvIDMap=new Map,this._convMap=new Map,this._convTotalUnreadCount=0}install(e){this._core=e;const{notificationCenter:t,InnerEvent:s,helper:n}=e;n.registerApi("getConversationList",this),n.registerApi("getConversationProfile",this),n.registerApi("setMessageRead",this),n.registerApi("getTotalUnreadMessageCount",this),n.registerApi("setConversationDraft",this),t.subscribeInnerEvent(s.RE_LOGIN,this._recoverConversations,this),t.subscribeInnerEvent(s.LOGIN,this.handleLoginSuccess,this),t.subscribeInnerEvent(s.NEW_MESSAGE,this._handleNewMessage,this),t.subscribeInnerEvent(s.MESSAGE_DELETED,this._handleMessageDeleted,this),t.subscribeInnerEvent(s.MESSAGE_REVOKED,this._handleMessageRevoked,this),t.subscribeInnerEvent(s.MESSAGE_MODIFIED,this._handleMessageModified,this),t.subscribeInnerEvent(s.DESTROY,this._dispose,this),console.log(`${this._name}.install`)}handleLoginSuccess(){this.syncConvList()}_handleNewMessage(e){const{conversationOptionsList:t=[],isInstantMessage:s=!0,isUnreadC2CMessage:n=!1,updateUnreadCount:o=!0}=e;if(console.log(`${this._name}._handleNewMessage, conversationOptionsList length:`,t.length),0===t.length)return;this._updateLocalConvList({conversationOptionsList:t,isInstantMessage:s,isUnreadC2CMessage:n,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConvNeedShow(e.conversationID))).length>0&&this._onConversationListUpdate()}_handleMessageDeleted(e){var s,n,o,i;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const a=(null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e))||[];let r={};for(let e=(a.length||0)-1;e>=0;e--)if(!a[e].isDeleted){r=a[e];break}const l=this._convMap.get(e);if(!l)return;let u=!1;l.lastMessage.lastSequence===r.sequence&&l.lastMessage.lastTime===r.time||((null===(i=null===(o=this._core)||void 0===o?void 0:o.helper)||void 0===i?void 0:i.isEmpty(r))&&(r=void 0),l.updateLastMessage(r),u=!0),e.startsWith(t)&&this._updateUnreadCount(e),u&&(this._onConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. \n update conversationID:${e} with lastMessage:`,l.lastMessage))}_handleMessageRevoked(e){console.log(`${this._name}._handleMessageRevoked`,JSON.stringify(e));const{messageList:t=[],updateUnreadCount:s=!0}=e;if(0===t.length)return;let n=null,o=!1;t.forEach((e=>{n=this._convMap.get(e.conversationID),n&&(s&&n.reduceUnreadCount()&&(o=!0),n.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(n.setLastMessageRevoked(!0),n.setLastMessageRevoker(e.revoker),o=!0))})),o&&this._onConversationListUpdate()}_handleMessageModified(e){var t,s;console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:n,message:o}=e,i=this._convMap.get(n);if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(i))return;const{lastMessage:a}=i;a&&a.lastTime===o.time&&a.lastSequence===o.sequence&&a.version!==o.version&&(a.type=o.type,a.payload=o.payload,a.messageForShow=P(o.type,o.payload),a.cloudCustomData=o.cloudCustomData,a.version=o.version,this._onConversationListUpdate(),console.log(`${this._name} conversationID:${n} lastMessage updated`))}syncConvList(){return e(this,arguments,void 0,(function*(e=!0){yield this._pagingGetConvList(e),this._pagingStatus=I.RESOLVED,this._onConversationListUpdate()}))}_pagingGetConvList(t){return e(this,void 0,void 0,(function*(){try{this._pagingStatus=I.PENDING;const s=yield function(t,s){return e(this,void 0,void 0,(function*(){const{pagingTimeStamp:e,pagingStartIndex:n,pagingPinnedTimeStamp:o,pagingPinnedStartIndex:i}=t;try{const t="recentcontact.page_get",a=null==s?void 0:s.helper.generateProtocolData({servcmd:t,data:{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:null==s?void 0:s.store.get("login").userId,StartIndex:n,TimeStamp:e,TopStartIndex:i,TopTimeStamp:o}}),r=`${a.head.seq}${t}`;return yield s.channel.sendPacket(a,{requestId:r})}catch(e){throw console.warn(`ConversationService.pagingGetConvList error: ${e}`),e}}))}({pagingTimeStamp:t?this._pagingTimeStamp:0,pagingStartIndex:t?this._pagingStartIndex:0,pagingPinnedTimeStamp:t?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:t?this._pagingPinnedStartIndex:0},this._core);if(s){const{CompleteFlag:e,SessionItem:n=[],TimeStamp:o,StartIndex:i,TopTimeStamp:a,TopStartIndex:r}=s;if(n.length>0){const e=this._getConvOptions(n);this._pagingConvIDMap=new Map([...this._pagingConvIDMap,...e.map((e=>[e.conversationID,1]))]),this._updateLocalConvList({conversationOptionsList:e,isFromGetConversations:!0,updateUnreadCount:!0}),this._onConversationListUpdate()}this._pagingTimeStamp=o,this._pagingStartIndex=i,this._pagingPinnedTimeStamp=a,this._pagingPinnedStartIndex=r,1!==e&&this._pagingGetConvList(t)}}catch(e){throw console.error(`${this._name}._pagingGetConvList fail:`,e),e}}))}_getConvOptions(e){const n=this._convertConvKey(e).filter((({type:e,userID:t})=>1===e&&!this._isNonExistentAccount(t)||2===e)),o=this._core.store.get("login").userId;return n.map((e=>{var n,i,a,r,l,u,d,c,p,g,v,h;if(E(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===L.C2C){const s={userID:e.userID,nick:e.nick,avatar:e.peerAvatar},g=null===(a=null===(i=null===(n=this._core)||void 0===n?void 0:n.user)||void 0===i?void 0:i.userProfile)||void 0===a?void 0:a.createProfile(e.userID,[s]);return{conversationID:`${t}${e.userID}`,type:t,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(r=e.lastMsg)||void 0===r?void 0:r.elements[0])?null===(l=e.lastMsg)||void 0===l?void 0:l.elements[0].type:null,payload:(null===(u=e.lastMsg)||void 0===u?void 0:u.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(d=e.lastMsg)||void 0===d?void 0:d.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:e.lastC2CMsgFromAccount===o&&e.time<=e.c2cPeerReadTime,revoker:(null===(p=null===(c=e.lastMsg)||void 0===c?void 0:c.revokerInfo)||void 0===p?void 0:p.revoker)||null},unreadCount:0,userProfile:g,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}return{conversationID:`${s}${e.groupID}`,type:s,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(g=e.lastMsg)||void 0===g?void 0:g.cloudCustomData)||"",isRevoked:e.lastMessageFlag===S.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(h=null===(v=e.lastMsg)||void 0===v?void 0:v.revokerInfo)||void 0===h?void 0:h.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:N(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}))}_convertConvKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,s,n,o;if(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(e))return null;let i="",a=null;return e.MsgBody&&(i=null===(n=e.MsgBody[0])||void 0===n?void 0:n.MsgType,a=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:a,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var s;if(!t)return t;const n=this._core.message.messageFactory.getElementClass(e);return n?null===(s=n.parseServerPushElement(t))||void 0===s?void 0:s.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var s={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(s[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(n=Object.getOwnPropertySymbols(e);o<n.length;o++)t.indexOf(n[o])<0&&Object.prototype.propertyIsEnumerable.call(e,n[o])&&(s[n[o]]=e[n[o]])}return s}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){let t="";return 0===e?t=M:1===e?t=y:2===e?t=f:3===e&&(t=T),t}_patchTypeAndPayload(e){const{event:t,elements:s=[]}=e.lastMsg||{};return E(t)?{type:s[0]?s[0].type:null,payload:s[0]?this._amendLayersOverLimitProp(s[0].content):null}:{type:h,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:s=0}=e,n=t-s;return n>0?n:0}_updateLocalConvList(e){const{newConvList:t}=this._getTmpConvListMapping(e);this._convMap=new Map(this._sortConvList([...this._convMap])),this._core.store.set("conversation",{conversationMap:this._convMap}),console.log(`${this._name}._updateLocalConvList newConvList: ${t.length}`)}_getTmpConvListMapping(e){const{conversationOptionsList:n,isFromGetConversations:o,isInstantMessage:i,isUnreadC2CMessage:a=!1,updateUnreadCount:r}=e,l=[],u=null==n?void 0:n.length;for(let e=0;e<u;e++){const u=new b(n[e]),{conversationID:d,type:c}=u;if(!this._isNonExistentAccount(d))if(this._convMap.has(d)){const l=this._convMap.get(d);if(o){this._convMap.set(d,u),c===t?u.unreadCount=l.unreadCount:c===s&&(u.groupProfile=JSON.parse(JSON.stringify(l.groupProfile)));continue}this._mergeConversationInfo({conversationID:d,tmpConversation:u,lastMessage:n[e].lastMessage,isFromGetConversations:o,isInstantMessage:i}),this._patchLastMessage({conversationID:d,lastMessage:n[e].lastMessage,isInstantMessage:i}),!0===r&&(null==l||l.updateUnreadCount({nextUnreadCount:u.unreadCount,isFromGetConversations:o,isUnreadC2CMessage:a}))}else l.push(u),this._convMap.set(d,u)}return{newConvList:l}}_isNonExistentAccount(e){let s;return e.startsWith(t)&&(s=e.replace(t,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}_mergeConversationInfo(e){var t,s;const{conversationID:n,tmpConversation:o,lastMessage:i,isFromGetConversations:a,isInstantMessage:r}=e,l=this._convMap.get(n),u=["unreadCount","allowType","adminForbidType","payload"];!1===r&&u.push("lastMessage"),a&&u.push("isPinned"),E(r)&&i&&null===(null==l?void 0:l.lastMessage.payload)&&(l.lastMessage.payload=i.payload),(null===(s=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===s?void 0:s.isEmpty(null==l?void 0:l.lastMessage.revoker))||(l.lastMessage.revoker=null);k(l,o,u,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{conversationID:t,lastMessage:n,isInstantMessage:o}=e,i=this._convMap.get(t);if(i&&n){const{payload:e,nameCard:t,nick:a,cloudCustomData:r=""}=n;o&&(e&&(i.lastMessage.payload=e),i.type===s&&(i.lastMessage.nameCard=t,i.lastMessage.nick=a)),i.lastMessage.cloudCustomData!==r&&(i.lastMessage.cloudCustomData=r)}}_sortConvList(e){const t=[],s=[],n=[],o=[];return e.forEach((e=>{var i,a,r,l;!0===e[1].isPinned?(null===(a=null===(i=this._core)||void 0===i?void 0:i.helper)||void 0===a?void 0:a.isEmpty(e[1].lastMessage.lastTime))?s.push(e):t.push(e):(null===(l=null===(r=this._core)||void 0===r?void 0:r.helper)||void 0===l?void 0:l.isEmpty(e[1].lastMessage.lastTime))?o.push(e):n.push(e)})),t.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(o)}_getLocalConvList(){return[...this._convMap.values()].filter((e=>this._isConvNeedShow(e.conversationID)))}_isConvNeedShow(e){const t=this._getLocalConversation(e);if(E(t))return!0;const o=t.type===n,i=t.type===s&&t.subType===a,l=t.type===s&&t.subType===r;return!(o||i||l)}_getLocalConversation(e){return this._convMap.get(e)}_updateUnreadCount(e,t=!0){var s,n;let o=!1;const i=this._getLocalConversation(e),a=null===(n=null===(s=this._core)||void 0===s?void 0:s.message.messageStore)||void 0===n?void 0:n.getLocalMessageList(e);if(!i)return o;const r=i.unreadCount,l=null==a?void 0:a.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return r!==l&&(i.unreadCount=l,o=!0,console.log(`${this._name}._updateUnreadCount\n from ${r} to ${l}, conversationID:${e}`),!0===t&&this._onConversationListUpdate()),o}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}_onConversationListUpdate(){var e;const t=this._getLocalConvList();this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.CONVERSATION_LIST_UPDATED,data:t}),this._onTotalUnreadCountUpdate()}_onTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._convTotalUnreadCount!==t&&(console.log(`${this._name}._onTotalUnreadCountUpdate from ${this._convTotalUnreadCount} to ${t}`),this._convTotalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}getConversationList(t){return e(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(t),isSyncCompleted:this._isSyncCompleted()}}}))}_getConversationList(e){if(E(e))return this._getLocalConvList();if(O(e)){if(0===e.length)return[];return this._getLocalConvList().filter((t=>e.includes(t.conversationID)))}if((e=>{if("object"!=typeof e||null===e)return!1;const t=Object.getPrototypeOf(e);if(null===t)return!0;let s=t;for(;null!==Object.getPrototypeOf(s);)s=Object.getPrototypeOf(s);return t===s})(e)){const{type:t,markType:s,groupName:n,hasUnreadCount:o,hasGroupAtInfo:i}=e;return this._getLocalConvList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,s)&&this._filterGroupName(e,n)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_isSyncCompleted(){return this._pagingStatus===I.RESOLVED}_filterType(e,n){return n!==t&&n!==s||e.type===n}_filterGroupName(e,t){return!D(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){return null===(s=t)||!("number"==typeof s&&!Number.isNaN(s-0)||"object"==typeof s&&s.constructor===Number)||(0===t?0===e.markList.length:e.markList.includes(t));var s}_filterUnreadCount(e,t){let s=!0;return!0===t?s=e.unreadCount>=1:!1===t&&(s=0===e.unreadCount),s}_recoverConversations(){return e(this,void 0,void 0,(function*(){try{yield this.syncConvList(),this._core.notificationCenter.emitInnerEvent(this._core.InnerEvent.RECOVER_CONVERSATIONS_COMPLETED)}catch(e){console.debug(e)}}))}_filterGroupAtInfo(e,t){let s=!0;return!0===t?s=e.groupAtInfoList.length>=1:!1===t&&(s=0===e.groupAtInfoList.length),s}getConversationProfile(n){return e(this,void 0,void 0,(function*(){let e;return this._convMap.has(n)?e=this._convMap.get(n):(e=new b({conversationID:n}),(e=>D(e)&&e.slice(0,3)===t)(n)?(e.type=t,e.userProfile={userID:n.replace(t,"")}):(e.type=s,e.groupProfile={groupID:n.replace(s,"")}),this._convMap.set(n,e)),{code:0,data:{conversation:e}}}))}setMessageRead(t){return e(this,void 0,void 0,(function*(){console.log(`${this._name}.setMessageRead ok, ${JSON.stringify(t)}`)}))}setConversationDraft(t){return e(this,void 0,void 0,(function*(){return console.log(`${this._name}.setConversationDraft , ${JSON.stringify(t)}`),{code:0,data:{conversation:{}}}}))}getTotalUnreadMessageCount(){const e=this._getLocalConvList();let t=0;return e.forEach((e=>{e.type!==o&&(""!==e.messageRemindType&&e.messageRemindType!==M||(t+=e.unreadCount))})),t}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.RE_LOGIN,this._recoverConversations,this),e.unSubscribeInnerEvent(t.LOGIN,this.handleLoginSuccess,this),e.unSubscribeInnerEvent(t.NEW_MESSAGE,this._handleNewMessage,this),e.unSubscribeInnerEvent(t.MESSAGE_DELETED,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(t.MESSAGE_REVOKED,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(t.MESSAGE_MODIFIED,this._handleMessageModified,this),e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};const A={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0},F={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!e.startsWith("C2C")&&!e.startsWith("GROUP"))||"conversationID is invalid."}]};return{install:function(e){U.install(e),e.helper.registerValidateConfig({auth:A,params:F})},handleLoginSuccess:function(){U.handleLoginSuccess()}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatConversation=t()}(this,(function(){"use strict";const e=new class{init(e){this.core=e}};function t(e,t,n,s){return new(n||(n=Promise))((function(o,i){function r(e){try{c(s.next(e))}catch(e){i(e)}}function a(e){try{c(s.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(r,a)}c((s=s.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const n=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,3)===n.CONV_C2C},s=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t.slice(0,5)===n.CONV_GROUP},o=t=>{const{core:{OuterConstant:n,utils:{isString:s}}}=e;return s(t)&&t===n.CONV_SYSTEM},i=t=>({lastTime:(null==t?void 0:t.time)||(null==t?void 0:t.lastTime)||0,lastSequence:(null==t?void 0:t.sequence)||(null==t?void 0:t.lastSequence)||0,fromAccount:(null==t?void 0:t.from)||(null==t?void 0:t.fromAccount)||"",messageForShow:e.core.common.getMessagePreviewText(null==t?void 0:t.type,null==t?void 0:t.payload),payload:(null==t?void 0:t.payload)||null,type:(null==t?void 0:t.type)||"",isRevoked:(null==t?void 0:t.isRevoked)||!1,cloudCustomData:(null==t?void 0:t.cloudCustomData)||"",onlineOnlyFlag:(null==t?void 0:t._onlineOnlyFlag)||!1,nick:(null==t?void 0:t.nick)||"",nameCard:(null==t?void 0:t.nameCard)||"",version:(null==t?void 0:t.version)||0,isPeerRead:(null==t?void 0:t.isPeerRead)||!1,revoker:(null==t?void 0:t.revoker)||null});function r(t){const{core:{utils:{isString:n}}}=e,s=[];if(!n(t))return s;const o=t.length;if(0===o)return s;for(let e=o-1;e>=0;e--)"1"===t[e]&&s.push(2**(o-e-1));return s}function a(t){const{OuterConstant:n}=e.core;let s="";return 0===t?s=n.MSG_REMIND_ACPT_AND_NOTE:1===t?s=n.MSG_REMIND_DISCARD:2===t?s=n.MSG_REMIND_ACPT_NOT_NOTE:3===t&&(s=n.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),s}function c(t){const{OuterConstant:n}=e.core;let s;return t.startsWith(n.CONV_C2C)&&(s=t.replace(n.CONV_C2C,"")),"@TLS#ERROR"===s||"@TLS#NOT_FOUND"===s}var l,u,d,_,p;!function(e){e.NOT_START="notStart",e.PENDING="pending",e.RESOLVED="resolved",e.REJECTED="rejected"}(l||(l={})),function(e){e[e.C2C=1]="C2C",e[e.GROUP=2]="GROUP"}(u||(u={})),function(e){e[e.C2C=8]="C2C",e[e.GROUP=2]="GROUP"}(d||(d={})),function(e){e[e.ONLY_CONVERSATIONID=1]="ONLY_CONVERSATIONID"}(_||(_={})),function(e){e[e.CONV_DELETED=1]="CONV_DELETED",e[e.CONV_PINED=2]="CONV_PINED",e[e.CONV_UNPINED=3]="CONV_UNPINED",e[e.CONV_MARK_UPDATED=4]="CONV_MARK_UPDATED",e[e.CONV_GROUP_ADDED=5]="CONV_GROUP_ADDED",e[e.CONV_GROUP_DELETED=6]="CONV_GROUP_DELETED",e[e.CONV_GROUP_UPDATED=7]="CONV_GROUP_UPDATED"}(p||(p={}));var h;!function(e){e[e.CONV_NOT_FOUND=2500]="CONV_NOT_FOUND",e[e.USER_OR_GRP_NOT_FOUND=2501]="USER_OR_GRP_NOT_FOUND",e[e.CONV_UN_RECORDED_TYPE=2502]="CONV_UN_RECORDED_TYPE"}(h||(h={}));class C{constructor(e){this.conversationID=e.conversationID||"",this.unreadCount=e.unreadCount||0,this.type=e.type||"",this.lastMessage=i(e.lastMessage),this.peerReadTime=e.peerReadTime||0,this.groupAtInfoList=[],this.remark=e.remark||"",this.isPinned=e.isPinned||!1,this.messageRemindType=e.messageRemindType,this.markList=e.markList||[],this.customData=e.customData||"",this.conversationGroupList=e.conversationGroupList||[],this.draftText=e.draftText||"",this.userProfile=e.userProfile,this.groupProfile=e.groupProfile,this.subType=e.subType||"",this._isInfoCompleted=!1,this._init()}_init(){const{core:{OuterConstant:t,utils:{isUndefined:n}}}=e;n(this.userProfile)&&this.type===t.CONV_C2C?this.userProfile={}:n(this.groupProfile)&&this.type===t.CONV_GROUP&&(this.groupProfile={}),this.subType&&this.type===t.CONV_GROUP&&(this.subType=this.groupProfile.type||"")}updateUnreadCount(t){const{core:{OuterConstant:n,utils:{isUndefined:s}}}=e,{nextUnreadCount:o,isFromGetConversations:i,isUnreadC2CMessage:r}=t;s(o)||(this.subType!==n.GRP_AVCHATROOM?i&&this.type===n.CONV_GROUP||i&&this.type===n.CONV_TOPIC||r&&this.type===n.CONV_C2C?this.unreadCount=o:this.unreadCount+=o:this.unreadCount=0)}updateLastMessage(e){this.lastMessage=i(e)}reduceUnreadCount(){return this.unreadCount>=1&&(this.unreadCount-=1,!0)}isLastMessageRevoked(t){const{core:{OuterConstant:n}}=e,{sequence:s,time:o}=t;return this.type===n.CONV_C2C&&s===this.lastMessage.lastSequence&&o===this.lastMessage.lastTime||this.type===n.CONV_GROUP&&s===this.lastMessage.lastSequence}setLastMessageRevoked(e){this.lastMessage.isRevoked=e}setLastMessageRevoker(e){this.lastMessage.revoker=e}setDraftText(e){this.draftText=e}updateGroupAtInfoList(t){const{core:{OuterConstant:n}}=e;let[...s]=t.groupAtType;s.includes(n.CONV_AT_ME)||s.includes(n.CONV_AT_ALL)||(s=[n.CONV_AT_ALL_AT_ME]);const o={from:t.from,groupID:t.groupID,messageSequence:t.sequence,atTypeArray:s,__random:t.__random,__sequence:t.__sequence};this.groupAtInfoList.push(o)}clearGroupAtInfoList(){this.groupAtInfoList.length=0}getProfileCompleted(){return this._isInfoCompleted}setProfileCompleted(){this._isInfoCompleted=!0}}var g=new class{constructor(){this._name="ConversationDataHandler",this._totalUnreadCount=0,this._groupAtTipsList=[]}init(e){this._core=e;const{helper:t,notificationCenter:n,appStore:{conversationStore:s},constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:i},InnerEvent:{MESSAGE_PUSH:r,NEW_MESSAGE:a,MESSAGE_DELETED:c,MESSAGE_REVOKED:l,MESSAGE_MODIFIED:u,CONVERSATION_UPDATED:d,LOGOUT:_,DESTROY:p}}=e;this._conversationStore=s,t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,i.CONVERSATION_UPDATE_AFTER_GROUP_LIST_SYNC_FINISHED,this._handleGroupListSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.RECEIVE_C2C_NEW_MESSAGE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this),t.registerWorkflowStep(o.RECEIVE_GROUP_NEW_MESSAGE,i.CREATE_OR_UPDATE_CONVERSATION_BY_RECEIVE_NEW_MESSAGE,this._handleNewMessage,this),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_RE_ONLINE,i.CONVERSATION_UPDATE_AFTER_UNREAD_SYNC_FINISHED,this._handleUnreadSyncFinished,this);const{InnerEventSubType:{GROUP_AT_TIPS:h}}=n;n.subscribeInnerEvent(a,this._handleNewMessage,this),n.subscribeInnerEvent(r,h,this._handleNewGroupAtTips,this),n.subscribeInnerEvent(c,this._handleMessageDeleted,this),n.subscribeInnerEvent(l,this._handleMessageRevoked,this),n.subscribeInnerEvent(u,this._handleMessageModified,this),n.subscribeInnerEvent(d,this._handleConversationUpdated,this),n.subscribeInnerEvent(_,this._reset,this),n.subscribeInnerEvent(p,this._dispose,this),console.log(`${this._name}.init`)}_handleUnreadSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,{conversationUpdateFieldList:n=[],groupTipList:s=[],isUnreadC2CMessage:o}=e.result[t.UNREAD_MESSAGE_SYNC]||{};let i=!1;n.forEach((e=>{const{conversationID:t,unreadCount:n}=e,s=this.getLocalConversation(t);s&&s.unreadCount!==n&&(s.updateUnreadCount({nextUnreadCount:n,isUnreadC2CMessage:o}),i=!0)})),i&&this.emitConversationListUpdate(),this._handleGroupAtTipsSynced(s)}_handleGroupAtTipsSynced(e){for(let t=0;t<e.length;t++)12===e[t].Event&&this._handleNewGroupAtTips(e[t])}_handleGroupListSyncFinished(e){const{constants:{WORKFLOW_STEP:t}}=this._core,n=e.result[t.GROUP_LIST_SYNC]||[],{OuterConstant:{CONV_GROUP:s}}=this._core;let o=!1;for(let e=0;e<n.length;e++){const t=n[e],i=`${s}${t.groupID}`;if(!this.hasLocalConversation(i))continue;const r=this.getLocalConversation(i);r.groupProfile=JSON.parse(JSON.stringify(t)),r.lastMessage.lastSequence<t.nextMessageSeq&&(r.lastMessage.lastSequence=t.nextMessageSeq-1),r.subType||(r.subType=t.type),o=!0}o&&this.emitConversationListUpdate()}_handleNewMessage(e){const{conversationUpdateFieldList:t=[],isInstantMessage:n=!0,isUnreadC2CMessage:s=!1,updateUnreadCount:o=!0}=e.result||{};if(console.log(`${this._name}._handleNewMessage, conversationUpdateFieldList length:`,t.length,e),0===t.length)return;this.updateLocalConversationList({conversationUpdateFieldList:t,isInstantMessage:n,isUnreadC2CMessage:s,isFromGetConversations:!1,updateUnreadCount:o});t.filter((e=>this._isConversationNeedShow(e.conversationID))).length>0&&this.emitConversationListUpdate()}_handleNewGroupAtTips(e){const{GroupTips:t=[]}=e;t.forEach((e=>{const{GroupAtTips:t,MsgBody:n,GroupAtType:s,MsgRandom:o,ClientSeq:i}=e;let r={};t?r=this._convertGroupAtTipsKey(t):n?r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(n)),{sync:!0}):s&&(r=Object.assign(Object.assign({},this._convertGroupAtTipsKey(e)),{sync:!0})),r.__random=o,r.__sequence=i,this._groupAtTipsList.push(r)})),console.log(`${this._name}._handleNewGroupAtTips groupAtTipsList: ${JSON.stringify(this._groupAtTipsList)}`),this._updateGroupAtInfoList()}_convertGroupAtTipsKey(e){const{From_Account:t,GroupId:n,MsgSeq:s,GroupAtType:o}=e;return{from:t,groupID:n,sequence:s,groupAtType:o}}_updateGroupAtInfoList(){if(0===this._groupAtTipsList.length)return;const{common:e,OuterConstant:t}=this._core,n=e.getCurrentUserID();let s=!1;this._groupAtTipsList.forEach((e=>{const{groupID:o,from:i}=e;if(i!==n){const n=this.getLocalConversation(`${t.CONV_GROUP}${o}`);n&&(n.updateGroupAtInfoList(e),s=!0)}})),s&&this.emitConversationListUpdate(),this._groupAtTipsList.length=0}_handleMessageDeleted(e){var t,n;console.log(`${this._name}._handleMessageDeleted, conversationID:`,e);const{message:{messageDataHandler:s},OuterConstant:o}=this._core,i=(null==s?void 0:s.getLocalMessageList(e))||[];let r={};for(let e=(i.length||0)-1;e>=0;e--)if(!i[e].isDeleted){r=i[e];break}const a=this.getLocalConversation(e);if(!a)return;let c=!1;a.lastMessage.lastSequence===r.sequence&&a.lastMessage.lastTime===r.time||((null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r))&&(r=void 0),a.updateLastMessage(r),c=!0),e.startsWith(o.CONV_C2C)&&this.updateUnreadCount(e),c&&(this.emitConversationListUpdate(),console.log(`${this._name}._handleMessageDeleted. update conversationID:${e} with lastMessage:`,a.lastMessage))}_handleMessageRevoked(e){const{messageList:t=[],updateUnreadCount:n=!0}=e;if(console.log(`${this._name}._handleMessageRevoked messageList:${t.length}`),0===t.length)return;let s=null,o=!1;t.forEach((e=>{s=this.getLocalConversation(e.conversationID),s&&(n&&s.reduceUnreadCount()&&(o=!0),s.isLastMessageRevoked({sequence:e.sequence,time:e.time})&&(s.setLastMessageRevoked(!0),s.setLastMessageRevoker(e.revoker),o=!0))})),o&&this.emitConversationListUpdate()}_handleMessageModified(e){console.log(`${this._name}._handleMessageModified`,JSON.stringify(e));const{conversationID:t,messageList:n}=e,s=this.getLocalConversation(t),{utils:{isEmpty:o},common:{getMessagePreviewText:i}}=this._core;if(o(s))return;const{lastMessage:r}=s;if(r){const e=(null==n?void 0:n[0])||{};r.lastTime===e.time&&r.lastSequence===e.sequence&&r.version!==e.version&&(r.type=e.type,r.payload=e.payload,r.messageForShow=i(e.type,e.payload),r.cloudCustomData=e.cloudCustomData,r.version=e.version,this.emitConversationListUpdate(),console.log(`${this._name} conversationID:${t} lastMessage updated`))}}_handleConversationUpdated(){this.emitConversationListUpdate()}updateLocalConversationList(e){const{isFromGetConversations:t}=e,{newConversationList:n}=this._getTmpConversationListMapping(e);this._sortConversationList(),t||this._updateNewConversationProfile(n),console.log(`${this._name}.updateLocalConversationList newConversationList: ${n.length}`)}_getTmpConversationListMapping(e){const{OuterConstant:t}=this._core,{conversationUpdateFieldList:n,isFromGetConversations:s,isInstantMessage:o,isUnreadC2CMessage:i=!1,updateUnreadCount:r}=e,a=[],l=null==n?void 0:n.length;for(let e=0;e<l;e++){const l=new C(n[e]),{conversationID:u,type:d}=l;if(!c(u))if(this.hasLocalConversation(u)){const a=this.getLocalConversation(u);if(s){this.setLocalConversation(u,l),d===t.CONV_C2C?l.unreadCount=(null==a?void 0:a.unreadCount)||0:d===t.CONV_GROUP&&(l.groupProfile=JSON.parse(JSON.stringify(null==a?void 0:a.groupProfile)));continue}this._mergeConversationInfo({conversationID:u,tmpConversation:l,lastMessage:n[e].lastMessage,isFromGetConversations:s,isInstantMessage:o}),this._patchLastMessage({conversationID:u,lastMessage:n[e].lastMessage,isInstantMessage:o}),!0===r&&(null==a||a.updateUnreadCount({nextUnreadCount:l.unreadCount,isFromGetConversations:s,isUnreadC2CMessage:i}))}else a.push(l),this.setLocalConversation(u,l)}return{newConversationList:a}}_mergeConversationInfo(e){const{conversationID:t,tmpConversation:n,lastMessage:s,isFromGetConversations:o,isInstantMessage:i}=e,r=this.getLocalConversation(t),a=["unreadCount","allowType","adminForbidType","payload"];!1===i&&a.push("lastMessage"),o&&a.push("isPinned");const{utils:{isUndefined:c,isEmpty:l},common:{deepMerge:u}}=this._core;c(i)&&s&&null===(null==r?void 0:r.lastMessage.payload)&&(r.lastMessage.payload=s.payload),l(null==r?void 0:r.lastMessage.revoker)||(r.lastMessage.revoker=null);u(r,n,a,[null,void 0,"",0,NaN])}_patchLastMessage(e){const{OuterConstant:t}=this._core,{conversationID:n,lastMessage:s,isInstantMessage:o}=e,i=this.getLocalConversation(n);if(i&&s){const{payload:e,nameCard:n,nick:r,cloudCustomData:a=""}=s;o&&(e&&(i.lastMessage.payload=e),i.type===t.CONV_GROUP&&(i.lastMessage.nameCard=n,i.lastMessage.nick=r)),i.lastMessage.cloudCustomData!==a&&(i.lastMessage.cloudCustomData=a)}}_sortConversationList(){const{utils:{isEmpty:e}}=this._core,t=[...this._conversationStore.getConversationMap()],n=[],s=[],o=[],i=[];t.forEach((t=>{!0===t[1].isPinned?e(t[1].lastMessage.lastTime)?s.push(t):n.push(t):e(t[1].lastMessage.lastTime)?i.push(t):o.push(t)}));const r=n.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime)).concat(s).concat(o.sort(((e,t)=>t[1].lastMessage.lastTime-e[1].lastMessage.lastTime))).concat(i);this._updateConversationMapFromList(r)}_updateNewConversationProfile(e){if(0===e.length)return;const t=[],n=[],{OuterConstant:{CONV_GROUP:s,CONV_C2C:o}}=this._core;e.forEach((e=>{const{conversationID:i,type:r}=e;if(r===o){const e=i.replace(o,"");t.push(e)}else if(r===s){const e=i.replace(s,"");n.push(e)}})),t.length>0&&this._updateC2CConversation(t),n.length>0&&this._updateGroupConversation(n)}_updateC2CConversation(e){var t;const{OuterConstant:{CONV_C2C:n},appStore:{userStore:s},user:o}=this._core;let i=!1;null===(t=o.userProfile)||void 0===t||t.getUserProfile({userIDList:e}).then((e=>{((null==e?void 0:e.data)||[]).forEach((e=>{var t;const{userID:o}=e,r=this.getLocalConversation(`${n}${o}`);if(r){const n=(null===(t=s.getFriend(o))||void 0===t?void 0:t.remark)||"";r.remark=n,r.userProfile=e,i=!0}})),i&&this.emitConversationListUpdate()})).catch((e=>{}))}_updateGroupConversation(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core;let s=!1;e.forEach((e=>{const o=n.getGroup(e),i=this.getLocalConversation(`${t}${e}`);o&&i&&(i.groupProfile=o,s=!0)})),s&&this.emitConversationListUpdate()}_isConversationNeedShow(e){const t=this.getLocalConversation(e);if(this._core.utils.isUndefined(t))return!0;const{OuterConstant:n}=this._core,s=t.type===n.CONV_TOPIC,o=t.type===n.CONV_GROUP&&t.subType===n.GRP_ROOM,i=t.type===n.CONV_GROUP&&t.subType===n.GRP_LIVE;return!(s||o||i)}updateUnreadCount(e,t=!0){var n,s;let o=!1;const i=this.getLocalConversation(e),r=null===(s=null===(n=this._core)||void 0===n?void 0:n.message.messageDataHandler)||void 0===s?void 0:s.getLocalMessageList(e);if(!i)return o;const a=i.unreadCount,c=null==r?void 0:r.filter((e=>!e.isRead&&!e._onlineOnlyFlag&&!e.isDeleted)).length;return console.log(`${this._name}._updateUnreadCount conversationID:${e} currentUnreadCount:${a} newUnreadCount:${c}`),a!==c&&(i.unreadCount=c,o=!0,!0===t&&this.emitConversationListUpdate()),o}emitConversationListUpdate(e=!1){e&&this._sortConversationList();const{OuterEvent:{CONVERSATION_LIST_UPDATED:t}}=this._core,n=this.getLocalConversationList();this._emitEvent({name:t,data:n}),this._emitTotalUnreadCountUpdate()}_emitTotalUnreadCountUpdate(){var e;const t=this.getTotalUnreadMessageCount();this._totalUnreadCount!==t&&(console.log(`${this._name}._emitTotalUnreadCountUpdate from ${this._totalUnreadCount} to ${t}`),this._totalUnreadCount=t,this._emitEvent({name:null===(e=this._core)||void 0===e?void 0:e.OuterEvent.TOTAL_UNREAD_MESSAGE_COUNT_UPDATED,data:t}))}_emitEvent(e){var t;null===(t=this._core)||void 0===t||t.notificationCenter.emitOuterEvent(e.name,e)}getTotalUnreadMessageCount(){const{OuterConstant:e}=this._core,t=this.getLocalConversationList();let n=0;return t.forEach((t=>{t.type!==e.CONV_SYSTEM&&(""!==t.messageRemindType&&t.messageRemindType!==e.MSG_REMIND_ACPT_AND_NOTE||(n+=t.unreadCount))})),n}getLocalConversationList(){return[...this._conversationStore.getConversationMap().values()].filter((e=>this._isConversationNeedShow(e.conversationID)))}hasLocalConversation(e){return this._conversationStore.getConversationMap().has(e)}getLocalConversation(e){return this._conversationStore.getConversationMap().get(e)}setLocalConversation(e,t){return this._conversationStore.getConversationMap().set(e,t)}deleteLocalConversation(e){this._conversationStore.getConversationMap().delete(e)}_updateConversationMapFromList(e){this._clearConversationMap();for(const[t,n]of e)this.setLocalConversation(t,n)}_clearConversationMap(){this._conversationStore.getConversationMap().clear()}patchMessageRemindType(e,t){let n=!1;e.forEach((e=>{const s=this.getLocalConversation(e);(null==s?void 0:s.messageRemindType)!==t&&(s.messageRemindType=t,n=!0)})),console.log(`${this._name}.patchMessageRemindType conversationIDList:${e} messageRemindType:${t} hasUpdated:${n}`),n&&this.emitConversationListUpdate()}markMessageAsRead(e){const{message:{messageDataHandler:t}}=this._core,{conversationID:n,lastReadTime:s=0,lastReadSequence:o=0}=e,i=null==t?void 0:t.getLocalMessageList(n);if(0===i.length)return;const{length:r}=i;for(let e=r-1;e>=0;e--){const t=i[e],n=s&&t.time>s,r=o&&t.sequence>o;if(!n&&!r){if("in"===t.flow&&t.isRead)break;t.setIsRead(!0)}}}appendToPinnedConversation(e){const t=[...this._conversationStore.getConversationMap().entries()],n=t.findIndex((e=>!1===e[1].isPinned));t.splice(n,0,[e.conversationID,e]),this._updateConversationMapFromList(t),this.emitConversationListUpdate()}_reset(){this._clearConversationMap(),this._totalUnreadCount=0,this._groupAtTipsList=[]}_dispose(){const{notificationCenter:e,InnerEvent:{NEW_MESSAGE:t,MESSAGE_DELETED:n,MESSAGE_REVOKED:s,MESSAGE_MODIFIED:o,CONVERSATION_UPDATED:i,LOGOUT:r,DESTROY:a}}=this._core,{InnerEventSubType:{GROUP_AT_TIPS:c}}=e;e.unSubscribeInnerEvent(t,this._handleNewMessage,this),e.unSubscribeInnerEvent(t,c,this._handleNewGroupAtTips,this),e.unSubscribeInnerEvent(n,this._handleMessageDeleted,this),e.unSubscribeInnerEvent(s,this._handleMessageRevoked,this),e.unSubscribeInnerEvent(o,this._handleMessageModified,this),e.unSubscribeInnerEvent(i,this._handleConversationUpdated,this),e.unSubscribeInnerEvent(r,this._reset,this),e.unSubscribeInnerEvent(a,this._dispose,this)}};function v(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var m=new class{constructor(){this._name="SyncConversationList",this._pagingStatus="",this._pagingTimeStamp=0,this._pagingStartIndex=0,this._pagingPinnedTimeStamp=0,this._pagingPinnedStartIndex=0}init(e){this._core=e;const{notificationCenter:t,InnerEvent:n,helper:s,constants:o}=e;s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,o.WORKFLOW_STEP.CONVERSATION_RECOVER,this._syncConversationListOnReOnline,this),s.registerWorkflowStep(o.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_LOGIN,o.WORKFLOW_STEP.CONVERSATION_LIST_SYNC,this._syncConversationList,this),t.subscribeInnerEvent(n.DESTROY,this._dispose,this),console.log(`${this._name}.init`)}isSyncCompleted(){return this._pagingStatus===l.RESOLVED}_syncConversationListOnReOnline(){return t(this,void 0,void 0,(function*(){return this._syncConversationList()}))}_syncConversationList(){return t(this,void 0,void 0,(function*(){yield this._pagingGetConversationList(!0),this._pagingStatus=l.RESOLVED,g.emitConversationListUpdate()}))}_pagingGetConversationList(e){return t(this,void 0,void 0,(function*(){try{this._pagingStatus=l.PENDING;const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,pagingTimeStamp:s,pagingStartIndex:o,pagingPinnedTimeStamp:i,pagingPinnedStartIndex:r}=e;return v("recentcontact.page_get",{AssistFlags:31,MsgAssistFlags:15,OrderType:1,From_Account:t,StartIndex:o,TimeStamp:s,TopStartIndex:r,TopTimeStamp:i},n)}))}({fromAccount:n.getCurrentUserID(),pagingTimeStamp:e?this._pagingTimeStamp:0,pagingStartIndex:e?this._pagingStartIndex:0,pagingPinnedTimeStamp:e?this._pagingPinnedTimeStamp:0,pagingPinnedStartIndex:e?this._pagingPinnedStartIndex:0},this._core),{CompleteFlag:o,SessionItem:i=[],TimeStamp:r,StartIndex:a,TopTimeStamp:c,TopStartIndex:u}=s||{};if(i.length>0){const e=this._getConversationOptions(i);g.updateLocalConversationList({conversationUpdateFieldList:e,isFromGetConversations:!0,updateUnreadCount:!0}),g.emitConversationListUpdate()}this._pagingTimeStamp=r,this._pagingStartIndex=a,this._pagingPinnedTimeStamp=c,this._pagingPinnedStartIndex=u,1!==o&&this._pagingGetConversationList(e)}catch(e){throw console.error(`${this._name}._pagingGetConversationList fail:`,e),e}}))}_getConversationOptions(e){const{utils:{isUndefined:t}}=this._core,n=this._convertConversationKey(e);return this._filterValidConversations(n).map((e=>(t(e.lastMsg)&&(e.lastMsg={elements:[]}),e.type===u.C2C?this._assembleC2COption(e):this._assembleGroupOption(e))))}_filterValidConversations(e){return e.filter((({type:e,userID:t})=>e===u.C2C&&!c(t)||2===e))}_assembleC2COption(e){var t,n,s,o,i,a;const{OuterConstant:c}=this._core,l=this._createUserprofile(e);return{conversationID:`${c.CONV_C2C}${e.userID}`,type:c.CONV_C2C,lastMessage:{lastTime:e.time,lastSequence:e.sequence,fromAccount:e.lastC2CMsgFromAccount,type:(null===(t=e.lastMsg)||void 0===t?void 0:t.elements[0])?null===(n=e.lastMsg)||void 0===n?void 0:n.elements[0].type:null,payload:(null===(s=e.lastMsg)||void 0===s?void 0:s.elements[0])?this._amendLayersOverLimitProp(e.lastMsg.elements[0].content):null,cloudCustomData:(null===(o=e.lastMsg)||void 0===o?void 0:o.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.C2C,onlineOnlyFlag:!1,nick:"",nameCard:"",version:0,isPeerRead:this._computeIsPeerRead(e),revoker:(null===(a=null===(i=e.lastMsg)||void 0===i?void 0:i.revokerInfo)||void 0===a?void 0:a.revoker)||null},unreadCount:0,userProfile:l,peerReadTime:e.peerReadTime,isPinned:1===e.isPinned,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],remark:e.friendRemark||"",messageRemindType:this._transMsgRemindType(e.messageRemindType)}}_createUserprofile(e){var t;const{userID:n,nick:s,peerAvatar:o}=e,i=[{tag:"Tag_Profile_IM_Nick",value:s},{tag:"Tag_Profile_IM_Image",value:o}];return null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(n,i)}_computeIsPeerRead(e){const{common:t}=this._core,n=t.getCurrentUserID(),{lastC2CMsgFromAccount:s,time:o,c2cPeerReadTime:i}=e;return s===n&&o<=i}_assembleGroupOption(e){var t,n,s;const{OuterConstant:o}=this._core;return{conversationID:`${o.CONV_GROUP}${e.groupID}`,type:o.CONV_GROUP,lastMessage:Object.assign(Object.assign({lastTime:e.time,lastSequence:e.sequence,fromAccount:e.msgGroupFromAccount},this._patchTypeAndPayload(e)),{cloudCustomData:(null===(t=e.lastMsg)||void 0===t?void 0:t.cloudCustomData)||"",isRevoked:e.lastMessageFlag===d.GROUP,onlineOnlyFlag:!1,nick:e.msgGroupFromNickName||"",nameCard:e.msgGroupFromCardName||"",revoker:(null===(s=null===(n=e.lastMsg)||void 0===n?void 0:n.revokerInfo)||void 0===s?void 0:s.revoker)||null}),groupProfile:{groupID:e.groupID,name:e.groupNick,avatar:e.groupImage,type:e.groupType,nextMessageSeq:e.nextMessageSeq},unreadCount:this._computeGroupUnreadCount(e),peerReadTime:0,isPinned:1===e.isPinned,version:0,customData:e.customMark||"",markList:r(e.standardMark),conversationGroupList:[],messageRemindType:this._transMsgRemindType(e.messageRemindType),subType:e.groupType}}_convertConversationKey(e){return e.map((e=>({type:e.Type,userID:e.To_Account,nick:e.C2cNick,peerAvatar:e.C2cImage,time:e.MsgTimeStamp,sequence:e.MsgSeq,lastC2CMsgFromAccount:e.LastC2cMsgFrom_Account,lastMsg:this._convertLastMsgKey(e.LastMsg),lastMessageFlag:e.LastMsgFlags,c2cPeerReadTime:e.LastC2cMsgPeerReadTime,peerReadTime:e.C2cPeerReadTime,friendRemark:e.C2cRemark,isPinned:e.TopFlags,standardMark:e.StandardMark,customMark:e.CustomMark,messageRemindType:e.MsgRecvOption,groupID:e.ToAccount,groupNick:e.GroupNick,groupImage:e.GroupImage,groupType:e.GroupType,nextMessageSeq:e.GroupNextMsgSeq,msgGroupFromAccount:e.MsgGroupFrom_Account,msgGroupFromNickName:e.MsgGroupFromNickName,MsgGroupFromCardName:e.MsgGroupFromCardName,unreadCount:e.UnreadMsgCount,noUnreadCount:e.GroupIgnoredUnreadSeqCount})))}_convertLastMsgKey(e){var t,n,s,o;if(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(e))return null;let i="",r=null;return e.MsgBody&&(i=null===(s=e.MsgBody[0])||void 0===s?void 0:s.MsgType,r=this._parseContent(i,e.MsgBody[0])),{event:e.Event,elements:[{type:i,content:r,cloudCustomData:e.CloudCustomData}],revokerInfo:{revoker:null===(o=e.RevokerInfo)||void 0===o?void 0:o.revoker}}}_parseContent(e,t){var n;if(!t)return t;const s=this._core.message.messageFactory.getElementClass(e);return s?null===(n=s.parseServerPushElement(t))||void 0===n?void 0:n.content:t}_amendLayersOverLimitProp(e){const{LayersOverLimit:t}=e;return(function(e,t){var n={};for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&t.indexOf(s)<0&&(n[s]=e[s]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(s=Object.getOwnPropertySymbols(e);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(e,s[o])&&(n[s[o]]=e[s[o]])}return n}(e,["LayersOverLimit"])).layersOverLimit=1===t,e}_transMsgRemindType(e){const{OuterConstant:t}=this._core;let n="";return 0===e?n=t.MSG_REMIND_ACPT_AND_NOTE:1===e?n=t.MSG_REMIND_DISCARD:2===e?n=t.MSG_REMIND_ACPT_NOT_NOTE:3===e&&(n=t.NOT_RECEIVE_OFFLINE_PUSH_EXCEPT_AT),n}_patchTypeAndPayload(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core,{event:s,elements:o=[]}=e.lastMsg||{};return n(s)?{type:o[0]?o[0].type:null,payload:o[0]?this._amendLayersOverLimitProp(o[0].content):null}:{type:t.MSG_GRP_TIP,payload:{}}}_computeGroupUnreadCount(e){const{unreadCount:t=0,noUnreadCount:n=0}=e,s=t-n;return s>0?s:0}_dispose(){const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.DESTROY,this._dispose,this)}};var f=new class{constructor(){this._name="GetConversationList"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationList",context:this})}getConversationList(e){return t(this,void 0,void 0,(function*(){return{code:0,data:{conversationList:this._getConversationList(e),isSyncCompleted:m.isSyncCompleted()}}}))}_getConversationList(e){const{utils:{isUndefined:t,isArray:n,isPlainObject:s}}=this._core;if(t(e))return g.getLocalConversationList();if(n(e)){if(0===e.length)return[];return g.getLocalConversationList().filter((t=>e.includes(t.conversationID)))}if(s(e)){const{type:t,markType:n,groupName:s,hasUnreadCount:o,hasGroupAtInfo:i}=e;return g.getLocalConversationList().filter((e=>this._filterType(e,t)&&this._filterMarkType(e,n)&&this._filterGroupName(e,s)&&this._filterUnreadCount(e,o)&&this._filterGroupAtInfo(e,i)))}return[]}_filterType(e,t){const{OuterConstant:n}=this._core;return t!==n.CONV_C2C&&t!==n.CONV_GROUP||e.type===t}_filterGroupName(e,t){const{utils:{isString:n}}=this._core;return!n(t)||(""===t?0===e.conversationGroupList.length:e.conversationGroupList.includes(t))}_filterMarkType(e,t){const{utils:{isNumber:n}}=this._core;return!n(t)||(0===t?0===e.markList.length:e.markList.includes(t))}_filterUnreadCount(e,t){let n=!0;return!0===t?n=e.unreadCount>=1:!1===t&&(n=0===e.unreadCount),n}_filterGroupAtInfo(e,t){let n=!0;return!0===t?n=e.groupAtInfoList.length>=1:!1===t&&(n=0===e.groupAtInfoList.length),n}};function O(e,n,s){return t(this,void 0,void 0,(function*(){const{helper:t,channel:o}=s,i=t.generateProtocolData({servcmd:e,data:n}),r=`${i.head.seq}${e}`;return yield o.sendPacket(i,{requestId:r})}))}var M=new class{constructor(){this._name="GetC2CMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){try{const{common:n}=this._core,s=yield function(e,n){return t(this,void 0,void 0,(function*(){const{toAccount:t,userIDList:s}=e;return O("openim.get_c2c_peer_mute_notifications",{To_Account:t,Peer_Account:s},n)}))}({toAccount:n.getCurrentUserID(),userIDList:e},this._core),{MuteNotificationsList:o=[]}=s||{};o.forEach((e=>{const{Peer_Account:t,MuteNotifications:n}=e,s=`${this._core.OuterConstant.CONV_C2C}${t}`,o=a(n);g.patchMessageRemindType([s],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var E=new class{constructor(){this._name="GetGroupMessageRemindType"}init(e){this._core=e}get(e){return t(this,void 0,void 0,(function*(){if(0!==e.length)try{const n=yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupIDList:t,responseFilter:s}=e;return O("group_open_http_svc.get_group_self_member_info",{GroupIdList:t,ResponseFilter:s},n)}))}({groupIDList:e,responseFilter:{MemberInfoFilter:["MsgFlag"]}},this._core),{GroupInfo:s=[]}=n||{};s.forEach((e=>{var t;const{GroupId:n,MemberList:s}=e,o=(null===(t=s[0])||void 0===t?void 0:t.MsgFlag)||"",i=`${this._core.OuterConstant.CONV_GROUP}${n}`;g.patchMessageRemindType([i],o)}))}catch(e){console.error(`${this._name}.get fail:`,e)}}))}};var I=new class{constructor(){this._name="GetConversationProfile"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getConversationProfile",context:this})}getConversationProfile(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:{CONV_C2C:t,CONV_GROUP:s,GRP_AVCHATROOM:i},appStore:{groupStore:r},utils:{isEmpty:a}}=this._core,c={code:0,data:{}};let l=g.getLocalConversation(e);if(o(e))return c.data.conversation=l,c;let u=!1;const d=n(e)?t:s;if(a(l)&&(u=!0,l=new C({conversationID:e,type:d})),console.log(`${this._name}.getConversationProfile conversationID:${e} isNewConversation:${u}`),c.data.conversation=l,null==l?void 0:l.getProfileCompleted())return c;if(d===t){const n=e.replace(t,"");yield this._handleC2CConversation(l,n),u&&(yield M.get([n]))}if(d===s){const t=e.replace(s,"");if(!r.getGroup(t))return c;yield this._handleGroupConversation(l,t),u&&l.groupProfile.type!==i&&(yield E.get([t]))}return c}))}_handleC2CConversation(e,n){return t(this,void 0,void 0,(function*(){var t,s;const{user:o,helper:i,utils:{isEmpty:r},appStore:{conversationStore:a,userStore:c}}=this._core,{conversationID:l}=e,u=yield null===(t=o.userProfile)||void 0===t?void 0:t.getUserProfile({userIDList:[n]});if(0===(null==u?void 0:u.data.length))throw new i.ChatError({code:h.USER_OR_GRP_NOT_FOUND});e.userProfile=null==u?void 0:u.data[0];const d=null===(s=c.getFriend(n))||void 0===s?void 0:s.remark;r(d)||e.remark===d||(e.remark=d),e.setProfileCompleted();const _=g.hasLocalConversation(l);console.log(`${this._name}._handleC2CConversation conversationID:${l} hasLocalConversation: ${_}`),_?a.updateConversation(l,e):g.appendToPinnedConversation(e)}))}_handleGroupConversation(e,n){return t(this,void 0,void 0,(function*(){const{apiMap:{getGroupProfile:t},appStore:{conversationStore:s}}=this._core,{conversationID:o}=e,i=yield t({groupID:n});e.groupProfile=null==i?void 0:i.data.group,e.setProfileCompleted();const r=g.hasLocalConversation(o);console.log(`${this._name}._handleGroupConversation conversationID:${o} hasLocalConversation: ${r}`),r?s.updateConversation(o,e):g.appendToPinnedConversation(e)}))}};var T=new class{init(e){const{helper:t}=e;t.registerApi({apiName:"getTotalUnreadMessageCount",context:this})}getTotalUnreadMessageCount(){return g.getTotalUnreadMessageCount()}};var L=new class{constructor(){this._name="SetMessageRead"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRead",context:this})}handleC2CMessageReadSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{ReadC2cMsgNotify:s}=e;if(!t(s)){const{UinPairReadArray:e=[]}=s;e.forEach((e=>{const{From_Account:t,LastReadTime:s}=e,o=`${n.CONV_C2C}${t}`;console.log(`${this._name}.handleC2CMessageReadSync conversationID:${o} lastReadTime:${s}`),g.markMessageAsRead({conversationID:o,lastReadTime:s}),g.updateUnreadCount(o)}))}}))}handleGroupMessageReadSync(e){const{OuterConstant:t,utils:{isUndefined:n}}=this._core;e.forEach((e=>{const{GroupReadInfoArray:s}=e.MsgBody;n(s)||s.forEach((e=>{const{GroupId:n,LastReadMsgSeq:s}=e,o=`${t.CONV_GROUP}${n}`;console.log(`${this._name}.handleGroupMessageReadSync conversationID:${o} lastReadSequence:${s}`),g.markMessageAsRead({conversationID:o,lastReadSequence:s}),g.updateUnreadCount(o),this._clearGroupAtInfoList(o)}))}))}setMessageRead(e){return t(this,void 0,void 0,(function*(){var t,n;const{OuterConstant:s}=this._core,{conversationID:o}=e,i={code:0,data:{}},r=g.getLocalConversation(o);if(console.log(`${this._name}.setMessageRead conversationID:${o} unreadCount:${(null==r?void 0:r.unreadCount)||0}`),!r)return i;const a=!(null===(n=null===(t=this._core)||void 0===t?void 0:t.helper)||void 0===n?void 0:n.isEmpty(r.groupAtInfoList));if(r.type===s.CONV_GROUP&&a&&this._deleteGroupAtTips(o),0===r.unreadCount)return i;if(r.type===s.CONV_C2C){const e=this._getLocalMessageMaxTime(r);yield this._setC2CMessageRead(o,e)}if(r.type===s.CONV_GROUP){const e=this._getLocalMessageMaxSequence(r);yield this._setGroupMessageRead(o,e)}return r.type===s.CONV_SYSTEM&&(r.unreadCount=0),g.emitConversationListUpdate(),i}))}_deleteGroupAtTips(e){return t(this,void 0,void 0,(function*(){console.log(`${this._name}._deleteGroupAtTips conversationID:${e}`);const n=g.getLocalConversation(e);if(!n)return;const s=(null==n?void 0:n.groupAtInfoList)||[];if(0!==s.length)try{const{common:n}=this._core,o=s.map((e=>({From_Account:e.from,To_Account:n.getCurrentUserID(),MsgSeq:e.__sequence,MsgRandom:e.__random,GroupId:e.groupID})));yield function(e,n){return t(this,void 0,void 0,(function*(){const{messageListToDelete:t}=e;return v("openim.deletemsg",{DelMsgList:t},n)}))}({messageListToDelete:o},this._core),console.log(`${this._name}._deleteGroupAtTips ok. count:${s.length}`),this._clearGroupAtInfoList(e)}catch(e){console.error(`${this._name}._deleteGroupAtTips fail:`,e)}}))}_clearGroupAtInfoList(e){const t=g.getLocalConversation(e);if(!t)return;let n=!1;t.groupAtInfoList.length>0&&(t.clearGroupAtInfoList(),n=!0,console.log(`${this._name}._clearGroupAtInfoList conversationID:${e} needEmitConversationUpdate:${n}`)),n&&g.emitConversationListUpdate()}_getLocalMessageMaxTime(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.time)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastTime)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxTime update lastMessageTime from ${i} to ${o}`),i=o),i}_getLocalMessageMaxSequence(e){var t;const{conversationID:n}=e,s=this._core.message.messageDataHandler.getLocalMessageList(n),o=Math.max(...s.map((e=>e.sequence)));let i=(null===(t=null==e?void 0:e.lastMessage)||void 0===t?void 0:t.lastSequence)||0;return o>i&&(console.log(`${this._name}._getLocalMessageMaxSequence update lastMessageSequence from ${i} to ${o}`),i=o),i}_setC2CMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){return v("openim.msgreaded",e,n)}))}({C2CMsgReaded:{Cookie:"",C2CMsgReadedItem:[{To_Account:e.replace("C2C",""),LastedMsgTime:n,Receipt:1}]}},this._core),console.log(`${this._name}._setC2CMessageRead ok, lastReadTime:${n}`),g.markMessageAsRead({conversationID:e,lastReadTime:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setC2CMessageRead fail:`,e),e}}))}_setGroupMessageRead(e,n){return t(this,void 0,void 0,(function*(){try{yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,lastMessageSequence:s}=e;return v("group_open_http_svc.msg_read_report",{GroupId:t,MsgReadedSeq:s},n)}))}({groupID:e.replace("GROUP",""),lastMessageSequence:n},this._core),console.log(`${this._name}._setGroupMessageRead ok, lastReadSequence:${n}`),g.markMessageAsRead({conversationID:e,lastReadSequence:n}),g.updateUnreadCount(e)}catch(e){throw console.warn(`${this._name}._setGroupMessageRead fail:`,e),e}}))}};var S=new class{constructor(){this._name="PinConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"pinConversation",context:this})}handleConversationPinned(e,t){const{utils:{isArray:n}}=this._core;if(!n(e))return;const{OuterConstant:s}=this._core;let o=!1;e.forEach((e=>{const{Type:n,To_Account:i,GroupId:r}=e;let a;1===n?a=g.getLocalConversation(`${s.CONV_C2C}${i}`):2===n&&(a=g.getLocalConversation(`${s.CONV_GROUP}${r}`)),a&&(console.log(`${this._name}.handleConversationPinned conversationID:${a.conversationID} localPinned:${a.isPinned} remotePinned:${t}`),t&&!a.isPinned&&(a.isPinned=!0,o=!0),!t&&a.isPinned&&(a.isPinned=!1,o=!0))})),o&&g.emitConversationListUpdate(!0)}pinConversation(e){return t(this,void 0,void 0,(function*(){const{OuterConstant:i,common:r}=this._core,{conversationID:a,isPinned:c}=e,l={code:0,data:{conversationID:a}},u=g.getLocalConversation(a);if(u&&u.isPinned===c)return l;if(o(a))return u&&(u.isPinned=c),g.emitConversationListUpdate(!0),l;try{let e=null;n(a)?e={Type:1,To_Account:a.replace(i.CONV_C2C,"")}:s(a)&&(e={Type:2,GroupId:a.replace(i.CONV_GROUP,"")});const o=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,operationType:s,itemList:o}=e;return v("recentcontact.top",{From_Account:t,OperationType:s,RecentContactItem:o},n)}))}({fromAccount:r.getCurrentUserID(),operationType:!0===c?1:2,itemList:[e]},this._core);if(console.log(`${this._name}.pinConversation ok, conversationID:${a} isPinned:${c}.`),o){if(u)u.isPinned!==c&&(u.isPinned=c);else{const e=new C({conversationID:a,type:n(a)?i.CONV_C2C:i.CONV_GROUP,isPinned:c});g.setLocalConversation(a,e)}g.emitConversationListUpdate(!0)}return l}catch(e){throw console.error(`${this._name}.pinConversation fail:`,e),e}}))}};var R=new class{constructor(){this._name="DeleteConversation"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"deleteConversation",context:this})}handleConversationDeleted(e){const{utils:{isArray:t}}=this._core;if(!t(e))return;const{OuterConstant:n}=this._core,s=[];e.forEach((e=>{const{Type:t,Peer_Account:o,GroupId:i}=e;1===t&&s.push(`${n.CONV_C2C}${o}`),2===t&&s.push(`${n.CONV_GROUP}${i}`)})),console.log(`${this._name}.handleConversationDeleted conversationIDList:${s}`),this._deleteLocalConversationList(s)}deleteConversation(e){return t(this,void 0,void 0,(function*(){const{utils:{isString:t}}=this._core;if(t(e))return console.log(`${this._name}.deleteConversation conversationID:${e}`),void(yield this._deleteConversation({conversationIDList:[e],flag:_.ONLY_CONVERSATIONID}));const n=Object.assign({},e);n.conversationIDList.length>100&&(n.conversationIDList=n.conversationIDList.slice(0,100)),yield this._deleteConversation(n)}))}_deleteConversation(e){return t(this,void 0,void 0,(function*(){const{conversationIDList:t,clearHistoryMessage:n=!0,flag:s=0}=e;console.log(`${this._name}._deleteConversation conversationIDList:${t} clearHistoryMessage:${n}`);try{const e=yield Promise.all([this._deleteConversationFromLocal(t),this._deleteConversationFromServer(t,n)]),o=[...e[0],...e[1]];if(0===o.length)throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});return console.log(`${this._name}._deleteConversation ok.`),{code:0,data:s===_.ONLY_CONVERSATIONID?{conversationID:o[0]}:{conversationIDList:o}}}catch(e){throw console.error(`${this._name}._deleteConversation fail:`,e),e}}))}_deleteConversationFromLocal(e){const{OuterConstant:t}=this._core;return e.filter((e=>{var n;if(!g.hasLocalConversation(e))return!1;const s=null===(n=g.getLocalConversation(e))||void 0===n?void 0:n.type;return s!==t.CONV_GROUP||this._hasLocalGroup(e)?s===t.CONV_SYSTEM&&(this._deleteLocalConversation(e),!0):(this._deleteLocalConversation(e),!0)}))}_deleteConversationFromServer(e,n){return t(this,void 0,void 0,(function*(){const{OuterConstant:s,common:o}=this._core,i={fromAccount:o.getCurrentUserID(),conversationList:[],clearHistoryMessage:n?1:0};if(e.forEach((e=>{var t;if(g.hasLocalConversation(e)){const n=(null===(t=g.getLocalConversation(e))||void 0===t?void 0:t.type)||"",o=e.replace(n,"");n===s.CONV_C2C?i.conversationList.push({To_Account:o,Type:1}):n===s.CONV_GROUP&&this._hasLocalGroup(e)&&i.conversationList.push({ToGroupid:o,Type:2})}})),0===i.conversationList.length)return[];const r=yield function(e,n){return t(this,void 0,void 0,(function*(){const{fromAccount:t,conversationList:s,clearHistoryMessage:o}=e;return v("recentcontact.batch_delete",{From_Account:t,ContactItem:s,ClearRamble:o},n)}))}(i,this._core);if(r){const{ResultItem:e=[]}=r,t=[];return e.length>0&&e.forEach((e=>{if(0===e.ResultCode){const n=1===e.type?`${s.CONV_C2C}${e.To_Account}`:`${s.CONV_GROUP}${e.ToGroupid}`;t.push(n)}})),this._deleteLocalConversationList(t),t}return[]}))}_deleteLocalConversationList(e){let t=!1;e.forEach((e=>{g.hasLocalConversation(e)&&(this._deleteLocalConversation(e,!1),t=!0)})),console.log(`${this._name}._deleteLocalConversationList isUpdate:${t}`),t&&g.emitConversationListUpdate()}_deleteLocalConversation(e,t=!0){const n=g.hasLocalConversation(e);console.log(`${this._name}._deleteLocalConversation conversationID:${e} has:${n}`),n&&(g.deleteLocalConversation(e),this._deleteConversationLocalMessage(e),t&&g.emitConversationListUpdate())}_hasLocalGroup(e){const{OuterConstant:{CONV_GROUP:t},appStore:{groupStore:n}}=this._core,s=e.replace(t,"");return!!n.getGroup(s)}_deleteConversationLocalMessage(e){console.log(`${this._name}._deleteConversationLocalMessage conversationID:${e}`),this._core.message.messageDataHandler.deleteConversationMessageList(e)}};var y=new class{constructor(){this._name="SetConversationDraft"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setConversationDraft",context:this})}setConversationDraft(e){return t(this,void 0,void 0,(function*(){const{conversationID:t,draftText:n}=e;if(console.log(`${this._name} conversationID:${t} draftText:${n}`),!g.hasLocalConversation(t))throw new this._core.helper.ChatError({code:h.CONV_NOT_FOUND});const s=g.getLocalConversation(t);return null==s||s.setDraftText(n),g.emitConversationListUpdate(),{code:0,data:{conversation:s}}}))}};var D=new class{constructor(){this._name="SetC2CMessageRemindType"}init(e){this._core=e}set(n,s){return t(this,void 0,void 0,(function*(){n.length>30&&(console.warn(`${this._name}.set userIDList length:${n.length} exceeds limit 30`),n.splice(30));const o=function(){const{MSG_REMIND_ACPT_AND_NOTE:t,MSG_REMIND_DISCARD:n,MSG_REMIND_ACPT_NOT_NOTE:s}=e.core.OuterConstant;return{[t]:0,[n]:1,[s]:2}}()[s],i=yield function(e,n){return t(this,void 0,void 0,(function*(){const{userIDList:t,receiveMessageOption:s}=e;return O("openim.set_c2c_peer_mute_notifications",{Peer_Account:t,Mute_Notifications:s},n)}))}({userIDList:n,receiveMessageOption:o},this._core),{ErrorList:r=[]}=i||{},a=[];r.forEach((e=>{const{Peer_Account:t,ErrorCode:s}=e;a.push({userID:t,code:s});const o=n.indexOf(t);o>-1&&n.splice(o,1)}));const c=[],l=[],{OuterConstant:u}=this._core;return n.forEach((e=>{l.push(`${u.CONV_C2C}${e}`),c.push({userID:e})})),g.patchMessageRemindType(l,s),{code:0,data:{successUserIDList:c,failureUserIDList:a}}}))}};var N=new class{constructor(){this._name="SetGroupMessageRemindType"}init(e){this._core=e}set(e,n){return t(this,void 0,void 0,(function*(){const{common:s,OuterConstant:o}=this._core;yield function(e,n){return t(this,void 0,void 0,(function*(){const{groupID:t,userID:s,receiveMessageOption:o}=e;return O("group_open_http_svc.modify_group_member_info",{GroupId:t,Member_Account:s,MsgFlag:o},n)}))}({groupID:e,userID:s.getCurrentUserID(),receiveMessageOption:n},this._core);const i=`${o.CONV_GROUP}${e}`;return g.patchMessageRemindType([i],n),{code:0,data:{groupID:e,messageRemindType:n}}}))}};var A=new class{constructor(){this._name="SetMessageRemindType"}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"setMessageRemindType",context:this})}handleC2CMessageRemindTypeSync(e){const{helper:{isEmpty:t},OuterConstant:n}=this._core;e.forEach((e=>{const{MuteNotificationsSync:s}=e;if(!t(s)){const{To_Account:e,MuteNotifications:t}=s,o=e.map((e=>`${n.CONV_C2C}${e}`)),i=a(t);console.log(`${this._name}.handleC2CMessageRemindTypeSync conversationIDList:${o} messageRemindType:${i}`),g.patchMessageRemindType(o,i)}}))}setMessageRemindType(e){return t(this,void 0,void 0,(function*(){const t="setMessageRemindType",{groupID:n,userIDList:s,messageRemindType:o}=e,{helper:i,utils:{isUndefined:r}}=this._core;try{if(!r(n)){console.log(`${this._name}.${t} groupID:${n} messageRemindType:${o}`);return yield N.set(n,o)}if(!r(s)){console.log(`${this._name}.${t} userIDList:${s} messageRemindType:${o}`);return yield D.set(s,o)}throw new i.ChatError({functionName:t,message:"userIDList or groupID is required"})}catch(e){const n=new i.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${this._name}.${t} fail:`,n),n}}))}};var P=new class{init(e){console.log("ConversationAction.init"),this._core=e,m.init(e),f.init(e),I.init(e),T.init(e),L.init(e),S.init(e),R.init(e),y.init(e),A.init(e);const{notificationCenter:t,InnerEvent:{MESSAGE_PUSH:n,DESTROY:s}}=this._core,{InnerEventSubType:{CONV_MODIFIED:o,C2C_MESSAGE_READ_SYNC:i,GROUP_MESSAGE_READ_SYNC:r,C2C_REMIND_TYPE_SYNC:a}}=t;t.subscribeInnerEvent(n,o,this._onConversationModified,this),t.subscribeInnerEvent(n,i,this._onC2CMessageReadSync,this),t.subscribeInnerEvent(n,a,this._onC2CMessageRemindTypeSync,this),t.subscribeInnerEvent(n,r,this._onGroupMessageReadSync,this),t.subscribeInnerEvent(s,this._dispose,this)}handleLoginSuccess(){m.handleLoginSuccess()}_onConversationModified(e){const{RecentContactMod:t=[]}=e;t.forEach((e=>{const{PushType:t}=e;if(t===p.CONV_DELETED){const{RecentContactList:t}=e.RecentContactDeleteItem;R.handleConversationDeleted(t)}if(t===p.CONV_PINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!0)}if(t===p.CONV_UNPINED){const{RecentContactList:t}=e.RecentContactTopItem;S.handleConversationPinned(t,!1)}}))}_onC2CMessageReadSync(e){const{C2cNotifyMsgArray:t=[]}=e;L.handleC2CMessageReadSync(t)}_onC2CMessageRemindTypeSync(e){const{C2cNotifyMsgArray:t=[]}=e;A.handleC2CMessageRemindTypeSync(t)}_onGroupMessageReadSync(e){const{GroupTips:t=[]}=e;L.handleGroupMessageReadSync(t)}_dispose(){const{notificationCenter:e,InnerEvent:{MESSAGE_PUSH:t,DESTROY:n}}=this._core,{InnerEventSubType:{CONV_MODIFIED:s,C2C_MESSAGE_READ_SYNC:o,GROUP_MESSAGE_READ_SYNC:i,C2C_REMIND_TYPE_SYNC:r}}=e;e.unSubscribeInnerEvent(t,s,this._onConversationModified,this),e.unSubscribeInnerEvent(t,o,this._onC2CMessageReadSync,this),e.unSubscribeInnerEvent(t,r,this._onC2CMessageRemindTypeSync,this),e.unSubscribeInnerEvent(t,i,this._onGroupMessageReadSync,this),e.unSubscribeInnerEvent(n,this._dispose,this)}};var G=new class{init(e){console.log("ReceiveMessageOptions.init"),this._core=e,D.init(e),N.init(e),M.init(e),E.init(e)}};const U=e=>!n(e)&&!s(e)&&!o(e),$={getConversationProfile:[{key:"conversationID",required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}],setMessageRead:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."}},pinConversation:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!U(e)||"conversationID is invalid."},isPinned:{required:!0,rules:["boolean"],allowEmpty:!1}},deleteConversation:[{key:"options",required:!0,rules:["string","object"],allowEmpty:!1,customValidator:t=>{const{core:{utils:{isArray:n,isObject:s,isString:o}}}=e;if(!o(t)&&!s(t))return"options is String or Object.";if(o(t)&&U(t))return"conversationID is invalid.";if(s(t)){if(!n(t.conversationIDList))return"conversationIDList is not Array.";if(0===t.conversationIDList.length)return"conversationIDList is empty.";if(t.conversationIDList.some((e=>{if(U(e))return!0})))return"conversationIDList includes invalid conversationID.";if(t.clearHistoryMessage&&"boolean"!=typeof t.clearHistoryMessage)return"clearHistoryMessage is not Boolean."}return!0}}],setConversationDraft:{conversationID:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>!(!n(e)&&!s(e))||"conversationID is invalid."},draftText:{required:!0,rules:["string"],allowEmpty:!0}}},V={getConversationList:!0,getConversationProfile:!0,getTotalUnreadCount:!0,setMessageRead:!0,pinConversation:!0,deleteConversation:!0,setConversationDraft:!0,setMessageRemindType:!0};return new class{install(t){e.init(t),P.init(t),G.init(t),g.init(t),t.helper.registerValidateConfig({auth:V,params:$})}handleLoginSuccess(){P.handleLoginSuccess()}}}));
@@ -0,0 +1,8 @@
1
+ declare const followPlugin: {
2
+ [key: string]: any;
3
+ };
4
+
5
+ export default followPlugin;
6
+ declare module '@tencentcloud/lite-chat/plugins/follow' {
7
+ export default followPlugin;
8
+ }
@@ -0,0 +1 @@
1
+ function o(o,t,e,r){return new(e||(e=Promise))((function(n,l){function i(o){try{u(r.next(o))}catch(o){l(o)}}function s(o){try{u(r.throw(o))}catch(o){l(o)}}function u(o){var t;o.done?n(o.value):(t=o.value,t instanceof e?t:new e((function(o){o(t)}))).then(i,s)}u((r=r.apply(o,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(e,r){return o(this,void 0,void 0,(function*(){var o;const{common:n,store:l}=t.core,i={FollowType:e,From_Account:null===(o=l.get("login"))||void 0===o?void 0:o.userId,StartCursor:r,WantNum:f()};return function(o){const{FollowItem:t=[],NextCursor:e,ActionStatus:r,ErrorCode:n,ErrorInfo:l,ErrorDisplay:i}=o;return{resultList:t.map((o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence}))),nextPageToken:e,actionStatus:r,errorCode:n,errorInfo:l,errorDisplay:i}}(yield n.buildAndSendPacket({servcmd:"follow.follow_get",data:i}))}))}function s(t){return o(this,void 0,void 0,(function*(){return i(l.FOLLOWERS,t)}))}function u(t){return o(this,void 0,void 0,(function*(){return i(l.MUTUAL,t)}))}function c(t){return o(this,void 0,void 0,(function*(){return i(l.FOLLOWING,t)}))}function a(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,FollowItem:e.map((o=>({To_Account:o})))};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_add",data:l}))}))}function d(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_delete",data:l}))}))}function f(){const o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0!==e){const o=Number(e);return o>1e3?1e3:o}return 500}const w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{install(o){this._core=o;const{helper:e,notificationCenter:r,InnerEvent:n}=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(n.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})}))}getMyFollowersList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})}))}getMutualFollowersList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})}))}_getFollowList(t){return o(this,void 0,void 0,(function*(){const{functionName:o,protocolFunction:r,nextCursor:n=""}=t;console.log(`${e} ${o} nextCursor:`,n);try{this._checkBusinessCapabilityBits(o);const t=yield r(n),{resultList:l=[],nextPageToken:i=""}=t,s=this._parseFollowItems(l);return console.log(`${e}.${o} nextCursor: ${n} from remote.`),{code:0,data:{resultList:s,nextCursor:i}}}catch(t){console.error(`${e}.${o} fail:`,t),this._handleError(o,t)}}))}followUser(t){return o(this,void 0,void 0,(function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:t,protocolFunction:a})}))}unfollowUser(t){return o(this,void 0,void 0,(function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:t,protocolFunction:d})}))}_handleUserFollowRelation(t){return o(this,void 0,void 0,(function*(){const{functionName:o,userIDList:e,protocolFunction:r}=t;try{const t=this._sliceUserIDList(e,20);this._checkBusinessCapabilityBits(o);const{resultList:n=[]}=yield r(t);return{code:0,data:n}}catch(t){this._handleError(o,t)}}))}getUserFollowInfo(r){return o(this,void 0,void 0,(function*(){const n="getUserFollowInfo";console.log(`${e} ${n} userIDList:`,r);try{this._checkBusinessCapabilityBits(n);const l=r||[this._core.common.getCurrentUserID()];console.log(`${e} ${n} userIDList: ${l}`);const i=yield function(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{FollowInfo:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{followInfoList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_get_info",data:l}))}))}(r),{followInfoList:s=[]}=i,u=[];return s.forEach((o=>{const{followerCount:t,followingCount:e,mutualFollowingCount:r}=o;u.push({followerCount:t,followingCount:e,mutualFollowingCount:r})})),{code:0,data:u}}catch(o){this._handleError(n,o)}}))}checkFollowType(r){return o(this,void 0,void 0,(function*(){const n="checkFollowType";console.log(`${e} ${n} userIDList:`,r);try{this._checkBusinessCapabilityBits(n),r.length>100&&(r=r.slice(0,100),console.warn(`${e} ${n} the length of userIDList cannot exceed 100`));const l=yield function(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_check",data:l}))}))}(r),{resultList:i=[]}=l;return{code:0,data:i.map((({userID:o,followType:t})=>({userID:o,followType:t})))}}catch(o){this._handleError(n,o)}}))}onFollowListUpdated(o){console.log(`${e} onFollowListUpdated`,o);const{FollowChangeList:t=[]}=o;t.forEach((o=>this._processFollowChangeItem(o)))}_processFollowChangeItem(o){const{From_Account:t,FollowDiffList:e=[]}=o,r=function(o,t){var e={};for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(o);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(o,r[n])&&(e[r[n]]=o[r[n]])}return e}(o,["From_Account","FollowDiffList"]),n={userID:t,avatar:r.FaceUrl,nick:r.NickName};e.forEach((o=>{const t=this._updateFollowRelation(o,n);this._notifyFollowChanges(t)}))}_updateFollowRelation(o,t){const{IsAdd:e,FollowType:r=0}=o,n=this._initFollowInfo(),l=n[r];return l.isAdd=1===e,l.userInfoList.push(l.isAdd?t:t.userID),n}_notifyFollowChanges(o){const{OuterEvent:t}=this._core,e={[l.FOLLOWERS]:t.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:t.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:t.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach((([o,t])=>{const r=Number(o);t.userInfoList.length>0&&e[r]&&this._emitFollowUpdated(e[r],t)}))}_initFollowInfo(){const o={};return Object.values(l).forEach((t=>{t!==l.NONE&&(o[t]={userInfoList:[],isAdd:!1})})),o}_emitFollowUpdated(o,t){console.log(`${e} _emitFollowUpdated`);const{notificationCenter:r}=this._core;r.emitOuterEvent(o,{name:o,data:t})}_sliceUserIDList(o,t){return o.slice(0,t)}_checkBusinessCapabilityBits(o){const{helper:t,store:e}=this._core;if(!(e.get("commercialConfig")||new Map).get(r))throw new t.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,t){const r=new this._core.helper.ChatError({functionName:o,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo});throw console.error(`${e} ${o} fail:`,r),r}_parseFollowItems(o){return o.map((o=>{var t;const{userID:e,followTime:r,profileItem:n=[]}=o,l=[];n.forEach((o=>{l.push({tag:o.Tag,value:o.Value})}));const i=null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(e,l);return{userID:e,followTime:r,nick:null==i?void 0:i.nick,avatar:null==i?void 0:i.avatar,allowType:null==i?void 0:i.allowType,adminForbidType:null==i?void 0:i.adminForbidType}}))}};export{p as default};
@@ -0,0 +1 @@
1
+ !function(o,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(o="undefined"!=typeof globalThis?globalThis:o||self).TencentCloudChatFollow=t()}(this,(function(){"use strict";function o(o,t,e,r){return new(e||(e=Promise))((function(n,l){function i(o){try{u(r.next(o))}catch(o){l(o)}}function s(o){try{u(r.throw(o))}catch(o){l(o)}}function u(o){var t;o.done?n(o.value):(t=o.value,t instanceof e?t:new e((function(o){o(t)}))).then(i,s)}u((r=r.apply(o,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t=new class{init(o){this.core=o}},e="Follow",r="FOLLOW",n=3122,l={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function i(e,r){return o(this,void 0,void 0,(function*(){var o;const{common:n,store:l}=t.core,i={FollowType:e,From_Account:null===(o=l.get("login"))||void 0===o?void 0:o.userId,StartCursor:r,WantNum:f()};return function(o){const{FollowItem:t=[],NextCursor:e,ActionStatus:r,ErrorCode:n,ErrorInfo:l,ErrorDisplay:i}=o;return{resultList:t.map((o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence}))),nextPageToken:e,actionStatus:r,errorCode:n,errorInfo:l,errorDisplay:i}}(yield n.buildAndSendPacket({servcmd:"follow.follow_get",data:i}))}))}function s(t){return o(this,void 0,void 0,(function*(){return i(l.FOLLOWERS,t)}))}function u(t){return o(this,void 0,void 0,(function*(){return i(l.MUTUAL,t)}))}function c(t){return o(this,void 0,void 0,(function*(){return i(l.FOLLOWING,t)}))}function a(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,FollowItem:e.map((o=>({To_Account:o})))};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_add",data:l}))}))}function d(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_delete",data:l}))}))}function f(){const o=t.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0!==e){const o=Number(e);return o>1e3?1e3:o}return 500}const w={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},h={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0};var p=new class{install(o){this._core=o;const{helper:e,notificationCenter:r,InnerEvent:n}=o;t.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:h,params:w}),r.subscribeInnerEvent(n.MESSAGE_PUSH,r.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:c,nextCursor:o})}))}getMyFollowersList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:s,nextCursor:o})}))}getMutualFollowersList(){return o(this,arguments,void 0,(function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:u,nextCursor:o})}))}_getFollowList(t){return o(this,void 0,void 0,(function*(){const{functionName:o,protocolFunction:r,nextCursor:n=""}=t;console.log(`${e} ${o} nextCursor:`,n);try{this._checkBusinessCapabilityBits(o);const t=yield r(n),{resultList:l=[],nextPageToken:i=""}=t,s=this._parseFollowItems(l);return console.log(`${e}.${o} nextCursor: ${n} from remote.`),{code:0,data:{resultList:s,nextCursor:i}}}catch(t){console.error(`${e}.${o} fail:`,t),this._handleError(o,t)}}))}followUser(t){return o(this,void 0,void 0,(function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:t,protocolFunction:a})}))}unfollowUser(t){return o(this,void 0,void 0,(function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:t,protocolFunction:d})}))}_handleUserFollowRelation(t){return o(this,void 0,void 0,(function*(){const{functionName:o,userIDList:e,protocolFunction:r}=t;try{const t=this._sliceUserIDList(e,20);this._checkBusinessCapabilityBits(o);const{resultList:n=[]}=yield r(t);return{code:0,data:n}}catch(t){this._handleError(o,t)}}))}getUserFollowInfo(r){return o(this,void 0,void 0,(function*(){const n="getUserFollowInfo";console.log(`${e} ${n} userIDList:`,r);try{this._checkBusinessCapabilityBits(n);const l=r||[this._core.common.getCurrentUserID()];console.log(`${e} ${n} userIDList: ${l}`);const i=yield function(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{FollowInfo:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{followInfoList:t.map((o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_get_info",data:l}))}))}(r),{followInfoList:s=[]}=i,u=[];return s.forEach((o=>{const{followerCount:t,followingCount:e,mutualFollowingCount:r}=o;u.push({followerCount:t,followingCount:e,mutualFollowingCount:r})})),{code:0,data:u}}catch(o){this._handleError(n,o)}}))}checkFollowType(r){return o(this,void 0,void 0,(function*(){const n="checkFollowType";console.log(`${e} ${n} userIDList:`,r);try{this._checkBusinessCapabilityBits(n),r.length>100&&(r=r.slice(0,100),console.warn(`${e} ${n} the length of userIDList cannot exceed 100`));const l=yield function(e){return o(this,void 0,void 0,(function*(){var o;const{common:r,store:n}=t.core,l={From_Account:null===(o=n.get("login"))||void 0===o?void 0:o.userId,To_Account:e};return function(o){const{ResultItem:t=[],ActionStatus:e,ErrorCode:r,ErrorInfo:n,ErrorDisplay:l}=o;return{resultList:t.map((o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo}))),actionStatus:e,errorCode:r,errorInfo:n,errorDisplay:l}}(yield r.buildAndSendPacket({servcmd:"follow.follow_check",data:l}))}))}(r),{resultList:i=[]}=l;return{code:0,data:i.map((({userID:o,followType:t})=>({userID:o,followType:t})))}}catch(o){this._handleError(n,o)}}))}onFollowListUpdated(o){console.log(`${e} onFollowListUpdated`,o);const{FollowChangeList:t=[]}=o;t.forEach((o=>this._processFollowChangeItem(o)))}_processFollowChangeItem(o){const{From_Account:t,FollowDiffList:e=[]}=o,r=function(o,t){var e={};for(var r in o)Object.prototype.hasOwnProperty.call(o,r)&&t.indexOf(r)<0&&(e[r]=o[r]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(r=Object.getOwnPropertySymbols(o);n<r.length;n++)t.indexOf(r[n])<0&&Object.prototype.propertyIsEnumerable.call(o,r[n])&&(e[r[n]]=o[r[n]])}return e}(o,["From_Account","FollowDiffList"]),n={userID:t,avatar:r.FaceUrl,nick:r.NickName};e.forEach((o=>{const t=this._updateFollowRelation(o,n);this._notifyFollowChanges(t)}))}_updateFollowRelation(o,t){const{IsAdd:e,FollowType:r=0}=o,n=this._initFollowInfo(),l=n[r];return l.isAdd=1===e,l.userInfoList.push(l.isAdd?t:t.userID),n}_notifyFollowChanges(o){const{OuterEvent:t}=this._core,e={[l.FOLLOWERS]:t.MY_FOLLOWERS_LIST_UPDATED,[l.FOLLOWING]:t.MY_FOLLOWING_LIST_UPDATED,[l.MUTUAL]:t.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach((([o,t])=>{const r=Number(o);t.userInfoList.length>0&&e[r]&&this._emitFollowUpdated(e[r],t)}))}_initFollowInfo(){const o={};return Object.values(l).forEach((t=>{t!==l.NONE&&(o[t]={userInfoList:[],isAdd:!1})})),o}_emitFollowUpdated(o,t){console.log(`${e} _emitFollowUpdated`);const{notificationCenter:r}=this._core;r.emitOuterEvent(o,{name:o,data:t})}_sliceUserIDList(o,t){return o.slice(0,t)}_checkBusinessCapabilityBits(o){const{helper:t,store:e}=this._core;if(!(e.get("commercialConfig")||new Map).get(r))throw new t.ChatError({functionName:o,code:n,replacement1:o})}_handleError(o,t){const r=new this._core.helper.ChatError({functionName:o,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo});throw console.error(`${e} ${o} fail:`,r),r}_parseFollowItems(o){return o.map((o=>{var t;const{userID:e,followTime:r,profileItem:n=[]}=o,l=[];n.forEach((o=>{l.push({tag:o.Tag,value:o.Value})}));const i=null===(t=this._core.user.userProfile)||void 0===t?void 0:t.createProfile(e,l);return{userID:e,followTime:r,nick:null==i?void 0:i.nick,avatar:null==i?void 0:i.avatar,allowType:null==i?void 0:i.allowType,adminForbidType:null==i?void 0:i.adminForbidType}}))}};return p}));
@@ -1 +1 @@
1
- function t(t,i,e,n){return new(e||(e=Promise))((function(r,s){function o(t){try{a(n.next(t))}catch(t){s(t)}}function c(t){try{a(n.throw(t))}catch(t){s(t)}}function a(t){var i;t.done?r(t.value):(i=t.value,i instanceof e?i:new e((function(t){t(i)}))).then(o,c)}a((n=n.apply(t,i||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const i="friend";var e=new class{init(t){this._core=t;const{helper:i}=t;i.registerApi("getBlacklist",this)}getBlacklist(){return t(this,void 0,void 0,(function*(){return console.log(`${i} getBlacklist`),{code:0,data:[]}}))}};var n=new class{init(t){this._core=t;const{helper:i}=t;i.registerApi("getFriendList",this)}getFriendList(){return t(this,void 0,void 0,(function*(){return console.log(`${i} getFriendList`),{code:0,data:[]}}))}};var r=new class{init(t){this._core=t;const{helper:i}=t;i.registerApi("getFriendApplicationList",this)}getFriendApplicationList(){return t(this,void 0,void 0,(function*(){return console.log(`${i} getFriendApplicationList`),{code:0,data:{friendApplicationList:[],unreadCount:0}}}))}};var s=new class{init(t){this._core=t}};const o={getBlacklist:!0,getFriendList:!0,getFriendApplicationList:!0};var c=new class{install(t){e.init(t),n.init(t),r.init(t),s.init(t),t.helper.registerValidateConfig({auth:o})}};export{c as default};
1
+ function e(e,t,r,i){return new(r||(r=Promise))((function(o,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,d)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="friend",r=100,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:`${c}Group`,REMARK:`${c}Remark`,ADDSOURCE:`${c}AddSource`,ADDWORDING:`${c}Wording`,ADDTIME:`${c}AddTime`},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function I(t,r){return e(this,void 0,void 0,(function*(){return function(e){return A(e,"ResultItem",(e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}))}))}function F(t,r){return e(this,void 0,void 0,(function*(){return function(e){return A(e,"InfoItem",(e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}))}))}function A(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){const{[t]:i=[],ActionStatus:o,ErrorCode:n,ErrorInfo:s,ErrorDisplay:d}=e;return{resultList:i.map(r),actionStatus:o,errorCode:n,errorInfo:s,errorDisplay:d}}const v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}};let g=class{constructor(e){var t;this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];const{userID:r,tagValueList:i=[],core:o}=e,n=null===(t=o.user.userProfile)||void 0===t?void 0:t.createProfile(r,i);this.userID=r,this.profile=n,i.forEach((e=>{const{tag:t,value:r}=e;t.indexOf("Tag_Profile_Custom")>-1&&this.friendCustomField.push({key:t,value:r});const i=v[t];null==i||i(this,r)}))}update(e){const t=[];this.friendCustomField.forEach((e=>{t.push(e.key)})),e.forEach((e=>{const{tag:r,value:i}=e;r.indexOf("Tag_Profile_Custom")>-1&&(t.indexOf(r)>-1?this.friendCustomField.forEach((e=>{e.key===r&&(e.value=i)})):this.friendCustomField.push({key:r,value:i}));const o=v[r];null==o||o(this,i)}))}};var L=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),t.registerApi({apiName:"getFriendProfile",context:this}),t.registerApi({apiName:"addFriend",context:this}),t.registerApi({apiName:"deleteFriend",context:this}),t.registerApi({apiName:"updateFriend",context:this}),t.registerApi({apiName:"checkFriend",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,(function*(){const{userStore:e}=this._core.appStore,r=[...e.getFriendMap().values()];return console.log(`${t} getFriendListFromCache, data `,r),{code:0,data:r}}))}syncFriendListFromServer(){return e(this,void 0,void 0,(function*(){var r;try{console.log(`${t} syncFriendListFromServer`);const i={From_Account:null===(r=this._core.store.get("login"))||void 0===r?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},o=yield function(t,r){return e(this,void 0,void 0,(function*(){return function(e){const{UserDataItem:t=[],StandardSequence:r,CustomSequence:i,FriendNum:o,CompleteFlag:n,NextStartIndex:s,ActionStatus:d,ErrorCode:a,ErrorInfo:c,ErrorDisplay:u}=e;return{friendList:t.map((e=>{var t;return{userID:e.To_Account,tagValueList:null===(t=e.ValueItem)||void 0===t?void 0:t.map((e=>({tag:e.Tag,value:e.Value})))}})),standardSequence:r,customSequence:i,friendNumber:o,completeFlag:n,nextStartIndex:s,actionStatus:d,errorCode:a,errorInfo:c,errorDisplay:u}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get",data:t}))}))}(i,this._core),{friendList:n,nextStartIndex:s,standardSequence:d,customSequence:a,completeFlag:c}=o;this._startIndex=s,this._standardSequence=d,this._customSequence=a,this._processFriendList(n),0===c?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),console.log(`${t} syncFriendListFromServer ok`)}catch(e){throw console.error(`${t} syncFriendListFromServer error:`,e),e}}))}getFriendProfile(i){return e(this,void 0,void 0,(function*(){var o;try{console.log(`${t} getFriendProfile params:`,i);let{userIDList:n}=i;n.length>r&&(n=n.slice(0,r));const{friendUserIdList:s,unFriendUserIdList:d}=this.partitionByIsFriend(n),a=this._createNonFriendErrorList(d);if(0===s.length)return{code:0,data:{friendList:[],failureUserIDList:a}};const c={From_Account:null===(o=this._core.store.get("login"))||void 0===o?void 0:o.userId,To_Account:s},u=(yield function(t,r){return e(this,void 0,void 0,(function*(){return function(e){const{InfoItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{friendProfileList:t.map((e=>{var t;return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null===(t=e.SnsProfileItem)||void 0===t?void 0:t.map((e=>({tag:e.Tag,value:e.Value}))))||[]}})),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:t}))}))}(c,this._core))||{},{successProfiles:l,failedProfiles:p}=this._processFriendProfileResponse(u);return{code:0,data:{friendList:l,failureUserIDList:[...p,...a]}}}catch(e){throw console.error(`${t} getFriendProfile error:`,e),e}}))}addFriend(r){return e(this,void 0,void 0,(function*(){var i;try{console.log(`${t} addFriend options:`,r);const{helper:o,store:n}=this._core,{to:s,source:d,type:c,wording:u,remark:l,groupName:p}=r,h={From_Account:null===(i=n.get("login"))||void 0===i?void 0:i.userId,AddFriendItem:[{To_Account:s,AddSource:d,AddWording:u,GroupName:p,Remark:l}],AddType:c},m=yield function(t,r){return e(this,void 0,void 0,(function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))}))}(h,this._core),{resultList:_=[]}=m,{userID:f,resultCode:I}=_[0];if(0===I)return console.log(`${t} addFriend ok`),{code:0,data:{userID:f}};if(I===a)return console.log(`${t} addFriend wait for the other party to agree`),{code:0,data:{userID:f,code:I,message:"wait for the other party to agree"}};throw new o.ChatError({functionName:"addFriend",code:I})}catch(e){throw console.error(`${t} addFriend error:`,e),e}}))}deleteFriend(i){return e(this,void 0,void 0,(function*(){var o;try{console.log(`${t} deleteFriend options:`,i);const{store:n}=this._core;let{userIDList:s,type:d}=i;const a=null===(o=n.get("login"))||void 0===o?void 0:o.userId;s.length>1e3&&(console.warn(`${t} deleteFriend the length of userIDList cannot exceed:`,1e3),s=s.slice(0,r));const{friendUserIdList:c,unFriendUserIdList:u}=this.partitionByIsFriend(s);if(0===c.length)return{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(u)}};const l={From_Account:a,To_Account:c,DeleteType:d},p=yield function(t,r){return e(this,void 0,void 0,(function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))}))}(l,this._core),{successUserIDList:h,failureUserIDList:m}=this._processOperationResult({resultList:p.resultList,includeRelation:!1});return console.log(`${t} deleteFriend ok`),{code:0,data:{successUserIDList:h,failureUserIDList:m}}}catch(e){throw console.error(`${t} deleteFriend error:`,e),e}}))}updateFriend(r){return e(this,void 0,void 0,(function*(){var e;try{console.log(`${t} updateFriend options:`,r);const{userID:o,remark:n,friendCustomField:s}=r,{helper:d,store:a,appStore:{userStore:c}}=this._core,u=null===(e=a.get("login"))||void 0===e?void 0:e.userId;if(!c.getFriendMap().has(o))throw new d.ChatError({functionName:"updateFriend",code:i});const l={From_Account:u,UpdateItem:[{To_Account:o,SnsItem:this._buildSnsItemList(n,s)}]},p=yield I(l,this._core),{resultList:h}=p,{to:m,resultCode:_,resultInfo:F}=h[0];if(f(_)||0===_){return{code:0,data:this._updateLocalFriend({userID:m,remark:n,friendCustomField:s})}}throw new d.ChatError({functionName:"updateFriend",code:_,message:F})}catch(e){throw console.error(`${t} updateFriend error:`,e),e}}))}checkFriend(r){return e(this,void 0,void 0,(function*(){var e;try{console.log(`${t} checkFriend options:`,r);const{userIDList:i,type:o}=r,{OuterConstant:n,store:s}=this._core,d=null===(e=s.get("login"))||void 0===e?void 0:e.userId,a={From_Account:d,To_Account:i,CheckType:o===n.SNS_CHECK_TYPE_SINGLE?o:n.SNS_CHECK_TYPE_BOTH},c=yield F(a,this._core),{successUserIDList:u=[],failureUserIDList:l=[]}=this._processOperationResult({resultList:c.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:u,failureUserIDList:l}}}catch(e){throw console.error(`${t} checkFriend error:`,e),e}}))}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){const{userStore:e}=this._core.appStore;e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(r){return e(this,void 0,void 0,(function*(){console.log(`${t} updateFriendList data:`,r);const{userStore:e}=this._core.appStore,{addedFriendList:i=[],removedFriendList:o=[]}=r;i.length>0&&(i.forEach((t=>{const r=new g({userID:t,core:this._core});e.getFriendMap().set(t,r)})),yield this.getFriendProfile({userIDList:i}),this._emitFriendListUpdated()),o.length>0&&(o.forEach((t=>{e.getFriendMap().delete(t)})),this._emitFriendListUpdated())}))}updateFriendInfo(e){console.log(`${t} updateFriendInfo data: `,e);const{appStore:{userStore:r,conversationStore:i},utils:{isEmpty:o}}=this._core,{userID:n,tagValueList:s}=e[0]||{},d=r.getFriend(n);if(o(s)||!d)return;const a=s.map((e=>({tag:e.BytesTag,value:e.BytesValue})));a.forEach((e=>{var t;const{tag:r,value:o}=e,s=null===(t=i.getConversation(`C2C${n}`))||void 0===t?void 0:t.remark;r===u.REMARK&&o!==s&&i.updateConversation(`C2C${n}`,{remark:o}),d.update(a)})),this._emitFriendListUpdated()}_processFriendList(e){const{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach((e=>{const{userID:t,tagValueList:i}=e;if(this._isInvalidFriend(t))return;const o=new g({userID:t,tagValueList:i,core:this._core});r.getFriendMap().set(t,o)}))}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,(function*(){try{console.log(`${t} _fetchFriendProfile`);const{appStore:{userStore:e},user:{userProfile:r}}=this._core,i=[...e.getFriendMap().keys()],o=100,n=Math.ceil(i.length/o);for(let t=0;t<n;t++){const n=t*o,s=Math.min(n+o,i.length),d=i.slice(n,s),a=yield null==r?void 0:r.getUserProfile({userIDList:d});if(a&&a.data){a.data.forEach((t=>{const r=e.getFriend(t.userID);r&&(r.profile=t)}))}this._emitFriendListUpdated()}}catch(e){throw console.error(`${t} _fetchFriendProfile error:`,e),e}}))}_emitFriendListUpdated(){const{notificationCenter:e,OuterEvent:r,appStore:{userStore:i}}=this._core,o=Array.from(i.getFriendMap().values());console.log(`${t} _emitFriendListUpdated friendList:`,o),e.emitOuterEvent(r.FRIEND_LIST_UPDATED,{name:r.FRIEND_LIST_UPDATED,data:o})}_updateCustomField(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let r=!1;return t.forEach((({key:t,value:i})=>{const o=e.find((e=>e.key===t));o?o.value!==i&&(o.value=i,r=!0):(e.push({key:t,value:i}),r=!0)})),r}_updateLocalFriend(e){const{userStore:t}=this._core.appStore,{userID:r,remark:i,friendCustomField:o}=e,n=t.getFriend(r);if(n)return f(i)||(n.remark=i),Array.isArray(o)&&o.length>0&&this._updateCustomField(n.friendCustomField,o),this._emitFriendListUpdated(),n}_processOperationResult(e){const{resultList:t,includeRelation:r=!1}=e,{isEmpty:i}=this._core.utils,o=[],n=[];return Array.isArray(t)&&!i(t)&&t.forEach((e=>{const{userID:t,relation:i,resultCode:s,resultInfo:d}=e;if(f(s)||0===s){const e={userID:t};r&&(e.code=0,e.relation=i),o.push(e)}else n.push({userID:t,code:s,message:d})})),{successUserIDList:o,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map((e=>({userID:e,code:i,message:"The specified userID is not my friend"})))}_buildSnsItemList(e,t){const r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&t.length>0&&t.forEach((e=>{r.push({tag:e.key,value:e.value})})),r}_processFriendProfileResponse(e){const{friendProfileList:r=[]}=e,{userStore:i}=this._core.appStore,o=[],n=[];return r.forEach((e=>{const{userID:t,resultCode:r,resultInfo:s,profileItem:d}=e;if(0===r){const e=new g({userID:t,tagValueList:d,core:this._core});o.push(e),i.getFriendMap().set(t,e)}else n.push({userID:t,code:r,message:s})})),console.log(`${t} _processFriendProfileResponse successProfiles:`,o),{successProfiles:o,failedProfiles:n}}partitionByIsFriend(e){const r=[],i=[];return e.forEach((e=>{const{userStore:t}=this._core.appStore;t.getFriendMap().has(e)?r.push(e):i.push(e)})),console.log(`${t} partitionByIsFriend, friendUserIdList: ${r}, unFriendUserIdList: ${i}`),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){const{userStore:t}=this._core.appStore;return t.getFriendMap().has(e)}};var y=new class{init(e){this.core=e}};function S(t){return e(this,void 0,void 0,(function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return T(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))}))}function E(t){return e(this,void 0,void 0,(function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return T(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))}))}function D(t){return e(this,void 0,void 0,(function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return T(yield i.buildAndSendPacket({servcmd:"sns.pendency_delete",data:o}))}))}function T(e){const{ResultItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:t.map((e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}var C=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),t.registerApi({apiName:"acceptFriendApplication",context:this}),t.registerApi({apiName:"refuseFriendApplication",context:this}),t.registerApi({apiName:"deleteFriendApplication",context:this}),t.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,(function*(){const 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*(){const i="syncFriendApplicationListFromServer";console.log(`${t} ${i}`);try{const t=yield function(t){return e(this,void 0,void 0,(function*(){var e;const{store:i,OuterConstant:o,common:n}=y.core,s={From_Account:null===(e=i.get("login"))||void 0===e?void 0:e.userId,PendencyType:o.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:t.startTime,LastSequence:t.currentSequence};return function(e){const{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:i,CurrentSequence:o,ActionStatus:n,ErrorCode:s,ErrorInfo:d,ErrorDisplay:a}=e;return{resultList:t.map((e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,image:e.Image}))),startTime:r,unreadCount:i,currentSequence:o,actionStatus:n,errorCode:s,errorInfo:d,errorDisplay:a}}(yield n.buildAndSendPacket({servcmd:"sns.pendency_get",data:s}))}))}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:n,currentSequence:s}=t;this._startTime=n,this._currentSequence=s,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach((e=>{const{userID:t,type:r}=e,i=this._createFriendApplication(e);this._friendApplicationMap.set(`${t}_${r}`,i)})),this._emitApplicationListUpdated()}catch(e){const r=new this._core.helper.ChatError({functionName: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(t){return e(this,void 0,void 0,(function*(){const{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:D})}))}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(`${e}_${t}`))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,(function*(){const{functionName:e,options:i,protocolFunction:o}=r;console.log(`${t} ${e} options:`,i);try{const r=yield o(i),{resultList:n=[]}=r,{resultCode:s,resultInfo:d}=n[0];if(0===s)return console.log(`${t} ${e} ok`),{code:0,data:{}};throw{errorCode:s,errorInfo:d}}catch(r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}}))}setFriendApplicationRead(){return e(this,void 0,void 0,(function*(){const r="setFriendApplicationRead";console.log(`${t} ${r}`);try{return yield function(){return e(this,void 0,void 0,(function*(){var e;const{store:t,common:r}=y.core,i={From_Account:null===(e=t.get("login"))||void 0===e?void 0:e.userId,LatestPendencyTimeStamp:(o=Math.floor(Date.now()/1e3),n=0,Math.round(Number(o)*Math.pow(10,n))/Math.pow(10,n))};var o,n;return function(e){const{ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}(yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:i}))}))}(),this._unreadCount=0,this._emitApplicationListUpdated(),console.log(`${t} ${r} ok`),{code:0,data:{}}}catch(e){const 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){const{from:r,addedApplicationList:i=[],removedApplicationList:o=[]}=e;console.log(`${t} updateFriendApplicationList data:`,e);const{isEmpty:n}=this._core.utils;n(i)||this.onApplicationAdded(i,r),n(o)||this.onApplicationDeleted()}onApplicationAdded(e,t){var r;const{store:i,OuterConstant:o}=this._core,n=t===(null===(r=i.get("login"))||void 0===r?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach((e=>{const t=`${e.userID}_${n}`;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))})),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){console.log(`${t} _emitApplicationListUpdated`);const{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*(){const{common:e}=y.core,t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return function(e){return M(e,(e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber})))}(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}))}))}function N(t){return e(this,void 0,void 0,(function*(){const{name:e,userIDList:r}=t,{common:i}=y.core,o={From_Account:i.getCurrentUserID(),GroupName:[e],To_Account:r};return function(e){return M(e,(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield i.buildAndSendPacket({servcmd:"sns.group_add",data:o}))}))}function P(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))}))}function G(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=R(i,l),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,(e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))}))}function w(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=R(i,p),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,(e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))}))}function U(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,{oldName:r,newName:i}=t,o={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:i};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:o}))}))}function R(e,t){return e.filter((e=>L.isMyFriend(e))).map((e=>({To_Account:e,UpdateType:t})))}function M(e,t){const{CurrentSequence:r,ActionStatus:i,ErrorCode:o,ErrorInfo:n,ErrorDisplay:s,ResultItem:d=[]}=e,a={currentSequence:r,actionStatus:i,errorCode:o,errorInfo:n,errorDisplay:s};return t&&d.length>0?Object.assign(Object.assign({},a),{resultList:d.map(t)}):a}class O{constructor(e){const{name:t="",userIDList:r=[]}=e;this.name=t,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){const t=this.userIDList.indexOf(e);t>-1&&(this.userIDList.splice(t,1),this.count=this.userIDList.length)}}var $=new class{constructor(){this._friendGroupMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),t.registerApi({apiName:"createFriendGroup",context:this}),t.registerApi({apiName:"deleteFriendGroup",context:this}),t.registerApi({apiName:"addToFriendGroup",context:this}),t.registerApi({apiName:"removeFromFriendGroup",context:this}),t.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,(function*(){const e=[...this._friendGroupMap.values()];return console.log(`${t} getFriendGroupListFromCache, data: `,e),{code:0,data:e}}))}syncFriendGroupListFromServer(){return e(this,void 0,void 0,(function*(){const e="syncFriendGroupListFromServer";console.log(`${t} ${e}`);try{const r=yield k(),{resultList:i=[]}=r;this._core.helper.isEmpty(i)&&console.log(`${t} ${e} ok. count: 0`),i.forEach((e=>{const t=new O(e);this._friendGroupMap.set(e.name,t)})),this._emitGroupListUpdated()}catch(t){this._handleError(e,t)}}))}createFriendGroup(r){return e(this,void 0,void 0,(function*(){const e="createFriendGroup";console.log(`${t} ${e} params:`,r);try{const{name:t}=r;this._checkGroupExist(e,t);const i=yield N(r),{successUserIDList:o,failureUserIDList:n}=this._parseCreateGroupResponse(i),s=new O({name:t,userIDList:o});return this._friendGroupMap.set(t,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(t){this._handleError(e,t)}}))}deleteFriendGroup(r){return e(this,void 0,void 0,(function*(){const e="deleteFriendGroup";console.log(`${t} ${e} params:`,r);try{const{name:t}=r;this._checkGroupNotExist(e,t),yield P(r);const i=this._friendGroupMap.get(t);return i&&(this._updateFriendGroup({name:t,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(t)),this._emitGroupListUpdated(),{code:0,data:i}}catch(t){this._handleError(e,t)}}))}addToFriendGroup(t){return e(this,void 0,void 0,(function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:G})}))}removeFromFriendGroup(t){return e(this,void 0,void 0,(function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:w})}))}renameFriendGroup(r){return e(this,void 0,void 0,(function*(){const e="renameFriendGroup";console.log(`${t} ${e} params:`,r);try{const{oldName:t,newName:i}=r;this._checkGroupNotExist(e,t),this._checkGroupExist(e,i),yield U(r);const o=this._updateGroupNameInCache(t,i);return o&&this._updateFriendGroup({name:t,userIDList:o.userIDList,action:_,newName:i}),this._emitGroupListUpdated(),{code:0,data:o}}catch(t){this._handleError(e,t)}}))}_updateFriendGroupMember(r){return e(this,void 0,void 0,(function*(){const{functionName:e,params:i,protocolFunction:o}=r;console.log(`${t} ${e} params:`,i);try{const{name:t}=i;this._checkGroupNotExist(e,t);const r=yield o(i),{friendGroup:n,failureUserIDList:s}=this._parseUpdateFriendGroupResponse(t,r);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:s}}}catch(t){this._handleError(e,t)}}))}_updateGroupNameInCache(e,t){const r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){const{resultList:t=[]}=e,r=[],i=[];return t.forEach((({userID:e,resultCode:t,resultInfo:o})=>{f(t)||0===t?r.push(e):i.push({userID:e,code:t,message:o})})),{successUserIDList:r,failureUserIDList:i}}_parseUpdateFriendGroupResponse(e,t){const{resultList:r=[]}=t,i=this._friendGroupMap.get(e),o=[],n=[],s=[];return r.forEach((t=>{0===t.resultCode?i&&(t.updateType===l?this._addFriendToGroup(e,t.userID,i,n):t.updateType===p&&this._removeFriendFromGroup(e,t.userID,i,s)):o.push({userID:t.userID,code:t.resultCode,message:t.resultInfo})})),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){const{notificationCenter:e,OuterEvent: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){const{name:r,userIDList:i,action:o,newName:n}=e,{userStore:s}=this._core.appStore;console.log(`${t} updateFriendGroup`,{name:r,userIDList:i,action:o,newName:n}),r&&!this._core.utils.isEmpty(i)&&i.forEach((e=>{const t=s.getFriend(e);if(!t)return;const{groupList:i}=t;switch(o){case h:-1===i.indexOf(r)&&(i.push(r),t.count=i.length);break;case m:{const e=i.indexOf(r);e>-1&&(i.splice(e,1),t.count=i.length);break}case _:{if(!n)return;const e=i.indexOf(r);-1!==e&&(i[e]=n);break}}}))}_handleError(e,r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}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){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),t.registerApi({apiName:"addToBlacklist",context:this}),t.registerApi({apiName:"removeFromBlacklist",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,(function*(){return 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`);const i={From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},o=yield function(t,r){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=r,o="sns.black_list_get",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{BlackListItem:a=[],StartIndex:c=0}=d;return{blackList:B(a),startIndex:c}}))}(i,this._core),{blackList:n=[],startIndex:s=0}=o;return this._startIndex=s,this._addBlacklistMap(n),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(`${t} syncBlacklistFromServer error:`,e),e}}))}addToBlacklist(r){return e(this,void 0,void 0,(function*(){try{console.log(`${t} addToBlacklist options:`,r);const i=this._preprocessBlacklist(r),o={From_Account:this._core.common.getCurrentUserID(),To_Account:i},n=yield function(t,r){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=r,o="sns.black_list_add",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}}))}(o,this._core),{blackList:s=[]}=n;return this._addBlacklistMap(s),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(`${t} addToBlacklist error:`,e),e}}))}removeFromBlacklist(r){return e(this,void 0,void 0,(function*(){try{console.log(`${t} removeFromBlacklist options:`,r);const i={From_Account:this._core.common.getCurrentUserID(),To_Account:r.userIDList},o=yield function(t,r){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=r,o="sns.black_list_delete",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}}))}(i,this._core),{blackList:n=[]}=o;return this._deleteBlacklistMap(n),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);const{addedBlacklist:r=[],removedBlacklist:i=[]}=e;let o=!1;if(r.length>0){r.some((e=>!this._blacklistMap.has(e)))&&(o=!0,this._addBlacklistMap(r.map((e=>({userID:e})))))}if(i.length>0){i.some((e=>this._blacklistMap.has(e)))&&(o=!0,this._deleteBlacklistMap(i.map((e=>({userID:e})))))}o&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(`${t} _addBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t,addBlackTimeStamp:r=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:r})}))}_deleteBlacklistMap(e){console.log(`${t} _deleteBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)}))}_preprocessBlacklist(e){let{userIDList:t}=e;const r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t.includes(r)&&(t=e.userIDList.filter((e=>e!==r))),t}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:r}=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})}};const 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=>{const{OuterConstant:t}=y.core;return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{const{OuterConstant:t}=y.core;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=>{const{OuterConstant:t}=y.core;return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},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`),this._core=e;const{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:s}}=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){const{from:t,addedBlacklist:r,removedBlacklist:i,addedFriendList:o,removedFriendList:n,addedApplicationList:s,removedApplicationList:d,friendUpdateInfo:a,reportTime:c}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),{isEmpty:u}=this._core.utils;u(r)&&u(i)||b.updateBlacklist({addedBlacklist:r,removedBlacklist:i}),u(o)&&u(n)||(L.updateFriendList({addedFriendList:o,removedFriendList:n}),C.updateFriendApplicationList({from:t,removedApplicationList:o})),u(a)||L.updateFriendInfo(a),u(s)&&u(d)||C.updateFriendApplicationList({from:t,addedApplicationList:s,removedApplicationList:d}),c&&C.onApplicationRead()}_parseFriendListModification(e){const{PushType:t,From_Account:r,To_Account:i,ReportTime:o,BlackListAdd_Account:n=[],BlackListDel_Account:s=[],FriendAdd_Account:d=[],FriendDel_Account:a=[],PendencyAdd:c=[],FrienPencydDel_Account:u=[],FriendUpInfo:l=[]}=e,p=l.map((e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]})));return{pushType:t,from:r,to:i,reportTime:o,addedBlacklist:n,removedBlacklist:s,addedFriendList:d,removedFriendList:a,addedApplicationList:c.map((e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick}))),friendUpdateInfo:p,removedApplicationList:u}}reset(){console.log(`${t} reset`),b.reset(),L.reset(),C.reset(),$.reset()}dispose(){console.log(`${t} dispose`);const{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};
package/plugins/friend.js CHANGED
@@ -1 +1 @@
1
- !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).TencentCloudChatFriend=e()}(this,(function(){"use strict";function t(t,e,i,n){return new(i||(i=Promise))((function(o,r){function s(t){try{l(n.next(t))}catch(t){r(t)}}function c(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(s,c)}l((n=n.apply(t,e||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const e="friend";var i=new class{init(t){this._core=t;const{helper:e}=t;e.registerApi("getBlacklist",this)}getBlacklist(){return t(this,void 0,void 0,(function*(){return console.log(`${e} getBlacklist`),{code:0,data:[]}}))}};var n=new class{init(t){this._core=t;const{helper:e}=t;e.registerApi("getFriendList",this)}getFriendList(){return t(this,void 0,void 0,(function*(){return console.log(`${e} getFriendList`),{code:0,data:[]}}))}};var o=new class{init(t){this._core=t;const{helper:e}=t;e.registerApi("getFriendApplicationList",this)}getFriendApplicationList(){return t(this,void 0,void 0,(function*(){return console.log(`${e} getFriendApplicationList`),{code:0,data:{friendApplicationList:[],unreadCount:0}}}))}};var r=new class{init(t){this._core=t}};const s={getBlacklist:!0,getFriendList:!0,getFriendApplicationList:!0};return new class{install(t){i.init(t),n.init(t),o.init(t),r.init(t),t.helper.registerValidateConfig({auth:s})}}}));
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).TencentCloudChatFriend=t()}(this,(function(){"use strict";function e(e,t,r,i){return new(r||(r=Promise))((function(o,n){function s(e){try{a(i.next(e))}catch(e){n(e)}}function d(e){try{a(i.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,d)}a((i=i.apply(e,t||[])).next())}))}"function"==typeof SuppressedError&&SuppressedError;const t="friend",r=100,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:`${c}Group`,REMARK:`${c}Remark`,ADDSOURCE:`${c}AddSource`,ADDWORDING:`${c}Wording`,ADDTIME:`${c}AddTime`},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function I(t,r){return e(this,void 0,void 0,(function*(){return function(e){return A(e,"ResultItem",(e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}))}))}function F(t,r){return e(this,void 0,void 0,(function*(){return function(e){return A(e,"InfoItem",(e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}))}))}function A(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){const{[t]:i=[],ActionStatus:o,ErrorCode:n,ErrorInfo:s,ErrorDisplay:d}=e;return{resultList:i.map(r),actionStatus:o,errorCode:n,errorInfo:s,errorDisplay:d}}const v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}};let g=class{constructor(e){var t;this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];const{userID:r,tagValueList:i=[],core:o}=e,n=null===(t=o.user.userProfile)||void 0===t?void 0:t.createProfile(r,i);this.userID=r,this.profile=n,i.forEach((e=>{const{tag:t,value:r}=e;t.indexOf("Tag_Profile_Custom")>-1&&this.friendCustomField.push({key:t,value:r});const i=v[t];null==i||i(this,r)}))}update(e){const t=[];this.friendCustomField.forEach((e=>{t.push(e.key)})),e.forEach((e=>{const{tag:r,value:i}=e;r.indexOf("Tag_Profile_Custom")>-1&&(t.indexOf(r)>-1?this.friendCustomField.forEach((e=>{e.key===r&&(e.value=i)})):this.friendCustomField.push({key:r,value:i}));const o=v[r];null==o||o(this,i)}))}};var L=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),t.registerApi({apiName:"getFriendProfile",context:this}),t.registerApi({apiName:"addFriend",context:this}),t.registerApi({apiName:"deleteFriend",context:this}),t.registerApi({apiName:"updateFriend",context:this}),t.registerApi({apiName:"checkFriend",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,(function*(){const{userStore:e}=this._core.appStore,r=[...e.getFriendMap().values()];return console.log(`${t} getFriendListFromCache, data `,r),{code:0,data:r}}))}syncFriendListFromServer(){return e(this,void 0,void 0,(function*(){var r;try{console.log(`${t} syncFriendListFromServer`);const i={From_Account:null===(r=this._core.store.get("login"))||void 0===r?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},o=yield function(t,r){return e(this,void 0,void 0,(function*(){return function(e){const{UserDataItem:t=[],StandardSequence:r,CustomSequence:i,FriendNum:o,CompleteFlag:n,NextStartIndex:s,ActionStatus:d,ErrorCode:a,ErrorInfo:c,ErrorDisplay:u}=e;return{friendList:t.map((e=>{var t;return{userID:e.To_Account,tagValueList:null===(t=e.ValueItem)||void 0===t?void 0:t.map((e=>({tag:e.Tag,value:e.Value})))}})),standardSequence:r,customSequence:i,friendNumber:o,completeFlag:n,nextStartIndex:s,actionStatus:d,errorCode:a,errorInfo:c,errorDisplay:u}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get",data:t}))}))}(i,this._core),{friendList:n,nextStartIndex:s,standardSequence:d,customSequence:a,completeFlag:c}=o;this._startIndex=s,this._standardSequence=d,this._customSequence=a,this._processFriendList(n),0===c?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),console.log(`${t} syncFriendListFromServer ok`)}catch(e){throw console.error(`${t} syncFriendListFromServer error:`,e),e}}))}getFriendProfile(i){return e(this,void 0,void 0,(function*(){var o;try{console.log(`${t} getFriendProfile params:`,i);let{userIDList:n}=i;n.length>r&&(n=n.slice(0,r));const{friendUserIdList:s,unFriendUserIdList:d}=this.partitionByIsFriend(n),a=this._createNonFriendErrorList(d);if(0===s.length)return{code:0,data:{friendList:[],failureUserIDList:a}};const c={From_Account:null===(o=this._core.store.get("login"))||void 0===o?void 0:o.userId,To_Account:s},u=(yield function(t,r){return e(this,void 0,void 0,(function*(){return function(e){const{InfoItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{friendProfileList:t.map((e=>{var t;return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null===(t=e.SnsProfileItem)||void 0===t?void 0:t.map((e=>({tag:e.Tag,value:e.Value}))))||[]}})),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}(yield r.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:t}))}))}(c,this._core))||{},{successProfiles:l,failedProfiles:p}=this._processFriendProfileResponse(u);return{code:0,data:{friendList:l,failureUserIDList:[...p,...a]}}}catch(e){throw console.error(`${t} getFriendProfile error:`,e),e}}))}addFriend(r){return e(this,void 0,void 0,(function*(){var i;try{console.log(`${t} addFriend options:`,r);const{helper:o,store:n}=this._core,{to:s,source:d,type:c,wording:u,remark:l,groupName:p}=r,h={From_Account:null===(i=n.get("login"))||void 0===i?void 0:i.userId,AddFriendItem:[{To_Account:s,AddSource:d,AddWording:u,GroupName:p,Remark:l}],AddType:c},m=yield function(t,r){return e(this,void 0,void 0,(function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))}))}(h,this._core),{resultList:_=[]}=m,{userID:f,resultCode:I}=_[0];if(0===I)return console.log(`${t} addFriend ok`),{code:0,data:{userID:f}};if(I===a)return console.log(`${t} addFriend wait for the other party to agree`),{code:0,data:{userID:f,code:I,message:"wait for the other party to agree"}};throw new o.ChatError({functionName:"addFriend",code:I})}catch(e){throw console.error(`${t} addFriend error:`,e),e}}))}deleteFriend(i){return e(this,void 0,void 0,(function*(){var o;try{console.log(`${t} deleteFriend options:`,i);const{store:n}=this._core;let{userIDList:s,type:d}=i;const a=null===(o=n.get("login"))||void 0===o?void 0:o.userId;s.length>1e3&&(console.warn(`${t} deleteFriend the length of userIDList cannot exceed:`,1e3),s=s.slice(0,r));const{friendUserIdList:c,unFriendUserIdList:u}=this.partitionByIsFriend(s);if(0===c.length)return{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(u)}};const l={From_Account:a,To_Account:c,DeleteType:d},p=yield function(t,r){return e(this,void 0,void 0,(function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))}))}(l,this._core),{successUserIDList:h,failureUserIDList:m}=this._processOperationResult({resultList:p.resultList,includeRelation:!1});return console.log(`${t} deleteFriend ok`),{code:0,data:{successUserIDList:h,failureUserIDList:m}}}catch(e){throw console.error(`${t} deleteFriend error:`,e),e}}))}updateFriend(r){return e(this,void 0,void 0,(function*(){var e;try{console.log(`${t} updateFriend options:`,r);const{userID:o,remark:n,friendCustomField:s}=r,{helper:d,store:a,appStore:{userStore:c}}=this._core,u=null===(e=a.get("login"))||void 0===e?void 0:e.userId;if(!c.getFriendMap().has(o))throw new d.ChatError({functionName:"updateFriend",code:i});const l={From_Account:u,UpdateItem:[{To_Account:o,SnsItem:this._buildSnsItemList(n,s)}]},p=yield I(l,this._core),{resultList:h}=p,{to:m,resultCode:_,resultInfo:F}=h[0];if(f(_)||0===_){return{code:0,data:this._updateLocalFriend({userID:m,remark:n,friendCustomField:s})}}throw new d.ChatError({functionName:"updateFriend",code:_,message:F})}catch(e){throw console.error(`${t} updateFriend error:`,e),e}}))}checkFriend(r){return e(this,void 0,void 0,(function*(){var e;try{console.log(`${t} checkFriend options:`,r);const{userIDList:i,type:o}=r,{OuterConstant:n,store:s}=this._core,d=null===(e=s.get("login"))||void 0===e?void 0:e.userId,a={From_Account:d,To_Account:i,CheckType:o===n.SNS_CHECK_TYPE_SINGLE?o:n.SNS_CHECK_TYPE_BOTH},c=yield F(a,this._core),{successUserIDList:u=[],failureUserIDList:l=[]}=this._processOperationResult({resultList:c.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:u,failureUserIDList:l}}}catch(e){throw console.error(`${t} checkFriend error:`,e),e}}))}dispose(){this.reset();const{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){const{userStore:e}=this._core.appStore;e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(r){return e(this,void 0,void 0,(function*(){console.log(`${t} updateFriendList data:`,r);const{userStore:e}=this._core.appStore,{addedFriendList:i=[],removedFriendList:o=[]}=r;i.length>0&&(i.forEach((t=>{const r=new g({userID:t,core:this._core});e.getFriendMap().set(t,r)})),yield this.getFriendProfile({userIDList:i}),this._emitFriendListUpdated()),o.length>0&&(o.forEach((t=>{e.getFriendMap().delete(t)})),this._emitFriendListUpdated())}))}updateFriendInfo(e){console.log(`${t} updateFriendInfo data: `,e);const{appStore:{userStore:r,conversationStore:i},utils:{isEmpty:o}}=this._core,{userID:n,tagValueList:s}=e[0]||{},d=r.getFriend(n);if(o(s)||!d)return;const a=s.map((e=>({tag:e.BytesTag,value:e.BytesValue})));a.forEach((e=>{var t;const{tag:r,value:o}=e,s=null===(t=i.getConversation(`C2C${n}`))||void 0===t?void 0:t.remark;r===u.REMARK&&o!==s&&i.updateConversation(`C2C${n}`,{remark:o}),d.update(a)})),this._emitFriendListUpdated()}_processFriendList(e){const{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach((e=>{const{userID:t,tagValueList:i}=e;if(this._isInvalidFriend(t))return;const o=new g({userID:t,tagValueList:i,core:this._core});r.getFriendMap().set(t,o)}))}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,(function*(){try{console.log(`${t} _fetchFriendProfile`);const{appStore:{userStore:e},user:{userProfile:r}}=this._core,i=[...e.getFriendMap().keys()],o=100,n=Math.ceil(i.length/o);for(let t=0;t<n;t++){const n=t*o,s=Math.min(n+o,i.length),d=i.slice(n,s),a=yield null==r?void 0:r.getUserProfile({userIDList:d});if(a&&a.data){a.data.forEach((t=>{const r=e.getFriend(t.userID);r&&(r.profile=t)}))}this._emitFriendListUpdated()}}catch(e){throw console.error(`${t} _fetchFriendProfile error:`,e),e}}))}_emitFriendListUpdated(){const{notificationCenter:e,OuterEvent:r,appStore:{userStore:i}}=this._core,o=Array.from(i.getFriendMap().values());console.log(`${t} _emitFriendListUpdated friendList:`,o),e.emitOuterEvent(r.FRIEND_LIST_UPDATED,{name:r.FRIEND_LIST_UPDATED,data:o})}_updateCustomField(e,t){if(!Array.isArray(e)||!Array.isArray(t))return!1;let r=!1;return t.forEach((({key:t,value:i})=>{const o=e.find((e=>e.key===t));o?o.value!==i&&(o.value=i,r=!0):(e.push({key:t,value:i}),r=!0)})),r}_updateLocalFriend(e){const{userStore:t}=this._core.appStore,{userID:r,remark:i,friendCustomField:o}=e,n=t.getFriend(r);if(n)return f(i)||(n.remark=i),Array.isArray(o)&&o.length>0&&this._updateCustomField(n.friendCustomField,o),this._emitFriendListUpdated(),n}_processOperationResult(e){const{resultList:t,includeRelation:r=!1}=e,{isEmpty:i}=this._core.utils,o=[],n=[];return Array.isArray(t)&&!i(t)&&t.forEach((e=>{const{userID:t,relation:i,resultCode:s,resultInfo:d}=e;if(f(s)||0===s){const e={userID:t};r&&(e.code=0,e.relation=i),o.push(e)}else n.push({userID:t,code:s,message:d})})),{successUserIDList:o,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map((e=>({userID:e,code:i,message:"The specified userID is not my friend"})))}_buildSnsItemList(e,t){const r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&t.length>0&&t.forEach((e=>{r.push({tag:e.key,value:e.value})})),r}_processFriendProfileResponse(e){const{friendProfileList:r=[]}=e,{userStore:i}=this._core.appStore,o=[],n=[];return r.forEach((e=>{const{userID:t,resultCode:r,resultInfo:s,profileItem:d}=e;if(0===r){const e=new g({userID:t,tagValueList:d,core:this._core});o.push(e),i.getFriendMap().set(t,e)}else n.push({userID:t,code:r,message:s})})),console.log(`${t} _processFriendProfileResponse successProfiles:`,o),{successProfiles:o,failedProfiles:n}}partitionByIsFriend(e){const r=[],i=[];return e.forEach((e=>{const{userStore:t}=this._core.appStore;t.getFriendMap().has(e)?r.push(e):i.push(e)})),console.log(`${t} partitionByIsFriend, friendUserIdList: ${r}, unFriendUserIdList: ${i}`),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){const{userStore:t}=this._core.appStore;return t.getFriendMap().has(e)}};var y=new class{init(e){this.core=e}};function S(t){return e(this,void 0,void 0,(function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return T(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))}))}function E(t){return e(this,void 0,void 0,(function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return T(yield i.buildAndSendPacket({servcmd:"sns.friend_response",data:o}))}))}function D(t){return e(this,void 0,void 0,(function*(){var e;const{store:r,common:i}=y.core,o={From_Account:null===(e=r.get("login"))||void 0===e?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return T(yield i.buildAndSendPacket({servcmd:"sns.pendency_delete",data:o}))}))}function T(e){const{ResultItem:t=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:t.map((e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}var C=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),t.registerApi({apiName:"acceptFriendApplication",context:this}),t.registerApi({apiName:"refuseFriendApplication",context:this}),t.registerApi({apiName:"deleteFriendApplication",context:this}),t.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,(function*(){const 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*(){const i="syncFriendApplicationListFromServer";console.log(`${t} ${i}`);try{const t=yield function(t){return e(this,void 0,void 0,(function*(){var e;const{store:i,OuterConstant:o,common:n}=y.core,s={From_Account:null===(e=i.get("login"))||void 0===e?void 0:e.userId,PendencyType:o.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:t.startTime,LastSequence:t.currentSequence};return function(e){const{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:i,CurrentSequence:o,ActionStatus:n,ErrorCode:s,ErrorInfo:d,ErrorDisplay:a}=e;return{resultList:t.map((e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,image:e.Image}))),startTime:r,unreadCount:i,currentSequence:o,actionStatus:n,errorCode:s,errorInfo:d,errorDisplay:a}}(yield n.buildAndSendPacket({servcmd:"sns.pendency_get",data:s}))}))}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:n,currentSequence:s}=t;this._startTime=n,this._currentSequence=s,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach((e=>{const{userID:t,type:r}=e,i=this._createFriendApplication(e);this._friendApplicationMap.set(`${t}_${r}`,i)})),this._emitApplicationListUpdated()}catch(e){const r=new this._core.helper.ChatError({functionName: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(t){return e(this,void 0,void 0,(function*(){const{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:D})}))}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(`${e}_${t}`))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,(function*(){const{functionName:e,options:i,protocolFunction:o}=r;console.log(`${t} ${e} options:`,i);try{const r=yield o(i),{resultList:n=[]}=r,{resultCode:s,resultInfo:d}=n[0];if(0===s)return console.log(`${t} ${e} ok`),{code:0,data:{}};throw{errorCode:s,errorInfo:d}}catch(r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}}))}setFriendApplicationRead(){return e(this,void 0,void 0,(function*(){const r="setFriendApplicationRead";console.log(`${t} ${r}`);try{return yield function(){return e(this,void 0,void 0,(function*(){var e;const{store:t,common:r}=y.core,i={From_Account:null===(e=t.get("login"))||void 0===e?void 0:e.userId,LatestPendencyTimeStamp:(o=Math.floor(Date.now()/1e3),n=0,Math.round(Number(o)*Math.pow(10,n))/Math.pow(10,n))};var o,n;return function(e){const{ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}(yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:i}))}))}(),this._unreadCount=0,this._emitApplicationListUpdated(),console.log(`${t} ${r} ok`),{code:0,data:{}}}catch(e){const 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){const{from:r,addedApplicationList:i=[],removedApplicationList:o=[]}=e;console.log(`${t} updateFriendApplicationList data:`,e);const{isEmpty:n}=this._core.utils;n(i)||this.onApplicationAdded(i,r),n(o)||this.onApplicationDeleted()}onApplicationAdded(e,t){var r;const{store:i,OuterConstant:o}=this._core,n=t===(null===(r=i.get("login"))||void 0===r?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach((e=>{const t=`${e.userID}_${n}`;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))})),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){console.log(`${t} _emitApplicationListUpdated`);const{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*(){const{common:e}=y.core,t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return function(e){return M(e,(e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber})))}(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}))}))}function N(t){return e(this,void 0,void 0,(function*(){const{name:e,userIDList:r}=t,{common:i}=y.core,o={From_Account:i.getCurrentUserID(),GroupName:[e],To_Account:r};return function(e){return M(e,(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield i.buildAndSendPacket({servcmd:"sns.group_add",data:o}))}))}function P(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))}))}function G(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=R(i,l),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,(e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))}))}function w(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,{name:r,userIDList:i}=t,o=R(i,p),n={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:o};return function(e){return M(e,(e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo})))}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:n}))}))}function U(t){return e(this,void 0,void 0,(function*(){const{common:e}=y.core,{oldName:r,newName:i}=t,o={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:i};return function(e){return M(e)}(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:o}))}))}function R(e,t){return e.filter((e=>L.isMyFriend(e))).map((e=>({To_Account:e,UpdateType:t})))}function M(e,t){const{CurrentSequence:r,ActionStatus:i,ErrorCode:o,ErrorInfo:n,ErrorDisplay:s,ResultItem:d=[]}=e,a={currentSequence:r,actionStatus:i,errorCode:o,errorInfo:n,errorDisplay:s};return t&&d.length>0?Object.assign(Object.assign({},a),{resultList:d.map(t)}):a}class O{constructor(e){const{name:t="",userIDList:r=[]}=e;this.name=t,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){const t=this.userIDList.indexOf(e);t>-1&&(this.userIDList.splice(t,1),this.count=this.userIDList.length)}}var $=new class{constructor(){this._friendGroupMap=new Map}init(e){this._core=e;const{helper:t}=e;t.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),t.registerApi({apiName:"createFriendGroup",context:this}),t.registerApi({apiName:"deleteFriendGroup",context:this}),t.registerApi({apiName:"addToFriendGroup",context:this}),t.registerApi({apiName:"removeFromFriendGroup",context:this}),t.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,(function*(){const e=[...this._friendGroupMap.values()];return console.log(`${t} getFriendGroupListFromCache, data: `,e),{code:0,data:e}}))}syncFriendGroupListFromServer(){return e(this,void 0,void 0,(function*(){const e="syncFriendGroupListFromServer";console.log(`${t} ${e}`);try{const r=yield k(),{resultList:i=[]}=r;this._core.helper.isEmpty(i)&&console.log(`${t} ${e} ok. count: 0`),i.forEach((e=>{const t=new O(e);this._friendGroupMap.set(e.name,t)})),this._emitGroupListUpdated()}catch(t){this._handleError(e,t)}}))}createFriendGroup(r){return e(this,void 0,void 0,(function*(){const e="createFriendGroup";console.log(`${t} ${e} params:`,r);try{const{name:t}=r;this._checkGroupExist(e,t);const i=yield N(r),{successUserIDList:o,failureUserIDList:n}=this._parseCreateGroupResponse(i),s=new O({name:t,userIDList:o});return this._friendGroupMap.set(t,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(t){this._handleError(e,t)}}))}deleteFriendGroup(r){return e(this,void 0,void 0,(function*(){const e="deleteFriendGroup";console.log(`${t} ${e} params:`,r);try{const{name:t}=r;this._checkGroupNotExist(e,t),yield P(r);const i=this._friendGroupMap.get(t);return i&&(this._updateFriendGroup({name:t,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(t)),this._emitGroupListUpdated(),{code:0,data:i}}catch(t){this._handleError(e,t)}}))}addToFriendGroup(t){return e(this,void 0,void 0,(function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:G})}))}removeFromFriendGroup(t){return e(this,void 0,void 0,(function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:w})}))}renameFriendGroup(r){return e(this,void 0,void 0,(function*(){const e="renameFriendGroup";console.log(`${t} ${e} params:`,r);try{const{oldName:t,newName:i}=r;this._checkGroupNotExist(e,t),this._checkGroupExist(e,i),yield U(r);const o=this._updateGroupNameInCache(t,i);return o&&this._updateFriendGroup({name:t,userIDList:o.userIDList,action:_,newName:i}),this._emitGroupListUpdated(),{code:0,data:o}}catch(t){this._handleError(e,t)}}))}_updateFriendGroupMember(r){return e(this,void 0,void 0,(function*(){const{functionName:e,params:i,protocolFunction:o}=r;console.log(`${t} ${e} params:`,i);try{const{name:t}=i;this._checkGroupNotExist(e,t);const r=yield o(i),{friendGroup:n,failureUserIDList:s}=this._parseUpdateFriendGroupResponse(t,r);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:s}}}catch(t){this._handleError(e,t)}}))}_updateGroupNameInCache(e,t){const r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){const{resultList:t=[]}=e,r=[],i=[];return t.forEach((({userID:e,resultCode:t,resultInfo:o})=>{f(t)||0===t?r.push(e):i.push({userID:e,code:t,message:o})})),{successUserIDList:r,failureUserIDList:i}}_parseUpdateFriendGroupResponse(e,t){const{resultList:r=[]}=t,i=this._friendGroupMap.get(e),o=[],n=[],s=[];return r.forEach((t=>{0===t.resultCode?i&&(t.updateType===l?this._addFriendToGroup(e,t.userID,i,n):t.updateType===p&&this._removeFriendFromGroup(e,t.userID,i,s)):o.push({userID:t.userID,code:t.resultCode,message:t.resultInfo})})),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){const{notificationCenter:e,OuterEvent: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){const{name:r,userIDList:i,action:o,newName:n}=e,{userStore:s}=this._core.appStore;console.log(`${t} updateFriendGroup`,{name:r,userIDList:i,action:o,newName:n}),r&&!this._core.utils.isEmpty(i)&&i.forEach((e=>{const t=s.getFriend(e);if(!t)return;const{groupList:i}=t;switch(o){case h:-1===i.indexOf(r)&&(i.push(r),t.count=i.length);break;case m:{const e=i.indexOf(r);e>-1&&(i.splice(e,1),t.count=i.length);break}case _:{if(!n)return;const e=i.indexOf(r);-1!==e&&(i[e]=n);break}}}))}_handleError(e,r){const i=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(`${t} ${e} error:`,i),i}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){this._core=e;const{helper:t,constants:r}=e;t.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),t.registerApi({apiName:"addToBlacklist",context:this}),t.registerApi({apiName:"removeFromBlacklist",context:this}),t.registerWorkflowStep(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,(function*(){return 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`);const i={From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},o=yield function(t,r){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=r,o="sns.black_list_get",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{BlackListItem:a=[],StartIndex:c=0}=d;return{blackList:B(a),startIndex:c}}))}(i,this._core),{blackList:n=[],startIndex:s=0}=o;return this._startIndex=s,this._addBlacklistMap(n),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(`${t} syncBlacklistFromServer error:`,e),e}}))}addToBlacklist(r){return e(this,void 0,void 0,(function*(){try{console.log(`${t} addToBlacklist options:`,r);const i=this._preprocessBlacklist(r),o={From_Account:this._core.common.getCurrentUserID(),To_Account:i},n=yield function(t,r){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=r,o="sns.black_list_add",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}}))}(o,this._core),{blackList:s=[]}=n;return this._addBlacklistMap(s),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(`${t} addToBlacklist error:`,e),e}}))}removeFromBlacklist(r){return e(this,void 0,void 0,(function*(){try{console.log(`${t} removeFromBlacklist options:`,r);const i={From_Account:this._core.common.getCurrentUserID(),To_Account:r.userIDList},o=yield function(t,r){return e(this,void 0,void 0,(function*(){const{helper:e,channel:i}=r,o="sns.black_list_delete",n=e.generateProtocolData({servcmd:o,data:t}),s=`${n.head.seq}${o}`,d=yield i.sendPacket(n,{requestId:s}),{ResultItem:a=[]}=d;return{blackList:B(a)}}))}(i,this._core),{blackList:n=[]}=o;return this._deleteBlacklistMap(n),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);const{addedBlacklist:r=[],removedBlacklist:i=[]}=e;let o=!1;if(r.length>0){r.some((e=>!this._blacklistMap.has(e)))&&(o=!0,this._addBlacklistMap(r.map((e=>({userID:e})))))}if(i.length>0){i.some((e=>this._blacklistMap.has(e)))&&(o=!0,this._deleteBlacklistMap(i.map((e=>({userID:e})))))}o&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(`${t} _addBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t,addBlackTimeStamp:r=Date.now()}=e;t&&!this._blacklistMap.has(t)&&this._blacklistMap.set(t,{userID:t,addBlackTimeStamp:r})}))}_deleteBlacklistMap(e){console.log(`${t} _deleteBlacklistMap blackList:`,e),e.forEach((e=>{const{userID:t}=e;t&&this._blacklistMap.has(t)&&this._blacklistMap.delete(t)}))}_preprocessBlacklist(e){let{userIDList:t}=e;const r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t.includes(r)&&(t=e.userIDList.filter((e=>e!==r))),t}_emitBlackListUpdated(){const{notificationCenter:e,OuterEvent:r}=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})}};const 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=>{const{OuterConstant:t}=y.core;return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{const{OuterConstant:t}=y.core;return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{const{OuterConstant:t}=y.core;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=>{const{OuterConstant:t}=y.core;return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},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};return new class{install(e){console.log(`${t} install`),this._core=e;const{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:s}}=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){const{from:t,addedBlacklist:r,removedBlacklist:i,addedFriendList:o,removedFriendList:n,addedApplicationList:s,removedApplicationList:d,friendUpdateInfo:a,reportTime:c}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),{isEmpty:u}=this._core.utils;u(r)&&u(i)||b.updateBlacklist({addedBlacklist:r,removedBlacklist:i}),u(o)&&u(n)||(L.updateFriendList({addedFriendList:o,removedFriendList:n}),C.updateFriendApplicationList({from:t,removedApplicationList:o})),u(a)||L.updateFriendInfo(a),u(s)&&u(d)||C.updateFriendApplicationList({from:t,addedApplicationList:s,removedApplicationList:d}),c&&C.onApplicationRead()}_parseFriendListModification(e){const{PushType:t,From_Account:r,To_Account:i,ReportTime:o,BlackListAdd_Account:n=[],BlackListDel_Account:s=[],FriendAdd_Account:d=[],FriendDel_Account:a=[],PendencyAdd:c=[],FrienPencydDel_Account:u=[],FriendUpInfo:l=[]}=e,p=l.map((e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]})));return{pushType:t,from:r,to:i,reportTime:o,addedBlacklist:n,removedBlacklist:s,addedFriendList:d,removedFriendList:a,addedApplicationList:c.map((e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick}))),friendUpdateInfo:p,removedApplicationList:u}}reset(){console.log(`${t} reset`),b.reset(),L.reset(),C.reset(),$.reset()}dispose(){console.log(`${t} dispose`);const{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()}}}));