blockUser static method
Future<Map<String, dynamic> ?>
blockUser(
- List<
String> ? uids, { - required dynamic onSuccess()?,
- required dynamic onError(
- CometChatException excep
Block a user from sending logged-in user any messages.
uids list of UID of users to be blocked
Block a user from sending logged-in user any messages.
uids list of UID of users to be blocked
receive a map which contains UIDs as the keys and "success" or "fail" as the value based on if the block operation for the UID was successful or not
method could throw PlatformException with error codes specifying the cause
Migration Note: Migrated from platform channels to native Dart implementation. Behavior and signature remain identical for backward compatibility.
Android Reference: UsersRequest.blockUsers(List<String> uids)
Implementation
static Future<Map<String, dynamic>?> blockUser(List<String>? uids,
{required Function(Map<String, dynamic> map)? onSuccess,
required Function(CometChatException excep)? onError}) async {
try {
// Validate UIDs
if (uids == null || uids.isEmpty) {
throw CometChatException(
ErrorCode.errorInvalidParameter,
'UIDs list cannot be empty',
'UIDs list cannot be empty',
);
}
// Get SDK instance
final sdk = SdkRegistry.getInstance();
// Call native Dart user repository
await sdk.users.blockUsers(uids);
// Create success map (matching Android SDK behavior)
final res = <String, dynamic>{};
for (final uid in uids) {
res[uid] = 'success';
}
// Call success callback
if (onSuccess != null) onSuccess(res);
return res;
} 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) {
_errorCallbackHandler(null, null, e, onError);
}
return null;
}