@tencentcloud/lite-chat 1.3.0 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/plugins/follow.js CHANGED
@@ -1 +1 @@
1
- !function(o,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(o="undefined"!=typeof globalThis?globalThis:o||self).TencentCloudChatFollow=e()}(this,function(){function u(o,i,s,u){return new(s=s||Promise)(function(t,e){function r(o){try{n(u.next(o))}catch(o){e(o)}}function l(o){try{n(u.throw(o))}catch(o){e(o)}}function n(o){var e;o.done?t(o.value):((e=o.value)instanceof s?e:new s(function(o){o(e)})).then(r,l)}n((u=u.apply(o,i||[])).next())})}let a=new class{init(o){this.core=o}},s="Follow",r={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function e(i,s){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={FollowType:i,From_Account:null==(e=e.get("login"))?void 0:e.userId,StartCursor:s,WantNum:function(){let o=a.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0===e)return 500;{let o=Number(e);return 1e3<o?1e3:o}}()},{FollowItem:o=[],NextCursor:e,ActionStatus:t,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:t,errorCode:r,errorInfo:l,errorDisplay:n}})}function t(o){return u(this,void 0,void 0,function*(){return e(r.FOLLOWERS,o)})}function l(o){return u(this,void 0,void 0,function*(){return e(r.MUTUAL,o)})}function n(o){return u(this,void 0,void 0,function*(){return e(r.FOLLOWING,o)})}function i(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,FollowItem:n.map(o=>({To_Account:o}))},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_add",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}function c(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_delete",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}let d={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},f={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0},o=new class{install(o){var{helper:e,notificationCenter:t,InnerEvent:r}=this._core=o;a.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:f,params:d}),t.subscribeInnerEvent(r.MESSAGE_PUSH,t.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:n,nextCursor:o})})}getMyFollowersList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:t,nextCursor:o})})}getMutualFollowersList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:l,nextCursor:o})})}_getFollowList(o){return u(this,void 0,void 0,function*(){var{functionName:l,protocolFunction:n,nextCursor:i=""}=o;console.log(s+` ${l} nextCursor:`,i);try{this._checkBusinessCapabilityBits(l);let o=yield n(i),{resultList:e=[],nextPageToken:t=""}=o,r=this._parseFollowItems(e);return console.log(s+`.${l} nextCursor: ${i} from remote.`),{code:0,data:{resultList:r,nextCursor:t}}}catch(o){console.error(s+`.${l} fail:`,o),this._handleError(l,o)}})}followUser(o){return u(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:o,protocolFunction:i})})}unfollowUser(o){return u(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:o,protocolFunction:c})})}_handleUserFollowRelation(o){return u(this,void 0,void 0,function*(){var{functionName:e,userIDList:t,protocolFunction:r}=o;try{let o=this._sliceUserIDList(t,20);this._checkBusinessCapabilityBits(e);var{resultList:l=[]}=yield r(o);return{code:0,data:l}}catch(o){this._handleError(e,o)}})}getUserFollowInfo(n){return u(this,void 0,void 0,function*(){var t="getUserFollowInfo";console.log(s+` ${t} userIDList:`,n);try{this._checkBusinessCapabilityBits(t);var l=n||[this._core.common.getCurrentUserID()];console.log(s+` ${t} userIDList: `+l);let o=yield function(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{FollowInfo:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get_info",data:e});return{followInfoList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}(n),{followInfoList:e=[]}=o,r=[];return e.forEach(o=>{var{followerCount:o,followingCount:e,mutualFollowingCount:t}=o;r.push({followerCount:o,followingCount:e,mutualFollowingCount:t})}),{code:0,data:r}}catch(o){this._handleError(t,o)}})}checkFollowType(r){return u(this,void 0,void 0,function*(){var e="checkFollowType";console.log(s+` ${e} userIDList:`,r);try{this._checkBusinessCapabilityBits(e),100<r.length&&(r=r.slice(0,100),console.warn(s+` ${e} the length of userIDList cannot exceed 100`));var o=yield function(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_check",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}(r),{resultList:t=[]}=o;return{code:0,data:t.map(({userID:o,followType:e})=>({userID:o,followType:e}))}}catch(o){this._handleError(e,o)}})}onFollowListUpdated(o){console.log(s+" onFollowListUpdated",o);var{FollowChangeList:o=[]}=o;o.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){let{From_Account:e,FollowDiffList:t=[]}=o,r=function(o,e){var t={};for(l in o)Object.prototype.hasOwnProperty.call(o,l)&&e.indexOf(l)<0&&(t[l]=o[l]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,l=Object.getOwnPropertySymbols(o);r<l.length;r++)e.indexOf(l[r])<0&&Object.prototype.propertyIsEnumerable.call(o,l[r])&&(t[l[r]]=o[l[r]]);return t}(o,["From_Account","FollowDiffList"]),l={userID:e,avatar:r.FaceUrl,nick:r.NickName};t.forEach(o=>{o=this._updateFollowRelation(o,l);this._notifyFollowChanges(o)})}_updateFollowRelation(o,e){var{IsAdd:o,FollowType:t=0}=o,r=this._initFollowInfo(),t=r[t];return t.isAdd=1===o,t.userInfoList.push(t.isAdd?e:e.userID),r}_notifyFollowChanges(o){let e=this._core["OuterEvent"],t={[r.FOLLOWERS]:e.MY_FOLLOWERS_LIST_UPDATED,[r.FOLLOWING]:e.MY_FOLLOWING_LIST_UPDATED,[r.MUTUAL]:e.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,e])=>{o=Number(o);0<e.userInfoList.length&&t[o]&&this._emitFollowUpdated(t[o],e)})}_initFollowInfo(){let e={};return Object.values(r).forEach(o=>{o!==r.NONE&&(e[o]={userInfoList:[],isAdd:!1})}),e}_emitFollowUpdated(o,e){console.log(s+" _emitFollowUpdated");var t=this._core["notificationCenter"];t.emitOuterEvent(o,{name:o,data:e})}_sliceUserIDList(o,e){return o.slice(0,e)}_checkBusinessCapabilityBits(o){var{helper:e,store:t}=this._core;if(!(t.get("commercialConfig")||new Map).get("FOLLOW"))throw new e.ChatError({functionName:o,code:3122,replacement1:o})}_handleError(o,e){e=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(s+` ${o} fail:`,e),e}_parseFollowItems(o){return o.map(o=>{let e,{userID:t,followTime:r,profileItem:l=[]}=o,n=[];l.forEach(o=>{n.push({tag:o.Tag,value:o.Value})});o=null==(e=this._core.user.userProfile)?void 0:e.createProfile(t,n);return{userID:t,followTime:r,nick:null==o?void 0:o.nick,avatar:null==o?void 0:o.avatar,allowType:null==o?void 0:o.allowType,adminForbidType:null==o?void 0:o.adminForbidType}})}};return o});
1
+ !function(o,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(o="undefined"!=typeof globalThis?globalThis:o||self).TencentCloudChatFollow=e()}(this,function(){function u(o,i,s,u){return new(s=s||Promise)(function(t,e){function r(o){try{n(u.next(o))}catch(o){e(o)}}function l(o){try{n(u.throw(o))}catch(o){e(o)}}function n(o){var e;o.done?t(o.value):((e=o.value)instanceof s?e:new s(function(o){o(e)})).then(r,l)}n((u=u.apply(o,i||[])).next())})}let a=new class{init(o){this.core=o}},s="Follow",r={NONE:0,FOLLOWERS:1,FOLLOWING:2,MUTUAL:3};function e(i,s){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={FollowType:i,From_Account:null==(e=e.get("login"))?void 0:e.userId,StartCursor:s,WantNum:function(){let o=a.core.store.get("cloudConfig")||{},e=null==o?void 0:o.follow_req_count;if(void 0===e)return 500;{let o=Number(e);return 1e3<o?1e3:o}}()},{FollowItem:o=[],NextCursor:e,ActionStatus:t,ErrorCode:r,ErrorInfo:l,ErrorDisplay:n}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followTime:o.FollowTime,profileItem:o.ProfileItem,profileSequence:o.ProfileSequence})),nextPageToken:e,actionStatus:t,errorCode:r,errorInfo:l,errorDisplay:n}})}function t(o){return u(this,void 0,void 0,function*(){return e(r.FOLLOWERS,o)})}function l(o){return u(this,void 0,void 0,function*(){return e(r.MUTUAL,o)})}function n(o){return u(this,void 0,void 0,function*(){return e(r.FOLLOWING,o)})}function i(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,FollowItem:n.map(o=>({To_Account:o}))},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_add",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}function c(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_delete",data:e});return{resultList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}let d={getMyFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],getMyFollowingsList:[{required:!1,rules:["string"],allowEmpty:!0}],getMutualFollowersList:[{required:!1,rules:["string"],allowEmpty:!0}],followUser:[{required:!0,rules:["array"],allowEmpty:!1}],unfollowUser:[{required:!0,rules:["array"],allowEmpty:!1}],checkFollow:[{required:!0,rules:["array"],allowEmpty:!1}],getUserFollowInfo:[{required:!0,rules:["array"],allowEmpty:!1}]},f={getMyFollowersList:!0,getMyFollowingsList:!0,getMutualFollowersList:!0,followUser:!0,unfollowUser:!0,checkFollow:!0,getUserFollowInfo:!0},o=new class{constructor(){this.name="Follow"}install(o){var{helper:e,notificationCenter:t,InnerEvent:r}=this._core=o;a.init(o),e.registerApi({apiName:"getMyFollowingList",context:this}),e.registerApi({apiName:"getMyFollowersList",context:this}),e.registerApi({apiName:"getMutualFollowersList",context:this}),e.registerApi({apiName:"followUser",context:this}),e.registerApi({apiName:"unfollowUser",context:this}),e.registerApi({apiName:"getUserFollowInfo",context:this}),e.registerApi({apiName:"checkFollowType",context:this}),e.registerValidateConfig({auth:f,params:d}),t.subscribeInnerEvent(r.MESSAGE_PUSH,t.InnerEventSubType.FOLLOW_LIST_UPDATED,this.onFollowListUpdated,this)}getMyFollowingList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowingList",protocolFunction:n,nextCursor:o})})}getMyFollowersList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMyFollowersList",protocolFunction:t,nextCursor:o})})}getMutualFollowersList(){return u(this,arguments,void 0,function*(o=""){return this._getFollowList({functionName:"getMutualFollowersList",protocolFunction:l,nextCursor:o})})}_getFollowList(o){return u(this,void 0,void 0,function*(){var{functionName:l,protocolFunction:n,nextCursor:i=""}=o;console.log(s+` ${l} nextCursor:`,i);try{this._checkBusinessCapabilityBits(l);let o=yield n(i),{resultList:e=[],nextPageToken:t=""}=o,r=this._parseFollowItems(e);return console.log(s+`.${l} nextCursor: ${i} from remote.`),{code:0,data:{resultList:r,nextCursor:t}}}catch(o){console.error(s+`.${l} fail:`,o),this._handleError(l,o)}})}followUser(o){return u(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"followUser",userIDList:o,protocolFunction:i})})}unfollowUser(o){return u(this,void 0,void 0,function*(){return this._handleUserFollowRelation({functionName:"unfollowUser",userIDList:o,protocolFunction:c})})}_handleUserFollowRelation(o){return u(this,void 0,void 0,function*(){var{functionName:e,userIDList:t,protocolFunction:r}=o;try{let o=this._sliceUserIDList(t,20);this._checkBusinessCapabilityBits(e);var{resultList:l=[]}=yield r(o);return{code:0,data:l}}catch(o){this._handleError(e,o)}})}getUserFollowInfo(n){return u(this,void 0,void 0,function*(){var t="getUserFollowInfo";console.log(s+` ${t} userIDList:`,n);try{this._checkBusinessCapabilityBits(t);var l=n||[this._core.common.getCurrentUserID()];console.log(s+` ${t} userIDList: `+l);let o=yield function(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{FollowInfo:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_get_info",data:e});return{followInfoList:o.map(o=>({userID:o.To_Account,resultCode:o.ResultCode,resultInfo:o.ResultInfo,followerCount:o.FollowerCount,followingCount:o.FollowingCount,mutualFollowingCount:o.MutualFollowingCount})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}(n),{followInfoList:e=[]}=o,r=[];return e.forEach(o=>{var{followerCount:o,followingCount:e,mutualFollowingCount:t}=o;r.push({followerCount:o,followingCount:e,mutualFollowingCount:t})}),{code:0,data:r}}catch(o){this._handleError(t,o)}})}checkFollowType(r){return u(this,void 0,void 0,function*(){var e="checkFollowType";console.log(s+` ${e} userIDList:`,r);try{this._checkBusinessCapabilityBits(e),100<r.length&&(r=r.slice(0,100),console.warn(s+` ${e} the length of userIDList cannot exceed 100`));var o=yield function(n){return u(this,void 0,void 0,function*(){var{common:o,store:e}=a.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:n},{ResultItem:o=[],ActionStatus:e,ErrorCode:t,ErrorInfo:r,ErrorDisplay:l}=o=yield o.buildAndSendPacket({servcmd:"follow.follow_check",data:e});return{resultList:o.map(o=>({userID:o.To_Account,followType:o.FollowType,resultCode:o.ResultCode,resultInfo:o.ResultInfo})),actionStatus:e,errorCode:t,errorInfo:r,errorDisplay:l}})}(r),{resultList:t=[]}=o;return{code:0,data:t.map(({userID:o,followType:e})=>({userID:o,followType:e}))}}catch(o){this._handleError(e,o)}})}onFollowListUpdated(o){console.log(s+" onFollowListUpdated",o);var{FollowChangeList:o=[]}=o;o.forEach(o=>this._processFollowChangeItem(o))}_processFollowChangeItem(o){let{From_Account:e,FollowDiffList:t=[]}=o,r=function(o,e){var t={};for(l in o)Object.prototype.hasOwnProperty.call(o,l)&&e.indexOf(l)<0&&(t[l]=o[l]);if(null!=o&&"function"==typeof Object.getOwnPropertySymbols)for(var r=0,l=Object.getOwnPropertySymbols(o);r<l.length;r++)e.indexOf(l[r])<0&&Object.prototype.propertyIsEnumerable.call(o,l[r])&&(t[l[r]]=o[l[r]]);return t}(o,["From_Account","FollowDiffList"]),l={userID:e,avatar:r.FaceUrl,nick:r.NickName};t.forEach(o=>{o=this._updateFollowRelation(o,l);this._notifyFollowChanges(o)})}_updateFollowRelation(o,e){var{IsAdd:o,FollowType:t=0}=o,r=this._initFollowInfo(),t=r[t];return t.isAdd=1===o,t.userInfoList.push(t.isAdd?e:e.userID),r}_notifyFollowChanges(o){let e=this._core["OuterEvent"],t={[r.FOLLOWERS]:e.MY_FOLLOWERS_LIST_UPDATED,[r.FOLLOWING]:e.MY_FOLLOWING_LIST_UPDATED,[r.MUTUAL]:e.MUTUAL_FOLLOWERS_LIST_UPDATED};Object.entries(o).forEach(([o,e])=>{o=Number(o);0<e.userInfoList.length&&t[o]&&this._emitFollowUpdated(t[o],e)})}_initFollowInfo(){let e={};return Object.values(r).forEach(o=>{o!==r.NONE&&(e[o]={userInfoList:[],isAdd:!1})}),e}_emitFollowUpdated(o,e){console.log(s+" _emitFollowUpdated");var t=this._core["notificationCenter"];t.emitOuterEvent(o,{name:o,data:e})}_sliceUserIDList(o,e){return o.slice(0,e)}_checkBusinessCapabilityBits(o){var{helper:e,store:t}=this._core;if(!(t.get("commercialConfig")||new Map).get("FOLLOW"))throw new e.ChatError({functionName:o,code:3122,replacement1:o})}_handleError(o,e){e=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(s+` ${o} fail:`,e),e}_parseFollowItems(o){return o.map(o=>{let e,{userID:t,followTime:r,profileItem:l=[]}=o,n=[];l.forEach(o=>{n.push({tag:o.Tag,value:o.Value})});o=null==(e=this._core.user.userProfile)?void 0:e.createProfile(t,n);return{userID:t,followTime:r,nick:null==o?void 0:o.nick,avatar:null==o?void 0:o.avatar,allowType:null==o?void 0:o.allowType,adminForbidType:null==o?void 0:o.adminForbidType}})}};return o});
@@ -1 +1 @@
1
- function e(e,s,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{n(d.next(e))}catch(e){t(e)}}function o(e){try{n(d.throw(e))}catch(e){t(e)}}function n(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}n((d=d.apply(e,s||[])).next())})}let t="friend",r=100,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:c+"Group",REMARK:c+"Remark",ADDSOURCE:c+"AddSource",ADDWORDING:c+"Wording",ADDTIME:c+"AddTime"},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function I(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function F(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function A(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:n}}let v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}},g=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),v[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=v[t];null!=e&&e(this,r)})}};var L=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){var e=this._core.appStore["userStore"],e=[...e.getFriendMap().values()];return console.log(t+" getFriendListFromCache, data ",e),{code:0,data:e}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){var r;try{console.log(t+" syncFriendListFromServer");var{friendList:i,nextStartIndex:o,standardSequence:n,customSequence:s,completeFlag:a}=yield function(c,l){return e(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:n,ActionStatus:s,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:n,actionStatus:s,errorCode:a,errorInfo:d,errorDisplay:u}})}({From_Account:null==(r=this._core.store.get("login"))?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},this._core);this._startIndex=o,this._standardSequence=n,this._customSequence=s,this._processFriendList(i),0===a?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),console.log(t+" syncFriendListFromServer ok")}catch(e){throw console.error(t+" syncFriendListFromServer error:",e),e}})}getFriendProfile(l){return e(this,void 0,void 0,function*(){var o;try{console.log(t+" getFriendProfile params:",l);let i=l["userIDList"];i.length>r&&(i=i.slice(0,r));var n,s,a,{friendUserIdList:d,unFriendUserIdList:u}=this.partitionByIsFriend(i),c=this._createNonFriendErrorList(u);return 0===d.length?{code:0,data:{friendList:[],failureUserIDList:c}}:(n=(yield function(n,s){return e(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield s.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:n});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(o=this._core.store.get("login"))?void 0:o.userId,To_Account:d},this._core))||{},{successProfiles:s,failedProfiles:a}=this._processFriendProfileResponse(n),{code:0,data:{friendList:s,failureUserIDList:[...a,...c]}})}catch(e){throw console.error(t+" getFriendProfile error:",e),e}})}addFriend(f){return e(this,void 0,void 0,function*(){var r;try{console.log(t+" addFriend options:",f);var{helper:i,store:o}=this._core,{to:n,source:s,type:d,wording:u,remark:c,groupName:l}=f,p=yield function(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}({From_Account:null==(r=o.get("login"))?void 0:r.userId,AddFriendItem:[{To_Account:n,AddSource:s,AddWording:u,GroupName:l,Remark:c}],AddType:d},this._core),{resultList:h=[]}=p,{userID:m,resultCode:_}=h[0];if(0===_)return console.log(t+" addFriend ok"),{code:0,data:{userID:m}};if(_===a)return console.log(t+" addFriend wait for the other party to agree"),{code:0,data:{userID:m,code:_,message:"wait for the other party to agree"}};throw new i.ChatError({functionName:"addFriend",code:_})}catch(e){throw console.error(t+" addFriend error:",e),e}})}deleteFriend(h){return e(this,void 0,void 0,function*(){var n;try{console.log(t+" deleteFriend options:",h);var s=this._core["store"];let{userIDList:i,type:o}=h;var a,d,u,c=null==(n=s.get("login"))?void 0:n.userId,{friendUserIdList:l,unFriendUserIdList:p}=(1e3<i.length&&(console.warn(t+" deleteFriend the length of userIDList cannot exceed:",1e3),i=i.slice(0,r)),this.partitionByIsFriend(i));return 0===l.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(p)}}:(a=yield function(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}({From_Account:c,To_Account:l,DeleteType:o},this._core),{successUserIDList:d,failureUserIDList:u}=this._processOperationResult({resultList:a.resultList,includeRelation:!1}),console.log(t+" deleteFriend ok"),{code:0,data:{successUserIDList:d,failureUserIDList:u}})}catch(e){throw console.error(t+" deleteFriend error:",e),e}})}updateFriend(m){return e(this,void 0,void 0,function*(){var e;try{console.log(t+" updateFriend options:",m);var{userID:r,remark:o,friendCustomField:n}=m,{helper:s,store:a,appStore:{userStore:d}}=this._core,u=null==(e=a.get("login"))?void 0:e.userId;if(!d.getFriendMap().has(r))throw new s.ChatError({functionName:"updateFriend",code:i});var c=(yield I({From_Account:u,UpdateItem:[{To_Account:r,SnsItem:this._buildSnsItemList(o,n)}]},this._core))["resultList"],{to:l,resultCode:p,resultInfo:h}=c[0];if(f(p)||0===p)return{code:0,data:this._updateLocalFriend({userID:l,remark:o,friendCustomField:n})};throw new s.ChatError({functionName:"updateFriend",code:p,message:h})}catch(e){throw console.error(t+" updateFriend error:",e),e}})}checkFriend(u){return e(this,void 0,void 0,function*(){var e;try{console.log(t+" checkFriend options:",u);var{userIDList:r,type:i}=u,{OuterConstant:o,store:n}=this._core,s=yield F({From_Account:null==(e=n.get("login"))?void 0:e.userId,To_Account:r,CheckType:i===o.SNS_CHECK_TYPE_SINGLE?i:o.SNS_CHECK_TYPE_BOTH},this._core),{successUserIDList:a=[],failureUserIDList:d=[]}=this._processOperationResult({resultList:s.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:a,failureUserIDList:d}}}catch(e){throw console.error(t+" checkFriend error:",e),e}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(o){return e(this,void 0,void 0,function*(){console.log(t+" updateFriendList data:",o);let r=this._core.appStore["userStore"],{addedFriendList:e=[],removedFriendList:i=[]}=o;0<e.length&&(e.forEach(e=>{var t=new g({userID:e,core:this._core});r.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:e}),this._emitFriendListUpdated()),0<i.length&&(i.forEach(e=>{r.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){console.log(t+" updateFriendInfo data: ",e);let{appStore:{userStore:r,conversationStore:o},utils:{isEmpty:i}}=this._core,{userID:n,tagValueList:s}=e[0]||{},a=r.getFriend(n);if(!i(s)&&a){let i=s.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=o.getConversation("C2C"+n))?void 0:r.remark;e===u.REMARK&&t!==r&&o.updateConversation("C2C"+n,{remark:t}),a.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new g({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){try{console.log(t+" _fetchFriendProfile");let{appStore:{userStore:r},user:{userProfile:i}}=this._core,o=[...r.getFriendMap().keys()],n=Math.ceil(o.length/100);for(let e=0;e<n;e++){var s=100*e,a=Math.min(100+s,o.length),d=o.slice(s,a),u=yield null==i?void 0:i.getUserProfile({userIDList:d});u&&u.data&&u.data.forEach(e=>{var t=r.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}}catch(e){throw console.error(t+" _fetchFriendProfile error:",e),e}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:r,appStore:{userStore:i}}=this._core,i=Array.from(i.getFriendMap().values());console.log(t+" _emitFriendListUpdated friendList:",i),e.emitOuterEvent(r.FRIEND_LIST_UPDATED,{name:r.FRIEND_LIST_UPDATED,data:i})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return f(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],n=[],s=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(f(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),n.push(e)}else s.push({userID:t,code:e,message:i})}),{successUserIDList:n,failureUserIDList:s}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:r=[]}=e,o=this._core.appStore["userStore"],n=[],s=[];return r.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new g({userID:t,tagValueList:i,core:this._core});n.push(e),o.getFriendMap().set(t,e)}else s.push({userID:t,code:e,message:r})}),console.log(t+" _processFriendProfileResponse successProfiles:",n),{successProfiles:n,failedProfiles:s}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),console.log(`${t} partitionByIsFriend, friendUserIdList: ${r}, unFriendUserIdList: `+i),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},y=new class{init(e){this.core=e}};function S(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return T(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function E(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return T(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function D(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return T(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function T(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var C=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){var e=[...this._friendApplicationMap.values()];return console.log(t+" getFriendApplicationListFromCache friendApplicationList:",e),{code:0,data:{friendApplicationList:e,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){let i="syncFriendApplicationListFromServer";console.log(t+" "+i);try{let t=yield function(u){return e(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:i}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:u.startTime,LastSequence:u.currentSequence},{PendencyItem:t=[],StartTime:i,UnreadPendencyCount:e,CurrentSequence:o,ActionStatus:n,ErrorCode:s,ErrorInfo:a,ErrorDisplay:d}=t=yield i.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,image:e.Image})),startTime:i,unreadCount:e,currentSequence:o,actionStatus:n,errorCode:s,errorInfo:a,errorDisplay:d}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:n,currentSequence:s}=t;this._startTime=n,this._currentSequence=s,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let r=new this._core.helper.ChatError({functionName:i,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${t} ${i} error:`,r),r}})}acceptFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"acceptFriendApplication",options:t,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(r){return e(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(e+"_"+t))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,function*(){let{functionName:n,options:s,protocolFunction:a}=r;console.log(t+` ${n} options:`,s);try{let e=yield a(s),{resultList:r=[]}=e,{resultCode:i,resultInfo:o}=r[0];if(0===i)return console.log(t+` ${n} ok`),{code:0,data:{}};throw{errorCode:i,errorInfo:o}}catch(e){let r=new this._core.helper.ChatError({functionName:n,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${n} error:`,r),r}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){var r="setFriendApplicationRead";console.log(t+" "+r);try{return yield function(){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),console.log(t+` ${r} ok`),{code:0,data:{}}}catch(e){var i=new this._core.helper.ChatError({functionName:r,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${r} error:`,i),i}})}updateFriendApplicationList(e){var{from:r,addedApplicationList:i=[],removedApplicationList:o=[]}=e,e=(console.log(t+" updateFriendApplicationList data:",e),this._core.utils)["isEmpty"];e(i)||this.onApplicationAdded(i,r),e(o)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,n=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var t=e.userID+"_"+n;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){console.log(t+" _emitApplicationListUpdated");var{notificationCenter:e,OuterEvent:r}=this._core;e.emitOuterEvent(r.FRIEND_APPLICATION_LIST_UPDATED,{name:r.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function k(){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return M(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}function N(i){return e(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=y.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return M(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function P(r){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return M(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}function G(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,l),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return M(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function w(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,p),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return M(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function U(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return M(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}function R(e,t){return e.filter(e=>L.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function M(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n,ResultItem:s=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n};return t&&0<s.length?Object.assign(Object.assign({},e),{resultList:s.map(t)}):e}class O{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var $=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){var e=[...this._friendGroupMap.values()];return console.log(t+" getFriendGroupListFromCache, data: ",e),{code:0,data:e}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){var r="syncFriendGroupListFromServer";console.log(t+" "+r);try{var e=yield k(),{resultList:i=[]}=e;this._core.helper.isEmpty(i)&&console.log(t+` ${r} ok. count: 0`),i.forEach(e=>{var t=new O(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(a){return e(this,void 0,void 0,function*(){var r="createFriendGroup";console.log(t+` ${r} params:`,a);try{let e=a["name"];this._checkGroupExist(r,e);var i=yield N(a),{successUserIDList:o,failureUserIDList:n}=this._parseCreateGroupResponse(i),s=new O({name:e,userIDList:o});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(r,e)}})}deleteFriendGroup(o){return e(this,void 0,void 0,function*(){var r="deleteFriendGroup";console.log(t+` ${r} params:`,o);try{let e=o["name"];this._checkGroupNotExist(r,e),yield P(o);var i=this._friendGroupMap.get(e);return i&&(this._updateFriendGroup({name:e,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(r,e)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:G})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:w})})}renameFriendGroup(o){return e(this,void 0,void 0,function*(){var r="renameFriendGroup";console.log(t+` ${r} params:`,o);try{let{oldName:e,newName:t}=o;this._checkGroupNotExist(r,e),this._checkGroupExist(r,t),yield U(o);var i=this._updateGroupNameInCache(e,t);return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:_,newName:t}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(r,e)}})}_updateFriendGroupMember(r){return e(this,void 0,void 0,function*(){var{functionName:o,params:n,protocolFunction:s}=r;console.log(t+` ${o} params:`,n);try{let e=n["name"],t=(this._checkGroupNotExist(o,e),yield s(n)),{friendGroup:r,failureUserIDList:i}=this._parseUpdateFriendGroupResponse(e,t);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:r,failureUserIDList:i}}}catch(e){this._handleError(o,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{f(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],n=[],s=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===l?this._addFriendToGroup(t,e.userID,i,n):e.updateType===p&&this._removeFriendFromGroup(t,e.userID,i,s)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,i=[...this._friendGroupMap.values()];console.log(t+" _emitGroupListUpdated friendGroupList:",i),e.emitOuterEvent(r.FRIEND_GROUP_LIST_UPDATED,{name:r.FRIEND_GROUP_LIST_UPDATED,data:i})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:n})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){let{name:i,userIDList:r,action:o,newName:n}=e,s=this._core.appStore["userStore"];console.log(t+" updateFriendGroup",{name:i,userIDList:r,action:o,newName:n}),i&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{var t=s.getFriend(e);if(t){var r=t["groupList"];switch(o){case h:-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case m:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case _:if(n){let e=r.indexOf(i);-1!==e&&(r[e]=n)}}}})}_handleError(e,r){r=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(t+` ${e} error:`,r),r}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var b=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return console.log(t+" getBlacklistFromCache"),{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{console.log(t+" syncBlacklistFromServer");var i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},this._core),{blackList:o=[],startIndex:n=0}=i;return this._startIndex=n,this._addBlacklistMap(o),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(t+" syncBlacklistFromServer error:",e),e}})}addToBlacklist(n){return e(this,void 0,void 0,function*(){try{console.log(t+" addToBlacklist options:",n);var r=this._preprocessBlacklist(n),i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:r},this._core),{blackList:o=[]}=i;return this._addBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(t+" addToBlacklist error:",e),e}})}removeFromBlacklist(o){return e(this,void 0,void 0,function*(){try{console.log(t+" removeFromBlacklist options:",o);var r=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:o.userIDList},this._core),{blackList:i=[]}=r;return this._deleteBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(t+" removeFromBlacklist error:",e),e}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){console.log(t+" updateBlacklist data:",e);var{addedBlacklist:e=[],removedBlacklist:r=[]}=e;let i=!1;0<e.length&&e.some(e=>!this._blacklistMap.has(e))&&(i=!0,this._addBlacklistMap(e.map(e=>({userID:e})))),0<r.length&&r.some(e=>this._blacklistMap.has(e))&&(i=!0,this._deleteBlacklistMap(r.map(e=>({userID:e})))),i&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(t+" _addBlacklistMap blackList:",e),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){console.log(t+" _deleteBlacklistMap blackList:",e),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,i=Array.from(this._blacklistMap.keys());console.log(t+" _emitBlackListUpdated blackList:",i),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:i})}};let q={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_APPLICATION_AGREE||e===t.SNS_APPLICATION_AGREE_AND_ADD||"type should be SNS_APPLICATION_AGREE or SNS_APPLICATION_AGREE_AND_ADD"}}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},x={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var V=new class{install(e){console.log(t+" install");var{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:s}}=this._core=e;y.init(e),L.init(e),C.init(e),$.init(e),b.init(e),r.registerValidateConfig({auth:x,params:q}),r.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,s.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){console.log(t+" handleLoginSuccess"),b.syncBlacklistFromServer(),L.syncFriendListFromServer(),C.syncFriendApplicationListFromServer(),$.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:n,removedApplicationList:s,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||b.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(L.updateFriendList({addedFriendList:i,removedFriendList:o}),C.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||L.updateFriendInfo(a),u(n)&&u(s)||C.updateFriendApplicationList({from:e,addedApplicationList:n,removedApplicationList:s}),d&&C.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:n=[],FriendAdd_Account:s=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:n,addedFriendList:s,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){console.log(t+" reset"),b.reset(),L.reset(),C.reset(),$.reset()}dispose(){console.log(t+" dispose");var{notificationCenter:e,InnerEvent:r}=this._core;e.unSubscribeInnerEvent(r.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(r.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),b.dispose(),L.dispose(),C.dispose(),$.dispose()}};export{V as default};
1
+ function e(e,s,a,d){return new(a=a||Promise)(function(r,t){function i(e){try{n(d.next(e))}catch(e){t(e)}}function o(e){try{n(d.throw(e))}catch(e){t(e)}}function n(e){var t;e.done?r(e.value):((t=e.value)instanceof a?t:new a(function(e){e(t)})).then(i,o)}n((d=d.apply(e,s||[])).next())})}let t="friend",r=100,i=2700,o=2710,n=2711,s=2716,d=2742,a=30539,c="Tag_SNS_IM_",u={GROUP:c+"Group",REMARK:c+"Remark",ADDSOURCE:c+"AddSource",ADDWORDING:c+"Wording",ADDTIME:c+"AddTime"},l="Update_Type_Add",p="Update_Type_Delete",h="add",m="remove",_="rename",f=e=>void 0===e;function I(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_update",data:t}),"ResultItem",e=>({to:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function F(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:t}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function A(e,t="ResultItem",r=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[t]:e=[],ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:e.map(r),actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:n}}let v={[u.REMARK]:(e,t)=>{e.remark=t},[u.GROUP]:(e,t)=>{e.groupList=t?JSON.parse(JSON.stringify(t)):[]},[u.ADDSOURCE]:(e,t)=>{e.source=t},[u.ADDWORDING]:(e,t)=>{e.wording=t},[u.ADDTIME]:(e,t)=>{e.addTime=t}},g=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:t=[],core:r}=e,r=null==(r=r.user.userProfile)?void 0:r.createProfile(e,t);this.userID=e,this.profile=r,t.forEach(e=>{var{tag:e,value:t}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:t}),v[e]);null!=e&&e(this,t)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:t,value:r}=e;-1<t.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(t)?this.friendCustomField.forEach(e=>{e.key===t&&(e.value=r)}):this.friendCustomField.push({key:t,value:r}));e=v[t];null!=e&&e(this,r)})}};var L=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getFriendList",context:this,methodName:"getFriendListFromCache"}),e.registerApi({apiName:"getFriendProfile",context:this}),e.registerApi({apiName:"addFriend",context:this}),e.registerApi({apiName:"deleteFriend",context:this}),e.registerApi({apiName:"updateFriend",context:this}),e.registerApi({apiName:"checkFriend",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return e(this,void 0,void 0,function*(){var e=this._core.appStore["userStore"],e=[...e.getFriendMap().values()];return console.log(t+" getFriendListFromCache, data ",e),{code:0,data:e}})}syncFriendListFromServer(){return e(this,void 0,void 0,function*(){var r;try{console.log(t+" syncFriendListFromServer");var{friendList:i,nextStartIndex:o,standardSequence:n,customSequence:s,completeFlag:a}=yield function(c,l){return e(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:t,CustomSequence:r,FriendNum:i,CompleteFlag:o,NextStartIndex:n,ActionStatus:s,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:t,customSequence:r,friendNumber:i,completeFlag:o,nextStartIndex:n,actionStatus:s,errorCode:a,errorInfo:d,errorDisplay:u}})}({From_Account:null==(r=this._core.store.get("login"))?void 0:r.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},this._core);this._startIndex=o,this._standardSequence=n,this._customSequence=s,this._processFriendList(i),0===a?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),console.log(t+" syncFriendListFromServer ok")}catch(e){throw console.error(t+" syncFriendListFromServer error:",e),e}})}getFriendProfile(l){return e(this,void 0,void 0,function*(){var o;try{console.log(t+" getFriendProfile params:",l);let i=l["userIDList"];i.length>r&&(i=i.slice(0,r));var n,s,a,{friendUserIdList:d,unFriendUserIdList:u}=this.partitionByIsFriend(i),c=this._createNonFriendErrorList(u);return 0===d.length?{code:0,data:{friendList:[],failureUserIDList:c}}:(n=(yield function(n,s){return e(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e=yield s.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:n});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}})}({From_Account:null==(o=this._core.store.get("login"))?void 0:o.userId,To_Account:d},this._core))||{},{successProfiles:s,failedProfiles:a}=this._processFriendProfileResponse(n),{code:0,data:{friendList:s,failureUserIDList:[...a,...c]}})}catch(e){throw console.error(t+" getFriendProfile error:",e),e}})}addFriend(f){return e(this,void 0,void 0,function*(){var r;try{console.log(t+" addFriend options:",f);var{helper:i,store:o}=this._core,{to:n,source:s,type:d,wording:u,remark:c,groupName:l}=f,p=yield function(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:t}))})}({From_Account:null==(r=o.get("login"))?void 0:r.userId,AddFriendItem:[{To_Account:n,AddSource:s,AddWording:u,GroupName:l,Remark:c}],AddType:d},this._core),{resultList:h=[]}=p,{userID:m,resultCode:_}=h[0];if(0===_)return console.log(t+" addFriend ok"),{code:0,data:{userID:m}};if(_===a)return console.log(t+" addFriend wait for the other party to agree"),{code:0,data:{userID:m,code:_,message:"wait for the other party to agree"}};throw new i.ChatError({functionName:"addFriend",code:_})}catch(e){throw console.error(t+" addFriend error:",e),e}})}deleteFriend(h){return e(this,void 0,void 0,function*(){var n;try{console.log(t+" deleteFriend options:",h);var s=this._core["store"];let{userIDList:i,type:o}=h;var a,d,u,c=null==(n=s.get("login"))?void 0:n.userId,{friendUserIdList:l,unFriendUserIdList:p}=(1e3<i.length&&(console.warn(t+" deleteFriend the length of userIDList cannot exceed:",1e3),i=i.slice(0,r)),this.partitionByIsFriend(i));return 0===l.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(p)}}:(a=yield function(t,r){return e(this,void 0,void 0,function*(){return A(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:t}))})}({From_Account:c,To_Account:l,DeleteType:o},this._core),{successUserIDList:d,failureUserIDList:u}=this._processOperationResult({resultList:a.resultList,includeRelation:!1}),console.log(t+" deleteFriend ok"),{code:0,data:{successUserIDList:d,failureUserIDList:u}})}catch(e){throw console.error(t+" deleteFriend error:",e),e}})}updateFriend(m){return e(this,void 0,void 0,function*(){var e;try{console.log(t+" updateFriend options:",m);var{userID:r,remark:o,friendCustomField:n}=m,{helper:s,store:a,appStore:{userStore:d}}=this._core,u=null==(e=a.get("login"))?void 0:e.userId;if(!d.getFriendMap().has(r))throw new s.ChatError({functionName:"updateFriend",code:i});var c=(yield I({From_Account:u,UpdateItem:[{To_Account:r,SnsItem:this._buildSnsItemList(o,n)}]},this._core))["resultList"],{to:l,resultCode:p,resultInfo:h}=c[0];if(f(p)||0===p)return{code:0,data:this._updateLocalFriend({userID:l,remark:o,friendCustomField:n})};throw new s.ChatError({functionName:"updateFriend",code:p,message:h})}catch(e){throw console.error(t+" updateFriend error:",e),e}})}checkFriend(u){return e(this,void 0,void 0,function*(){var e;try{console.log(t+" checkFriend options:",u);var{userIDList:r,type:i}=u,{OuterConstant:o,store:n}=this._core,s=yield F({From_Account:null==(e=n.get("login"))?void 0:e.userId,To_Account:r,CheckType:i===o.SNS_CHECK_TYPE_SINGLE?i:o.SNS_CHECK_TYPE_BOTH},this._core),{successUserIDList:a=[],failureUserIDList:d=[]}=this._processOperationResult({resultList:s.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:a,failureUserIDList:d}}}catch(e){throw console.error(t+" checkFriend error:",e),e}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:t}=this._core;e.unSubscribeInnerEvent(t.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(o){return e(this,void 0,void 0,function*(){console.log(t+" updateFriendList data:",o);let r=this._core.appStore["userStore"],{addedFriendList:e=[],removedFriendList:i=[]}=o;0<e.length&&(e.forEach(e=>{var t=new g({userID:e,core:this._core});r.getFriendMap().set(e,t)}),yield this.getFriendProfile({userIDList:e}),this._emitFriendListUpdated()),0<i.length&&(i.forEach(e=>{r.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){console.log(t+" updateFriendInfo data: ",e);let{appStore:{userStore:r,conversationStore:o},utils:{isEmpty:i}}=this._core,{userID:n,tagValueList:s}=e[0]||{},a=r.getFriend(n);if(!i(s)&&a){let i=s.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:t}=e,r=null==(r=o.getConversation("C2C"+n))?void 0:r.remark;e===u.REMARK&&t!==r&&o.updateConversation("C2C"+n,{remark:t}),a.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:t},appStore:{userStore:r}}=this._core;t(e)||e.forEach(e=>{var{userID:e,tagValueList:t}=e;this._isInvalidFriend(e)||(t=new g({userID:e,tagValueList:t,core:this._core}),r.getFriendMap().set(e,t))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return e(this,void 0,void 0,function*(){try{console.log(t+" _fetchFriendProfile");let{appStore:{userStore:r},user:{userProfile:i}}=this._core,o=[...r.getFriendMap().keys()],n=Math.ceil(o.length/100);for(let e=0;e<n;e++){var s=100*e,a=Math.min(100+s,o.length),d=o.slice(s,a),u=yield null==i?void 0:i.getUserProfile({userIDList:d});u&&u.data&&u.data.forEach(e=>{var t=r.getFriend(e.userID);t&&(t.profile=e)}),this._emitFriendListUpdated()}}catch(e){throw console.error(t+" _fetchFriendProfile error:",e),e}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:r,appStore:{userStore:i}}=this._core,i=Array.from(i.getFriendMap().values());console.log(t+" _emitFriendListUpdated friendList:",i),e.emitOuterEvent(r.FRIEND_LIST_UPDATED,{name:r.FRIEND_LIST_UPDATED,data:i})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:t,value:e})=>{var r=i.find(e=>e.key===t);r?r.value!==e&&(r.value=e,o=!0):(i.push({key:t,value:e}),o=!0)}),o}_updateLocalFriend(e){var t=this._core.appStore["userStore"],{userID:e,remark:r,friendCustomField:i}=e,t=t.getFriend(e);if(t)return f(r)||(t.remark=r),Array.isArray(i)&&0<i.length&&this._updateCustomField(t.friendCustomField,i),this._emitFriendListUpdated(),t}_processOperationResult(e){let{resultList:t,includeRelation:o=!1}=e,r=this._core.utils["isEmpty"],n=[],s=[];return Array.isArray(t)&&!r(t)&&t.forEach(e=>{var{userID:t,relation:r,resultCode:e,resultInfo:i}=e;if(f(e)||0===e){let e={userID:t};o&&(e.code=0,e.relation=r),n.push(e)}else s.push({userID:t,code:e,message:i})}),{successUserIDList:n,failureUserIDList:s}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:i,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,t){let r=[];return f(e)||r.push({Tag:u.REMARK,Value:e}),Array.isArray(t)&&0<t.length&&t.forEach(e=>{r.push({tag:e.key,value:e.value})}),r}_processFriendProfileResponse(e){let{friendProfileList:r=[]}=e,o=this._core.appStore["userStore"],n=[],s=[];return r.forEach(e=>{var{userID:t,resultCode:e,resultInfo:r,profileItem:i}=e;if(0===e){let e=new g({userID:t,tagValueList:i,core:this._core});n.push(e),o.getFriendMap().set(t,e)}else s.push({userID:t,code:e,message:r})}),console.log(t+" _processFriendProfileResponse successProfiles:",n),{successProfiles:n,failedProfiles:s}}partitionByIsFriend(e){let r=[],i=[];return e.forEach(e=>{var t=this._core.appStore["userStore"];(t.getFriendMap().has(e)?r:i).push(e)}),console.log(`${t} partitionByIsFriend, friendUserIdList: ${r}, unFriendUserIdList: `+i),{friendUserIdList:r,unFriendUserIdList:i}}isMyFriend(e){var t=this._core.appStore["userStore"];return t.getFriendMap().has(e)}},y=new class{init(e){this.core=e}};function S(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:r.type,Remark:r.remark}]};return T(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function E(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:r.userID,ResponseAction:"Response_Action_Reject"}]};return T(yield t.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function D(r){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[r.userID],PendencyType:r.type};return T(yield t.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function T(e){var{ResultItem:e=[],ActionStatus:t,ErrorCode:r,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:t,errorCode:r,errorInfo:i,errorDisplay:o}}var C=new class{constructor(){this._friendApplicationMap=new Map,this._unreadCount=0,this._startTime=0,this._currentSequence=0}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendApplicationList",context:this,methodName:"getFriendApplicationListFromCache"}),e.registerApi({apiName:"acceptFriendApplication",context:this}),e.registerApi({apiName:"refuseFriendApplication",context:this}),e.registerApi({apiName:"deleteFriendApplication",context:this}),e.registerApi({apiName:"setFriendApplicationRead",context:this})}getFriendApplicationListFromCache(){return e(this,void 0,void 0,function*(){var e=[...this._friendApplicationMap.values()];return console.log(t+" getFriendApplicationListFromCache friendApplicationList:",e),{code:0,data:{friendApplicationList:e,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return e(this,void 0,void 0,function*(){let i="syncFriendApplicationListFromServer";console.log(t+" "+i);try{let t=yield function(u){return e(this,void 0,void 0,function*(){var{store:e,OuterConstant:t,common:i}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:t.SNS_APPLICATION_TYPE_BOTH,MaxLimited:r,StartTime:u.startTime,LastSequence:u.currentSequence},{PendencyItem:t=[],StartTime:i,UnreadPendencyCount:e,CurrentSequence:o,ActionStatus:n,ErrorCode:s,ErrorInfo:a,ErrorDisplay:d}=t=yield i.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:t.map(e=>({userID:e.To_Account,time:e.AddTime,source:e.AddSource,wording:e.AddWording,nick:e.Nick,type:e.PendencyType,image:e.Image})),startTime:i,unreadCount:e,currentSequence:o,actionStatus:n,errorCode:s,errorInfo:a,errorDisplay:d}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:i,unreadCount:o,startTime:n,currentSequence:s}=t;this._startTime=n,this._currentSequence=s,this._unreadCount=o,this._friendApplicationMap.clear(),Array.isArray(i)&&i.forEach(e=>{var{userID:t,type:r}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(t+"_"+r,e)}),this._emitApplicationListUpdated()}catch(e){let r=new this._core.helper.ChatError({functionName:i,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${t} ${i} error:`,r),r}})}acceptFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"acceptFriendApplication",options:t,protocolFunction:S})})}refuseFriendApplication(t){return e(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:t,protocolFunction:E})})}deleteFriendApplication(r){return e(this,void 0,void 0,function*(){var{userID:e,type:t}=r;return this._checkApplicationExists(e,t,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:r,protocolFunction:D})})}_checkApplicationExists(e,t,r){if(!this._friendApplicationMap.has(e+"_"+t))throw new this._core.helper.ChatError({functionName:r,code:s})}_operationApplication(r){return e(this,void 0,void 0,function*(){let{functionName:n,options:s,protocolFunction:a}=r;console.log(t+` ${n} options:`,s);try{let e=yield a(s),{resultList:r=[]}=e,{resultCode:i,resultInfo:o}=r[0];if(0===i)return console.log(t+` ${n} ok`),{code:0,data:{}};throw{errorCode:i,errorInfo:o}}catch(e){let r=new this._core.helper.ChatError({functionName:n,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${n} error:`,r),r}})}setFriendApplicationRead(){return e(this,void 0,void 0,function*(){var r="setFriendApplicationRead";console.log(t+" "+r);try{return yield function(){return e(this,void 0,void 0,function*(){var{store:e,common:t}=y.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,LatestPendencyTimeStamp:(e=Math.floor(Date.now()/1e3),Math.round(Number(e)*Math.pow(10,0))/Math.pow(10,0))},{ActionStatus:t,ErrorCode:e,ErrorInfo:r,ErrorDisplay:i}=t=yield t.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:t,errorCode:e,errorInfo:r,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),console.log(t+` ${r} ok`),{code:0,data:{}}}catch(e){var i=new this._core.helper.ChatError({functionName:r,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(t+` ${r} error:`,i),i}})}updateFriendApplicationList(e){var{from:r,addedApplicationList:i=[],removedApplicationList:o=[]}=e,e=(console.log(t+" updateFriendApplicationList data:",e),this._core.utils)["isEmpty"];e(i)||this.onApplicationAdded(i,r),e(o)||this.onApplicationDeleted()}onApplicationAdded(e,t){let r,{store:i,OuterConstant:o}=this._core,n=t===(null==(r=i.get("login"))?void 0:r.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var t=e.userID+"_"+n;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(t)||(this._unreadCount+=1),this._friendApplicationMap.set(t,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){console.log(t+" _emitApplicationListUpdated");var{notificationCenter:e,OuterEvent:r}=this._core;e.emitOuterEvent(r.FRIEND_APPLICATION_LIST_UPDATED,{name:r.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function k(){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return M(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:t}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}function N(i){return e(this,void 0,void 0,function*(){var{name:e,userIDList:t}=i,r=y.core["common"],e={From_Account:r.getCurrentUserID(),GroupName:[e],To_Account:t};return M(yield r.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function P(r){return e(this,void 0,void 0,function*(){var e=y.core["common"],t={From_Account:e.getCurrentUserID(),GroupName:[r.name]};return M(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:t}))})}function G(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,l),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return M(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function w(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{name:t,userIDList:r}=i,r=R(r,p),t={From_Account:e.getCurrentUserID(),GroupOldName:t,UpdateGroupItem:r};return M(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function U(i){return e(this,void 0,void 0,function*(){var e=y.core["common"],{oldName:t,newName:r}=i,t={From_Account:e.getCurrentUserID(),GroupOldName:t,GroupNewName:r};return M(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:t}))})}function R(e,t){return e.filter(e=>L.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:t}))}function M(e,t){var{CurrentSequence:e,ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n,ResultItem:s=[]}=e,e={currentSequence:e,actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n};return t&&0<s.length?Object.assign(Object.assign({},e),{resultList:s.map(t)}):e}class O{constructor(e){var{name:e="",userIDList:t=[]}=e;this.name=e,this.userIDList=t,this.count=t.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){e=this.userIDList.indexOf(e);-1<e&&(this.userIDList.splice(e,1),this.count=this.userIDList.length)}}var $=new class{constructor(){this._friendGroupMap=new Map}init(e){e=(this._core=e).helper;e.registerApi({apiName:"getFriendGroupList",context:this,methodName:"getFriendGroupListFromCache"}),e.registerApi({apiName:"createFriendGroup",context:this}),e.registerApi({apiName:"deleteFriendGroup",context:this}),e.registerApi({apiName:"addToFriendGroup",context:this}),e.registerApi({apiName:"removeFromFriendGroup",context:this}),e.registerApi({apiName:"renameFriendGroup",context:this})}getFriendGroupListFromCache(){return e(this,void 0,void 0,function*(){var e=[...this._friendGroupMap.values()];return console.log(t+" getFriendGroupListFromCache, data: ",e),{code:0,data:e}})}syncFriendGroupListFromServer(){return e(this,void 0,void 0,function*(){var r="syncFriendGroupListFromServer";console.log(t+" "+r);try{var e=yield k(),{resultList:i=[]}=e;this._core.helper.isEmpty(i)&&console.log(t+` ${r} ok. count: 0`),i.forEach(e=>{var t=new O(e);this._friendGroupMap.set(e.name,t)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(a){return e(this,void 0,void 0,function*(){var r="createFriendGroup";console.log(t+` ${r} params:`,a);try{let e=a["name"];this._checkGroupExist(r,e);var i=yield N(a),{successUserIDList:o,failureUserIDList:n}=this._parseCreateGroupResponse(i),s=new O({name:e,userIDList:o});return this._friendGroupMap.set(e,s),this._emitGroupListUpdated(),{code:0,data:{friendGroup:s,failureUserIDList:n}}}catch(e){this._handleError(r,e)}})}deleteFriendGroup(o){return e(this,void 0,void 0,function*(){var r="deleteFriendGroup";console.log(t+` ${r} params:`,o);try{let e=o["name"];this._checkGroupNotExist(r,e),yield P(o);var i=this._friendGroupMap.get(e);return i&&(this._updateFriendGroup({name:e,userIDList:i.userIDList,action:m}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(r,e)}})}addToFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:t,protocolFunction:G})})}removeFromFriendGroup(t){return e(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:t,protocolFunction:w})})}renameFriendGroup(o){return e(this,void 0,void 0,function*(){var r="renameFriendGroup";console.log(t+` ${r} params:`,o);try{let{oldName:e,newName:t}=o;this._checkGroupNotExist(r,e),this._checkGroupExist(r,t),yield U(o);var i=this._updateGroupNameInCache(e,t);return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:_,newName:t}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(r,e)}})}_updateFriendGroupMember(r){return e(this,void 0,void 0,function*(){var{functionName:o,params:n,protocolFunction:s}=r;console.log(t+` ${o} params:`,n);try{let e=n["name"],t=(this._checkGroupNotExist(o,e),yield s(n)),{friendGroup:r,failureUserIDList:i}=this._parseUpdateFriendGroupResponse(e,t);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:r,failureUserIDList:i}}}catch(e){this._handleError(o,e)}})}_updateGroupNameInCache(e,t){var r=this._friendGroupMap.get(e);return r&&(r.name=t,this._friendGroupMap.delete(e),this._friendGroupMap.set(t,r)),r}_parseCreateGroupResponse(e){let{resultList:t=[]}=e,i=[],o=[];return t.forEach(({userID:e,resultCode:t,resultInfo:r})=>{f(t)||0===t?i.push(e):o.push({userID:e,code:t,message:r})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(t,e){let{resultList:r=[]}=e,i=this._friendGroupMap.get(t),o=[],n=[],s=[];return r.forEach(e=>{0===e.resultCode?i&&(e.updateType===l?this._addFriendToGroup(t,e.userID,i,n):e.updateType===p&&this._removeFriendFromGroup(t,e.userID,i,s)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,t,r,i){r.addToUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:h})}_removeFriendFromGroup(e,t,r,i){r.removeFromUserIDList(t),i.push(t),this._updateFriendGroup({name:e,userIDList:i,action:m})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,i=[...this._friendGroupMap.values()];console.log(t+" _emitGroupListUpdated friendGroupList:",i),e.emitOuterEvent(r.FRIEND_GROUP_LIST_UPDATED,{name:r.FRIEND_GROUP_LIST_UPDATED,data:i})}_checkGroupNotExist(e,t){if(!this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:n})}_checkGroupExist(e,t){if(this._friendGroupMap.has(t))throw new this._core.helper.ChatError({functionName:e,code:o})}_updateFriendGroup(e){let{name:i,userIDList:r,action:o,newName:n}=e,s=this._core.appStore["userStore"];console.log(t+" updateFriendGroup",{name:i,userIDList:r,action:o,newName:n}),i&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{var t=s.getFriend(e);if(t){var r=t["groupList"];switch(o){case h:-1===r.indexOf(i)&&(r.push(i),t.count=r.length);break;case m:{let e=r.indexOf(i);-1<e&&(r.splice(e,1),t.count=r.length);break}case _:if(n){let e=r.indexOf(i);-1!==e&&(r[e]=n)}}}})}_handleError(e,r){r=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(t+` ${e} error:`,r),r}reset(){this._friendGroupMap.clear()}dispose(){this.reset()}};function B(e){return e&&0!==e.length?e.map(e=>({userID:e.To_Account,addBlackTimeStamp:e.AddBlackTimeStamp})):[]}var b=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:t}=this._core=e;e.registerApi({apiName:"getBlacklist",context:this,methodName:"getBlacklistFromCache"}),e.registerApi({apiName:"addToBlacklist",context:this}),e.registerApi({apiName:"removeFromBlacklist",context:this}),e.registerWorkflowStep(t.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,t.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return e(this,void 0,void 0,function*(){return console.log(t+" getBlacklistFromCache"),{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return e(this,void 0,void 0,function*(){try{console.log(t+" syncBlacklistFromServer");var i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_get",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{BlackListItem:t=[],StartIndex:e=0}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:r,StartIndex:this._startIndex},this._core),{blackList:o=[],startIndex:n=0}=i;return this._startIndex=n,this._addBlacklistMap(o),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(t+" syncBlacklistFromServer error:",e),e}})}addToBlacklist(n){return e(this,void 0,void 0,function*(){try{console.log(t+" addToBlacklist options:",n);var r=this._preprocessBlacklist(n),i=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_add",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:r},this._core),{blackList:o=[]}=i;return this._addBlacklistMap(o),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(t+" addToBlacklist error:",e),e}})}removeFromBlacklist(o){return e(this,void 0,void 0,function*(){try{console.log(t+" removeFromBlacklist options:",o);var r=yield function(i,o){return e(this,void 0,void 0,function*(){var{helper:e,channel:t}=o,r="sns.black_list_delete",e=e.generateProtocolData({servcmd:r,data:i}),r=e.head.seq+r,{ResultItem:t=[]}=yield t.sendPacket(e,{requestId:r});return{blackList:B(t)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:o.userIDList},this._core),{blackList:i=[]}=r;return this._deleteBlacklistMap(i),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(t+" removeFromBlacklist error:",e),e}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){console.log(t+" updateBlacklist data:",e);var{addedBlacklist:e=[],removedBlacklist:r=[]}=e;let i=!1;0<e.length&&e.some(e=>!this._blacklistMap.has(e))&&(i=!0,this._addBlacklistMap(e.map(e=>({userID:e})))),0<r.length&&r.some(e=>this._blacklistMap.has(e))&&(i=!0,this._deleteBlacklistMap(r.map(e=>({userID:e})))),i&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(t+" _addBlacklistMap blackList:",e),e.forEach(e=>{var{userID:e,addBlackTimeStamp:t=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:t})})}_deleteBlacklistMap(e){console.log(t+" _deleteBlacklistMap blackList:",e),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let t=e["userIDList"],r=this._core.common.getCurrentUserID();if(1===t.length&&t[0]===r)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:d});return t=t.includes(r)?e.userIDList.filter(e=>e!==r):t}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,i=Array.from(this._blacklistMap.keys());console.log(t+" _emitBlackListUpdated blackList:",i),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:i})}};let q={addToBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromBlacklist:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},getFriendProfile:{userIDList:{required:!0,rules:["array"],allowEmpty:!1}},addFriend:{to:{required:!0,rules:["string"],allowEmpty:!1},source:{required:!0,rules:["string"],allowEmpty:!1},wording:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_ADD_TYPE_SINGLE||e===t.SNS_ADD_TYPE_BOTH||"type should be SNS_ADD_TYPE_SINGLE or SNS_ADD_TYPE_BOTH"}},remark:{required:!1,rules:["string"],allowEmpty:!0},groupName:{required:!1,rules:["string"],allowEmpty:!0}},deleteFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_DELETE_TYPE_SINGLE||e===t.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_APPLICATION_AGREE||e===t.SNS_APPLICATION_AGREE_AND_ADD||"type should be SNS_APPLICATION_AGREE or SNS_APPLICATION_AGREE_AND_ADD"}}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var t=y.core["OuterConstant"];return e===t.SNS_APPLICATION_SENT_TO_ME||e===t.SNS_APPLICATION_SENT_BY_ME||"type should be SNS_APPLICATION_SENT_TO_ME or SNS_APPLICATION_SENT_BY_ME"}}},createFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},deleteFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1}},addToFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},removeFromFriendGroup:{name:{required:!0,rules:["string"],allowEmpty:!1},userIDList:{required:!0,rules:["array"],allowEmpty:!1}},renameFriendGroup:{oldName:{required:!0,rules:["string"],allowEmpty:!1},newName:{required:!0,rules:["string"],allowEmpty:!1}}},x={getBlacklist:!0,addToBlacklist:!0,removeFromBlacklist:!0,getFriendList:!0,addFriend:!0,deleteFriend:!0,updateFriend:!0,checkFriend:!0,getFriendProfile:!0,getFriendApplicationList:!0,acceptFriendApplication:!0,refuseFriendApplication:!0,deleteFriendApplication:!0,setFriendApplicationRead:!0,getFriendGroupList:!0,createFriendGroup:!0,deleteFriendGroup:!0,addToFriendGroup:!0,removeFromFriendGroup:!0,renameFriendGroup:!0};var V=new class{constructor(){this.name="Friend"}install(e){console.log(t+" install");var{helper:r,notificationCenter:i,InnerEvent:o,constants:{WORKFLOW_NAME:n,WORKFLOW_STEP:s}}=this._core=e;y.init(e),L.init(e),C.init(e),$.init(e),b.init(e),r.registerValidateConfig({auth:x,params:q}),r.registerWorkflowStep(n.SYNC_SERVER_INFO_AFTER_LOGIN,s.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),i.subscribeInnerEvent(o.LOGOUT,this.reset,this),i.subscribeInnerEvent(o.MESSAGE_PUSH,i.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){console.log(t+" handleLoginSuccess"),b.syncBlacklistFromServer(),L.syncFriendListFromServer(),C.syncFriendApplicationListFromServer(),$.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:t,removedBlacklist:r,addedFriendList:i,removedFriendList:o,addedApplicationList:n,removedApplicationList:s,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(t)&&u(r)||b.updateBlacklist({addedBlacklist:t,removedBlacklist:r}),u(i)&&u(o)||(L.updateFriendList({addedFriendList:i,removedFriendList:o}),C.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||L.updateFriendInfo(a),u(n)&&u(s)||C.updateFriendApplicationList({from:e,addedApplicationList:n,removedApplicationList:s}),d&&C.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:t,To_Account:r,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:n=[],FriendAdd_Account:s=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:t,to:r,reportTime:i,addedBlacklist:o,removedBlacklist:n,addedFriendList:s,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){console.log(t+" reset"),b.reset(),L.reset(),C.reset(),$.reset()}dispose(){console.log(t+" dispose");var{notificationCenter:e,InnerEvent:r}=this._core;e.unSubscribeInnerEvent(r.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(r.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),b.dispose(),L.dispose(),C.dispose(),$.dispose()}};export{V as default};
package/plugins/friend.js CHANGED
@@ -1 +1 @@
1
- !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatFriend=r()}(this,function(){function m(e,s,a,d){return new(a=a||Promise)(function(t,r){function i(e){try{n(d.next(e))}catch(e){r(e)}}function o(e){try{n(d.throw(e))}catch(e){r(e)}}function n(e){var r;e.done?t(e.value):((r=e.value)instanceof a?r:new a(function(e){e(r)})).then(i,o)}n((d=d.apply(e,s||[])).next())})}let _="friend",l=100,e="Tag_SNS_IM_",d={GROUP:e+"Group",REMARK:e+"Remark",ADDSOURCE:e+"AddSource",ADDWORDING:e+"Wording",ADDTIME:e+"AddTime"},a="Update_Type_Add",u="Update_Type_Delete",c="remove",p="rename",h=e=>void 0===e;function f(e,r="ResultItem",t=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[r]:e=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:e.map(t),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}let o={[d.REMARK]:(e,r)=>{e.remark=r},[d.GROUP]:(e,r)=>{e.groupList=r?JSON.parse(JSON.stringify(r)):[]},[d.ADDSOURCE]:(e,r)=>{e.source=r},[d.ADDWORDING]:(e,r)=>{e.wording=r},[d.ADDTIME]:(e,r)=>{e.addTime=r}},v=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:r=[],core:t}=e,t=null==(t=t.user.userProfile)?void 0:t.createProfile(e,r);this.userID=e,this.profile=t,r.forEach(e=>{var{tag:e,value:r}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:r}),o[e]);null!=e&&e(this,r)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:r,value:t}=e;-1<r.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(r)?this.friendCustomField.forEach(e=>{e.key===r&&(e.value=t)}):this.friendCustomField.push({key:r,value:t}));e=o[r];null!=e&&e(this,t)})}};var I=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:r}=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(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return m(this,void 0,void 0,function*(){var e=this._core.appStore["userStore"],e=[...e.getFriendMap().values()];return console.log(_+" getFriendListFromCache, data ",e),{code:0,data:e}})}syncFriendListFromServer(){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" syncFriendListFromServer");var{friendList:r,nextStartIndex:t,standardSequence:i,customSequence:o,completeFlag:n}=yield function(c,l){return m(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:r,CustomSequence:t,FriendNum:i,CompleteFlag:o,NextStartIndex:n,ActionStatus:s,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:r,customSequence:t,friendNumber:i,completeFlag:o,nextStartIndex:n,actionStatus:s,errorCode:a,errorInfo:d,errorDisplay:u}})}({From_Account:null==(e=this._core.store.get("login"))?void 0:e.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},this._core);this._startIndex=t,this._standardSequence=i,this._customSequence=o,this._processFriendList(r),0===n?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),console.log(_+" syncFriendListFromServer ok")}catch(e){throw console.error(_+" syncFriendListFromServer error:",e),e}})}getFriendProfile(d){return m(this,void 0,void 0,function*(){var r;try{console.log(_+" getFriendProfile params:",d);let e=d["userIDList"];e.length>l&&(e=e.slice(0,l));var t,i,o,{friendUserIdList:n,unFriendUserIdList:s}=this.partitionByIsFriend(e),a=this._createNonFriendErrorList(s);return 0===n.length?{code:0,data:{friendList:[],failureUserIDList:a}}:(t=(yield function(n,s){return m(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:r,ErrorCode:t,ErrorInfo:i,ErrorDisplay:o}=e=yield s.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:n});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:r,errorCode:t,errorInfo:i,errorDisplay:o}})}({From_Account:null==(r=this._core.store.get("login"))?void 0:r.userId,To_Account:n},this._core))||{},{successProfiles:i,failedProfiles:o}=this._processFriendProfileResponse(t),{code:0,data:{friendList:i,failureUserIDList:[...o,...a]}})}catch(e){throw console.error(_+" getFriendProfile error:",e),e}})}addFriend(h){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" addFriend options:",h);var{helper:r,store:t}=this._core,{to:i,source:o,type:n,wording:s,remark:a,groupName:d}=h,u=yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:e}))})}({From_Account:null==(e=t.get("login"))?void 0:e.userId,AddFriendItem:[{To_Account:i,AddSource:o,AddWording:s,GroupName:d,Remark:a}],AddType:n},this._core),{resultList:c=[]}=u,{userID:l,resultCode:p}=c[0];if(0===p)return console.log(_+" addFriend ok"),{code:0,data:{userID:l}};if(30539===p)return console.log(_+" addFriend wait for the other party to agree"),{code:0,data:{userID:l,code:p,message:"wait for the other party to agree"}};throw new r.ChatError({functionName:"addFriend",code:p})}catch(e){throw console.error(_+" addFriend error:",e),e}})}deleteFriend(c){return m(this,void 0,void 0,function*(){var t;try{console.log(_+" deleteFriend options:",c);var i=this._core["store"];let{userIDList:e,type:r}=c;var o,n,s,a=null==(t=i.get("login"))?void 0:t.userId,{friendUserIdList:d,unFriendUserIdList:u}=(1e3<e.length&&(console.warn(_+" deleteFriend the length of userIDList cannot exceed:",1e3),e=e.slice(0,l)),this.partitionByIsFriend(e));return 0===d.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(u)}}:(o=yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:e}))})}({From_Account:a,To_Account:d,DeleteType:r},this._core),{successUserIDList:n,failureUserIDList:s}=this._processOperationResult({resultList:o.resultList,includeRelation:!1}),console.log(_+" deleteFriend ok"),{code:0,data:{successUserIDList:n,failureUserIDList:s}})}catch(e){throw console.error(_+" deleteFriend error:",e),e}})}updateFriend(p){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" updateFriend options:",p);var{userID:r,remark:t,friendCustomField:i}=p,{helper:o,store:n,appStore:{userStore:s}}=this._core,a=null==(e=n.get("login"))?void 0:e.userId;if(!s.getFriendMap().has(r))throw new o.ChatError({functionName:"updateFriend",code:2700});var d=(yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.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:r,SnsItem:this._buildSnsItemList(t,i)}]},this._core))["resultList"],{to:u,resultCode:c,resultInfo:l}=d[0];if(h(c)||0===c)return{code:0,data:this._updateLocalFriend({userID:u,remark:t,friendCustomField:i})};throw new o.ChatError({functionName:"updateFriend",code:c,message:l})}catch(e){throw console.error(_+" updateFriend error:",e),e}})}checkFriend(d){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" checkFriend options:",d);var{userIDList:r,type:t}=d,{OuterConstant:i,store:o}=this._core,n=yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:e}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}({From_Account:null==(e=o.get("login"))?void 0:e.userId,To_Account:r,CheckType:t===i.SNS_CHECK_TYPE_SINGLE?t:i.SNS_CHECK_TYPE_BOTH},this._core),{successUserIDList:s=[],failureUserIDList:a=[]}=this._processOperationResult({resultList:n.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:a}}}catch(e){throw console.error(_+" checkFriend error:",e),e}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:r}=this._core;e.unSubscribeInnerEvent(r.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(i){return m(this,void 0,void 0,function*(){console.log(_+" updateFriendList data:",i);let t=this._core.appStore["userStore"],{addedFriendList:e=[],removedFriendList:r=[]}=i;0<e.length&&(e.forEach(e=>{var r=new v({userID:e,core:this._core});t.getFriendMap().set(e,r)}),yield this.getFriendProfile({userIDList:e}),this._emitFriendListUpdated()),0<r.length&&(r.forEach(e=>{t.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){console.log(_+" updateFriendInfo data: ",e);let{appStore:{userStore:r,conversationStore:o},utils:{isEmpty:t}}=this._core,{userID:n,tagValueList:s}=e[0]||{},a=r.getFriend(n);if(!t(s)&&a){let i=s.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:r}=e,t=null==(t=o.getConversation("C2C"+n))?void 0:t.remark;e===d.REMARK&&r!==t&&o.updateConversation("C2C"+n,{remark:r}),a.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:r},appStore:{userStore:t}}=this._core;r(e)||e.forEach(e=>{var{userID:e,tagValueList:r}=e;this._isInvalidFriend(e)||(r=new v({userID:e,tagValueList:r,core:this._core}),t.getFriendMap().set(e,r))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return m(this,void 0,void 0,function*(){try{console.log(_+" _fetchFriendProfile");let{appStore:{userStore:t},user:{userProfile:r}}=this._core,i=[...t.getFriendMap().keys()],o=Math.ceil(i.length/100);for(let e=0;e<o;e++){var n=100*e,s=Math.min(100+n,i.length),a=i.slice(n,s),d=yield null==r?void 0:r.getUserProfile({userIDList:a});d&&d.data&&d.data.forEach(e=>{var r=t.getFriend(e.userID);r&&(r.profile=e)}),this._emitFriendListUpdated()}}catch(e){throw console.error(_+" _fetchFriendProfile error:",e),e}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:r,appStore:{userStore:t}}=this._core,t=Array.from(t.getFriendMap().values());console.log(_+" _emitFriendListUpdated friendList:",t),e.emitOuterEvent(r.FRIEND_LIST_UPDATED,{name:r.FRIEND_LIST_UPDATED,data:t})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:r,value:e})=>{var t=i.find(e=>e.key===r);t?t.value!==e&&(t.value=e,o=!0):(i.push({key:r,value:e}),o=!0)}),o}_updateLocalFriend(e){var r=this._core.appStore["userStore"],{userID:e,remark:t,friendCustomField:i}=e,r=r.getFriend(e);if(r)return h(t)||(r.remark=t),Array.isArray(i)&&0<i.length&&this._updateCustomField(r.friendCustomField,i),this._emitFriendListUpdated(),r}_processOperationResult(e){let{resultList:r,includeRelation:o=!1}=e,t=this._core.utils["isEmpty"],n=[],s=[];return Array.isArray(r)&&!t(r)&&r.forEach(e=>{var{userID:r,relation:t,resultCode:e,resultInfo:i}=e;if(h(e)||0===e){let e={userID:r};o&&(e.code=0,e.relation=t),n.push(e)}else s.push({userID:r,code:e,message:i})}),{successUserIDList:n,failureUserIDList:s}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:2700,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,r){let t=[];return h(e)||t.push({Tag:d.REMARK,Value:e}),Array.isArray(r)&&0<r.length&&r.forEach(e=>{t.push({tag:e.key,value:e.value})}),t}_processFriendProfileResponse(e){let{friendProfileList:r=[]}=e,o=this._core.appStore["userStore"],n=[],s=[];return r.forEach(e=>{var{userID:r,resultCode:e,resultInfo:t,profileItem:i}=e;if(0===e){let e=new v({userID:r,tagValueList:i,core:this._core});n.push(e),o.getFriendMap().set(r,e)}else s.push({userID:r,code:e,message:t})}),console.log(_+" _processFriendProfileResponse successProfiles:",n),{successProfiles:n,failedProfiles:s}}partitionByIsFriend(e){let t=[],i=[];return e.forEach(e=>{var r=this._core.appStore["userStore"];(r.getFriendMap().has(e)?t:i).push(e)}),console.log(`${_} partitionByIsFriend, friendUserIdList: ${t}, unFriendUserIdList: `+i),{friendUserIdList:t,unFriendUserIdList:i}}isMyFriend(e){var r=this._core.appStore["userStore"];return r.getFriendMap().has(e)}},F=new class{init(e){this.core=e}};function r(t){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return n(yield r.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function t(t){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return n(yield r.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function i(t){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return n(yield r.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function n(e){var{ResultItem:e=[],ActionStatus:r,ErrorCode:t,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:r,errorCode:t,errorInfo:i,errorDisplay:o}}var A=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 m(this,void 0,void 0,function*(){var e=[...this._friendApplicationMap.values()];return console.log(_+" getFriendApplicationListFromCache friendApplicationList:",e),{code:0,data:{friendApplicationList:e,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return m(this,void 0,void 0,function*(){let t="syncFriendApplicationListFromServer";console.log(_+" "+t);try{let e=yield function(d){return m(this,void 0,void 0,function*(){var{store:e,OuterConstant:r,common:t}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:r.SNS_APPLICATION_TYPE_BOTH,MaxLimited:l,StartTime:d.startTime,LastSequence:d.currentSequence},{PendencyItem:r=[],StartTime:t,UnreadPendencyCount:e,CurrentSequence:i,ActionStatus:o,ErrorCode:n,ErrorInfo:s,ErrorDisplay:a}=r=yield t.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:r.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:t,unreadCount:e,currentSequence:i,actionStatus:o,errorCode:n,errorInfo:s,errorDisplay:a}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:r,unreadCount:t,startTime:i,currentSequence:o}=e;this._startTime=i,this._currentSequence=o,this._unreadCount=t,this._friendApplicationMap.clear(),Array.isArray(r)&&r.forEach(e=>{var{userID:r,type:t}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(r+"_"+t,e)}),this._emitApplicationListUpdated()}catch(e){let r=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${_} ${t} error:`,r),r}})}acceptFriendApplication(e){return m(this,void 0,void 0,function*(){return this._operationApplication({functionName:"acceptFriendApplication",options:e,protocolFunction:r})})}refuseFriendApplication(e){return m(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:e,protocolFunction:t})})}deleteFriendApplication(t){return m(this,void 0,void 0,function*(){var{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:i})})}_checkApplicationExists(e,r,t){if(!this._friendApplicationMap.has(e+"_"+r))throw new this._core.helper.ChatError({functionName:t,code:2716})}_operationApplication(e){return m(this,void 0,void 0,function*(){let{functionName:o,options:n,protocolFunction:s}=e;console.log(_+` ${o} options:`,n);try{let e=yield s(n),{resultList:r=[]}=e,{resultCode:t,resultInfo:i}=r[0];if(0===t)return console.log(_+` ${o} ok`),{code:0,data:{}};throw{errorCode:t,errorInfo:i}}catch(e){let r=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(_+` ${o} error:`,r),r}})}setFriendApplicationRead(){return m(this,void 0,void 0,function*(){var r="setFriendApplicationRead";console.log(_+" "+r);try{return yield function(){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.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:r,ErrorCode:e,ErrorInfo:t,ErrorDisplay:i}=r=yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:r,errorCode:e,errorInfo:t,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),console.log(_+` ${r} ok`),{code:0,data:{}}}catch(e){var t=new this._core.helper.ChatError({functionName:r,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(_+` ${r} error:`,t),t}})}updateFriendApplicationList(e){var{from:r,addedApplicationList:t=[],removedApplicationList:i=[]}=e,e=(console.log(_+" updateFriendApplicationList data:",e),this._core.utils)["isEmpty"];e(t)||this.onApplicationAdded(t,r),e(i)||this.onApplicationDeleted()}onApplicationAdded(e,r){let t,{store:i,OuterConstant:o}=this._core,n=r===(null==(t=i.get("login"))?void 0:t.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var r=e.userID+"_"+n;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(r)||(this._unreadCount+=1),this._friendApplicationMap.set(r,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){console.log(_+" _emitApplicationListUpdated");var{notificationCenter:e,OuterEvent:r}=this._core;e.emitOuterEvent(r.FRIEND_APPLICATION_LIST_UPDATED,{name:r.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function s(i){return m(this,void 0,void 0,function*(){var e=F.core["common"],{name:r,userIDList:t}=i,t=L(t,a),r={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:t};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:r}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function g(i){return m(this,void 0,void 0,function*(){var e=F.core["common"],{name:r,userIDList:t}=i,t=L(t,u),r={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:t};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:r}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function L(e,r){return e.filter(e=>I.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:r}))}function y(e,r){var{CurrentSequence:e,ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n,ResultItem:s=[]}=e,e={currentSequence:e,actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:n};return r&&0<s.length?Object.assign(Object.assign({},e),{resultList:s.map(r)}):e}class S{constructor(e){var{name:e="",userIDList:r=[]}=e;this.name=e,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){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 m(this,void 0,void 0,function*(){var e=[...this._friendGroupMap.values()];return console.log(_+" getFriendGroupListFromCache, data: ",e),{code:0,data:e}})}syncFriendGroupListFromServer(){return m(this,void 0,void 0,function*(){var r="syncFriendGroupListFromServer";console.log(_+" "+r);try{var e=yield function(){return m(this,void 0,void 0,function*(){var e=F.core["common"],r={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return y(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:r}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}(),{resultList:t=[]}=e;this._core.helper.isEmpty(t)&&console.log(_+` ${r} ok. count: 0`),t.forEach(e=>{var r=new S(e);this._friendGroupMap.set(e.name,r)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(s){return m(this,void 0,void 0,function*(){var r="createFriendGroup";console.log(_+` ${r} params:`,s);try{let e=s["name"];this._checkGroupExist(r,e);var t=yield function(i){return m(this,void 0,void 0,function*(){var{name:e,userIDList:r}=i,t=F.core["common"],e={From_Account:t.getCurrentUserID(),GroupName:[e],To_Account:r};return y(yield t.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}(s),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(t),n=new S({name:e,userIDList:i});return this._friendGroupMap.set(e,n),this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:o}}}catch(e){this._handleError(r,e)}})}deleteFriendGroup(i){return m(this,void 0,void 0,function*(){var r="deleteFriendGroup";console.log(_+` ${r} params:`,i);try{let e=i["name"];this._checkGroupNotExist(r,e),yield function(t){return m(this,void 0,void 0,function*(){var e=F.core["common"],r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return y(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))})}(i);var t=this._friendGroupMap.get(e);return t&&(this._updateFriendGroup({name:e,userIDList:t.userIDList,action:c}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:t}}catch(e){this._handleError(r,e)}})}addToFriendGroup(e){return m(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:e,protocolFunction:s})})}removeFromFriendGroup(e){return m(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:e,protocolFunction:g})})}renameFriendGroup(o){return m(this,void 0,void 0,function*(){var t="renameFriendGroup";console.log(_+` ${t} params:`,o);try{let{oldName:e,newName:r}=o;this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield function(i){return m(this,void 0,void 0,function*(){var e=F.core["common"],{oldName:r,newName:t}=i,r={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:t};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:r}))})}(o);var i=this._updateGroupNameInCache(e,r);return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:p,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(e){return m(this,void 0,void 0,function*(){var{functionName:o,params:n,protocolFunction:s}=e;console.log(_+` ${o} params:`,n);try{let e=n["name"],r=(this._checkGroupNotExist(o,e),yield s(n)),{friendGroup:t,failureUserIDList:i}=this._parseUpdateFriendGroupResponse(e,r);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:t,failureUserIDList:i}}}catch(e){this._handleError(o,e)}})}_updateGroupNameInCache(e,r){var t=this._friendGroupMap.get(e);return t&&(t.name=r,this._friendGroupMap.delete(e),this._friendGroupMap.set(r,t)),t}_parseCreateGroupResponse(e){let{resultList:r=[]}=e,i=[],o=[];return r.forEach(({userID:e,resultCode:r,resultInfo:t})=>{h(r)||0===r?i.push(e):o.push({userID:e,code:r,message:t})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(r,e){let{resultList:t=[]}=e,i=this._friendGroupMap.get(r),o=[],n=[],s=[];return t.forEach(e=>{0===e.resultCode?i&&(e.updateType===a?this._addFriendToGroup(r,e.userID,i,n):e.updateType===u&&this._removeFriendFromGroup(r,e.userID,i,s)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,r,t,i){t.addToUserIDList(r),i.push(r),this._updateFriendGroup({name:e,userIDList:i,action:"add"})}_removeFriendFromGroup(e,r,t,i){t.removeFromUserIDList(r),i.push(r),this._updateFriendGroup({name:e,userIDList:i,action:c})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,t=[...this._friendGroupMap.values()];console.log(_+" _emitGroupListUpdated friendGroupList:",t),e.emitOuterEvent(r.FRIEND_GROUP_LIST_UPDATED,{name:r.FRIEND_GROUP_LIST_UPDATED,data:t})}_checkGroupNotExist(e,r){if(!this._friendGroupMap.has(r))throw new this._core.helper.ChatError({functionName:e,code:2711})}_checkGroupExist(e,r){if(this._friendGroupMap.has(r))throw new this._core.helper.ChatError({functionName:e,code:2710})}_updateFriendGroup(e){let{name:i,userIDList:r,action:o,newName:n}=e,s=this._core.appStore["userStore"];console.log(_+" updateFriendGroup",{name:i,userIDList:r,action:o,newName:n}),i&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{var r=s.getFriend(e);if(r){var t=r["groupList"];switch(o){case"add":-1===t.indexOf(i)&&(t.push(i),r.count=t.length);break;case c:{let e=t.indexOf(i);-1<e&&(t.splice(e,1),r.count=t.length);break}case p:if(n){let e=t.indexOf(i);-1!==e&&(t[e]=n)}}}})}_handleError(e,r){r=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(_+` ${e} error:`,r),r}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 T=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:r}=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(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return m(this,void 0,void 0,function*(){return console.log(_+" getBlacklistFromCache"),{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return m(this,void 0,void 0,function*(){try{console.log(_+" syncBlacklistFromServer");var e=yield function(i,o){return m(this,void 0,void 0,function*(){var{helper:e,channel:r}=o,t="sns.black_list_get",e=e.generateProtocolData({servcmd:t,data:i}),t=e.head.seq+t,{BlackListItem:r=[],StartIndex:e=0}=yield r.sendPacket(e,{requestId:t});return{blackList:D(r),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:l,StartIndex:this._startIndex},this._core),{blackList:r=[],startIndex:t=0}=e;return this._startIndex=t,this._addBlacklistMap(r),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(_+" syncBlacklistFromServer error:",e),e}})}addToBlacklist(i){return m(this,void 0,void 0,function*(){try{console.log(_+" addToBlacklist options:",i);var e=this._preprocessBlacklist(i),r=yield function(i,o){return m(this,void 0,void 0,function*(){var{helper:e,channel:r}=o,t="sns.black_list_add",e=e.generateProtocolData({servcmd:t,data:i}),t=e.head.seq+t,{ResultItem:r=[]}=yield r.sendPacket(e,{requestId:t});return{blackList:D(r)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:e},this._core),{blackList:t=[]}=r;return this._addBlacklistMap(t),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(_+" addToBlacklist error:",e),e}})}removeFromBlacklist(t){return m(this,void 0,void 0,function*(){try{console.log(_+" removeFromBlacklist options:",t);var e=yield function(i,o){return m(this,void 0,void 0,function*(){var{helper:e,channel:r}=o,t="sns.black_list_delete",e=e.generateProtocolData({servcmd:t,data:i}),t=e.head.seq+t,{ResultItem:r=[]}=yield r.sendPacket(e,{requestId:t});return{blackList:D(r)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:t.userIDList},this._core),{blackList:r=[]}=e;return this._deleteBlacklistMap(r),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(_+" removeFromBlacklist error:",e),e}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){console.log(_+" updateBlacklist data:",e);var{addedBlacklist:e=[],removedBlacklist:r=[]}=e;let t=!1;0<e.length&&e.some(e=>!this._blacklistMap.has(e))&&(t=!0,this._addBlacklistMap(e.map(e=>({userID:e})))),0<r.length&&r.some(e=>this._blacklistMap.has(e))&&(t=!0,this._deleteBlacklistMap(r.map(e=>({userID:e})))),t&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(_+" _addBlacklistMap blackList:",e),e.forEach(e=>{var{userID:e,addBlackTimeStamp:r=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:r})})}_deleteBlacklistMap(e){console.log(_+" _deleteBlacklistMap blackList:",e),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let r=e["userIDList"],t=this._core.common.getCurrentUserID();if(1===r.length&&r[0]===t)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:2742});return r=r.includes(t)?e.userIDList.filter(e=>e!==t):r}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,t=Array.from(this._blacklistMap.keys());console.log(_+" _emitBlackListUpdated blackList:",t),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:t})}};let C={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 r=F.core["OuterConstant"];return e===r.SNS_ADD_TYPE_SINGLE||e===r.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 r=F.core["OuterConstant"];return e===r.SNS_DELETE_TYPE_SINGLE||e===r.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var r=F.core["OuterConstant"];return e===r.SNS_APPLICATION_AGREE||e===r.SNS_APPLICATION_AGREE_AND_ADD||"type should be SNS_APPLICATION_AGREE or SNS_APPLICATION_AGREE_AND_ADD"}}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var r=F.core["OuterConstant"];return e===r.SNS_APPLICATION_SENT_TO_ME||e===r.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{install(e){console.log(_+" install");var{helper:r,notificationCenter:t,InnerEvent:i,constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:n}}=this._core=e;F.init(e),I.init(e),A.init(e),E.init(e),T.init(e),r.registerValidateConfig({auth:k,params:C}),r.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,n.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),t.subscribeInnerEvent(i.LOGOUT,this.reset,this),t.subscribeInnerEvent(i.MESSAGE_PUSH,t.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){console.log(_+" handleLoginSuccess"),T.syncBlacklistFromServer(),I.syncFriendListFromServer(),A.syncFriendApplicationListFromServer(),E.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:r,removedBlacklist:t,addedFriendList:i,removedFriendList:o,addedApplicationList:n,removedApplicationList:s,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(r)&&u(t)||T.updateBlacklist({addedBlacklist:r,removedBlacklist:t}),u(i)&&u(o)||(I.updateFriendList({addedFriendList:i,removedFriendList:o}),A.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||I.updateFriendInfo(a),u(n)&&u(s)||A.updateFriendApplicationList({from:e,addedApplicationList:n,removedApplicationList:s}),d&&A.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:r,To_Account:t,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:n=[],FriendAdd_Account:s=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:r,to:t,reportTime:i,addedBlacklist:o,removedBlacklist:n,addedFriendList:s,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){console.log(_+" reset"),T.reset(),I.reset(),A.reset(),E.reset()}dispose(){console.log(_+" dispose");var{notificationCenter:e,InnerEvent:r}=this._core;e.unSubscribeInnerEvent(r.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(r.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),T.dispose(),I.dispose(),A.dispose(),E.dispose()}}});
1
+ !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r():"function"==typeof define&&define.amd?define(r):(e="undefined"!=typeof globalThis?globalThis:e||self).TencentCloudChatFriend=r()}(this,function(){function m(e,s,a,d){return new(a=a||Promise)(function(t,r){function i(e){try{n(d.next(e))}catch(e){r(e)}}function o(e){try{n(d.throw(e))}catch(e){r(e)}}function n(e){var r;e.done?t(e.value):((r=e.value)instanceof a?r:new a(function(e){e(r)})).then(i,o)}n((d=d.apply(e,s||[])).next())})}let _="friend",l=100,e="Tag_SNS_IM_",d={GROUP:e+"Group",REMARK:e+"Remark",ADDSOURCE:e+"AddSource",ADDWORDING:e+"Wording",ADDTIME:e+"AddTime"},a="Update_Type_Add",u="Update_Type_Delete",c="remove",p="rename",h=e=>void 0===e;function f(e,r="ResultItem",t=e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})){var{[r]:e=[],ActionStatus:r,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n}=e;return{resultList:e.map(t),actionStatus:r,errorCode:i,errorInfo:o,errorDisplay:n}}let o={[d.REMARK]:(e,r)=>{e.remark=r},[d.GROUP]:(e,r)=>{e.groupList=r?JSON.parse(JSON.stringify(r)):[]},[d.ADDSOURCE]:(e,r)=>{e.source=r},[d.ADDWORDING]:(e,r)=>{e.wording=r},[d.ADDTIME]:(e,r)=>{e.addTime=r}},v=class{constructor(e){this.userID="",this.source="",this.wording="",this.remark="",this.addTime=0,this.groupList=[],this.friendCustomField=[];var{userID:e,tagValueList:r=[],core:t}=e,t=null==(t=t.user.userProfile)?void 0:t.createProfile(e,r);this.userID=e,this.profile=t,r.forEach(e=>{var{tag:e,value:r}=e,e=(-1<e.indexOf("Tag_Profile_Custom")&&this.friendCustomField.push({key:e,value:r}),o[e]);null!=e&&e(this,r)})}update(e){let i=[];this.friendCustomField.forEach(e=>{i.push(e.key)}),e.forEach(e=>{let{tag:r,value:t}=e;-1<r.indexOf("Tag_Profile_Custom")&&(-1<i.indexOf(r)?this.friendCustomField.forEach(e=>{e.key===r&&(e.value=t)}):this.friendCustomField.push({key:r,value:t}));e=o[r];null!=e&&e(this,t)})}};var I=new class{constructor(){this._startIndex=0,this._standardSequence=0,this._customSequence=0}init(e){var{helper:e,constants:r}=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(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.FRIEND_RECOVER,this.syncFriendListFromServer,this)}getFriendListFromCache(){return m(this,void 0,void 0,function*(){var e=this._core.appStore["userStore"],e=[...e.getFriendMap().values()];return console.log(_+" getFriendListFromCache, data ",e),{code:0,data:e}})}syncFriendListFromServer(){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" syncFriendListFromServer");var{friendList:r,nextStartIndex:t,standardSequence:i,customSequence:o,completeFlag:n}=yield function(c,l){return m(this,void 0,void 0,function*(){var{UserDataItem:e=[],StandardSequence:r,CustomSequence:t,FriendNum:i,CompleteFlag:o,NextStartIndex:n,ActionStatus:s,ErrorCode:a,ErrorInfo:d,ErrorDisplay:u}=e=yield l.common.buildAndSendPacket({servcmd:"sns.friend_get",data:c});return{friendList:e.map(e=>{return{userID:e.To_Account,tagValueList:null==(e=e.ValueItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value}))}}),standardSequence:r,customSequence:t,friendNumber:i,completeFlag:o,nextStartIndex:n,actionStatus:s,errorCode:a,errorInfo:d,errorDisplay:u}})}({From_Account:null==(e=this._core.store.get("login"))?void 0:e.userId,StartIndex:this._startIndex,StandardSequence:this._standardSequence,CustomSequence:this._customSequence},this._core);this._startIndex=t,this._standardSequence=i,this._customSequence=o,this._processFriendList(r),0===n?yield this.syncFriendListFromServer():(this._emitFriendListUpdated(),this._fetchFriendProfile()),console.log(_+" syncFriendListFromServer ok")}catch(e){throw console.error(_+" syncFriendListFromServer error:",e),e}})}getFriendProfile(d){return m(this,void 0,void 0,function*(){var r;try{console.log(_+" getFriendProfile params:",d);let e=d["userIDList"];e.length>l&&(e=e.slice(0,l));var t,i,o,{friendUserIdList:n,unFriendUserIdList:s}=this.partitionByIsFriend(e),a=this._createNonFriendErrorList(s);return 0===n.length?{code:0,data:{friendList:[],failureUserIDList:a}}:(t=(yield function(n,s){return m(this,void 0,void 0,function*(){var{InfoItem:e=[],ActionStatus:r,ErrorCode:t,ErrorInfo:i,ErrorDisplay:o}=e=yield s.common.buildAndSendPacket({servcmd:"sns.friend_get_specified",data:n});return{friendProfileList:e.map(e=>{return{userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo,relation:e.Relation,standardSequence:e.StandardSequence,customSequence:e.CustomSequence,profileItem:(null==(e=e.SnsProfileItem)?void 0:e.map(e=>({tag:e.Tag,value:e.Value})))||[]}}),actionStatus:r,errorCode:t,errorInfo:i,errorDisplay:o}})}({From_Account:null==(r=this._core.store.get("login"))?void 0:r.userId,To_Account:n},this._core))||{},{successProfiles:i,failedProfiles:o}=this._processFriendProfileResponse(t),{code:0,data:{friendList:i,failureUserIDList:[...o,...a]}})}catch(e){throw console.error(_+" getFriendProfile error:",e),e}})}addFriend(h){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" addFriend options:",h);var{helper:r,store:t}=this._core,{to:i,source:o,type:n,wording:s,remark:a,groupName:d}=h,u=yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.common.buildAndSendPacket({servcmd:"sns.friend_add",data:e}))})}({From_Account:null==(e=t.get("login"))?void 0:e.userId,AddFriendItem:[{To_Account:i,AddSource:o,AddWording:s,GroupName:d,Remark:a}],AddType:n},this._core),{resultList:c=[]}=u,{userID:l,resultCode:p}=c[0];if(0===p)return console.log(_+" addFriend ok"),{code:0,data:{userID:l}};if(30539===p)return console.log(_+" addFriend wait for the other party to agree"),{code:0,data:{userID:l,code:p,message:"wait for the other party to agree"}};throw new r.ChatError({functionName:"addFriend",code:p})}catch(e){throw console.error(_+" addFriend error:",e),e}})}deleteFriend(c){return m(this,void 0,void 0,function*(){var t;try{console.log(_+" deleteFriend options:",c);var i=this._core["store"];let{userIDList:e,type:r}=c;var o,n,s,a=null==(t=i.get("login"))?void 0:t.userId,{friendUserIdList:d,unFriendUserIdList:u}=(1e3<e.length&&(console.warn(_+" deleteFriend the length of userIDList cannot exceed:",1e3),e=e.slice(0,l)),this.partitionByIsFriend(e));return 0===d.length?{code:0,data:{friendList:[],failureUserIDList:this._createNonFriendErrorList(u)}}:(o=yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.common.buildAndSendPacket({servcmd:"sns.friend_delete",data:e}))})}({From_Account:a,To_Account:d,DeleteType:r},this._core),{successUserIDList:n,failureUserIDList:s}=this._processOperationResult({resultList:o.resultList,includeRelation:!1}),console.log(_+" deleteFriend ok"),{code:0,data:{successUserIDList:n,failureUserIDList:s}})}catch(e){throw console.error(_+" deleteFriend error:",e),e}})}updateFriend(p){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" updateFriend options:",p);var{userID:r,remark:t,friendCustomField:i}=p,{helper:o,store:n,appStore:{userStore:s}}=this._core,a=null==(e=n.get("login"))?void 0:e.userId;if(!s.getFriendMap().has(r))throw new o.ChatError({functionName:"updateFriend",code:2700});var d=(yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.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:r,SnsItem:this._buildSnsItemList(t,i)}]},this._core))["resultList"],{to:u,resultCode:c,resultInfo:l}=d[0];if(h(c)||0===c)return{code:0,data:this._updateLocalFriend({userID:u,remark:t,friendCustomField:i})};throw new o.ChatError({functionName:"updateFriend",code:c,message:l})}catch(e){throw console.error(_+" updateFriend error:",e),e}})}checkFriend(d){return m(this,void 0,void 0,function*(){var e;try{console.log(_+" checkFriend options:",d);var{userIDList:r,type:t}=d,{OuterConstant:i,store:o}=this._core,n=yield function(e,r){return m(this,void 0,void 0,function*(){return f(yield r.common.buildAndSendPacket({servcmd:"sns.friend_check",data:e}),"InfoItem",e=>({userID:e.To_Account,relation:e.Relation,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}({From_Account:null==(e=o.get("login"))?void 0:e.userId,To_Account:r,CheckType:t===i.SNS_CHECK_TYPE_SINGLE?t:i.SNS_CHECK_TYPE_BOTH},this._core),{successUserIDList:s=[],failureUserIDList:a=[]}=this._processOperationResult({resultList:n.resultList,includeRelation:!0});return{code:0,data:{successUserIDList:s,failureUserIDList:a}}}catch(e){throw console.error(_+" checkFriend error:",e),e}})}dispose(){this.reset();var{notificationCenter:e,InnerEvent:r}=this._core;e.unSubscribeInnerEvent(r.LOGOUT,this.reset,this)}reset(){var e=this._core.appStore["userStore"];e.getFriendMap().clear(),this._startIndex=0,this._standardSequence=0,this._customSequence=0}updateFriendList(i){return m(this,void 0,void 0,function*(){console.log(_+" updateFriendList data:",i);let t=this._core.appStore["userStore"],{addedFriendList:e=[],removedFriendList:r=[]}=i;0<e.length&&(e.forEach(e=>{var r=new v({userID:e,core:this._core});t.getFriendMap().set(e,r)}),yield this.getFriendProfile({userIDList:e}),this._emitFriendListUpdated()),0<r.length&&(r.forEach(e=>{t.getFriendMap().delete(e)}),this._emitFriendListUpdated())})}updateFriendInfo(e){console.log(_+" updateFriendInfo data: ",e);let{appStore:{userStore:r,conversationStore:o},utils:{isEmpty:t}}=this._core,{userID:n,tagValueList:s}=e[0]||{},a=r.getFriend(n);if(!t(s)&&a){let i=s.map(e=>({tag:e.BytesTag,value:e.BytesValue}));i.forEach(e=>{var{tag:e,value:r}=e,t=null==(t=o.getConversation("C2C"+n))?void 0:t.remark;e===d.REMARK&&r!==t&&o.updateConversation("C2C"+n,{remark:r}),a.update(i)}),this._emitFriendListUpdated()}}_processFriendList(e){let{utils:{isEmpty:r},appStore:{userStore:t}}=this._core;r(e)||e.forEach(e=>{var{userID:e,tagValueList:r}=e;this._isInvalidFriend(e)||(r=new v({userID:e,tagValueList:r,core:this._core}),t.getFriendMap().set(e,r))})}_isInvalidFriend(e){return"@TLS#NOT_FOUND"===e||""===e}_fetchFriendProfile(){return m(this,void 0,void 0,function*(){try{console.log(_+" _fetchFriendProfile");let{appStore:{userStore:t},user:{userProfile:r}}=this._core,i=[...t.getFriendMap().keys()],o=Math.ceil(i.length/100);for(let e=0;e<o;e++){var n=100*e,s=Math.min(100+n,i.length),a=i.slice(n,s),d=yield null==r?void 0:r.getUserProfile({userIDList:a});d&&d.data&&d.data.forEach(e=>{var r=t.getFriend(e.userID);r&&(r.profile=e)}),this._emitFriendListUpdated()}}catch(e){throw console.error(_+" _fetchFriendProfile error:",e),e}})}_emitFriendListUpdated(){var{notificationCenter:e,OuterEvent:r,appStore:{userStore:t}}=this._core,t=Array.from(t.getFriendMap().values());console.log(_+" _emitFriendListUpdated friendList:",t),e.emitOuterEvent(r.FRIEND_LIST_UPDATED,{name:r.FRIEND_LIST_UPDATED,data:t})}_updateCustomField(i,e){if(!Array.isArray(i)||!Array.isArray(e))return!1;let o=!1;return e.forEach(({key:r,value:e})=>{var t=i.find(e=>e.key===r);t?t.value!==e&&(t.value=e,o=!0):(i.push({key:r,value:e}),o=!0)}),o}_updateLocalFriend(e){var r=this._core.appStore["userStore"],{userID:e,remark:t,friendCustomField:i}=e,r=r.getFriend(e);if(r)return h(t)||(r.remark=t),Array.isArray(i)&&0<i.length&&this._updateCustomField(r.friendCustomField,i),this._emitFriendListUpdated(),r}_processOperationResult(e){let{resultList:r,includeRelation:o=!1}=e,t=this._core.utils["isEmpty"],n=[],s=[];return Array.isArray(r)&&!t(r)&&r.forEach(e=>{var{userID:r,relation:t,resultCode:e,resultInfo:i}=e;if(h(e)||0===e){let e={userID:r};o&&(e.code=0,e.relation=t),n.push(e)}else s.push({userID:r,code:e,message:i})}),{successUserIDList:n,failureUserIDList:s}}_createNonFriendErrorList(e){return e.map(e=>({userID:e,code:2700,message:"The specified userID is not my friend"}))}_buildSnsItemList(e,r){let t=[];return h(e)||t.push({Tag:d.REMARK,Value:e}),Array.isArray(r)&&0<r.length&&r.forEach(e=>{t.push({tag:e.key,value:e.value})}),t}_processFriendProfileResponse(e){let{friendProfileList:r=[]}=e,o=this._core.appStore["userStore"],n=[],s=[];return r.forEach(e=>{var{userID:r,resultCode:e,resultInfo:t,profileItem:i}=e;if(0===e){let e=new v({userID:r,tagValueList:i,core:this._core});n.push(e),o.getFriendMap().set(r,e)}else s.push({userID:r,code:e,message:t})}),console.log(_+" _processFriendProfileResponse successProfiles:",n),{successProfiles:n,failedProfiles:s}}partitionByIsFriend(e){let t=[],i=[];return e.forEach(e=>{var r=this._core.appStore["userStore"];(r.getFriendMap().has(e)?t:i).push(e)}),console.log(`${_} partitionByIsFriend, friendUserIdList: ${t}, unFriendUserIdList: `+i),{friendUserIdList:t,unFriendUserIdList:i}}isMyFriend(e){var r=this._core.appStore["userStore"];return r.getFriendMap().has(e)}},F=new class{init(e){this.core=e}};function r(t){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:t.type,Remark:t.remark}]};return n(yield r.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function t(t){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,ResponseFriendItem:[{To_Account:t.userID,ResponseAction:"Response_Action_Reject"}]};return n(yield r.buildAndSendPacket({servcmd:"sns.friend_response",data:e}))})}function i(t){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,To_Account:[t.userID],PendencyType:t.type};return n(yield r.buildAndSendPacket({servcmd:"sns.pendency_delete",data:e}))})}function n(e){var{ResultItem:e=[],ActionStatus:r,ErrorCode:t,ErrorInfo:i,ErrorDisplay:o}=e;return{resultList:e.map(e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo})),actionStatus:r,errorCode:t,errorInfo:i,errorDisplay:o}}var A=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 m(this,void 0,void 0,function*(){var e=[...this._friendApplicationMap.values()];return console.log(_+" getFriendApplicationListFromCache friendApplicationList:",e),{code:0,data:{friendApplicationList:e,unreadCount:this._unreadCount}}})}syncFriendApplicationListFromServer(){return m(this,void 0,void 0,function*(){let t="syncFriendApplicationListFromServer";console.log(_+" "+t);try{let e=yield function(d){return m(this,void 0,void 0,function*(){var{store:e,OuterConstant:r,common:t}=F.core,e={From_Account:null==(e=e.get("login"))?void 0:e.userId,PendencyType:r.SNS_APPLICATION_TYPE_BOTH,MaxLimited:l,StartTime:d.startTime,LastSequence:d.currentSequence},{PendencyItem:r=[],StartTime:t,UnreadPendencyCount:e,CurrentSequence:i,ActionStatus:o,ErrorCode:n,ErrorInfo:s,ErrorDisplay:a}=r=yield t.buildAndSendPacket({servcmd:"sns.pendency_get",data:e});return{resultList:r.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:t,unreadCount:e,currentSequence:i,actionStatus:o,errorCode:n,errorInfo:s,errorDisplay:a}})}({startTime:this._startTime,currentSequence:this._currentSequence}),{resultList:r,unreadCount:t,startTime:i,currentSequence:o}=e;this._startTime=i,this._currentSequence=o,this._unreadCount=t,this._friendApplicationMap.clear(),Array.isArray(r)&&r.forEach(e=>{var{userID:r,type:t}=e,e=this._createFriendApplication(e);this._friendApplicationMap.set(r+"_"+t,e)}),this._emitApplicationListUpdated()}catch(e){let r=new this._core.helper.ChatError({functionName:t,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(`${_} ${t} error:`,r),r}})}acceptFriendApplication(e){return m(this,void 0,void 0,function*(){return this._operationApplication({functionName:"acceptFriendApplication",options:e,protocolFunction:r})})}refuseFriendApplication(e){return m(this,void 0,void 0,function*(){return this._operationApplication({functionName:"refuseFriendApplication",options:e,protocolFunction:t})})}deleteFriendApplication(t){return m(this,void 0,void 0,function*(){var{userID:e,type:r}=t;return this._checkApplicationExists(e,r,"deleteFriendApplication"),this._operationApplication({functionName:"deleteFriendApplication",options:t,protocolFunction:i})})}_checkApplicationExists(e,r,t){if(!this._friendApplicationMap.has(e+"_"+r))throw new this._core.helper.ChatError({functionName:t,code:2716})}_operationApplication(e){return m(this,void 0,void 0,function*(){let{functionName:o,options:n,protocolFunction:s}=e;console.log(_+` ${o} options:`,n);try{let e=yield s(n),{resultList:r=[]}=e,{resultCode:t,resultInfo:i}=r[0];if(0===t)return console.log(_+` ${o} ok`),{code:0,data:{}};throw{errorCode:t,errorInfo:i}}catch(e){let r=new this._core.helper.ChatError({functionName:o,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(_+` ${o} error:`,r),r}})}setFriendApplicationRead(){return m(this,void 0,void 0,function*(){var r="setFriendApplicationRead";console.log(_+" "+r);try{return yield function(){return m(this,void 0,void 0,function*(){var{store:e,common:r}=F.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:r,ErrorCode:e,ErrorInfo:t,ErrorDisplay:i}=r=yield r.buildAndSendPacket({servcmd:"sns.pendency_report",data:e});return{actionStatus:r,errorCode:e,errorInfo:t,errorDisplay:i}})}(),this._unreadCount=0,this._emitApplicationListUpdated(),console.log(_+` ${r} ok`),{code:0,data:{}}}catch(e){var t=new this._core.helper.ChatError({functionName:r,code:null==e?void 0:e.errorCode,message:null==e?void 0:e.errorInfo});throw console.error(_+` ${r} error:`,t),t}})}updateFriendApplicationList(e){var{from:r,addedApplicationList:t=[],removedApplicationList:i=[]}=e,e=(console.log(_+" updateFriendApplicationList data:",e),this._core.utils)["isEmpty"];e(t)||this.onApplicationAdded(t,r),e(i)||this.onApplicationDeleted()}onApplicationAdded(e,r){let t,{store:i,OuterConstant:o}=this._core,n=r===(null==(t=i.get("login"))?void 0:t.userId)?o.SNS_APPLICATION_SENT_BY_ME:o.SNS_APPLICATION_SENT_TO_ME;e.forEach(e=>{var r=e.userID+"_"+n;n!==o.SNS_APPLICATION_SENT_TO_ME||this._friendApplicationMap.has(r)||(this._unreadCount+=1),this._friendApplicationMap.set(r,this._createFriendApplication(Object.assign(Object.assign({},e),{type:n})))}),this._emitApplicationListUpdated()}onApplicationDeleted(){this._startTime=0,this._currentSequence=0,this.syncFriendApplicationListFromServer()}onApplicationRead(){this._unreadCount=0,this._emitApplicationListUpdated()}reset(){this._startTime=0,this._currentSequence=0,this._unreadCount=0,this._friendApplicationMap.clear()}dispose(){this.reset()}_createFriendApplication(e){return{userID:e.userID||"",nick:e.nick||"",avatar:e.avatar||"",time:e.time||0,source:e.source||"",wording:e.wording||"",type:e.type||""}}_emitApplicationListUpdated(){console.log(_+" _emitApplicationListUpdated");var{notificationCenter:e,OuterEvent:r}=this._core;e.emitOuterEvent(r.FRIEND_APPLICATION_LIST_UPDATED,{name:r.FRIEND_APPLICATION_LIST_UPDATED,data:{friendApplicationList:[...this._friendApplicationMap.values()],unreadCount:this._unreadCount}})}};function s(i){return m(this,void 0,void 0,function*(){var e=F.core["common"],{name:r,userIDList:t}=i,t=L(t,a),r={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:t};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:r}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function g(i){return m(this,void 0,void 0,function*(){var e=F.core["common"],{name:r,userIDList:t}=i,t=L(t,u),r={From_Account:e.getCurrentUserID(),GroupOldName:r,UpdateGroupItem:t};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:r}),e=>({userID:e.To_Account,updateType:e.UpdateType,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}function L(e,r){return e.filter(e=>I.isMyFriend(e)).map(e=>({To_Account:e,UpdateType:r}))}function y(e,r){var{CurrentSequence:e,ActionStatus:t,ErrorCode:i,ErrorInfo:o,ErrorDisplay:n,ResultItem:s=[]}=e,e={currentSequence:e,actionStatus:t,errorCode:i,errorInfo:o,errorDisplay:n};return r&&0<s.length?Object.assign(Object.assign({},e),{resultList:s.map(r)}):e}class S{constructor(e){var{name:e="",userIDList:r=[]}=e;this.name=e,this.userIDList=r,this.count=r.length}addToUserIDList(e){-1===this.userIDList.indexOf(e)&&(this.userIDList.push(e),this.count=this.userIDList.length)}removeFromUserIDList(e){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 m(this,void 0,void 0,function*(){var e=[...this._friendGroupMap.values()];return console.log(_+" getFriendGroupListFromCache, data: ",e),{code:0,data:e}})}syncFriendGroupListFromServer(){return m(this,void 0,void 0,function*(){var r="syncFriendGroupListFromServer";console.log(_+" "+r);try{var e=yield function(){return m(this,void 0,void 0,function*(){var e=F.core["common"],r={From_Account:e.getCurrentUserID(),LastSequence:0,NeedFriend:"Need_Friend_Type_Yes"};return y(yield e.buildAndSendPacket({servcmd:"sns.group_get",data:r}),e=>({name:e.GroupName,userIDList:e.To_Account||[],count:e.FriendNumber}))})}(),{resultList:t=[]}=e;this._core.helper.isEmpty(t)&&console.log(_+` ${r} ok. count: 0`),t.forEach(e=>{var r=new S(e);this._friendGroupMap.set(e.name,r)}),this._emitGroupListUpdated()}catch(e){this._handleError(r,e)}})}createFriendGroup(s){return m(this,void 0,void 0,function*(){var r="createFriendGroup";console.log(_+` ${r} params:`,s);try{let e=s["name"];this._checkGroupExist(r,e);var t=yield function(i){return m(this,void 0,void 0,function*(){var{name:e,userIDList:r}=i,t=F.core["common"],e={From_Account:t.getCurrentUserID(),GroupName:[e],To_Account:r};return y(yield t.buildAndSendPacket({servcmd:"sns.group_add",data:e}),e=>({userID:e.To_Account,resultCode:e.ResultCode,resultInfo:e.ResultInfo}))})}(s),{successUserIDList:i,failureUserIDList:o}=this._parseCreateGroupResponse(t),n=new S({name:e,userIDList:i});return this._friendGroupMap.set(e,n),this._emitGroupListUpdated(),{code:0,data:{friendGroup:n,failureUserIDList:o}}}catch(e){this._handleError(r,e)}})}deleteFriendGroup(i){return m(this,void 0,void 0,function*(){var r="deleteFriendGroup";console.log(_+` ${r} params:`,i);try{let e=i["name"];this._checkGroupNotExist(r,e),yield function(t){return m(this,void 0,void 0,function*(){var e=F.core["common"],r={From_Account:e.getCurrentUserID(),GroupName:[t.name]};return y(yield e.buildAndSendPacket({servcmd:"sns.group_delete",data:r}))})}(i);var t=this._friendGroupMap.get(e);return t&&(this._updateFriendGroup({name:e,userIDList:t.userIDList,action:c}),this._friendGroupMap.delete(e)),this._emitGroupListUpdated(),{code:0,data:t}}catch(e){this._handleError(r,e)}})}addToFriendGroup(e){return m(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"addToFriendGroup",params:e,protocolFunction:s})})}removeFromFriendGroup(e){return m(this,void 0,void 0,function*(){return this._updateFriendGroupMember({functionName:"removeFromFriendGroup",params:e,protocolFunction:g})})}renameFriendGroup(o){return m(this,void 0,void 0,function*(){var t="renameFriendGroup";console.log(_+` ${t} params:`,o);try{let{oldName:e,newName:r}=o;this._checkGroupNotExist(t,e),this._checkGroupExist(t,r),yield function(i){return m(this,void 0,void 0,function*(){var e=F.core["common"],{oldName:r,newName:t}=i,r={From_Account:e.getCurrentUserID(),GroupOldName:r,GroupNewName:t};return y(yield e.buildAndSendPacket({servcmd:"sns.group_update",data:r}))})}(o);var i=this._updateGroupNameInCache(e,r);return i&&this._updateFriendGroup({name:e,userIDList:i.userIDList,action:p,newName:r}),this._emitGroupListUpdated(),{code:0,data:i}}catch(e){this._handleError(t,e)}})}_updateFriendGroupMember(e){return m(this,void 0,void 0,function*(){var{functionName:o,params:n,protocolFunction:s}=e;console.log(_+` ${o} params:`,n);try{let e=n["name"],r=(this._checkGroupNotExist(o,e),yield s(n)),{friendGroup:t,failureUserIDList:i}=this._parseUpdateFriendGroupResponse(e,r);return this._emitGroupListUpdated(),{code:0,data:{friendGroup:t,failureUserIDList:i}}}catch(e){this._handleError(o,e)}})}_updateGroupNameInCache(e,r){var t=this._friendGroupMap.get(e);return t&&(t.name=r,this._friendGroupMap.delete(e),this._friendGroupMap.set(r,t)),t}_parseCreateGroupResponse(e){let{resultList:r=[]}=e,i=[],o=[];return r.forEach(({userID:e,resultCode:r,resultInfo:t})=>{h(r)||0===r?i.push(e):o.push({userID:e,code:r,message:t})}),{successUserIDList:i,failureUserIDList:o}}_parseUpdateFriendGroupResponse(r,e){let{resultList:t=[]}=e,i=this._friendGroupMap.get(r),o=[],n=[],s=[];return t.forEach(e=>{0===e.resultCode?i&&(e.updateType===a?this._addFriendToGroup(r,e.userID,i,n):e.updateType===u&&this._removeFriendFromGroup(r,e.userID,i,s)):o.push({userID:e.userID,code:e.resultCode,message:e.resultInfo})}),{friendGroup:i,failureUserIDList:o}}_addFriendToGroup(e,r,t,i){t.addToUserIDList(r),i.push(r),this._updateFriendGroup({name:e,userIDList:i,action:"add"})}_removeFriendFromGroup(e,r,t,i){t.removeFromUserIDList(r),i.push(r),this._updateFriendGroup({name:e,userIDList:i,action:c})}_emitGroupListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,t=[...this._friendGroupMap.values()];console.log(_+" _emitGroupListUpdated friendGroupList:",t),e.emitOuterEvent(r.FRIEND_GROUP_LIST_UPDATED,{name:r.FRIEND_GROUP_LIST_UPDATED,data:t})}_checkGroupNotExist(e,r){if(!this._friendGroupMap.has(r))throw new this._core.helper.ChatError({functionName:e,code:2711})}_checkGroupExist(e,r){if(this._friendGroupMap.has(r))throw new this._core.helper.ChatError({functionName:e,code:2710})}_updateFriendGroup(e){let{name:i,userIDList:r,action:o,newName:n}=e,s=this._core.appStore["userStore"];console.log(_+" updateFriendGroup",{name:i,userIDList:r,action:o,newName:n}),i&&!this._core.utils.isEmpty(r)&&r.forEach(e=>{var r=s.getFriend(e);if(r){var t=r["groupList"];switch(o){case"add":-1===t.indexOf(i)&&(t.push(i),r.count=t.length);break;case c:{let e=t.indexOf(i);-1<e&&(t.splice(e,1),r.count=t.length);break}case p:if(n){let e=t.indexOf(i);-1!==e&&(t[e]=n)}}}})}_handleError(e,r){r=new this._core.helper.ChatError({functionName:e,code:null==r?void 0:r.errorCode,message:null==r?void 0:r.errorInfo});throw console.error(_+` ${e} error:`,r),r}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 T=new class{constructor(){this._blacklistMap=new Map,this._retryCount=0,this._startIndex=0}init(e){var{helper:e,constants:r}=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(r.WORKFLOW_NAME.SYNC_SERVER_INFO_AFTER_RE_ONLINE,r.WORKFLOW_STEP.BLACKLIST_RECOVER,this.syncBlacklistFromServer,this)}getBlacklistFromCache(){return m(this,void 0,void 0,function*(){return console.log(_+" getBlacklistFromCache"),{code:0,data:Array.from(this._blacklistMap.keys())}})}syncBlacklistFromServer(){return m(this,void 0,void 0,function*(){try{console.log(_+" syncBlacklistFromServer");var e=yield function(i,o){return m(this,void 0,void 0,function*(){var{helper:e,channel:r}=o,t="sns.black_list_get",e=e.generateProtocolData({servcmd:t,data:i}),t=e.head.seq+t,{BlackListItem:r=[],StartIndex:e=0}=yield r.sendPacket(e,{requestId:t});return{blackList:D(r),startIndex:e}})}({From_Account:this._core.common.getCurrentUserID(),MaxLimited:l,StartIndex:this._startIndex},this._core),{blackList:r=[],startIndex:t=0}=e;return this._startIndex=t,this._addBlacklistMap(r),this._emitBlackListUpdated(),0!==this._startIndex&&this._retryCount<10?(this._retryCount++,yield this.syncBlacklistFromServer()):this._retryCount=0,{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw this._retryCount=0,console.error(_+" syncBlacklistFromServer error:",e),e}})}addToBlacklist(i){return m(this,void 0,void 0,function*(){try{console.log(_+" addToBlacklist options:",i);var e=this._preprocessBlacklist(i),r=yield function(i,o){return m(this,void 0,void 0,function*(){var{helper:e,channel:r}=o,t="sns.black_list_add",e=e.generateProtocolData({servcmd:t,data:i}),t=e.head.seq+t,{ResultItem:r=[]}=yield r.sendPacket(e,{requestId:t});return{blackList:D(r)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:e},this._core),{blackList:t=[]}=r;return this._addBlacklistMap(t),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(_+" addToBlacklist error:",e),e}})}removeFromBlacklist(t){return m(this,void 0,void 0,function*(){try{console.log(_+" removeFromBlacklist options:",t);var e=yield function(i,o){return m(this,void 0,void 0,function*(){var{helper:e,channel:r}=o,t="sns.black_list_delete",e=e.generateProtocolData({servcmd:t,data:i}),t=e.head.seq+t,{ResultItem:r=[]}=yield r.sendPacket(e,{requestId:t});return{blackList:D(r)}})}({From_Account:this._core.common.getCurrentUserID(),To_Account:t.userIDList},this._core),{blackList:r=[]}=e;return this._deleteBlacklistMap(r),this._emitBlackListUpdated(),{code:0,data:Array.from(this._blacklistMap.keys())}}catch(e){throw console.error(_+" removeFromBlacklist error:",e),e}})}dispose(){this.reset()}reset(){this._retryCount=0,this._startIndex=0,this._blacklistMap.clear()}updateBlacklist(e){console.log(_+" updateBlacklist data:",e);var{addedBlacklist:e=[],removedBlacklist:r=[]}=e;let t=!1;0<e.length&&e.some(e=>!this._blacklistMap.has(e))&&(t=!0,this._addBlacklistMap(e.map(e=>({userID:e})))),0<r.length&&r.some(e=>this._blacklistMap.has(e))&&(t=!0,this._deleteBlacklistMap(r.map(e=>({userID:e})))),t&&this._emitBlackListUpdated()}_addBlacklistMap(e){console.log(_+" _addBlacklistMap blackList:",e),e.forEach(e=>{var{userID:e,addBlackTimeStamp:r=Date.now()}=e;e&&!this._blacklistMap.has(e)&&this._blacklistMap.set(e,{userID:e,addBlackTimeStamp:r})})}_deleteBlacklistMap(e){console.log(_+" _deleteBlacklistMap blackList:",e),e.forEach(e=>{e=e.userID;e&&this._blacklistMap.has(e)&&this._blacklistMap.delete(e)})}_preprocessBlacklist(e){let r=e["userIDList"],t=this._core.common.getCurrentUserID();if(1===r.length&&r[0]===t)throw new this._core.helper.ChatError({functionName:"addToBlacklist",code:2742});return r=r.includes(t)?e.userIDList.filter(e=>e!==t):r}_emitBlackListUpdated(){var{notificationCenter:e,OuterEvent:r}=this._core,t=Array.from(this._blacklistMap.keys());console.log(_+" _emitBlackListUpdated blackList:",t),e.emitOuterEvent(r.BLACKLIST_UPDATED,{name:r.BLACKLIST_UPDATED,data:t})}};let C={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 r=F.core["OuterConstant"];return e===r.SNS_ADD_TYPE_SINGLE||e===r.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 r=F.core["OuterConstant"];return e===r.SNS_DELETE_TYPE_SINGLE||e===r.SNS_DELETE_TYPE_BOTH||"type should be SNS_DELETE_TYPE_SINGLE or SNS_DELETE_TYPE_BOTH"}}},checkFriend:{userIDList:{required:!0,rules:["array"],allowEmpty:!1},type:{required:!1,rules:["string"],allowEmpty:!0}},updateFriend:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},friendCustomField:{required:!1,rules:["array"],allowEmpty:!0}},acceptFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},remark:{required:!1,rules:["string"],allowEmpty:!0},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var r=F.core["OuterConstant"];return e===r.SNS_APPLICATION_AGREE||e===r.SNS_APPLICATION_AGREE_AND_ADD||"type should be SNS_APPLICATION_AGREE or SNS_APPLICATION_AGREE_AND_ADD"}}},refuseFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1}},deleteFriendApplication:{userID:{required:!0,rules:["string"],allowEmpty:!1},type:{required:!0,rules:["string"],allowEmpty:!1,customValidator:e=>{var r=F.core["OuterConstant"];return e===r.SNS_APPLICATION_SENT_TO_ME||e===r.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){console.log(_+" install");var{helper:r,notificationCenter:t,InnerEvent:i,constants:{WORKFLOW_NAME:o,WORKFLOW_STEP:n}}=this._core=e;F.init(e),I.init(e),A.init(e),E.init(e),T.init(e),r.registerValidateConfig({auth:k,params:C}),r.registerWorkflowStep(o.SYNC_SERVER_INFO_AFTER_LOGIN,n.FRIEND_AND_BLACKLIST_SYNC,this.handleLoginSuccess,this),t.subscribeInnerEvent(i.LOGOUT,this.reset,this),t.subscribeInnerEvent(i.MESSAGE_PUSH,t.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this)}handleLoginSuccess(){console.log(_+" handleLoginSuccess"),T.syncBlacklistFromServer(),I.syncFriendListFromServer(),A.syncFriendApplicationListFromServer(),E.syncFriendGroupListFromServer()}onFriendModified(e){var{from:e,addedBlacklist:r,removedBlacklist:t,addedFriendList:i,removedFriendList:o,addedApplicationList:n,removedApplicationList:s,friendUpdateInfo:a,reportTime:d}=this._parseFriendListModification(null==e?void 0:e.FriendListMod[0]),u=this._core.utils["isEmpty"];u(r)&&u(t)||T.updateBlacklist({addedBlacklist:r,removedBlacklist:t}),u(i)&&u(o)||(I.updateFriendList({addedFriendList:i,removedFriendList:o}),A.updateFriendApplicationList({from:e,removedApplicationList:i})),u(a)||I.updateFriendInfo(a),u(n)&&u(s)||A.updateFriendApplicationList({from:e,addedApplicationList:n,removedApplicationList:s}),d&&A.onApplicationRead()}_parseFriendListModification(e){var{PushType:e,From_Account:r,To_Account:t,ReportTime:i,BlackListAdd_Account:o=[],BlackListDel_Account:n=[],FriendAdd_Account:s=[],FriendDel_Account:a=[],PendencyAdd:d=[],FrienPencydDel_Account:u=[],FriendUpInfo:c=[]}=e,c=c.map(e=>({userID:e.Friend_Account,tagValueList:[...e.SNS]}));return{pushType:e,from:r,to:t,reportTime:i,addedBlacklist:o,removedBlacklist:n,addedFriendList:s,removedFriendList:a,addedApplicationList:d.map(e=>({userID:e.PendencyAdd_Account,source:e.AddSource,time:e.AddTime,wording:e.AddWording,nick:e.ProfileImNick})),friendUpdateInfo:c,removedApplicationList:u}}reset(){console.log(_+" reset"),T.reset(),I.reset(),A.reset(),E.reset()}dispose(){console.log(_+" dispose");var{notificationCenter:e,InnerEvent:r}=this._core;e.unSubscribeInnerEvent(r.LOGOUT,this.reset,this),e.unSubscribeInnerEvent(r.MESSAGE_PUSH,e.InnerEventSubType.FRIEND_LIST_MODIFIED,this.onFriendModified,this),T.dispose(),I.dispose(),A.dispose(),E.dispose()}}});