Skip to main content

Monitor User Group Status Changes

The SDK has supported ultra group user group functionality since version 5.4.0.

You can set up listeners to receive corresponding notifications when changes occur in ultra group user groups.

The IMLib SDK provides callbacks for the following operations. The notification scope and callback data vary as follows:

  • User added to a user group: The added user receives a notification containing the ultra group ID and user group ID.
  • User removed from a user group: The removed user receives a notification containing the ultra group ID and user group ID.
  • Channel bound to a user group: All users in the user group receive a notification containing the ultra group ID, channel ID, channel type, and user group ID.
  • Channel unbound from a user group: All users in the user group receive a notification containing the ultra group ID, channel ID, channel type, and user group ID.
  • User group deleted: All users in the user group receive a notification containing the ultra group ID and user group ID.

No callback is triggered when creating a user group.

Monitor User Group Change Notifications

You can set up a user group change listener using the setUserGroupStatusListener method after initializing the IMLib SDK but before connecting to IM.

Sample Code

ChannelClient.getInstance().setUserGroupStatusListener(
new IRongCoreListener.UserGroupStatusListener() {
@Override
public void userGroupDisbandFrom(
ConversationIdentifier identifier, String[] userGroupIds) {
}

@Override
public void userAddedTo(
ConversationIdentifier identifier, String[] userGroupIds) {
}

@Override
public void userRemovedFrom(
ConversationIdentifier identifier, String[] userGroupIds) {
}

@Override
public void userGroupBindTo(
ConversationIdentifier identifier,
IRongCoreEnum.UltraGroupChannelType channelType,
String[] userGroupIds) {
}

@Override
public void userGroupUnbindFrom(
ConversationIdentifier identifier,
IRongCoreEnum.UltraGroupChannelType channelType,
String[] userGroupIds) {

}
}
);

The IMLib SDK provides callback methods related to user group changes in the IRongCoreListener.UserGroupStatusListener interface. You can retrieve the ultra group ID (targetId) and channel ID (channelId) from the returned ConversationIdentifier.

interface UserGroupStatusListener {
/**
* Current user receives disband notification for user groups in an ultra group
*
* @param identifier Conversation identifier
* @param userGroupIds List of user group IDs
*/
void userGroupDisbandFrom(ConversationIdentifier identifier, String[] userGroupIds);

/**
* Current user is added to a user group in an ultra group
*
* @param identifier Conversation identifier
* @param userGroupIds List of user group IDs
*/
void userAddedTo(ConversationIdentifier identifier, String[] userGroupIds);

/**
* Current user is removed from a user group in an ultra group
*
* @param identifier Conversation identifier
* @param userGroupIds List of user group IDs
*/
void userRemovedFrom(ConversationIdentifier identifier, String[] userGroupIds);

/**
* Callback when a channel binds to user groups
*
* @param identifier Channel identifier
* @param channelType Channel type
* @param userGroupIds List of user group IDs
*/
void userGroupBindTo(
ConversationIdentifier identifier,
IRongCoreEnum.UltraGroupChannelType channelType,
String[] userGroupIds);

/**
* Callback when a channel unbinds from user groups
*
* @param identifier Channel identifier
* @param channelType Channel type
* @param userGroupIds List of user group IDs
*/
void userGroupUnbindFrom(
ConversationIdentifier identifier,
IRongCoreEnum.UltraGroupChannelType channelType,
String[] userGroupIds);
}

UI Update Considerations

Since the same user may appear in both private channel member lists and (multiple) user groups bound to private channels, your app can query your business server upon receiving callbacks to determine whether the user should retain access to the private channel, then refresh the UI accordingly.

For users not covered by notifications, your app can query data from your business server when they navigate to relevant pages and decide whether UI updates are needed.