logo
On this page

Manage users

ZEGOCLOUD's In-app Chat (the ZIM SDK) provides the capability of user management, allows users to update their personal profile, such as username, and status updates.

Implementation Process

Manage the extended field

The ZIM SDK provides user extended fields to describe additional properties of users. Developers can use extended fields to customize user attributes through the updateUserExtendedData interface. The usage of extended fields can be defined by developers, and the SDK will only pass the fields without any further processing.

After modifying the extended field properties, users can receive the modification results through ZIMUserExtendedDataUpdatedCallback.

Example
std::string new_user_extended_data = "{\"user_avatar\":\"https://url\",\"user_name\":\"new_name\",\"user_sex\":\"male\",\"user_birth\":\"1970-01-01\",\"user_phone\":\"12345678901\"}";

zim_->updateUserExtendedData(new_user_extended_data, [=](const std::string &extended_data, zim::ZIMError error_info){
    if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
        // Modification successful
    }
});
1
Copied!

Modify User Name

The user name userName is a string used to describe the user's nickname. Developers can configure it through the ZIMUserInfo object. The ZIM SDK supports users to modify their user names after logging in through the updateUserName interface.

After modifying the user name, users can receive the modification results through ZIMUserNameUpdatedCallback.

Example
// Modify user name
// userName is a string with a maximum of 256 bytes, no special character restrictions.
std::string new_user_name = "new_name";

zim_->updateUserName(new_user_name, [=](const std::string &userName, const zim::ZIMError &errorInfo){
    if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
        // Modification successful
    }
});
1
Copied!

Set User Avatar

The ZIM SDK supports users to set or modify their avatars after logging in through the updateUserAvatarUrl interface.

After setting the user avatar, users can receive the setting results through the ZIMUserAvatarUrlUpdatedCallback.

Warning

When a user modifies his/her avatar, other users need to call the queryUsersInfo interface and set the isQueryFromServer parameter in ZIMUsersInfoQueryConfig to true to re-query the user information to obtain the latest avatar.

Example
// URL maximum 500 bytes, no special character restrictions
std::string user_avatar_url = "";

zim_->updateUserAvatarUrl(user_avatar_url, [=](const std::string &userAvatarUrl, zim::ZIMError error_info){
    if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
         // Operation successful
    }
});
1
Copied!

Query User Information

Users can query the full information of specified users, including user names and user extended fields, through the queryUsersInfo interface. Only in this interface can users obtain user avatar URLs and user extended field information.

After querying the information, users can receive the query results through the ZIMUsersInfoQueriedCallback.

Example
// Query user information
// Usage restrictions: The number of UserID to be queried in a single call to the interface cannot exceed 10; 
// within 10 seconds, the cumulative total number of UserID queried by multiple calls to the interface cannot exceed 10.
std::string target_user_id = "user_id_1";

std::vector<std::string> user_id_list;
user_id_list.push_back(target_user_id);

zim::ZIMUsersInfoQueryConfig config;
// false is for local query, which prioritizes returning data from the local database. 
// If there is no corresponding user information in the local database and the query frequency limit has not been reached, it will automatically upgrade to query from the server.
// true is for server query, which prioritizes pulling user information from the server. 
// When the query frequency limit is reached, user information that has not been queried from the server will attempt to return data from the local database.
config.isQueryFromServer = false; 

zim_->queryUsersInfo(user_id_list, config, [=](const std::vector<zim::ZIMUserFullInfo> &userList, const std::vector<zim::ZIMErrorUserInfo> &errorUserList, const ZIM::ZIMError &errorInfo) {
    if (errorInfo.code == ZIM_ERROR_CODE_SUCCESS) {
        // Query succeeded
    }
});
1
Copied!

Previous

Authentication

Next

Multi-device login