@tencentcloud/lite-chat 4.1.0 → 4.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/basic.es.js +1 -1
- package/basic.js +1 -1
- package/package.json +11 -11
- package/plugins/friend.es.js +1 -1
- package/plugins/friend.js +1 -1
- package/plugins/group.es.js +1 -1
- package/plugins/group.js +1 -1
- package/plugins/rich-media-message.es.js +1 -1
- package/plugins/rich-media-message.js +1 -1
- package/professional.es.js +1 -1
- package/professional.js +1 -1
- package/standard.es.js +1 -1
- package/standard.js +1 -1
- package/CHANGELOG.md +0 -407
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tencentcloud/lite-chat",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.2",
|
|
4
4
|
"description": "Tencent Cloud Chat SDK for Web/Mini Program/uni-app/React Native/Donut",
|
|
5
5
|
"main": "standard.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"
|
|
10
|
-
"
|
|
9
|
+
"types": "./index.d.ts",
|
|
10
|
+
"default": "./standard.js"
|
|
11
11
|
},
|
|
12
12
|
"./basic": {
|
|
13
|
-
"
|
|
14
|
-
"
|
|
13
|
+
"types": "./basic.d.ts",
|
|
14
|
+
"default": "./basic.js"
|
|
15
15
|
},
|
|
16
16
|
"./standard": {
|
|
17
|
-
"
|
|
18
|
-
"
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"default": "./standard.js"
|
|
19
19
|
},
|
|
20
20
|
"./professional": {
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"types": "./professional.d.ts",
|
|
22
|
+
"default": "./professional.js"
|
|
23
23
|
},
|
|
24
24
|
"./plugins/*": {
|
|
25
|
-
"
|
|
26
|
-
"
|
|
25
|
+
"types": "./plugins/*.d.ts",
|
|
26
|
+
"default": "./plugins/*.js"
|
|
27
27
|
}
|
|
28
28
|
},
|
|
29
29
|
"keywords": ["chat", "real-time chat", "uni-app", "React Native", "Donut", "push", "messaging", "IM", "trtc"],
|
package/plugins/friend.es.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
function e(e,n,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{s(d.next(e))}catch(e){t(e)}}function o(e){try{s(d.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}s((d=d.apply(e,n||[])).next())})}let t="friend",r=100,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:c+"Group",REMARK:c+"Remark",ADDSOURCE:c+"AddSource",ADDWORDING:c+"Wording",ADDTIME:c+"AddTime"},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function F(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function I(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:s}}let v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}},A=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),v[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=v[t];null!=e&&e(this,r)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){var{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,e=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",t+" getFriendListFromCache, data:"+i(e)),{code:0,data:e}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){let u,{ssoLog:c,helper:r}=this._core;try{c.debug("syncFriendListFromServer",t+" syncFriendListFromServer");let r={From_Account:null==(u=this._core.store.get("login"))?void 0:u.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},i=yield function(c,l){return e(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:s,ActionStatus:n,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:s,actionStatus:n,errorCode:a,errorInfo:d,errorDisplay:u}})}(r,this._core),{friendList:o,nextStartIndex:s,standardSequence:n,customSequence:a,completeFlag:d}=i;this._startIndex=s,this._standardSequence=n,this._customSequence=a,this._processFriendList(o),0===d?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),c.debug("syncFriendListFromServer",t+" syncFriendListFromServer ok")}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}getFriendProfile(c){return e(this,void 0,void 0,function*(){var i;try{let t=c["userIDList"];t.length>r&&(t=t.slice(0,r));var o,s,n,{friendUserIdList:a,unFriendUserIdList:d}=this.partitionByIsFriend(t),u=this._createNonFriendErrorList(d);return 0===a.length?{code:0,data:{friendList:[],failureUserIDList:u}}:(o=(yield function(s,n){return e(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield n.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:s});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(i=this._core.store.get("login"))?void 0:i.userId,To_Account:a},this._core))||{},{successProfiles:s,failedProfiles:n}=this._processFriendProfileResponse(o),{code:0,data:{friendList:s,failureUserIDList:[...n,...u]}})}catch(e){let t=(e||{})["errorCode"];throw new this._core.helper.ChatError({code:t})}})}addFriend(v){return e(this,void 0,void 0,function*(){var r,{helper:i,store:o,ssoLog:s}=this._core;try{var{to:n,source:d,type:u,wording:c,remark:l,groupName:p}=v,h=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}({From_Account:null==(r=o.get("login"))?void 0:r.userId,AddFriendItem:[{To_Account:n,AddSource:d,AddWording:c,GroupName:p,Remark:l}],AddType:u},this._core),{resultList:m=[]}=h,{userID:_,resultCode:f}=m[0];if(0===f)return s.debug("addFriend",t+" addFriend ok"),{code:0,data:{userID:_}};if(f===a)return s.debug("addFriend",t+" addFriend wait for the other party to agree"),{code:0,data:{userID:_,code:f,message:"wait for the other party to agree"}};throw new i.ChatError({functionName:"addFriend",code:f})}catch(e){let t=(e||{})["errorCode"];throw new i.ChatError({code:t})}})}deleteFriend(m){return e(this,void 0,void 0,function*(){var s,{store:n,ssoLog:a,helper:i}=this._core;try{let{userIDList:i,type:o}=m;var d,u,c,l=null==(s=n.get("login"))?void 0:s.userId,{friendUserIdList:p,unFriendUserIdList:h}=(1e3<i.length&&(a.info("deleteFriend",t+" deleteFriend the length of userIDList cannot exceed:1000"),i=i.slice(0,r)),this.partitionByIsFriend(i));return 0===p.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(h)}}:(d=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}({From_Account:l,To_Account:p,DeleteType:o},this._core),{successUserIDList:u,failureUserIDList:c}=this._processOperationResult({resultList:d.resultList,includeRelation:!1}),{code:0,data:{successUserIDList:u,failureUserIDList:c}})}catch(e){let t=(e||{})["errorCode"];throw new i.ChatError({code:t})}})}updateFriend(h){return e(this,void 0,void 0,function*(){var t,{helper:r,store:e,appStore:{userStore:o}}=this._core;try{var{userID:s,remark:n,friendCustomField:a}=h,d=null==(t=e.get("login"))?void 0:t.userId;if(!o.getFriendMap().has(s))throw new r.ChatError({functionName:"updateFriend",code:i});var u=(yield F({From_Account:d,UpdateItem:[{To_Account:s,SnsItem:this._buildSnsItemList(n,a)}]},this._core))["resultList"],{to:c,resultCode:l,resultInfo:p}=u[0];if(f(l)||0===l)return{code:0,data:this._updateLocalFriend({userID:c,remark:n,friendCustomField:a})};throw new r.ChatError({functionName:"updateFriend",code:l,message:p})}catch(t){let e=(t||{})["errorCode"];throw new r.ChatError({code:e})}})}checkFriend(c){return e(this,void 0,void 0,function*(){let a,{OuterConstant:d,store:u,helper:t}=this._core;try{let{userIDList:e,type:t}=c,r=null==(a=u.get("login"))?void 0:a.userId,i={From_Account:r,To_Account:e,CheckType:t===d.SNS_CHECK_TYPE_SINGLE?t:d.SNS_CHECK_TYPE_BOTH},o=yield I(i,this._core),{successUserIDList:s=[],failureUserIDList:n=[]}=this._processOperationResult({resultList:o.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:n}}}catch(a){let e=(a||{})["errorCode"];throw new t.ChatError({code:e})}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(n){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core;e.debug("updateFriendList",t+" updateFriendList data:"+r(n));let i=this._core.appStore["userStore"],{addedFriendList:o=[],removedFriendList:s=[]}=n;0<o.length&&(o.forEach(e=>{var t=new A({userID:e,core:this._core});i.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:o}),this._emitFriendListUpdated()),0<s.length&&(s.forEach(e=>{i.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",t+" updateFriendInfo data:"+i(e));let{appStore:{userStore:o,conversationStore:s},utils:{isEmpty:n}}=this._core,{userID:a,tagValueList:d}=e[0]||{},c=o.getFriend(a);if(!n(d)&&c){let i=d.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=s.getConversation("C2C"+a))?void 0:r.remark;e===u.REMARK&&t!==r&&s.updateConversation("C2C"+a,{remark:t}),c.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new A({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){let{appStore:{userStore:s},user:{userProfile:n},ssoLog:e}=this._core,a=(e.debug("_fetchFriendProfile",t+" _fetchFriendProfile"),[...s.getFriendMap().keys()]),r=Math.ceil(a.length/100);for(let o=0;o<r;o++){let e=100*o,t=Math.min(100+e,a.length),r=a.slice(e,t),i=yield null==n?void 0:n.getUserProfile({userIDList:r});i&&i.data&&i.data.forEach(e=>{var t=s.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,r=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:r})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return f(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],s=[],n=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(f(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),s.push(e)}else n.push({userID:t,code:e,message:i})}),{successUserIDList:s,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:t=[]}=e,o=this._core.appStore["userStore"],s=[],n=[];return t.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new A({userID:t,tagValueList:i,core:this._core});s.push(e),o.getFriendMap().set(t,e)}else n.push({userID:t,code:e,message:r})}),{successProfiles:s,failedProfiles:n}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},y=new class{init(e){this.core=e}};function S(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return C(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function E(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function D(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return C(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function C(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",t+" getFriendApplicationListFromCache friendApplicationList:"+r(i)),{code:0,data:{friendApplicationList:i,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){let{ssoLog:i,utils:{safeStringify:o}}=this._core,s="syncFriendApplicationListFromServer";try{let t=yield function(u){return e(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:i}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:u.startTime,LastSequence:u.currentSequence},{PendencyItem:t=[],StartTime:i,UnreadPendencyCount:e,CurrentSequence:o,ActionStatus:s,ErrorCode:n,ErrorInfo:a,ErrorDisplay:d}=t=yield i.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,image:e.Image})),startTime:i,unreadCount:e,currentSequence:o,actionStatus:s,errorCode:n,errorInfo:a,errorDisplay:d}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:s,currentSequence:n}=t;this._startTime=s,this._currentSequence=n,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw i.error("syncFriendApplicationListFromServer",`${t} ${s} error:`,{error:r}),r}})}acceptFriendApplication(r){return e(this,void 0,void 0,function*(){var{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:t}=this._core["OuterConstant"];return[e,t].includes(r.type)||(r.type=t),this._operationApplication({functionName:"acceptFriendApplication",options:r,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(r){return e(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(e+"_"+t))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,function*(){let{functionName:s,options:n,protocolFunction:a}=r;console.log(t+` ${s} options:`,n);try{let e=yield a(n),{resultList:r=[]}=e,{resultCode:i,resultInfo:o}=r[0];if(0===i)return console.log(t+` ${s} ok`),{code:0,data:{}};throw{errorCode:i,errorInfo:o}}catch(e){let r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${s} error:`,r),r}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){var{from:e,addedApplicationList:t=[],removedApplicationList:r=[]}=e,i=this._core.utils["isEmpty"];i(t)||this.onApplicationAdded(t,e),i(r)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,s=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var t=e.userID+"_"+s;s!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:s})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function k(){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return U(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}function N(i){return e(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=y.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return U(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function G(r){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return U(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}function w(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,l),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function P(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,p),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function M(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}function R(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function U(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s,ResultItem:n=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s};return t&&0<n.length?Object.assign(Object.assign({},e),{resultList:n.map(t)}):e}class O{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendGroupMap.values()];return e.debug(t+" getFriendGroupListFromCache, data:"+r(i)),{code:0,data:i}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){var e=this._core["ssoLog"],r="syncFriendGroupListFromServer";try{var i=yield k(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",t+` ${r} ok. count: 0`),o.forEach(e=>{var t=new O(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(n){return e(this,void 0,void 0,function*(){var t="createFriendGroup";try{var e=n["name"],r=(this._checkGroupExist(t,e),yield N(n)),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(r),s=new O({name:e,userIDList:i});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:o}}}catch(e){this._handleError(t,e)}})}deleteFriendGroup(i){return e(this,void 0,void 0,function*(){var t="deleteFriendGroup";try{var e=i["name"],r=(this._checkGroupNotExist(t,e),yield G(i),this._friendGroupMap.get(e));return r&&(this._updateFriendGroup({name:e,userIDList:r.userIDList,action:m}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:r}}catch(e){this._handleError(t,e)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:w})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:P})})}renameFriendGroup(o){return e(this,void 0,void 0,function*(){var t="renameFriendGroup";try{var{oldName:e,newName:r}=o,i=(this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield M(o),this._updateGroupNameInCache(e,r));return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:_,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(a){return e(this,void 0,void 0,function*(){var{functionName:t,params:r,protocolFunction:i}=a;try{let e=r["name"];this._checkGroupNotExist(t,e);var o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(e,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(t,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{f(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],s=[],n=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===l?this._addFriendToGroup(t,e.userID,i,s):e.updateType===p&&this._removeFriendFromGroup(t,e.userID,i,n)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:n})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){let{name:i,userIDList:t,action:o,newName:s}=e,n=this._core.appStore["userStore"];i&&!this._core.utils.isEmpty(t)&&t.forEach(e=>{var t=n.getFriend(e);if(t){var r=t["groupList"];switch(o){case h:-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case m:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case _:if(s){let e=r.indexOf(i);-1!==e&&(r[e]=s)}}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var q=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(t+" syncBlacklistFromServer");var i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},this._core),{blackList:o=[],startIndex:s=0}=i;return this._startIndex=s,this._addBlacklistMap(o),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(s){return e(this,void 0,void 0,function*(){let r=this._core["helper"];try{let t=this._preprocessBlacklist(s),r={From_Account:this._core.common.getCurrentUserID(),To_Account:t},i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}(r,this._core),{blackList:o=[]}=i;return this._addBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}removeFromBlacklist(o){return e(this,void 0,void 0,function*(){let r=this._core["helper"];try{let t={From_Account:this._core.common.getCurrentUserID(),To_Account:o.userIDList},r=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}(t,this._core),{blackList:i=[]}=r;return this._deleteBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core,{addedBlacklist:r=[],removedBlacklist:i=[]}=(r.debug("updateBlacklist",t+" updateBlacklist data: "+i(e)),e);let o=!1;0<r.length&&r.some(e=>!this._blacklistMap.has(e))&&(o=!0,this._addBlacklistMap(r.map(e=>({userID:e})))),0<i.length&&i.some(e=>this._blacklistMap.has(e))&&(o=!0,this._deleteBlacklistMap(i.map(e=>({userID:e})))),o&&this._emitBlackListUpdated()}_addBlacklistMap(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",t+" _addBlacklistMap blackList: "+i(e)),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",t+" _deleteBlacklistMap blackList: "+i(e)),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:r,ssoLog:i,utils:{safeStringify:o}}=this._core,s=Array.from(this._blacklistMap.keys());i.debug(t+" _emitBlackListUpdated blackList:"+o(s)),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:s})}};let x={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},$={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var V=new class{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(t+" install");var{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:s,WORKFLOW_STEP:n}}=this._core=e;y.init(e),g.init(e),T.init(e),b.init(e),q.init(e),r.registerValidateConfig({auth:$,params:x}),r.registerWorkflowStep(s.SYNC_SERVER_INFO_AFTER_LOGIN,n.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){q.syncBlacklistFromServer(),g.syncFriendListFromServer(),T.syncFriendApplicationListFromServer(),b.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:s,removedApplicationList:n,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||q.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(g.updateFriendList({addedFriendList:i,removedFriendList:o}),T.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||g.updateFriendInfo(a),u(s)&&u(n)||T.updateFriendApplicationList({from:e,addedApplicationList:s,removedApplicationList:n}),d&&T.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:s=[],FriendAdd_Account:n=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:s,addedFriendList:n,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),q.dispose(),g.dispose(),T.dispose(),b.dispose()}};export{V as default};
|
|
1
|
+
function e(e,n,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{s(d.next(e))}catch(e){t(e)}}function o(e){try{s(d.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}s((d=d.apply(e,n||[])).next())})}let t="friend",r=100,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:c+"Group",REMARK:c+"Remark",ADDSOURCE:c+"AddSource",ADDWORDING:c+"Wording",ADDTIME:c+"AddTime"},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function F(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function I(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function L(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:s}}let v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}},A=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),v[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=v[t];null!=e&&e(this,r)})}};var g=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){var{appStore:{userStore:e},ssoLog:r,utils:{safeStringify:i}}=this._core,e=[...e.getFriendMap().values()];return r.debug("getFriendListFromCache",t+" getFriendListFromCache, data:"+i(e)),{code:0,data:e}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){let u,{ssoLog:c,helper:r}=this._core;try{c.debug("syncFriendListFromServer",t+" syncFriendListFromServer");let r={From_Account:null==(u=this._core.store.get("login"))?void 0:u.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},i=yield function(c,l){return e(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:s,ActionStatus:n,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:s,actionStatus:n,errorCode:a,errorInfo:d,errorDisplay:u}})}(r,this._core),{friendList:o,nextStartIndex:s,standardSequence:n,customSequence:a,completeFlag:d}=i;this._startIndex=s,this._standardSequence=n,this._customSequence=a,this._processFriendList(o),0===d?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),c.debug("syncFriendListFromServer",t+" syncFriendListFromServer ok")}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}getFriendProfile(c){return e(this,void 0,void 0,function*(){var i;try{let t=c["userIDList"];t.length>r&&(t=t.slice(0,r));var o,s,n,{friendUserIdList:a,unFriendUserIdList:d}=this.partitionByIsFriend(t),u=this._createNonFriendErrorList(d);return 0===a.length?{code:0,data:{friendList:[],failureUserIDList:u}}:(o=(yield function(s,n){return e(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield n.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:s});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(i=this._core.store.get("login"))?void 0:i.userId,To_Account:a},this._core))||{},{successProfiles:s,failedProfiles:n}=this._processFriendProfileResponse(o),{code:0,data:{friendList:s,failureUserIDList:[...n,...u]}})}catch(e){let t=(e||{})["errorCode"];throw new this._core.helper.ChatError({code:t})}})}addFriend(v){return e(this,void 0,void 0,function*(){var r,{helper:i,store:o,ssoLog:s}=this._core;try{var{to:n,source:d,type:u,wording:c,remark:l,groupName:p}=v,h=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}({From_Account:null==(r=o.get("login"))?void 0:r.userId,AddFriendItem:[{To_Account:n,AddSource:d,AddWording:c,GroupName:p,Remark:l}],AddType:u},this._core),{resultList:m=[]}=h,{userID:_,resultCode:f}=m[0];if(0===f)return s.debug("addFriend",t+" addFriend ok"),{code:0,data:{userID:_}};if(f===a)return s.debug("addFriend",t+" addFriend wait for the other party to agree"),{code:0,data:{userID:_,code:f,message:"wait for the other party to agree"}};throw new i.ChatError({functionName:"addFriend",code:f})}catch(e){let t=(e||{})["errorCode"];throw new i.ChatError({code:t})}})}deleteFriend(m){return e(this,void 0,void 0,function*(){var s,{store:n,ssoLog:a,helper:i}=this._core;try{let{userIDList:i,type:o}=m;var d,u,c,l=null==(s=n.get("login"))?void 0:s.userId,{friendUserIdList:p,unFriendUserIdList:h}=(1e3<i.length&&(a.info("deleteFriend",t+" deleteFriend the length of userIDList cannot exceed:1000"),i=i.slice(0,r)),this.partitionByIsFriend(i));return 0===p.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(h)}}:(d=yield function(t,r){return e(this,void 0,void 0,function*(){return L(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}({From_Account:l,To_Account:p,DeleteType:o},this._core),{successUserIDList:u,failureUserIDList:c}=this._processOperationResult({resultList:d.resultList,includeRelation:!1}),{code:0,data:{successUserIDList:u,failureUserIDList:c}})}catch(e){let t=(e||{})["errorCode"];throw new i.ChatError({code:t})}})}updateFriend(h){return e(this,void 0,void 0,function*(){var t,{helper:r,store:e,appStore:{userStore:o}}=this._core;try{var{userID:s,remark:n,friendCustomField:a}=h,d=null==(t=e.get("login"))?void 0:t.userId;if(!o.getFriendMap().has(s))throw new r.ChatError({functionName:"updateFriend",code:i});var u=(yield F({From_Account:d,UpdateItem:[{To_Account:s,SnsItem:this._buildSnsItemList(n,a)}]},this._core))["resultList"],{to:c,resultCode:l,resultInfo:p}=u[0];if(f(l)||0===l)return{code:0,data:this._updateLocalFriend({userID:c,remark:n,friendCustomField:a})};throw new r.ChatError({functionName:"updateFriend",code:l,message:p})}catch(t){let e=(t||{})["errorCode"];throw new r.ChatError({code:e})}})}checkFriend(c){return e(this,void 0,void 0,function*(){let a,{OuterConstant:d,store:u,helper:t}=this._core;try{let{userIDList:e,type:t}=c,r=null==(a=u.get("login"))?void 0:a.userId,i={From_Account:r,To_Account:e,CheckType:t===d.SNS_CHECK_TYPE_SINGLE?t:d.SNS_CHECK_TYPE_BOTH},o=yield I(i,this._core),{successUserIDList:s=[],failureUserIDList:n=[]}=this._processOperationResult({resultList:o.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:n}}}catch(a){let e=(a||{})["errorCode"];throw new t.ChatError({code:e})}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(n){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core;e.debug("updateFriendList",t+" updateFriendList data:"+r(n));let i=this._core.appStore["userStore"],{addedFriendList:o=[],removedFriendList:s=[]}=n;0<o.length&&(o.forEach(e=>{var t=new A({userID:e,core:this._core});i.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:o}),this._emitFriendListUpdated()),0<s.length&&(s.forEach(e=>{i.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("updateFriendList",t+" updateFriendInfo data:"+i(e));let{appStore:{userStore:o,conversationStore:s},utils:{isEmpty:n}}=this._core,{userID:a,tagValueList:d}=e[0]||{},c=o.getFriend(a);if(!n(d)&&c){let i=d.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=s.getConversation("C2C"+a))?void 0:r.remark;e===u.REMARK&&t!==r&&s.updateConversation("C2C"+a,{remark:t}),c.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new A({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){let{appStore:{userStore:s},user:{userProfile:n},ssoLog:e}=this._core,a=(e.debug("_fetchFriendProfile",t+" _fetchFriendProfile"),[...s.getFriendMap().keys()]),r=Math.ceil(a.length/100);for(let o=0;o<r;o++){let e=100*o,t=Math.min(100+e,a.length),r=a.slice(e,t),i=yield null==n?void 0:n.getUserProfile({userIDList:r});i&&i.data&&i.data.forEach(e=>{var t=s.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,r=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:r})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return f(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],s=[],n=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(f(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),s.push(e)}else n.push({userID:t,code:e,message:i})}),{successUserIDList:s,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:t=[]}=e,o=this._core.appStore["userStore"],s=[],n=[];return t.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new A({userID:t,tagValueList:i,core:this._core});s.push(e),o.getFriendMap().set(t,e)}else n.push({userID:t,code:e,message:r})}),{successProfiles:s,failedProfiles:n}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},y=new class{init(e){this.core=e}};function S(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return C(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function E(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return C(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function D(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return C(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function C(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var T=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",t+" getFriendApplicationListFromCache friendApplicationList:"+r(i)),{code:0,data:{friendApplicationList:i,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){let{ssoLog:i,utils:{safeStringify:o}}=this._core,s="syncFriendApplicationListFromServer";try{let t=yield function(u){return e(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:i}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:u.startTime,LastSequence:u.currentSequence},{PendencyItem:t=[],StartTime:i,UnreadPendencyCount:e,CurrentSequence:o,ActionStatus:s,ErrorCode:n,ErrorInfo:a,ErrorDisplay:d}=t=yield i.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,avatar:e.Image})),startTime:i,unreadCount:e,currentSequence:o,actionStatus:s,errorCode:n,errorInfo:a,errorDisplay:d}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:s,currentSequence:n}=t;this._startTime=s,this._currentSequence=n,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw i.error("syncFriendApplicationListFromServer",`${t} ${s} error:`,{error:r}),r}})}acceptFriendApplication(r){return e(this,void 0,void 0,function*(){var{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:t}=this._core["OuterConstant"];return[e,t].includes(r.type)||(r.type=t),this._operationApplication({functionName:"acceptFriendApplication",options:r,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(r){return e(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(e+"_"+t))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,function*(){let{functionName:s,options:n,protocolFunction:a}=r;console.log(t+` ${s} options:`,n);try{let e=yield a(n),{resultList:r=[]}=e,{resultCode:i,resultInfo:o}=r[0];if(0===i)return console.log(t+` ${s} ok`),{code:0,data:{}};throw{errorCode:i,errorInfo:o}}catch(e){let r=new this._core.helper.ChatError({functionName:s,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${s} error:`,r),r}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){try{return yield function(){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){var{from:e,addedApplicationList:t=[],removedApplicationList:r=[]}=e,i=this._core.utils["isEmpty"];i(t)||this.onApplicationAdded(t,e),i(r)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,s=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var t=e.userID+"_"+s;s!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:s})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function k(){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return U(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}function N(i){return e(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=y.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return U(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function G(r){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return U(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}function w(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,l),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function P(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,p),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function M(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return U(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}function R(e,t){return e.filter(e=>g.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function U(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s,ResultItem:n=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s};return t&&0<n.length?Object.assign(Object.assign({},e),{resultList:n.map(t)}):e}class O{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var b=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:r}}=this._core,i=[...this._friendGroupMap.values()];return e.debug(t+" getFriendGroupListFromCache, data:"+r(i)),{code:0,data:i}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){var e=this._core["ssoLog"],r="syncFriendGroupListFromServer";try{var i=yield k(),{resultList:o=[]}=i;this._core.helper.isEmpty(o)&&e.debug("syncFriendGroupListFromServer",t+` ${r} ok. count: 0`),o.forEach(e=>{var t=new O(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(n){return e(this,void 0,void 0,function*(){var t="createFriendGroup";try{var e=n["name"],r=(this._checkGroupExist(t,e),yield N(n)),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(r),s=new O({name:e,userIDList:i});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:o}}}catch(e){this._handleError(t,e)}})}deleteFriendGroup(i){return e(this,void 0,void 0,function*(){var t="deleteFriendGroup";try{var e=i["name"],r=(this._checkGroupNotExist(t,e),yield G(i),this._friendGroupMap.get(e));return r&&(this._updateFriendGroup({name:e,userIDList:r.userIDList,action:m}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:r}}catch(e){this._handleError(t,e)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:w})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:P})})}renameFriendGroup(o){return e(this,void 0,void 0,function*(){var t="renameFriendGroup";try{var{oldName:e,newName:r}=o,i=(this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield M(o),this._updateGroupNameInCache(e,r));return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:_,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(a){return e(this,void 0,void 0,function*(){var{functionName:t,params:r,protocolFunction:i}=a;try{let e=r["name"];this._checkGroupNotExist(t,e);var o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(e,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(t,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{f(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],s=[],n=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===l?this._addFriendToGroup(t,e.userID,i,s):e.updateType===p&&this._removeFriendFromGroup(t,e.userID,i,n)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:n})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){let{name:i,userIDList:t,action:o,newName:s}=e,n=this._core.appStore["userStore"];i&&!this._core.utils.isEmpty(t)&&t.forEach(e=>{var t=n.getFriend(e);if(t){var r=t["groupList"];switch(o){case h:-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case m:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case _:if(s){let e=r.indexOf(i);-1!==e&&(r[e]=s)}}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var q=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(t+" syncBlacklistFromServer");var i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},this._core),{blackList:o=[],startIndex:s=0}=i;return this._startIndex=s,this._addBlacklistMap(o),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(s){return e(this,void 0,void 0,function*(){let r=this._core["helper"];try{let t=this._preprocessBlacklist(s),r={From_Account:this._core.common.getCurrentUserID(),To_Account:t},i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}(r,this._core),{blackList:o=[]}=i;return this._addBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}removeFromBlacklist(o){return e(this,void 0,void 0,function*(){let r=this._core["helper"];try{let t={From_Account:this._core.common.getCurrentUserID(),To_Account:o.userIDList},r=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}(t,this._core),{blackList:i=[]}=r;return this._deleteBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core,{addedBlacklist:r=[],removedBlacklist:i=[]}=(r.debug("updateBlacklist",t+" updateBlacklist data: "+i(e)),e);let o=!1;0<r.length&&r.some(e=>!this._blacklistMap.has(e))&&(o=!0,this._addBlacklistMap(r.map(e=>({userID:e})))),0<i.length&&i.some(e=>this._blacklistMap.has(e))&&(o=!0,this._deleteBlacklistMap(i.map(e=>({userID:e})))),o&&this._emitBlackListUpdated()}_addBlacklistMap(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_addBlacklistMap",t+" _addBlacklistMap blackList: "+i(e)),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){var{ssoLog:r,utils:{safeStringify:i}}=this._core;r.debug("_deleteBlacklistMap",t+" _deleteBlacklistMap blackList: "+i(e)),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:r,ssoLog:i,utils:{safeStringify:o}}=this._core,s=Array.from(this._blacklistMap.keys());i.debug(t+" _emitBlackListUpdated blackList:"+o(s)),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:s})}};let x={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},$={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var V=new class{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(t+" install");var{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:s,WORKFLOW_STEP:n}}=this._core=e;y.init(e),g.init(e),T.init(e),b.init(e),q.init(e),r.registerValidateConfig({auth:$,params:x}),r.registerWorkflowStep(s.SYNC_SERVER_INFO_AFTER_LOGIN,n.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){q.syncBlacklistFromServer(),g.syncFriendListFromServer(),T.syncFriendApplicationListFromServer(),b.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:s,removedApplicationList:n,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||q.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(g.updateFriendList({addedFriendList:i,removedFriendList:o}),T.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||g.updateFriendInfo(a),u(s)&&u(n)||T.updateFriendApplicationList({from:e,addedApplicationList:s,removedApplicationList:n}),d&&T.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:s=[],FriendAdd_Account:n=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:s,addedFriendList:n,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){q.reset(),g.reset(),T.reset(),b.reset()}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),q.dispose(),g.dispose(),T.dispose(),b.dispose()}};export{V as default};
|
package/plugins/friend.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatFriend=t()}(this,function(){function _(e,n,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{s(d.next(e))}catch(e){t(e)}}function o(e){try{s(d.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}s((d=d.apply(e,n||[])).next())})}let f="friend",h=100,e="Tag_SNS_IM_",u={GROUP:e+"Group",REMARK:e+"Remark",ADDSOURCE:e+"AddSource",ADDWORDING:e+"Wording",ADDTIME:e+"AddTime"},a="Update_Type_Add",d="Update_Type_Delete",c="remove",l="rename",m=e=>void 0===e;function v(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:s}}let o={[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}},p=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),o[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=o[t];null!=e&&e(this,r)})}};var F=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return _(this,void 0,void 0,function*(){var{appStore:{userStore:e},ssoLog:t,utils:{safeStringify:r}}=this._core,e=[...e.getFriendMap().values()];return t.debug("getFriendListFromCache",f+" getFriendListFromCache, data:"+r(e)),{code:0,data:e}})}syncFriendListFromServer(){return _(this,void 0,void 0,function*(){let a,{ssoLog:d,helper:r}=this._core;try{d.debug("syncFriendListFromServer",f+" syncFriendListFromServer");let e={From_Account:null==(a=this._core.store.get("login"))?void 0:a.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},t=yield function(c,l){return _(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:s,ActionStatus:n,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:s,actionStatus:n,errorCode:a,errorInfo:d,errorDisplay:u}})}(e,this._core),{friendList:r,nextStartIndex:i,standardSequence:o,customSequence:s,completeFlag:n}=t;this._startIndex=i,this._standardSequence=o,this._customSequence=s,this._processFriendList(r),0===n?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),d.debug("syncFriendListFromServer",f+" syncFriendListFromServer ok")}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}getFriendProfile(d){return _(this,void 0,void 0,function*(){var t;try{let e=d["userIDList"];e.length>h&&(e=e.slice(0,h));var r,i,o,{friendUserIdList:s,unFriendUserIdList:n}=this.partitionByIsFriend(e),a=this._createNonFriendErrorList(n);return 0===s.length?{code:0,data:{friendList:[],failureUserIDList:a}}:(r=(yield function(s,n){return _(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield n.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:s});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(t=this._core.store.get("login"))?void 0:t.userId,To_Account:s},this._core))||{},{successProfiles:i,failedProfiles:o}=this._processFriendProfileResponse(r),{code:0,data:{friendList:i,failureUserIDList:[...o,...a]}})}catch(e){let t=(e||{})["errorCode"];throw new this._core.helper.ChatError({code:t})}})}addFriend(m){return _(this,void 0,void 0,function*(){var e,{helper:r,store:t,ssoLog:i}=this._core;try{var{to:o,source:s,type:n,wording:a,remark:d,groupName:u}=m,c=yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_add",data:e}))})}({From_Account:null==(e=t.get("login"))?void 0:e.userId,AddFriendItem:[{To_Account:o,AddSource:s,AddWording:a,GroupName:u,Remark:d}],AddType:n},this._core),{resultList:l=[]}=c,{userID:p,resultCode:h}=l[0];if(0===h)return i.debug("addFriend",f+" addFriend ok"),{code:0,data:{userID:p}};if(30539===h)return i.debug("addFriend",f+" addFriend wait for the other party to agree"),{code:0,data:{userID:p,code:h,message:"wait for the other party to agree"}};throw new r.ChatError({functionName:"addFriend",code:h})}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}deleteFriend(p){return _(this,void 0,void 0,function*(){var r,{store:i,ssoLog:o,helper:s}=this._core;try{let{userIDList:e,type:t}=p;var n,a,d,u=null==(r=i.get("login"))?void 0:r.userId,{friendUserIdList:c,unFriendUserIdList:l}=(1e3<e.length&&(o.info("deleteFriend",f+" deleteFriend the length of userIDList cannot exceed:1000"),e=e.slice(0,h)),this.partitionByIsFriend(e));return 0===c.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(l)}}:(n=yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:e}))})}({From_Account:u,To_Account:c,DeleteType:t},this._core),{successUserIDList:a,failureUserIDList:d}=this._processOperationResult({resultList:n.resultList,includeRelation:!1}),{code:0,data:{successUserIDList:a,failureUserIDList:d}})}catch(e){let t=(e||{})["errorCode"];throw new s.ChatError({code:t})}})}updateFriend(p){return _(this,void 0,void 0,function*(){var t,{helper:r,store:e,appStore:{userStore:i}}=this._core;try{var{userID:o,remark:s,friendCustomField:n}=p,a=null==(t=e.get("login"))?void 0:t.userId;if(!i.getFriendMap().has(o))throw new r.ChatError({functionName:"updateFriend",code:2700});var d=(yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_update",data:e}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}({From_Account:a,UpdateItem:[{To_Account:o,SnsItem:this._buildSnsItemList(s,n)}]},this._core))["resultList"],{to:u,resultCode:c,resultInfo:l}=d[0];if(m(c)||0===c)return{code:0,data:this._updateLocalFriend({userID:u,remark:s,friendCustomField:n})};throw new r.ChatError({functionName:"updateFriend",code:c,message:l})}catch(t){let e=(t||{})["errorCode"];throw new r.ChatError({code:e})}})}checkFriend(c){return _(this,void 0,void 0,function*(){let a,{OuterConstant:d,store:u,helper:t}=this._core;try{let{userIDList:e,type:t}=c,r=null==(a=u.get("login"))?void 0:a.userId,i={From_Account:r,To_Account:e,CheckType:t===d.SNS_CHECK_TYPE_SINGLE?t:d.SNS_CHECK_TYPE_BOTH},o=yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_check",data:e}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}(i,this._core),{successUserIDList:s=[],failureUserIDList:n=[]}=this._processOperationResult({resultList:o.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:n}}}catch(a){let e=(a||{})["errorCode"];throw new t.ChatError({code:e})}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(s){return _(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core;e.debug("updateFriendList",f+" updateFriendList data:"+t(s));let r=this._core.appStore["userStore"],{addedFriendList:i=[],removedFriendList:o=[]}=s;0<i.length&&(i.forEach(e=>{var t=new p({userID:e,core:this._core});r.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:i}),this._emitFriendListUpdated()),0<o.length&&(o.forEach(e=>{r.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("updateFriendList",f+" updateFriendInfo data:"+r(e));let{appStore:{userStore:i,conversationStore:o},utils:{isEmpty:s}}=this._core,{userID:n,tagValueList:a}=e[0]||{},d=i.getFriend(n);if(!s(a)&&d){let i=a.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=o.getConversation("C2C"+n))?void 0:r.remark;e===u.REMARK&&t!==r&&o.updateConversation("C2C"+n,{remark:t}),d.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new p({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return _(this,void 0,void 0,function*(){let{appStore:{userStore:s},user:{userProfile:n},ssoLog:e}=this._core,a=(e.debug("_fetchFriendProfile",f+" _fetchFriendProfile"),[...s.getFriendMap().keys()]),t=Math.ceil(a.length/100);for(let o=0;o<t;o++){let e=100*o,t=Math.min(100+e,a.length),r=a.slice(e,t),i=yield null==n?void 0:n.getUserProfile({userIDList:r});i&&i.data&&i.data.forEach(e=>{var t=s.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,r=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:r})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return m(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],s=[],n=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(m(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),s.push(e)}else n.push({userID:t,code:e,message:i})}),{successUserIDList:s,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:2700,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return m(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:t=[]}=e,o=this._core.appStore["userStore"],s=[],n=[];return t.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new p({userID:t,tagValueList:i,core:this._core});s.push(e),o.getFriendMap().set(t,e)}else n.push({userID:t,code:e,message:r})}),{successProfiles:s,failedProfiles:n}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},I=new class{init(e){this.core=e}};function i(r){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return n(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function t(r){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return n(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function s(r){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return n(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function n(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var L=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return _(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core,r=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",f+" getFriendApplicationListFromCache friendApplicationList:"+t(r)),{code:0,data:{friendApplicationList:r,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return _(this,void 0,void 0,function*(){let{ssoLog:r,utils:{safeStringify:e}}=this._core,i="syncFriendApplicationListFromServer";try{let e=yield function(d){return _(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:r}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:h,StartTime:d.startTime,LastSequence:d.currentSequence},{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:e,CurrentSequence:i,ActionStatus:o,ErrorCode:s,ErrorInfo:n,ErrorDisplay:a}=t=yield r.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,image:e.Image})),startTime:r,unreadCount:e,currentSequence:i,actionStatus:o,errorCode:s,errorInfo:n,errorDisplay:a}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:t,unreadCount:r,startTime:i,currentSequence:o}=e;this._startTime=i,this._currentSequence=o,this._unreadCount=r,this._friendApplicationMap.clear(),Array.isArray(t)&&t.forEach(e=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let t=new this._core.helper.ChatError({functionName:i,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw r.error("syncFriendApplicationListFromServer",`${f} ${i} error:`,{error:t}),t}})}acceptFriendApplication(r){return _(this,void 0,void 0,function*(){var{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:t}=this._core["OuterConstant"];return[e,t].includes(r.type)||(r.type=t),this._operationApplication({functionName:"acceptFriendApplication",options:r,protocolFunction:i})})}refuseFriendApplication(e){return _(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:e,protocolFunction:t})})}deleteFriendApplication(r){return _(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,protocolFunction:s})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(e+"_"+t))throw new this._core.helper.ChatError({functionName:r,code:2716})}_operationApplication(e){return _(this,void 0,void 0,function*(){let{functionName:o,options:s,protocolFunction:n}=e;console.log(f+` ${o} options:`,s);try{let e=yield n(s),{resultList:t=[]}=e,{resultCode:r,resultInfo:i}=t[0];if(0===r)return console.log(f+` ${o} ok`),{code:0,data:{}};throw{errorCode:r,errorInfo:i}}catch(e){let t=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(f+` ${o} error:`,t),t}})}setFriendApplicationRead(){return _(this,void 0,void 0,function*(){try{return yield function(){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){var{from:e,addedApplicationList:t=[],removedApplicationList:r=[]}=e,i=this._core.utils["isEmpty"];i(t)||this.onApplicationAdded(t,e),i(r)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,s=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var t=e.userID+"_"+s;s!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:s})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function r(i){return _(this,void 0,void 0,function*(){var e=I.core["common"],{name:t,userIDList:r}=i,r=g(r,a),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function A(i){return _(this,void 0,void 0,function*(){var e=I.core["common"],{name:t,userIDList:r}=i,r=g(r,d),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function g(e,t){return e.filter(e=>F.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function y(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s,ResultItem:n=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s};return t&&0<n.length?Object.assign(Object.assign({},e),{resultList:n.map(t)}):e}class S{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var E=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return _(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core,r=[...this._friendGroupMap.values()];return e.debug(f+" getFriendGroupListFromCache, data:"+t(r)),{code:0,data:r}})}syncFriendGroupListFromServer(){return _(this,void 0,void 0,function*(){var e=this._core["ssoLog"],t="syncFriendGroupListFromServer";try{var r=yield function(){return _(this,void 0,void 0,function*(){var e=I.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return y(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}(),{resultList:i=[]}=r;this._core.helper.isEmpty(i)&&e.debug("syncFriendGroupListFromServer",f+` ${t} ok. count: 0`),i.forEach(e=>{var t=new S(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(t,e)}})}createFriendGroup(n){return _(this,void 0,void 0,function*(){var t="createFriendGroup";try{var e=n["name"],r=(this._checkGroupExist(t,e),yield function(i){return _(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=I.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return y(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}(n)),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(r),s=new S({name:e,userIDList:i});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:o}}}catch(e){this._handleError(t,e)}})}deleteFriendGroup(i){return _(this,void 0,void 0,function*(){var t="deleteFriendGroup";try{var e=i["name"],r=(this._checkGroupNotExist(t,e),yield function(r){return _(this,void 0,void 0,function*(){var e=I.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return y(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}(i),this._friendGroupMap.get(e));return r&&(this._updateFriendGroup({name:e,userIDList:r.userIDList,action:c}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:r}}catch(e){this._handleError(t,e)}})}addToFriendGroup(e){return _(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:e,protocolFunction:r})})}removeFromFriendGroup(e){return _(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:e,protocolFunction:A})})}renameFriendGroup(o){return _(this,void 0,void 0,function*(){var t="renameFriendGroup";try{var{oldName:e,newName:r}=o,i=(this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield function(i){return _(this,void 0,void 0,function*(){var e=I.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}(o),this._updateGroupNameInCache(e,r));return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:l,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(e){return _(this,void 0,void 0,function*(){var{functionName:t,params:r,protocolFunction:i}=e;try{let e=r["name"];this._checkGroupNotExist(t,e);var o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(e,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(t,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{m(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],s=[],n=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===a?this._addFriendToGroup(t,e.userID,i,s):e.updateType===d&&this._removeFriendFromGroup(t,e.userID,i,n)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:"add"})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:c})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:2711})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:2710})}_updateFriendGroup(e){let{name:i,userIDList:t,action:o,newName:s}=e,n=this._core.appStore["userStore"];i&&!this._core.utils.isEmpty(t)&&t.forEach(e=>{var t=n.getFriend(e);if(t){var r=t["groupList"];switch(o){case"add":-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case c:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case l:if(s){let e=r.indexOf(i);-1!==e&&(r[e]=s)}}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function D(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var C=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return _(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return _(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(f+" syncBlacklistFromServer");var e=yield function(i,o){return _(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:D(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:h,StartIndex:this._startIndex},this._core),{blackList:t=[],startIndex:r=0}=e;return this._startIndex=r,this._addBlacklistMap(t),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(o){return _(this,void 0,void 0,function*(){let r=this._core["helper"];try{let e=this._preprocessBlacklist(o),t={From_Account:this._core.common.getCurrentUserID(),To_Account:e},r=yield function(i,o){return _(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:D(t)}})}(t,this._core),{blackList:i=[]}=r;return this._addBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}removeFromBlacklist(i){return _(this,void 0,void 0,function*(){let r=this._core["helper"];try{let e={From_Account:this._core.common.getCurrentUserID(),To_Account:i.userIDList},t=yield function(i,o){return _(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:D(t)}})}(e,this._core),{blackList:r=[]}=t;return this._deleteBlacklistMap(r),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core,{addedBlacklist:t=[],removedBlacklist:r=[]}=(t.debug("updateBlacklist",f+" updateBlacklist data: "+r(e)),e);let i=!1;0<t.length&&t.some(e=>!this._blacklistMap.has(e))&&(i=!0,this._addBlacklistMap(t.map(e=>({userID:e})))),0<r.length&&r.some(e=>this._blacklistMap.has(e))&&(i=!0,this._deleteBlacklistMap(r.map(e=>({userID:e})))),i&&this._emitBlackListUpdated()}_addBlacklistMap(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("_addBlacklistMap",f+" _addBlacklistMap blackList: "+r(e)),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("_deleteBlacklistMap",f+" _deleteBlacklistMap blackList: "+r(e)),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:2742});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:t,ssoLog:r,utils:{safeStringify:i}}=this._core,o=Array.from(this._blacklistMap.keys());r.debug(f+" _emitBlackListUpdated blackList:"+i(o)),e.emitOuterEvent(t.BLACKLIST_UPDATED,{name:t.BLACKLIST_UPDATED,data:o})}};let T={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=I.core["OuterConstant"];return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=I.core["OuterConstant"];return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=I.core["OuterConstant"];return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},k={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{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(f+" install");var{helper:t,notificationCenter:r,InnerEvent:i,constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:s}}=this._core=e;I.init(e),F.init(e),L.init(e),E.init(e),C.init(e),t.registerValidateConfig({auth:k,params:T}),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,s.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),r.subscribeInnerEvent(i.LOGOUT,this.reset,this),r.subscribeInnerEvent(i.MESSAGE_PUSH,r.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){C.syncBlacklistFromServer(),F.syncFriendListFromServer(),L.syncFriendApplicationListFromServer(),E.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:s,removedApplicationList:n,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||C.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(F.updateFriendList({addedFriendList:i,removedFriendList:o}),L.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||F.updateFriendInfo(a),u(s)&&u(n)||L.updateFriendApplicationList({from:e,addedApplicationList:s,removedApplicationList:n}),d&&L.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:s=[],FriendAdd_Account:n=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:s,addedFriendList:n,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){C.reset(),F.reset(),L.reset(),E.reset()}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),C.dispose(),F.dispose(),L.dispose(),E.dispose()}}});
|
|
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(){function _(e,n,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{s(d.next(e))}catch(e){t(e)}}function o(e){try{s(d.throw(e))}catch(e){t(e)}}function s(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}s((d=d.apply(e,n||[])).next())})}let f="friend",h=100,e="Tag_SNS_IM_",u={GROUP:e+"Group",REMARK:e+"Remark",ADDSOURCE:e+"AddSource",ADDWORDING:e+"Wording",ADDTIME:e+"AddTime"},a="Update_Type_Add",d="Update_Type_Delete",c="remove",l="rename",m=e=>void 0===e;function v(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:s}}let o={[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}},p=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),o[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=o[t];null!=e&&e(this,r)})}};var F=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return _(this,void 0,void 0,function*(){var{appStore:{userStore:e},ssoLog:t,utils:{safeStringify:r}}=this._core,e=[...e.getFriendMap().values()];return t.debug("getFriendListFromCache",f+" getFriendListFromCache, data:"+r(e)),{code:0,data:e}})}syncFriendListFromServer(){return _(this,void 0,void 0,function*(){let a,{ssoLog:d,helper:r}=this._core;try{d.debug("syncFriendListFromServer",f+" syncFriendListFromServer");let e={From_Account:null==(a=this._core.store.get("login"))?void 0:a.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},t=yield function(c,l){return _(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:s,ActionStatus:n,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:s,actionStatus:n,errorCode:a,errorInfo:d,errorDisplay:u}})}(e,this._core),{friendList:r,nextStartIndex:i,standardSequence:o,customSequence:s,completeFlag:n}=t;this._startIndex=i,this._standardSequence=o,this._customSequence=s,this._processFriendList(r),0===n?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),d.debug("syncFriendListFromServer",f+" syncFriendListFromServer ok")}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}getFriendProfile(d){return _(this,void 0,void 0,function*(){var t;try{let e=d["userIDList"];e.length>h&&(e=e.slice(0,h));var r,i,o,{friendUserIdList:s,unFriendUserIdList:n}=this.partitionByIsFriend(e),a=this._createNonFriendErrorList(n);return 0===s.length?{code:0,data:{friendList:[],failureUserIDList:a}}:(r=(yield function(s,n){return _(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield n.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:s});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(t=this._core.store.get("login"))?void 0:t.userId,To_Account:s},this._core))||{},{successProfiles:i,failedProfiles:o}=this._processFriendProfileResponse(r),{code:0,data:{friendList:i,failureUserIDList:[...o,...a]}})}catch(e){let t=(e||{})["errorCode"];throw new this._core.helper.ChatError({code:t})}})}addFriend(m){return _(this,void 0,void 0,function*(){var e,{helper:r,store:t,ssoLog:i}=this._core;try{var{to:o,source:s,type:n,wording:a,remark:d,groupName:u}=m,c=yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_add",data:e}))})}({From_Account:null==(e=t.get("login"))?void 0:e.userId,AddFriendItem:[{To_Account:o,AddSource:s,AddWording:a,GroupName:u,Remark:d}],AddType:n},this._core),{resultList:l=[]}=c,{userID:p,resultCode:h}=l[0];if(0===h)return i.debug("addFriend",f+" addFriend ok"),{code:0,data:{userID:p}};if(30539===h)return i.debug("addFriend",f+" addFriend wait for the other party to agree"),{code:0,data:{userID:p,code:h,message:"wait for the other party to agree"}};throw new r.ChatError({functionName:"addFriend",code:h})}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}deleteFriend(p){return _(this,void 0,void 0,function*(){var r,{store:i,ssoLog:o,helper:s}=this._core;try{let{userIDList:e,type:t}=p;var n,a,d,u=null==(r=i.get("login"))?void 0:r.userId,{friendUserIdList:c,unFriendUserIdList:l}=(1e3<e.length&&(o.info("deleteFriend",f+" deleteFriend the length of userIDList cannot exceed:1000"),e=e.slice(0,h)),this.partitionByIsFriend(e));return 0===c.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(l)}}:(n=yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:e}))})}({From_Account:u,To_Account:c,DeleteType:t},this._core),{successUserIDList:a,failureUserIDList:d}=this._processOperationResult({resultList:n.resultList,includeRelation:!1}),{code:0,data:{successUserIDList:a,failureUserIDList:d}})}catch(e){let t=(e||{})["errorCode"];throw new s.ChatError({code:t})}})}updateFriend(p){return _(this,void 0,void 0,function*(){var t,{helper:r,store:e,appStore:{userStore:i}}=this._core;try{var{userID:o,remark:s,friendCustomField:n}=p,a=null==(t=e.get("login"))?void 0:t.userId;if(!i.getFriendMap().has(o))throw new r.ChatError({functionName:"updateFriend",code:2700});var d=(yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_update",data:e}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}({From_Account:a,UpdateItem:[{To_Account:o,SnsItem:this._buildSnsItemList(s,n)}]},this._core))["resultList"],{to:u,resultCode:c,resultInfo:l}=d[0];if(m(c)||0===c)return{code:0,data:this._updateLocalFriend({userID:u,remark:s,friendCustomField:n})};throw new r.ChatError({functionName:"updateFriend",code:c,message:l})}catch(t){let e=(t||{})["errorCode"];throw new r.ChatError({code:e})}})}checkFriend(c){return _(this,void 0,void 0,function*(){let a,{OuterConstant:d,store:u,helper:t}=this._core;try{let{userIDList:e,type:t}=c,r=null==(a=u.get("login"))?void 0:a.userId,i={From_Account:r,To_Account:e,CheckType:t===d.SNS_CHECK_TYPE_SINGLE?t:d.SNS_CHECK_TYPE_BOTH},o=yield function(e,t){return _(this,void 0,void 0,function*(){return v(yield t.common.buildAndSendPacket({servcmd:"sns.friend_check",data:e}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}(i,this._core),{successUserIDList:s=[],failureUserIDList:n=[]}=this._processOperationResult({resultList:o.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:n}}}catch(a){let e=(a||{})["errorCode"];throw new t.ChatError({code:e})}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(s){return _(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core;e.debug("updateFriendList",f+" updateFriendList data:"+t(s));let r=this._core.appStore["userStore"],{addedFriendList:i=[],removedFriendList:o=[]}=s;0<i.length&&(i.forEach(e=>{var t=new p({userID:e,core:this._core});r.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:i}),this._emitFriendListUpdated()),0<o.length&&(o.forEach(e=>{r.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("updateFriendList",f+" updateFriendInfo data:"+r(e));let{appStore:{userStore:i,conversationStore:o},utils:{isEmpty:s}}=this._core,{userID:n,tagValueList:a}=e[0]||{},d=i.getFriend(n);if(!s(a)&&d){let i=a.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=o.getConversation("C2C"+n))?void 0:r.remark;e===u.REMARK&&t!==r&&o.updateConversation("C2C"+n,{remark:t}),d.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new p({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return _(this,void 0,void 0,function*(){let{appStore:{userStore:s},user:{userProfile:n},ssoLog:e}=this._core,a=(e.debug("_fetchFriendProfile",f+" _fetchFriendProfile"),[...s.getFriendMap().keys()]),t=Math.ceil(a.length/100);for(let o=0;o<t;o++){let e=100*o,t=Math.min(100+e,a.length),r=a.slice(e,t),i=yield null==n?void 0:n.getUserProfile({userIDList:r});i&&i.data&&i.data.forEach(e=>{var t=s.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:t,appStore:{userStore:r}}=this._core,r=Array.from(r.getFriendMap().values());e.emitOuterEvent(t.FRIEND_LIST_UPDATED,{name:t.FRIEND_LIST_UPDATED,data:r})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return m(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],s=[],n=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(m(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),s.push(e)}else n.push({userID:t,code:e,message:i})}),{successUserIDList:s,failureUserIDList:n}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:2700,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return m(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:t=[]}=e,o=this._core.appStore["userStore"],s=[],n=[];return t.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new p({userID:t,tagValueList:i,core:this._core});s.push(e),o.getFriendMap().set(t,e)}else n.push({userID:t,code:e,message:r})}),{successProfiles:s,failedProfiles:n}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},I=new class{init(e){this.core=e}};function i(r){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return n(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function t(r){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return n(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function s(r){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return n(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function n(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var L=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return _(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core,r=[...this._friendApplicationMap.values()];return e.debug("getFriendApplicationListFromCache",f+" getFriendApplicationListFromCache friendApplicationList:"+t(r)),{code:0,data:{friendApplicationList:r,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return _(this,void 0,void 0,function*(){let{ssoLog:r,utils:{safeStringify:e}}=this._core,i="syncFriendApplicationListFromServer";try{let e=yield function(d){return _(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:r}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:h,StartTime:d.startTime,LastSequence:d.currentSequence},{PendencyItem:t=[],StartTime:r,UnreadPendencyCount:e,CurrentSequence:i,ActionStatus:o,ErrorCode:s,ErrorInfo:n,ErrorDisplay:a}=t=yield r.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,avatar:e.Image})),startTime:r,unreadCount:e,currentSequence:i,actionStatus:o,errorCode:s,errorInfo:n,errorDisplay:a}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:t,unreadCount:r,startTime:i,currentSequence:o}=e;this._startTime=i,this._currentSequence=o,this._unreadCount=r,this._friendApplicationMap.clear(),Array.isArray(t)&&t.forEach(e=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let t=new this._core.helper.ChatError({functionName:i,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw r.error("syncFriendApplicationListFromServer",`${f} ${i} error:`,{error:t}),t}})}acceptFriendApplication(r){return _(this,void 0,void 0,function*(){var{SNS_APPLICATION_AGREE:e,SNS_APPLICATION_AGREE_AND_ADD:t}=this._core["OuterConstant"];return[e,t].includes(r.type)||(r.type=t),this._operationApplication({functionName:"acceptFriendApplication",options:r,protocolFunction:i})})}refuseFriendApplication(e){return _(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:e,protocolFunction:t})})}deleteFriendApplication(r){return _(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,protocolFunction:s})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(e+"_"+t))throw new this._core.helper.ChatError({functionName:r,code:2716})}_operationApplication(e){return _(this,void 0,void 0,function*(){let{functionName:o,options:s,protocolFunction:n}=e;console.log(f+` ${o} options:`,s);try{let e=yield n(s),{resultList:t=[]}=e,{resultCode:r,resultInfo:i}=t[0];if(0===r)return console.log(f+` ${o} ok`),{code:0,data:{}};throw{errorCode:r,errorInfo:i}}catch(e){let t=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(f+` ${o} error:`,t),t}})}setFriendApplicationRead(){return _(this,void 0,void 0,function*(){try{return yield function(){return _(this,void 0,void 0,function*(){var{store:e,common:t}=I.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),{code:0,data:{}}}catch(e){throw new this._core.helper.ChatError({functionName:"setFriendApplicationRead",code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo})}})}updateFriendApplicationList(e){var{from:e,addedApplicationList:t=[],removedApplicationList:r=[]}=e,i=this._core.utils["isEmpty"];i(t)||this.onApplicationAdded(t,e),i(r)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,s=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var t=e.userID+"_"+s;s!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:s})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core;e.emitOuterEvent(t.FRIEND_APPLICATION_LIST_UPDATED,{name:t.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function r(i){return _(this,void 0,void 0,function*(){var e=I.core["common"],{name:t,userIDList:r}=i,r=g(r,a),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function A(i){return _(this,void 0,void 0,function*(){var e=I.core["common"],{name:t,userIDList:r}=i,r=g(r,d),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function g(e,t){return e.filter(e=>F.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function y(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:s,ResultItem:n=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:s};return t&&0<n.length?Object.assign(Object.assign({},e),{resultList:n.map(t)}):e}class S{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var E=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return _(this,void 0,void 0,function*(){var{ssoLog:e,utils:{safeStringify:t}}=this._core,r=[...this._friendGroupMap.values()];return e.debug(f+" getFriendGroupListFromCache, data:"+t(r)),{code:0,data:r}})}syncFriendGroupListFromServer(){return _(this,void 0,void 0,function*(){var e=this._core["ssoLog"],t="syncFriendGroupListFromServer";try{var r=yield function(){return _(this,void 0,void 0,function*(){var e=I.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return y(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}(),{resultList:i=[]}=r;this._core.helper.isEmpty(i)&&e.debug("syncFriendGroupListFromServer",f+` ${t} ok. count: 0`),i.forEach(e=>{var t=new S(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(t,e)}})}createFriendGroup(n){return _(this,void 0,void 0,function*(){var t="createFriendGroup";try{var e=n["name"],r=(this._checkGroupExist(t,e),yield function(i){return _(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=I.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return y(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}(n)),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(r),s=new S({name:e,userIDList:i});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:o}}}catch(e){this._handleError(t,e)}})}deleteFriendGroup(i){return _(this,void 0,void 0,function*(){var t="deleteFriendGroup";try{var e=i["name"],r=(this._checkGroupNotExist(t,e),yield function(r){return _(this,void 0,void 0,function*(){var e=I.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return y(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}(i),this._friendGroupMap.get(e));return r&&(this._updateFriendGroup({name:e,userIDList:r.userIDList,action:c}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:r}}catch(e){this._handleError(t,e)}})}addToFriendGroup(e){return _(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:e,protocolFunction:r})})}removeFromFriendGroup(e){return _(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:e,protocolFunction:A})})}renameFriendGroup(o){return _(this,void 0,void 0,function*(){var t="renameFriendGroup";try{var{oldName:e,newName:r}=o,i=(this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield function(i){return _(this,void 0,void 0,function*(){var e=I.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}(o),this._updateGroupNameInCache(e,r));return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:l,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(e){return _(this,void 0,void 0,function*(){var{functionName:t,params:r,protocolFunction:i}=e;try{let e=r["name"];this._checkGroupNotExist(t,e);var o=yield i(r),{friendGroup:s,failureUserIDList:n}=this._parseUpdateFriendGroupResponse(e,o);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(t,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{m(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],s=[],n=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===a?this._addFriendToGroup(t,e.userID,i,s):e.updateType===d&&this._removeFriendFromGroup(t,e.userID,i,n)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:"add"})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:c})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:t}=this._core,r=[...this._friendGroupMap.values()];e.emitOuterEvent(t.FRIEND_GROUP_LIST_UPDATED,{name:t.FRIEND_GROUP_LIST_UPDATED,data:r})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:2711})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:2710})}_updateFriendGroup(e){let{name:i,userIDList:t,action:o,newName:s}=e,n=this._core.appStore["userStore"];i&&!this._core.utils.isEmpty(t)&&t.forEach(e=>{var t=n.getFriend(e);if(t){var r=t["groupList"];switch(o){case"add":-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case c:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case l:if(s){let e=r.indexOf(i);-1!==e&&(r[e]=s)}}}})}_handleError(e,t){throw new this._core.helper.ChatError({functionName:e,code:null==t?void 0:t.errorCode,message:null==t?void 0:t.errorInfo})}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function D(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var C=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return _(this,void 0,void 0,function*(){return{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return _(this,void 0,void 0,function*(){try{this._core.ssoLog.debug(f+" syncBlacklistFromServer");var e=yield function(i,o){return _(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:D(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:h,StartIndex:this._startIndex},this._core),{blackList:t=[],startIndex:r=0}=e;return this._startIndex=r,this._addBlacklistMap(t),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,e}})}addToBlacklist(o){return _(this,void 0,void 0,function*(){let r=this._core["helper"];try{let e=this._preprocessBlacklist(o),t={From_Account:this._core.common.getCurrentUserID(),To_Account:e},r=yield function(i,o){return _(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:D(t)}})}(t,this._core),{blackList:i=[]}=r;return this._addBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}removeFromBlacklist(i){return _(this,void 0,void 0,function*(){let r=this._core["helper"];try{let e={From_Account:this._core.common.getCurrentUserID(),To_Account:i.userIDList},t=yield function(i,o){return _(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:D(t)}})}(e,this._core),{blackList:r=[]}=t;return this._deleteBlacklistMap(r),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){let t=(e||{})["errorCode"];throw new r.ChatError({code:t})}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core,{addedBlacklist:t=[],removedBlacklist:r=[]}=(t.debug("updateBlacklist",f+" updateBlacklist data: "+r(e)),e);let i=!1;0<t.length&&t.some(e=>!this._blacklistMap.has(e))&&(i=!0,this._addBlacklistMap(t.map(e=>({userID:e})))),0<r.length&&r.some(e=>this._blacklistMap.has(e))&&(i=!0,this._deleteBlacklistMap(r.map(e=>({userID:e})))),i&&this._emitBlackListUpdated()}_addBlacklistMap(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("_addBlacklistMap",f+" _addBlacklistMap blackList: "+r(e)),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){var{ssoLog:t,utils:{safeStringify:r}}=this._core;t.debug("_deleteBlacklistMap",f+" _deleteBlacklistMap blackList: "+r(e)),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:2742});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:t,ssoLog:r,utils:{safeStringify:i}}=this._core,o=Array.from(this._blacklistMap.keys());r.debug(f+" _emitBlackListUpdated blackList:"+i(o)),e.emitOuterEvent(t.BLACKLIST_UPDATED,{name:t.BLACKLIST_UPDATED,data:o})}};let T={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=I.core["OuterConstant"];return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=I.core["OuterConstant"];return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=I.core["OuterConstant"];return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},k={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{constructor(){this.name="Friend"}install(e){e.ssoLog.debug(f+" install");var{helper:t,notificationCenter:r,InnerEvent:i,constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:s}}=this._core=e;I.init(e),F.init(e),L.init(e),E.init(e),C.init(e),t.registerValidateConfig({auth:k,params:T}),t.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,s.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),r.subscribeInnerEvent(i.LOGOUT,this.reset,this),r.subscribeInnerEvent(i.MESSAGE_PUSH,r.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){C.syncBlacklistFromServer(),F.syncFriendListFromServer(),L.syncFriendApplicationListFromServer(),E.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:s,removedApplicationList:n,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||C.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(F.updateFriendList({addedFriendList:i,removedFriendList:o}),L.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||F.updateFriendInfo(a),u(s)&&u(n)||L.updateFriendApplicationList({from:e,addedApplicationList:s,removedApplicationList:n}),d&&L.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:s=[],FriendAdd_Account:n=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:s,addedFriendList:n,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){C.reset(),F.reset(),L.reset(),E.reset()}dispose(){var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(t.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),C.dispose(),F.dispose(),L.dispose(),E.dispose()}}});
|