updateGroupMemberScope static method

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

Updates a group member's scope (role).

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

Android Reference: GroupMembersRequest.updateGroupMemberScope(String guid, String uid, String scope)

In order to change the scope of a group member

guid The GUID of the group for which the member's scope needs to be changed

uid The UID of the member whose scope you would like to change

the updated scope of the member. can be CometChatMemberScope.admin , CometChatMemberScope.participant, CometChatMemberScope.moderator

method could throw PlatformException with error codes specifying the cause

Implementation

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

    // Call repository
    await sdk.groupMembers.changeMemberScope(guid, uid, scope);

    // Call success callback
    final result = 'Member scope updated 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;
}