List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().followUser
(userIDList, new V2TIMValueCallback<List<V2TIMFollowOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowOperationResult> followOperationResultList) {// 关注用户操作成功}@Overridepublic void onError(int code, String desc) {// 关注用户操作失败}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance] followUser:userIDList succ:^(NSArray<V2TIMFollowOperationResult *> *resultList) {// 关注用户操作成功} fail:^(int code, NSString *desc) {// 关注用户操作失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowOperationResultVector>{};callback->SetCallback([=](const V2TIMFollowOperationResultVector& followOperationResultList) {// 关注用户操作成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 关注用户操作失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->FollowUser(userIDList, callback);
List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().unfollowUser
(userIDList, new V2TIMValueCallback<List<V2TIMFollowOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowOperationResult> followOperationResultList) {// 取消关注用户操作成功}@Overridepublic void onError(int code, String desc) {// 取消关注用户操作失败}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance]unfollowUser
:userIDList succ:^(NSArray<V2TIMFollowOperationResult *> *resultList) {// 取消关注用户操作成功} fail:^(int code, NSString *desc) {// 取消关注用户操作失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowOperationResultVector>{};callback->SetCallback([=](const V2TIMFollowOperationResultVector& followOperationResultList) {// 取消关注用户操作成功delete callback;},[=](int error_code, const V2TIMString& error_message) {// 取消关注用户操作失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->UnfollowUser
(userIDList, callback);
{...String nextCursor = "";getMyFollowingList(nextCursor);...}public void getMyFollowingList(String nextCursor) {V2TIMManager.getFriendshipManager().getMyFollowingList(nextCursor, new V2TIMValueCallback<V2TIMUserInfoResult>() {@Overridepublic void onSuccess(V2TIMUserInfoResult v2TIMUserInfoResult) {StringBuilder stringBuilder = new StringBuilder();if (v2TIMUserInfoResult.getNextCursor().length() > 0) {// 继续分页拉取getMyFollowingList(v2TIMUserInfoResult.getNextCursor());...} else {// 拉取结束}}@Overridepublic void onError(int code, String desc) {// 拉取失败}});}
- (void)getMyFollowingList:(NSString *)cursor {[[V2TIMManager sharedInstance] getMyFollowingList:cursor succ:^(NSString *nextCursor, NSArray<V2TIMUserFullInfo *> *userInfoList) {if (nextCursor.length > 0) {// 继续分页拉取[self getMyFollowingList:nextCursor];//...} else {// 拉取结束}} fail:^(int code, NSString *desc) {// 拉取失败}];}
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMString nextCursor = u8"";void GetMyFollowingList(const V2TIMString& nextCursor) {auto callback = new ValueCallback<V2TIMUserInfoResult>{};callback->SetCallback([=](const V2TIMUserInfoResult& userInfoResult) {if (userInfoResult.nextCursor.Length() > 0) {// 继续分页拉取GetMyFollowingList(userInfoResult.nextCursor);...} else {// 拉取结束}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 拉取失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetMyFollowingList(nextCursor, callback);}
nextCursor
参数填写为 ""
, 回调成功后如果返回的 nextCursor
不为 ""
,可以传入该值再次拉取,直至 nextCursor
返回为 ""
,表示全部拉取完成。{...String nextCursor = "";getMyFollowersList
(nextCursor);...}public voidgetMyFollowersList
(String nextCursor) {V2TIMManager.getFriendshipManager().getMyFollowersList
(nextCursor, new V2TIMValueCallback<V2TIMUserInfoResult>() {@Overridepublic void onSuccess(V2TIMUserInfoResult v2TIMUserInfoResult) {StringBuilder stringBuilder = new StringBuilder();// 拉取成功if (v2TIMUserInfoResult.getNextCursor().length() > 0) {// 继续分页拉取getMyFollowersList
(v2TIMUserInfoResult.getNextCursor());...} else {// 拉取结束}}@Overridepublic void onError(int code, String desc) {// 拉取失败}});}
- (void)getMyFollowersList
:(NSString *)cursor {[[V2TIMManager sharedInstance]getMyFollowersList
:cursor succ:^(NSString *nextCursor, NSArray<V2TIMUserFullInfo *> *userInfoList) {if (nextCursor.length > 0) {// 继续分页拉取[selfgetMyFollowersList
:nextCursor];//...} else {// 拉取结束}} fail:^(int code, NSString *desc) {// 拉取失败}];}
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMString nextCursor = u8"";void GetMyFollowersList(const V2TIMString& nextCursor) {auto callback = new ValueCallback<V2TIMUserInfoResult>{};callback->SetCallback([=](const V2TIMUserInfoResult& userInfoResult) {// 拉取成功if (userInfoResult.nextCursor.Length() > 0) {// 继续分页拉取GetMyFollowersList(userInfoResult.nextCursor);...} else {// 拉取结束}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 拉取失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetMyFollowersList(nextCursor, callback);}
nextCursor
参数填写为 ""
, 回调成功后如果返回的 nextCursor
不为 ""
,可以传入该值再次拉取,直至 nextCursor
返回为 ""
,表示全部拉取完成。getMutualFollowersList
(Android / iOS & Mac / Windows) 接口来拉取与自己互相关注的用户列表(互相关注的用户都可以在彼此的关注用户列表和粉丝用户列表中找到对方)。{...String nextCursor = "";getMutualFollowersList(nextCursor);...}public void getMutualFollowersList(String nextCursor) {V2TIMManager.getFriendshipManager().getMutualFollowersList(nextCursor, new V2TIMValueCallback<V2TIMUserInfoResult>() {@Overridepublic void onSuccess(V2TIMUserInfoResult v2TIMUserInfoResult) {StringBuilder stringBuilder = new StringBuilder();// 拉取成功if (v2TIMUserInfoResult.getNextCursor().length() > 0) {// 继续分页拉取getMutualFollowersList(v2TIMUserInfoResult.getNextCursor());...} else {// 拉取结束}}@Overridepublic void onError(int code, String desc) {// 拉取失败}});}
- (void)getMutualFollowersList:(NSString *)cursor {[[V2TIMManager sharedInstance] getMutualFollowersList:cursor succ:^(NSString *nextCursor, NSArray<V2TIMUserFullInfo *> *userInfoList) {if (nextCursor.length > 0) {// 继续分页拉取[self getMutualFollowersList:nextCursor];//...} else {// 拉取结束}} fail:^(int code, NSString *desc) {// 拉取失败}];}
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMString nextCursor = u8"";void GetMutualFollowersList(const V2TIMString& nextCursor) {auto callback = new ValueCallback<V2TIMUserInfoResult>{};callback->SetCallback([=](const V2TIMUserInfoResult& userInfoResult) {// 拉取成功if (userInfoResult.nextCursor.Length() > 0) {// 继续分页拉取GetMutualFollowersList(userInfoResult.nextCursor);...} else {// 拉取结束}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 拉取失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetMutualFollowersList(nextCursor, callback);}
nextCursor
参数填写为 ""
, 回调成功后如果返回的 nextCursor
不为 ""
,可以传入该值再次拉取,直至 nextCursor
返回为 ""
,表示全部拉取完成。V2TIMFollowInfo
(Android / iOS & Mac / Windows) 的 followingCount
、followersCount
和 mutualFollowersCount
来获取指定用户的关注、粉丝和互关用户数量。List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().getUserFollowInfo(userIDList, new V2TIMValueCallback<List<V2TIMFollowInfo>>() {@Overridepublic void onSuccess(List<V2TIMFollowInfo> followInfoList) {// 获取成功for (V2TIMFollowInfo followInfo : V2TIMFollowInfoList) {if (followInfo.getResultCode() == 0) {// 此处可以获取到用户 followInfo.getUserID() 对应的关注/粉丝/互关用户的数量信息// 也即 followInfo.getFollowingCount(), followInfo.getFollowersCount() 和 followInfo.getMutualFollowersCount()}}}@Overridepublic void onError(int code, String desc) {// 获取失败}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance] getUserFollowInfo:userIDList succ:^(NSArray<V2TIMFollowInfo *> *resultList) {// 获取成功for (V2TIMFollowInfo *result in resultList) {if (result.resultCode == 0) {// 此处可以获取到用户 result.userID 对应的关注/粉丝/互关用户的数量信息// 也即 result.followingCount, result.followersCount 以及 result.mutualFollowersCount 信息}}} fail:^(int code, NSString *desc) {// 获取失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowInfoVector>{};callback->SetCallback([=](const V2TIMFollowInfoVector& followInfoList) {// 获取成功for (size_t i = 0; i < followInfoList.Size(); ++i) {if (followInfoList[i].resultCode == 0) {// 此处可以获取到用户 followInfoList[i].userID 对应的关注/粉丝/互关用户的数量信息// 也即 followInfoList[i].followingCount, followInfoList[i].followersCount 和 followInfoList[i].mutualFollowersCount}}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 获取失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetUserFollowInfo
(userIDList, callback);
V2TIMFollowTypeCheckResult
(Android / iOS & Mac / Windows) 的 followType
字段来获取自己与该用户的关系:V2TIMFollowTypeCheckResult.followType | 与自己的关系 |
V2TIM_FOLLOW_TYPE_NONE | 无任何关系 |
V2TIM_FOLLOW_TYPE_IN_MY_FOLLOWING_LIST | 对方仅在我的关注列表中 |
V2TIM_FOLLOW_TYPE_IN_MY_FOLLOWERS_LIST | 对方仅在我的粉丝列表中 |
V2TIM_FOLLOW_TYPE_IN_BOTH_FOLLOWERS_LIST | 对方与我互相关注(对方既在我的关注列表,也在我的粉丝列表) |
List<String> userIDList = Arrays.asList("useridA", "useridB");V2TIMManager.getFriendshipManager().checkFollowType(userIDList, new V2TIMValueCallback<List<V2TIMFollowTypeCheckResult>>() {@Overridepublic void onSuccess(List<V2TIMFollowTypeCheckResult> followTypeCheckResultList) {// 检查关注关系成功for (V2TIMFollowTypeCheckResult followTypeCheckResult : followTypeCheckResultList) {if (followTypeCheckResult.getResultCode() == 0) {// 此处可以获取到自己与用户 followTypeCheckResult.getUserID() 的关系 followTypeCheckResult.getFollowType()}}}@Overridepublic void onError(int code, String desc) {// 检查关注关系失败}});
NSArray *useridList = @[@"useridA", @"useridB"];[[V2TIMManager sharedInstance] checkFollowType:userIDList succ:^(NSArray<V2TIMFollowTypeCheckResultListSucc *> *resultList) {// 检查关注关系成功for (V2TIMFollowTypeCheckResult *result in resultList) {if (result.resultCode == 0) {// 此处可以获取到自己与用户 result.userID 的关系 result.followType}}} fail:^(int code, NSString *desc) {// 检查关注关系失败}];
template <class T>class ValueCallback final : public V2TIMValueCallback<T> {public:using SuccessCallback = std::function<void(const T&)>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;ValueCallback() = default;~ValueCallback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess(const T& value) override {if (success_callback_) {success_callback_(value);}}void OnError(int error_code, const V2TIMString& error_message) override {if (error_callback_) {error_callback_(error_code, error_message);}}private:SuccessCallback success_callback_;ErrorCallback error_callback_;};V2TIMStringVector userIDList;userIDList.PushBack(u8"useridA");userIDList.PushBack(u8"useridB");auto callback = new ValueCallback<V2TIMFollowTypeCheckResultVector>{};callback->SetCallback([=](const V2TIMFollowTypeCheckResultVector& followTypeCheckResultList) {// 检查关注关系成功for (size_t i = 0; i < followTypeCheckResultList.Size(); ++i) {if (followTypeCheckResultList[i].resultCode == 0) {// 此处可以获取到自己与用户 followTypeCheckResultList[i].userID 的关系 followTypeCheckResultList[i].followType}}delete callback;},[=](int error_code, const V2TIMString& error_message) {// 检查关注关系失败delete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->FollowUser(userIDList, callback);
列表变更通知 | 说明 |
当通知中的 isAdd 为 true 时,表示列表新增用户的通知,此时会返回完整的用户资料当通知中的 isAdd 为 false 时,表示列表删除用户的通知,此时返回的用户资料中仅有用户 ID | |
| |
|
Alice
和 Bob
,这两个用户相互关注过程中,相关列表变更通知和关系变更如下:事件 | Alice | Bob | ||
| 收到的通知 | 与 Bob 的关系 | 收到的通知 | 与 Alice 的关系 |
Alice 关注 Bob | ||||
Bob 关注 Alice |
Alice
和 Bob
, 这两个用户相互取消关注过程中,相关列表变更通知和关系变更如下:事件 | Alice | Bob | ||
| 收到的通知 | 与 Bob 的关系 | 收到的通知 | 与 Alice 的关系 |
Alice 取消关注 Bob | ||||
Bob 取消关注 Alice |
V2TIMFriendshipListener v2TIMFriendshipListener = new V2TIMFriendshipListener() {@Overridepublic void onMyFollowingListChanged(List<V2TIMUserFullInfo> userInfoList, boolean isAdd) {if (isAdd) {// 关注列表新增用户的通知} else {// 关注列表删除用户的通知}}@Overridepublic void onMyFollowersListChanged(List<V2TIMUserFullInfo> userInfoList, boolean isAdd) {if (isAdd) {// 粉丝列表新增用户的通知} else {// 粉丝列表删除用户的通知}}@Overridepublic void onMutualFollowersListChanged(List<V2TIMUserFullInfo> userInfoList, boolean isAdd) {if (isAdd) {// 互关列表新增用户的通知} else {// 互关列表删除用户的通知}}};// 添加关系链监听器V2TIMManager.getFriendshipManager().addFriendListener(v2TIMFriendshipListener);
// 添加关系链监听器[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onMyFollowingListChanged:(NSArray<V2TIMUserFullInfo *> *)userInfoList isAdd:(BOOL)isAdd {if (isAdd) {// 关注列表新增用户的通知} else {// 关注列表删除用户的通知}}- (void)onMyFollowersListChanged:(NSArray<V2TIMUserFullInfo *> *)userInfoList isAdd:(BOOL)isAdd {if (isAdd) {// 粉丝列表新增用户的通知} else {// 粉丝列表删除用户的通知}}- (void)onMutualFollowersListChanged:(NSArray<V2TIMUserFullInfo *> *)userInfoList isAdd:(BOOL)isAdd {if (isAdd) {// 互关列表新增用户的通知} else {// 互关列表删除用户的通知}}
class FriendshipListener final : public V2TIMFriendshipListener {public:FriendshipListener() = default;~FriendshipListener() override = default;void OnMyFollowingListChanged(const V2TIMUserFullInfoVector &userInfoList, bool isAdd) override {if (isAdd) {// 关注列表新增用户的通知} else {// 关注列表删除用户的通知}}void OnMyFollowersListChanged(const V2TIMUserFullInfoVector &userInfoList, bool isAdd) override {if (isAdd) {// 粉丝列表新增用户的通知} else {// 粉丝列表删除用户的通知}}void OnMutualFollowersListChanged(const V2TIMUserFullInfoVector &userInfoList, bool isAdd) override {if (isAdd) {// 互关列表新增用户的通知} else {// 互关列表删除用户的通知}}// 其他成员函数 ...};// 添加关系链事件监听器,注意在移除监听器之前需要保持 friendshipListener 的生命期,以免接收不到事件回调FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
本页内容是否解决了您的问题?