unbanGroupMember static method

Future<String?> unbanGroupMember({
  1. required String guid,
  2. required String uid,
  3. required dynamic onSuccess(
    1. String result
    )?,
  4. required dynamic onError(
    1. CometChatException excep
    )?,
})

Unbans a member from a group.

Migration Note: Migrated from platform channels to native Dart. Behavior and signature remain identical.

Android Reference: BannedGroupMembersRequest.unbanGroupMember(String guid, String uid)

Only Admin or Moderators of the group can unban a previously banned member from the group

guid The UID of the group from which user is to be unbanned

uid The UID of the user to be unbanned

method could throw PlatformException with error codes specifying the cause

Implementation

static Future<String?> unbanGroupMember(
    {required String guid,
    required String uid,
    required Function(String result)? onSuccess,
    required Function(CometChatException excep)? onError}) async {
  try {
    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call repository
    await sdk.bannedMembers.unbanMember(guid, uid);

    // Call success callback
    final result = 'Member unbanned successfully';
    if (onSuccess != null) onSuccess(result);
    return result;
  } on SdkException catch (sdkEx) {
    // Convert SdkException to CometChatException
    final cometChatEx = CometChatException(
      sdkEx.code,
      sdkEx.details ?? sdkEx.message,
      sdkEx.message,
    );
    _errorCallbackHandler(cometChatEx, null, null, onError);
  } catch (e) {
    // Handle unexpected errors
    _errorCallbackHandler(null, null, e, onError);
  }
  return null;
}