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 ZIMUserExtendedDataUpdatedResult.

Example
var extendedData = JSON.stringify({ age: 18, birthdy: '2000-01-01' });

zim.updateUserExtendedData(extendedData)
    .then(function ({ extendedData }) {
        // Operation successful
    })
    .catch(function (err) {
        // Operation failed
    });
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 ZIMUserNameUpdatedResult.

Example
// Modify user name
// userName is a string with a maximum of 256 bytes, no special character restrictions.
var userName = 'new_name';

zim.updateUserName(userName)
    .then(function ({ userName }) {
        // Operation successful
    })
    .catch(function (err) {
        // Operation failed
    });
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 ZIMUserAvatarUrlUpdatedResult.

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
var userAvatarUrl = 'https://xxxx';

zim.updateUserAvatarUrl(userAvatarUrl)
    .then(function ({ userAvatarUrl }) {
        // Operation successful
    })
    .catch(function (err) {
        // Operation failed
    });
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 ZIMUsersInfoQueriedResult.

Example
// Limitations: The number of UserID queries in a single API call cannot exceed 10; Within 10 seconds, the cumulative total of all UserID queries cannot exceed 10.
var userIDs = ['id1', 'id2'];

zim.queryUsersInfo(userIDs, { isQueryFromServer: false })
    .then(function ({ userList, errorUserList }) {
        // Operation successful
    })
    .catch(function (err) {
        // Operation failed
    });
1
Copied!

Previous

Authentication

Next

Multi-device login