tencent cloud

Feedback

Android&iOS&Windows&Mac

Last updated: 2024-04-23 17:07:47

    Overview

    The group profile refers to the information about the group, such as group ID, group type, custom group field, and the number of joined members. It is saved in the V2TIMGroupInfo object, which is created and returned by the IM SDK and cannot be customized. The methods to get the group profile are in the V2TIMGroupManager(Android) / V2TIMManager(Group)(iOS and macOS) core class.

    Getting the Group Profile

    Call getGroupsInfo (Android / iOS and macOS / Windows) to get the group profile. This API supports passing in multiple groupID values at a time to batch get group profiles.
    Sample code:
    Android
    iOS and macOS
    Windows
    V2TIMManager.getGroupManager().getGroupsInfo(groupIDList, new V2TIMValueCallback<List<V2TIMGroupInfoResult>>() {
    @Override
    public void onSuccess(List<V2TIMGroupInfoResult> v2TIMGroupInfoResults) {
    // Obtained the group profile successfully
    }
    
    @Override
    public void onError(int code, String desc) {
    // Failed to obtain the group profile
    }
    });
    [[V2TIMManager sharedInstance] getGroupsInfo:@[@"groupA"] succ:^(NSArray<V2TIMGroupInfoResult *> *groupResultList) {
    // Obtained the group profile successfully
    } fail:^(int code, NSString *desc) {
    // Failed to obtain the group profile
    }];
    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 groupIDList;
    groupIDList.PushBack("group1");
    
    auto callback = new ValueCallback<V2TIMGroupInfoResultVector>{};
    callback->SetCallback(
    [=](const V2TIMGroupInfoResultVector& groupInfoResultList) {
    // Obtained the group profile successfully
    delete callback;
    },
    [=](int error_code, const V2TIMString& error_message) {
    // Failed to obtain the group profile
    delete callback;
    });
    V2TIMManager::GetInstance()->GetGroupManager()->GetGroupsInfo(groupIDList, callback);

    Modifying Group Profiles

    Call setGroupInfo (Android / iOS and macOS / Windows) to modify the group profile.
    If you have called addGroupListener to add a group event listener, after the group profile is modified, all the group members will receive the onGroupInfoChanged callback (Android / iOS and macOS / Windows).
    Member roles that can modify the group profile vary by group type as follows:
    Group Type
    Member Roles Allowed to Modify the Group Profile
    Work group (Work)
    All group members
    Public group (Public)
    Group owner and admin
    Meeting group (Meeting)
    Group owner and admin
    Community (Community)
    Group owner and admin
    Audio-video group (AVChatRoom)
    Group owner
    Caution
    Not all the fields of the group profile V2TIMGroupInfo can be modified, but only those writable.
    Sample code:
    Android
    iOS and macOS
    Windows
    // Sample code: Modify group profile
    V2TIMGroupInfo v2TIMGroupInfo = new V2TIMGroupInfo();
    v2TIMGroupInfo.setGroupID("Group ID of the group to be modified");
    v2TIMGroupInfo.setFaceUrl("http://xxxx");
    V2TIMManager.getGroupManager().setGroupInfo(v2TIMGroupInfo, new V2TIMCallback() {
    @Override
    public void onSuccess() {
    // Modified the group profile successfully
    }
    
    @Override
    public void onError(int code, String desc) {
    // Failed to modify the group profile
    }
    });
    V2TIMGroupInfo *info = [[V2TIMGroupInfo alloc] init];
    info.groupID = @"Group ID of the group to be modified";
    info.faceURL = @"http://xxxx";
    [[V2TIMManager sharedInstance] setGroupInfo:info succ:^{
    // Modified the group profile successfully
    } fail:^(int code, NSString *desc) {
    // Failed to modify the group profile
    }];
    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_;
    };
    
    V2TIMGroupInfo info;
    info.groupID = "Group ID to be modified";
    info.faceURL = "http://xxxx";
    info.modifyFlag |= V2TIM_GROUP_INFO_MODIFY_FLAG_FACE_URL;
    
    auto callback = new Callback;
    callback->SetCallback(
    [=]() {
    // Modified the group profile successfully
    delete callback;
    },
    [=](int error_code, const V2TIMString& error_message) {
    // Failed to modify the group profile
    delete callback;
    });
    
    V2TIMManager::GetInstance()->GetGroupManager()->SetGroupInfo(info, callback);

    Setting a Custom Group Field

    The customInfo attribute in the V2TIMGroupInfo group profile is the custom group field, which can be modified by calling the setGroupInfo API mentioned in the previous section.
    Unlike setting other fields in V2TIMGroupInfo, setting the custom group field involves two steps:
    1. In the IM console, configure the key of the custom group field. The key is a string of up to 16 bytes. If the key is not preconfigured, setting the key-value will fail.
    2. Call the setGroupInfo API to set the field with up to 512 bytes.
    Caution
    1. You can set up to ten custom fields, which cannot be deleted and whose name and type cannot be changed.
    2. The custom field is mainly used to ensure compatibility with v1 and v2. If you use the API on v2, we recommend you use the initGroupAttributes API to set the group attribute. This allows for greater flexibility (requiring no configuration in the console) and storage (up to 16 KB). For more information, see Custom Group Attribute.

    Setting the Group Message Receiving Option

    Any group member can call the setGroupReceiveMessageOpt API (Android / iOS and macOS / Windows) to change the group message receiving option. This setting will take effect only for the group member and will not affect the setting of other group members.
    V2TIMReceiveMessageOpt has the following options:
    Message Receiving Option
    Description
    V2TIM_RECEIVE_MESSAGE
    Messages will be received when the user is online, and push notifications will be received when the user is offline.
    V2TIM_NOT_RECEIVE_MESSAGE
    No group messages will be received.
    V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE
    Messages will be received when the user is online, and no push notifications will be received when the user is offline.
    V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE_EXCEPT_AT
    Receive messages online, and only receive push for at messages when offline.
    Different V2TIMReceiveMessageOpt options can be used to implement group message notification muting:
    No group messages will be received. With the group message receiving option set to V2TIM_NOT_RECEIVE_MESSAGE, no group message will be received, and the conversation list will not be updated.
    Group messages will be received but will not be notified to the user, and a badge without the unread count will be displayed on the conversation list UI.
    1. The group message receiving option is set to V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE.
    2. When the receiver receives a new group message and needs to update the conversation list, it can get the unread count through unreadCount (Android / iOS and macOS / Windows) of V2TIMConversation.
    3. The receiver displays a badge rather than the unread count when identifying the group message receiving option as V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE based on the recvOpt (Android / iOS and macOS / Windows) of V2TIMConversation.
    Receive group messages but notify only for at messages, and a badge without the unread count will be displayed on the conversation list UI.
    The group message receiving option setting is V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE_EXCEPT_AT. After this setting, group messages are received but only at messages are notified.
    Note
    As this method requires the unreadCount feature, it applies only to work groups (Work), public groups (Public), and communities (Community), but not to audio-video groups (AVChatRoom) or meeting groups (Meeting). For more information on group types, see Group System.
    Sample code:
    Android
    iOS and macOS
    Windows
    V2TIMManager.getMessageManager().setGroupReceiveMessageOpt("groupA", V2TIMMessage.V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE, new V2TIMCallback() {
    @Override
    public void onSuccess() {
    // Changed the group message receiving option successfully
    }
    
    @Override
    public void onError(int code, String desc) {
    // Failed to change the group message receiving option
    }
    });
    [[V2TIMManager sharedInstance] setGroupReceiveMessageOpt:@"groupA" opt:V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE succ:^{
    // Changed the group message receiving option successfully
    } fail:^(int code, NSString *desc) {
    // Failed to change the group message receiving option
    }];
    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 groupID = "groupA";
    V2TIMReceiveMessageOpt opt = V2TIMReceiveMessageOpt::V2TIM_RECEIVE_NOT_NOTIFY_MESSAGE;
    
    auto callback = new Callback;
    callback->SetCallback(
    [=]() {
    // Changed the group message receiving option successfully
    delete callback;
    },
    [=](int error_code, const V2TIMString& error_message) {
    // Failed to change the group message receiving option
    delete callback;
    });
    
    V2TIMManager::GetInstance()->GetMessageManager()->SetGroupReceiveMessageOpt(groupID, opt, callback);
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support