Group Information
To display group avatars (not group member avatars), group names, etc., on the Global IM UIKit UI, the application layer (App) needs to actively provide group information (Group
) 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 display on the UI.
- User Information: Includes nickname and avatar.
- Group Information: Includes group name and group avatar.
- Group Member User Information: Only supports group user nicknames.
User information, group information, and group member user information must be actively obtained by the app 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 services.
This document only describes how the application layer (App) provides group information (Group
) to the Global IM UIKit SDK to enable the display of group avatars (not group member avatars), group names, and other functionalities on the Global IM UIKit UI.
Group group = new Group(groupId, groupName, groupPortrait);
// From version 5.3.0, a new String-type extra field is added.
Group group = new Group(groupId, groupName, groupPortrait, extra);
Refresh Group Information
If the App locally holds group information data, it can directly refresh the locally cached and database-stored group information (group name and group avatar). After refreshing, the Global IM UIKit UI will display the latest group information Group
.
Refreshing group information must be done after Global IM UIKit has successfully established an IM connection; otherwise, local data cannot be refreshed. Possible applicable scenarios include:
- When the App is launched for the first time and successfully establishes an IM connection, it can provide the user information required by its business in bulk to the SDK, which will write it to the cache and local database for subsequent use.
- After the IM connection is established, if the group name, avatar, etc., change, the App server notifies the client (e.g., via a message), and the client calls the interface to refresh the group information.
Group group = new Group(groupId, groupName, groupPortrait);
ConfigCenter.getUserInfoConfig().refreshGroupInfoCache(group);
If the App does not hold data locally, it is recommended to dynamically provide group information when Global IM UIKit needs to display the data.
Dynamically Provide Group Information
Starting from Global IM UIKit version 5.X, the SDK has designed the "Group Information Provider" UserDataProvider.GroupInfoProvider
interface class. If Global IM UIKit cannot obtain the group name and group avatar from UserInfoConfig
, it will trigger the getGroupInfo
callback method of GroupInfoProvider
. The App should provide the group name and group avatar required by the SDK in this callback.
After obtaining the group information data, the SDK will automatically set and refresh the group name and avatar, as well as implement the relevant UI display.
public interface GroupInfoProvider {
/**
* Get group information.
*
* @param groupId Group ID.
* @return Group information.
*/
Group getGroupInfo(String groupId);
}
Step 1: Set the Group Information Provider
In Global IM UIKit, you can use the setGroupInfoProvider
method of UserInfoConfig
to set the group information provider. This must be done after SDK initialization and before establishing the IM connection. It is recommended to set this during the application lifecycle.
// Allow the SDK to persistently store group information locally.
boolean isCacheGroupInfo = true;
ConfigCenter.getUserInfoConfig().setGroupInfoProvider(new UserDataProvider.GroupInfoProvider() {
@Override
public Group getGroupInfo(String groupId) {
...// The App needs to provide group information here.
}
}, isCacheGroupInfo);
Parameter | Type | Description |
---|---|---|
groupProvider | UserDataProvider.GroupInfoProvider | Group information provider interface. |
isCacheGroupInfo | boolean | Whether to persistently store group information in the SDK's local database. true means store. false means do not store. |
It is recommended to set
isCacheGroupInfo
totrue
, i.e., persistently store group information locally.
During the App lifecycle, if the SDK has obtained group information, it will cache this information in memory. If persistent storage is allowed, the SDK will first retrieve group 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:
- When the SDK needs to display group information on the UI, it first queries the data already obtained from memory.
- 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.
- If the SDK cannot query the required information from the cache or local database, it will trigger the callback method of
UserDataProvider.GroupInfoProvider
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 Information to the SDK
When group information needs to be displayed (e.g., on the conversation list page or conversation page), Global IM UIKit will call the getGroupInfo
method of UserInfoConfig
for each group ID to obtain group information. If the SDK cannot query the required group information from the cache or local database, it will trigger the callback method of UserDataProvider.GroupInfoProvider
, requesting the App to provide group information data.
Please provide group information data to the SDK when the getGroupInfo
callback of UserDataProvider.GroupInfoProvider
is triggered.
-
Asynchronously obtain group information, then manually refresh: The App can use this method to avoid time-consuming operations affecting the UI.
-
The App needs to directly return
null
in thegetGroupInfo
method, and at the same time, the App should trigger the logic to obtain group information forgroupId
in this method. Note that this step will temporarily set the user information ofgroupId
to empty.ConfigCenter.getUserInfoConfig().setGroupInfoProvider(new UserDataProvider.GroupInfoProvider {
@Override
public Group getGroupInfo(String groupId) {
...// When group information needs to be displayed (e.g., on the conversation list page or conversation page), Global IM UIKit will first call getGroupInfo for each group ID.
// The App should complete the asynchronous request for group information here. Subsequently, provide it to the SDK via refreshGroupInfoCache.
return null;
}
}, true); -
After the App successfully obtains the group information data for
groupId
, it should call therefreshGroupInfoCache
method ofUserInfoConfig
to manually refresh the group information forgroupId
. The SDK will refresh the UI after receiving this group's information. For details, see Refresh Group Information.Group group = new Group(groupId, groupName, groupPortrait);
ConfigCenter.getUserInfoConfig().refreshGroupInfoCache(group);
-
-
Synchronously return group information: The App can also directly return the group information for
groupId
. The SDK will refresh the UI after receiving this group's information.ConfigCenter.getUserInfoConfig().setGroupInfoProvider(new UserDataProvider.GroupInfoProvider() {
@Override
public Group getGroupInfo(String groupId) {
Group group = new Group(groupId, groupName, groupPortrait);
return group;
}
}, true);