Skip to main content

Monitoring User Group Status Changes

The IMLib 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 targetId and userGroupId list.
  • User removed from a user group: The removed user receives a notification containing the ultra group targetId and userGroupId list.
  • Channel bound to a user group: All users in the user group receive a notification containing the ultra group targetId, channelId, channel type, and userGroupId list.
  • Channel unbound from a user group: All users in the user group receive a notification containing the ultra group targetId, channelId, channel type, and userGroupId list.
  • User group deleted: All users in the user group receive a notification containing the ultra group targetId and userGroupId list.

When creating user groups via Server API, the IMLib SDK will not receive callbacks.

Listening for User Group Change Notifications

You can add a channel change delegate after initializing the IMLib SDK but before connecting to IM using the setUserGroupStatusDelegate: method:

[[RCChannelClient sharedChannelManager] setUserGroupStatusDelegate:self];

The IMLib SDK provides callback methods related to user group changes in the RCUserGroupStatusDelegate protocol. You can obtain ultra group targetId data from the returned RCConversationIdentifier, and ultra group targetId and channelId data from the returned RCChannelIdentifier.

Delegate Callback Methods

@protocol RCUserGroupStatusDelegate <NSObject>
/*!
Current user receives disband notification for user groups in an ultra group

@param identifier Conversation identifier [identifier.type:ConversationType_ULTRAGROUP ]
@param userGroupIds List of user group IDs

@discussion
@warning
@since
*/
- (void)userGroupDisbandFrom:(RCConversationIdentifier *)identifier
userGroupIds:(NSArray<NSString *> *)userGroupIds;

/*!
Current user added to user groups in an ultra group

@param identifier Conversation identifier [identifier.type:ConversationType_ULTRAGROUP ]
@param userGroupIds List of user group IDs

@discussion
@warning
@since
*/
- (void)userAddedTo:(RCConversationIdentifier *)identifier
userGroupIds:(NSArray<NSString *> *)userGroupIds;

/*!
Current user removed from user groups in an ultra group

@param identifier Conversation identifier
@param userGroupIds List of user group IDs

@discussion
@warning
@since
*/
- (void)userRemovedFrom:(RCConversationIdentifier *)identifier
userGroupIds:(NSArray<NSString *> *)userGroupIds;


/*!
Callback for binding user groups to channels

@param identifier Channel identifier
@param channelType Channel type
@param userGroupIds List of user group IDs

@discussion
@warning
@since
*/
- (void)userGroupBindTo:(RCChannelIdentifier *)identifier
channelType:(RCUltraGroupChannelType)channelType
userGroupIds:(NSArray<NSString *> *)userGroupIds;

/*!
Callback for unbinding user groups from channels

@param identifier Channel identifier
@param channelType Channel type
@param userGroupIds List of user group IDs

@discussion
@warning
@since
*/
- (void)userGroupUnbindFrom:(RCChannelIdentifier *)identifier
channelType:(RCUltraGroupChannelType)channelType
userGroupIds:(NSArray<NSString *> *)userGroupIds;
@end

UI Update Considerations

Since the same user may appear in both private channel member lists and (multiple) user groups bound to private channels, you can query your business server upon receiving callbacks to verify whether the user still has access to the private channel, and refresh the UI accordingly.

For users not within the notification scope, you can query data from your business server when they access relevant pages and determine whether UI refreshes are needed.