List<String> userIDList = new ArrayList<>();userIDList.add("user1");userIDList.add("user2");V2TIMManager.getFriendshipManager().createFriendGroup("Friends at university", userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {// Friend group created successfully}@Overridepublic void onError(int code, String desc) {// Failed to create the friend group}});
// Create a friend group[[V2TIMManager sharedInstance] createFriendGroup:@"Friends at university" userIDList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {// Friend group created successfully} fail:^(int code, NSString *desc) {// Failed to create the friend group}];
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 groupName = u8"Friends at university";V2TIMStringVector userIDList;userIDList.PushBack(u8"user1");userIDList.PushBack(u8"user2");auto callback = new ValueCallback<V2TIMFriendOperationResultVector>{};callback->SetCallback([=](const V2TIMFriendOperationResultVector& friendOperationResultList) {// Friend group created successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to create the friend groupdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->CreateFriendGroup(groupName, userIDList, callback);
deleteFriendGroup
API (Android / iOS and Mac / Windows) to delete a friend group. This will not delete the friends.List<String> friendGroupList = new ArrayList<>();friendGroupList.add("Friends at university");V2TIMManager.getFriendshipManager().deleteFriendGroup(friendGroupList, new V2TIMCallback() {@Overridepublic void onSuccess() {// Friend group deleted successfully}@Overridepublic void onError(int code, String desc) {// Failed to delete the friend group}});
// Delete a friend group[[V2TIMManager sharedInstance] deleteFriendGroup:@[@"Friends at university"] succ:^{// Friend list deleted successfully} fail:^(int code, NSString *desc) {// Failed to delete the friend group}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}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 groupNameList;groupNameList.PushBack(u8"Friends at university");auto callback = new Callback{};callback->SetCallback([=]() {// Friend group deleted successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to delete the friend groupdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->DeleteFriendGroup(groupNameList, callback);
V2TIMManager.getFriendshipManager().renameFriendGroup("Friends at university", "Friends in high school", new V2TIMCallback() {@Overridepublic void onSuccess() {// Friend group name changed successfully}@Overridepublic void onError(int code, String desc) {// Failed to rename the friend group}});
// Rename a friend group[[V2TIMManager sharedInstance] renameFriendGroup:@"Friends at university" newName:@"Friends in high school" succ:^{// Friend group name changed successfully} fail:^(int code, NSString *desc) {// Failed to rename the friend group}];
class Callback final : public V2TIMCallback {public:using SuccessCallback = std::function<void()>;using ErrorCallback = std::function<void(int, const V2TIMString&)>;Callback() = default;~Callback() override = default;void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {success_callback_ = std::move(success_callback);error_callback_ = std::move(error_callback);}void OnSuccess() override {if (success_callback_) {success_callback_();}}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 oldName = u8"Friends at university";V2TIMString newName = u8"Friends in high school";auto callback = new Callback{};callback->SetCallback([=]() {// Friend group name changed successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to rename the friend groupdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->RenameFriendGroup(oldName, newName, callback);
List<String> friendGroups = new ArrayList<>();friendGroups.add("Friends at university");V2TIMManager.getFriendshipManager().getFriendGroups(friendGroups, new V2TIMValueCallback<List<V2TIMFriendGroup>>() {@Overridepublic void onSuccess(List<V2TIMFriendGroup> v2TIMFriendGroups) {// Friend group obtained successfully}@Overridepublic void onError(int code, String desc) {// Failed to obtain the friend group}});
// Get a friend group[[V2TIMManager sharedInstance] getFriendGroupList:@[@"Friends at university"] succ:^(NSArray<V2TIMFriendGroup *> *groups) {// Friend group obtained successfully} fail:^(int code, NSString *desc) {// Failed to obtain the friend group}];
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 groupNameList;groupNameList.PushBack(u8"Friends at university");auto callback = new ValueCallback<V2TIMFriendGroupVector>{};callback->SetCallback([=](const V2TIMFriendGroupVector& friendGroupList) {// Friend group obtained successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to obtain the friend groupdelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->GetFriendGroups(groupNameList, callback);
addFriendsToFriendGroup
API (Android / iOS and Mac / Windows) to add a friend to a friend group.List<String> userIDList = new ArrayList<>();userIDList.add("user1");userIDList.add("user2");V2TIMManager.getFriendshipManager().addFriendsToFriendGroup("Friends at university", userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {// Added successfully}@Overridepublic void onError(int code, String desc) {// Failed to add}});
// Add a friend to a friend group[[V2TIMManager sharedInstance] addFriendsToFriendGroup:@"Friends at university" userIDList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {// Added successfully} fail:^(int code, NSString *desc) {// Failed to add}];
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 groupName = u8"Friends at university";V2TIMStringVector userIDList;userIDList.PushBack(u8"user1");userIDList.PushBack(u8"user2");auto callback = new ValueCallback<V2TIMFriendOperationResultVector>{};callback->SetCallback([=](const V2TIMFriendOperationResultVector& friendOperationResultList) {// Added successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to adddelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendsToFriendGroup(groupName, userIDList, callback);
deleteFriendsFromFriendGroup
API (Android / iOS and Mac / Windows) to remove a friend from a friend group. This will only remove the friend from the friend group and will not delete the friend.List<String> userIDList = new ArrayList<>();userIDList.add("user1");userIDList.add("user2");V2TIMManager.getFriendshipManager().deleteFriendsFromFriendGroup("Friends at university", userIDList, new V2TIMValueCallback<List<V2TIMFriendOperationResult>>() {@Overridepublic void onSuccess(List<V2TIMFriendOperationResult> v2TIMFriendOperationResults) {// Deleted successfully}@Overridepublic void onError(int code, String desc) {// Failed to delete}});
// Remove a friend from a friend group[[V2TIMManager sharedInstance] deleteFriendsFromFriendGroup:@"Friends at university" userIDList:@[@"user1", @"user2"] succ:^(NSArray<V2TIMFriendOperationResult *> *resultList) {// Deleted successfully} fail:^(int code, NSString *desc) {// Failed to delete}];
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 groupName = u8"Friends at university";V2TIMStringVector userIDList;userIDList.PushBack(u8"user1");userIDList.PushBack(u8"user2");auto callback = new ValueCallback<V2TIMFriendOperationResultVector>{};callback->SetCallback([=](const V2TIMFriendOperationResultVector& friendOperationResultList) {// Deleted successfullydelete callback;},[=](int error_code, const V2TIMString& error_message) {// Failed to deletedelete callback;});V2TIMManager::GetInstance()->GetFriendshipManager()->DeleteFriendsFromFriendGroup(groupName, userIDList,callback);
addFriendListener
(Android / iOS & Mac / Windows) to listen for the notification of a friend group change.V2TIMFriendshipListener v2TIMFriendshipListener = new V2TIMFriendshipListener() {@Overridepublic void onFriendGroupCreated(String groupName, List<V2TIMFriendInfo> friendInfoList) {// Received the notification of friend group creation}@Overridepublic void onFriendGroupDeleted(List<String> groupNameList) {// Received the notification of friend group deletion}@Overridepublic void onFriendGroupNameChanged(String oldGroupName, String newGroupName) {// Received the notification of friend group renaming}@Overridepublic void onFriendsAddedToGroup(String groupName, List<V2TIMFriendInfo> friendInfoList) {// Received the notification of a friend added to a group}@Overridepublic void onFriendsDeletedFromGroup(String groupName, List<String> friendIDList) {// Received the notification of a friend deleted from a group}};// Add a relationship listenerV2TIMManager.getFriendshipManager().addFriendListener(v2TIMFriendshipListener);
// Add a relationship listener[[V2TIMManager sharedInstance] addFriendListener:self];- (void)onFriendGroupCreated:(NSString *)groupName friendInfoList:(NSArray<V2TIMFriendInfo *> *)friendInfoList {// Received the notification of friend group creation}- (void)onFriendGroupDeleted:(NSArray<NSString *> *)groupNameList {// Received the notification of friend group deletion}- (void)onFriendGroupNameChanged:(NSString *)oldGroupName newGroupName:(NSString *)newGroupName {// Received the notification of friend group renaming}- (void)onFriendsAddedToGroup:(NSString *)groupName friendInfoList:(NSArray<V2TIMFriendInfo *> *)friendInfoList {// Received the notification of a friend added to a group}- (void)onFriendsDeletedFromGroup:(NSString *)groupName friendIDList:(NSArray<NSString *> *)friendIDList {// Received the notification of a friend deleted from a group}
class FriendshipListener final : public V2TIMFriendshipListener {public:FriendshipListener() = default;~FriendshipListener() override = default;void OnFriendGroupCreated(const V2TIMString &groupName, const V2TIMFriendInfoVector &friendInfoList) override {// Received the notification of friend group creation}void OnFriendGroupDeleted(const V2TIMStringVector &groupNameList) override {// Received the notification of friend group deletion}void OnFriendGroupNameChanged(const V2TIMString &oldGroupName, const V2TIMString &newGroupName) override {// Received the notification of a friend added to a group}void OnFriendsAddedToGroup(const V2TIMString &groupName, const V2TIMFriendInfoVector &friendInfoList) override {// Received the notification of a friend added to a group}void OnFriendsDeletedFromGroup(const V2TIMString &groupName, const V2TIMStringVector &friendIDList) override {// Received the notification of a friend deleted from a group}// Other members ...};// Add a relationship event listener. Keep `friendshipListener` valid before the listener is removed to ensure event callbacks are received.SDKListener sdkListener;FriendshipListener friendshipListener;V2TIMManager::GetInstance()->GetFriendshipManager()->AddFriendListener(&friendshipListener);
Was this page helpful?