@tencentcloud/lite-chat 1.5.2 → 1.6.0

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