@tencentcloud/lite-chat 1.4.0 → 1.4.2

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