Skip to main content

Group Member User Information

To display group member nicknames on the Global IM UIKit UI, the application layer (App) needs to actively provide group member user information (GroupUserInfo) to the Global IM UIKit SDK.

Global IM UIKit uses the UserInfoConfig class to uniformly manage the following data. The App needs to use UserInfoConfig to provide data to Global IM UIKit for UI display.

  • User Information: Includes nickname and avatar.
  • Group Information: Includes group name and group avatar.
  • Group Member User Information: Only supports group member nicknames.

User information, group information, and group member user information must be actively obtained by the application developer from the App server and provided to the SDK. RC does not provide App user and group information hosting services. The user nickname and avatar on the RC server are only used for push notification services.

This document only describes how the application layer (App) provides group member nicknames and avatars (GroupUserInfo) to the Global IM UIKit SDK.

GroupUserInfo groupUserInfo = new GroupUserInfo(groupId, userId, nickname, extra);

Refresh Group Member User Information

If the App locally holds group member information data (group nicknames), it can directly refresh the local cache and the group member information data stored in the database. After refreshing, the Global IM UIKit UI will display the latest group member user information GroupUserInfo.

Refreshing group member information must be done after Global IM UIKit has successfully established an IM connection; otherwise, local data cannot be refreshed. Possible applicable scenarios include:

  • After the App is launched for the first time and successfully establishes an IM connection, it can provide the SDK with the group member information required by its business in bulk. The SDK will then write this information into the cache and local database for future use.
  • After the IM connection is established, if a group member nickname changes, the App server notifies the client (e.g., via a message), and the client calls the interface to refresh the group member information.
ConfigCenter.getUserInfoConfig().refreshGroupUserInfoCache(groupUserInfo);

If the App does not hold the data locally, it is recommended to dynamically provide group member user information when Global IM UIKit needs to display the data.

Dynamically Provide Group Member User Information

Starting from Global IM UIKit version 5.X, the SDK has designed the "Group Member User Information Provider" UserDataProvider.GroupUserInfoProvider interface class. If Global IM UIKit cannot obtain group member user information from UserInfoConfig, it will trigger the getGroupUserInfo callback method of GroupUserInfoProvider. The App should provide the group member nickname required by the SDK in this callback.

After obtaining the group member user information data, the SDK will automatically set the group member's nickname within the group and implement the related UI display.

/**
* GroupUserInfo Provider.
*/
public interface GroupUserInfoProvider {
/**
* Get GroupUserInfo.
*
* @param groupId Group ID.
* @param userId User ID.
* @return GroupUserInfo.
*/
GroupUserInfo getGroupUserInfo(String groupId, String userId);
}

Step 1: Set the Group Member User Information Provider

Use the ConfigCenter.getUserInfoConfig().setGroupUserInfoProvider() method to set the group member user information provider. This must be done after SDK initialization and before establishing an IM connection. It is recommended to set this during the application lifecycle.

// Allow the SDK to persistently store group member user information locally
boolean isCacheGroupUserInfo = true;

ConfigCenter.getUserInfoConfig().setGroupUserInfoProvider(new UserDataProvider.GroupUserInfoProvider() {
@Override
public GroupUserInfo getGroupUserInfo(String groupId, String userId) {
...// The App needs to provide group member user information here.
}
}, isCacheGroupUserInfo);
ParameterTypeDescription
groupUserInfoProviderUserDataProvider.GroupUserInfoProviderGroup member user information provider interface
isCacheGroupUserInfobooleanWhether to persistently store group member user information in the SDK's local database. true means store. false means do not store.

It is recommended to set isCacheGroupUserInfo to true, i.e., persistently store group member user information locally.

During the App's lifecycle, if the SDK has obtained group member user information, it will cache this information in memory. If persistent storage is allowed, the SDK will first retrieve group member user information from the local database, and the data will still be available the next time the App starts. The SDK's default behavior when processing the corresponding information is as follows:

  1. When the SDK needs to display group member user information on the UI, it first queries the data already obtained from memory.
  2. If the SDK can query the required information from the cache or local database, it will directly return the data to the UI layer and refresh the UI.
  3. If the SDK cannot query the required information from the cache or local database, it will trigger the callback method of UserDataProvider.GroupUserInfoProvider and attempt to obtain the information from the application layer. After receiving the corresponding information provided by the application layer, the SDK will refresh the UI.

Step 2: Provide Group Member User Information to the SDK

When group member user information needs to be displayed (e.g., on the conversation list page, group chat page), Global IM UIKit will call the getGroupUserInfo method of UserInfoConfig for each user to obtain user information. If the SDK cannot query the required data from the cache or local database, it will trigger the callback method of UserDataProvider.GroupUserInfoProvider, requiring the App to provide group member information data.

Please provide group member user information to the SDK when the getGroupUserInfo callback of UserDataProvider.GroupUserInfoProvider is triggered.

  • Asynchronously obtain group member user information, then manually refresh: The App can use this method to avoid time-consuming operations affecting the UI.

    1. The App should directly return null in the getGroupUserInfo method. At the same time, the App needs to trigger the logic to obtain the group member information of userId in this method. Note that this step will temporarily set the nickname of userId in the group to empty.

      ConfigCenter.getUserInfoConfig().setGroupUserInfoProvider(new UserDataProvider.GroupUserInfoProvider() {
      @Override
      public GroupUserInfo getGroupUserInfo(String groupId, String userId) {
      ... // When group information needs to be displayed (e.g., on the conversation list page, conversation page), Global IM UIKit will first call getGroupUserInfo based on the group ID and user ID.
      // The App should complete the asynchronous request for user information logic here. The information will be provided to the SDK later via refreshGroupUserInfoCache.
      return null;
      }
      }, true);
    2. After the App successfully obtains the nickname data of userId in the group, it calls the refreshGroupUserInfoCache method to manually refresh the group member nickname. The SDK will refresh the UI after receiving this group member user information. For details, see Refresh Group Member User Information.

  • Synchronously return group member information: The App can also directly return the group member user information of userId. The SDK will refresh the UI after receiving this data.

    ConfigCenter.getUserInfoConfig().setGroupUserInfoProvider(new UserDataProvider.GroupUserInfoProvider() {
    @Override
    public GroupUserInfo getGroupUserInfo(String groupId, String userId) {
    GroupUserInfo groupUserInfo = new GroupUserInfo(groupId, userId, "Xiao Hua");
    return groupUserInfo; // Synchronously return the group member nickname.
    }
    }, true);