Group Member User Information
Chat UI SDK supports two approaches for displaying user information:
- User information provider delegate approach (this document): You must actively retrieve user information, group information, and group member user information from your app server and provide it to the SDK. The user nickname and avatar passed when registering to obtain a token from the Nexconn server are used only for push notifications.
- [User information managed approach]: Chat UI SDK supports switching to the managed information approach to display user and group information in the channel page and channel list.
Chat UI SDK uses the NCUserInfoManager class to manage the following data. Your app needs to use NCUserInfoManager to provide data to Chat UI SDK for display in the UI.
- User information: includes nickname and avatar
- Group information: includes group name and group avatar
- Group member user information: supports only group member nicknames
This document describes how your application layer (App) provides group member nicknames (GroupUserInfo) to the Chat UI SDK.
Refresh Group Member User Information
If your app locally holds group member user information data (group nicknames), you can directly refresh the group member user information stored in the local cache and database. After refreshing, the Chat UI SDK displays the latest group member user information (GroupUserInfo).
Refresh group member user information only after Chat UI SDK has successfully established an IM connection. Otherwise, local data cannot be refreshed. Applicable scenarios include:
- When your app starts for the first time and successfully establishes an IM connection, you can batch-provide the group member user information required by your business to the SDK, which writes it to the cache and local database for subsequent use.
- After the IM connection is established, if a group member nickname changes, your app server notifies the client (for example, using a message), and the client calls the interface to refresh the group member user information.
NCUserInfoManager.getInstance().refreshGroupUserInfoCache(groupUserInfo);
If your app does not hold data locally, we recommend dynamically providing group member user information when Chat UI SDK needs to display the data.
Dynamically provide group member user information
The SDK provides the UserDataProvider.GroupUserInfoProvider interface class for group member user information providers. If Chat UI SDK cannot retrieve group member user information from NCUserInfoManager, it triggers the getGroupUserInfo callback method of GroupUserInfoProvider. Your app should provide the group member nickname required by the SDK in this callback.
After retrieving the group member user information, the SDK automatically sets the group member's nickname within the group and implements the related UI display.
Set group member user information provider to supply group information to the SDK
During the application lifecycle, after initialization and before connection, call the setGroupUserInfoProvider method of NCUserInfoManager to set the group member user information provider.
During your app lifecycle, if the SDK has retrieved group member user information and allows persistent storage (isCacheGroupUserInfo is true), it caches the information in memory. The SDK retrieves group member user information from the local database first, and the data remains available when your app restarts. The SDK's default behavior when processing the corresponding information is as follows:
- When the SDK needs to display group member user information in the UI, it first queries the retrieved data from memory.
- If the SDK can query the required information from the cache or local database, it directly returns the data to the UI layer and refreshes the UI.
- If the SDK cannot query the required information from the cache or local database, it triggers the callback method of
UserDataProvider.GroupUserInfoProviderand attempts to retrieve the information from the application layer. After receiving the corresponding information provided by the application layer, the SDK refreshes the UI.
We recommend setting isCacheGroupUserInfo to true to persistently store group member user information locally.
Provide group member user information to the SDK when the getGroupUserInfo callback of UserDataProvider.GroupUserInfoProvider is triggered.
-
Asynchronously retrieve group member user information, then manually refresh: Your app can use this approach to avoid time-consuming operations affecting the UI.
-
Your app should directly return
nullin thegetGroupUserInfomethod. Meanwhile, your app needs to trigger its own logic to retrieve the group member user information foruserIdin this method. Note that this step temporarily sets the nickname ofuserIdwithin the group to empty.JavaNCUserInfoManager.getInstance().setGroupUserInfoProvider(new UserDataProvider.GroupUserInfoProvider() {
@Override
public GroupUserInfo getGroupUserInfo(String groupId, String userId) {
... // When group information needs to be displayed (for example, in the channel list page or channel page), Chat UI SDK first calls getGroupUserInfo sequentially based on the group ID and user ID.
// Your app completes the asynchronous request logic for user information here. Subsequently, provide it to the SDK through refreshGroupUserInfoCache.
return null;
}
}, true); -
After your app successfully retrieves the nickname data of
userIdwithin the group, call therefreshGroupUserInfoCachemethod to manually refresh the group member nickname. The SDK refreshes the UI after receiving the group member user information. See Refresh Group Member User Information.
-
-
Synchronously return group member information: Your app can also directly return the group member user information for
userId. The SDK refreshes the UI after receiving the data.JavaNCUserInfoManager.getInstance().setGroupUserInfoProvider(new UserDataProvider.GroupUserInfoProvider() {
@Override
public GroupUserInfo getGroupUserInfo(String groupId, String userId) {
GroupUserInfo groupUserInfo = new GroupUserInfo(groupId, userId, "Alice");
return groupUserInfo; //Synchronously return the group member nickname.
}
}, true);
Retrieve group member user information
Your app can actively call the getGroupUserInfo method of NCUserInfoManager to retrieve group member user information. The SDK's behavior is as follows:
- First, it attempts to retrieve the data provided by the application layer from the local cache. If the SDK was authorized to store user information in the local database when setting the group member user information provider (that is,
isCacheGroupUserInfoistrue), the SDK also attempts to retrieve group member user information from the local database. - If there is no data for the related information locally, the SDK triggers the
getGroupUserInfocallback method ofGroupUserInfoProvider. If your app layer has provided data in this callback, the SDK can successfully retrieve the group member user information (GroupUserInfo).
GroupUserInfo groupUserInfo = NCUserInfoManager.getInstance().getGroupUserInfo(groupId, userId);
| Parameter | Type | Description |
|---|---|---|
| groupId | String | Group ID |
| userId | String | User ID |