logo
On this page

Manage group info


ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of group information management, allowing you to get or modify group info, such as group name, nickname in the group, group avatar, group notice, and more.

Warning
  • Before you use this feature, you must join a group first. To join a group, refer to the Chapter Join a group of Manage groups.
  • All in-group members (group owner included) can use this feature.

Get group info

To know the detailed info of the group you joined, call the queryGroupInfo method.

You will receive the group info through the callback ZIMGroupInfoQueriedCallback after the query succeeds.

SampleCode
// Get the group info, such as group name, nicknames, group notice.
zim_->queryGroupInfo(group_id, 
    [=](const ZIMGroupInfo &groupInfo, zim::ZIMError errorInfo) {
        int code = errorInfo.code;
    });
1
Copied!

Modify the group name

To modify the group name after joining a group, call the updateGroupName method.

All group members receive a notification through the callback onGroupNameUpdated after the group name is modified successfully.

SampleCode
// Modify the group name.
zim_->updateGroupName("new_group_name", group_id, 
    [=](const std::string &groupID, const std::string &groupName, zim::ZIMError errorInfo){
        int error_code = errorInfo.code;    
    });
1
Copied!

Modify the group avatar

After logging in and joining a group, if a user wants to modify the avatar of the group they have joined, they can do so by calling the updateGroupAvatarUrl interface to modify the group avatar.

After a successful modification, all group members will receive a notification through onGroupAvatarUrlUpdated.

SampleCode
// Group members modify group avatar
// URL maximum 500 bytes, no special character restrictions
zim_->updateGroupAvatarUrl("new_group_avatar_url", group_id, 
    [=](const std::string &groupID, const std::string &groupName, zim::ZIMError errorInfo){
        int error_code = errorInfo.code;    
    });
1
Copied!

Modify the group notice

To modify the group notice after joining a group, call the updateGroupNotice method.

All group members receive a notification through the callback onGroupNoticeUpdated when the group notice is modified successfully.

SampleCode
// Modify the group notice.
zim_->updateGroupNotice("new_group_notice", group_id, 
    [=](const std::string &groupID, const std::string &groupNotice, ZIMError errorInfo){
        int error_code = errorInfo.code;
    });
1
Copied!

Modify the group alias

Group alias is a personalized nickname set by users for a group chat to distinguish from other group chats. For example, you can set the alias for a work group as "Work Group" and the alias for a family group as "Family Group", which makes it more convenient to identify the group chats.

Note

Group alias is only visible to the user who sets it and does not affect the display of the group name for other group chat members.

After logging in and joining a group, if a user wants to modify the group alias, the user can call the updateGroupAlias interface to modify the group alias. The group alias is only visible to the user themselves, and the alias for the corresponding conversation will be automatically synchronized.

SampleCode
// Modify the group alias
// groupAlias is a string with a maximum of 256 bytes, with no special character restrictions.
std::string group_alias = "NewAlias";
std::string group_id = "GroupID";
zim_->updateGroupAlias(group_alias, group_id, 
    [=](const std::string &groupID, const std::string &groupAlias, zim::ZIMError errorInfo){
        int error_code = errorInfo.code;    
    });
1
Copied!

After the modification is successful, all devices of the user can receive notifications through onGroupAliasUpdated.

SampleCode
// Listen for group alias update notifications
class zim_event_handler : public zim::ZIMEventHandler {
    void onGroupAliasUpdated(ZIM * /*zim*/, const std::string & /*groupAlias*/,
                                     const std::string & /*operatedUserID*/,
                                     const std::string & /*groupID*/) override {
        // Business logic
    }
}
1
Copied!

In addition, the user will also receive the onConversationChanged callback to know when the conversationAlias is updated. For more details, please refer to Get the conversation list - Listen for conversation changes.

Previous

Manage groups

Next

Manage group properties