Group information
Chat UI SDK supports two approaches for displaying user information:
- User information provider delegate (this document): Retrieve user information, group information, and group member 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]: Switch to the managed 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 must use NCUserInfoManager to provide data to Chat UI SDK for UI display.
- User information: Nickname and avatar
- Group information: Group name and group avatar
- Group member user information: Group user nicknames only
This document describes how to provide group information (GroupInfo) to Chat UI SDK to display group avatars (not group member avatars), group names, and other information in the Chat UI.
Refresh group information
If your app holds group information locally, refresh the group information (group name and group avatar) stored in the local cache and database. After refreshing, the Chat UI displays the latest group information GroupInfo.
Refresh group information after Chat UI SDK successfully establishes an IM connection. Otherwise, the local data cannot be refreshed. Applicable scenarios include:
- When the app starts for the first time and successfully establishes an IM connection, batch-provide the user information required by your business to the SDK. The SDK writes it to the cache and local database for subsequent use.
- After the IM connection is established, if group name, avatar, or other information changes, the app server notifies the client (for example, using a message), and the client calls the interface to refresh the group information.
GroupInfo groupInfo = new GroupInfo(groupId, groupName, groupPortrait);
NCUserInfoManager.getInstance().refreshGroupInfoCache(groupInfo);
If your app does not hold data locally, dynamically provide group information when Chat UI SDK needs to display the data.
Dynamically provide group information
The SDK provides the UserDataProvider.GroupInfoProvider interface for group information providers. If Chat UI SDK cannot retrieve the group name and group avatar from NCUserInfoManager, it triggers the getGroupInfo callback method of GroupInfoProvider. Provide the group name and group avatar in this callback.
After retrieving the group information data, the SDK automatically sets and refreshes the group name and avatar and displays them in the UI.
Set the group information provider
Use the setGroupInfoProvider method of NCUserInfoManager to set the group information provider. Set it after SDK initialization and before establishing the IM connection. We recommend setting it during the application lifecycle.
During the app lifecycle, if the SDK has retrieved information for a group and persistent storage is allowed (isCacheGroupInfo is true), the SDK caches the information in memory. The SDK retrieves group information from the local database first, and the data remains available when the app restarts. The SDK processes the information as follows:
- When the SDK needs to display group information in the UI, it first queries the data from memory.
- If the SDK finds the required information in the cache or local database, it returns the data to the UI layer and refreshes the UI.
- If the SDK cannot find the required information in the cache or local database, it triggers the callback method of
UserDataProvider.GroupInfoProviderand retrieves the information from the application layer. After receiving the information, the SDK refreshes the UI.
We recommend setting isCacheGroupInfo to true to persistently store group information locally.
Provide group information data to the SDK when the getGroupInfo callback of UserDataProvider.GroupInfoProvider is triggered.
-
Asynchronously retrieve group information, then manually refresh: Use this approach to avoid time-consuming operations affecting the UI.
-
Return
nullin thegetGroupInfomethod. At the same time, trigger the logic to retrieve the group information forgroupIdin this method. This step temporarily sets the user information forgroupIdto null.Parameters
Parameter Type Description groupProvider UserDataProvider.GroupInfoProviderGroup information provider interface isCacheGroupInfo boolean Whether to persistently store group information in the SDK local database. truestores the information.falsedoes not store it.Sample code
JavaNCUserInfoManager.getInstance().setGroupInfoProvider(new UserDataProvider.GroupInfoProvider() {
@Override
public GroupInfo getGroupInfo(String groupId) {
...// When group information needs to be displayed (for example, in the channel list page or channel page), Chat UI SDK calls getGroupInfo based on the group ID
// Complete the logic to asynchronously request group information. Then provide it to the SDK through refreshGroupInfoCache.
return null;
}
}, true); -
After successfully retrieving the group information data for
groupId, call therefreshGroupInfoCachemethod ofNCUserInfoManagerto manually refresh the group information forgroupId. The SDK refreshes the UI after receiving the information. See Refresh group information.JavaGroupInfo groupInfo = new GroupInfo(groupId, groupName, groupPortrait);
NCUserInfoManager.getInstance().refreshGroupInfoCache(groupInfo);
-
-
Synchronously return group information: Directly return the group information for
groupId. The SDK refreshes the UI after receiving the information.JavaNCUserInfoManager.getInstance().setGroupInfoProvider(new UserDataProvider.GroupInfoProvider() {
@Override
public GroupInfo getGroupInfo(String groupId) {
GroupInfo groupInfo = new GroupInfo(groupId, groupName, groupPortrait);
return groupInfo;
}
}, true);
Get group information
Call the getGroupInfo method of NCUserInfoManager to retrieve group information. The SDK processes the request as follows:
- First, it retrieves the data from the local cache. If the SDK was authorized to store group information in the local database when setting the group information provider (that is,
isCacheGroupInfoistrue), the SDK also retrieves group information from the local database. - If there is no data locally, the SDK triggers the
getGroupInfocallback method ofGroupInfoProvider. If your app has provided data in this callback, the SDK successfully retrieves the group informationGroupInfo.
GroupInfo groupInfo = NCUserInfoManager.getInstance().getGroupInfo(groupId);