isExtensionEnabled static method

Future<bool> isExtensionEnabled(
  1. String extensionId, {
  2. dynamic onSuccess(
    1. bool
    )?,
  3. dynamic onError(
    1. CometChatException excep
    )?,
})

Checks if a CometChat extension is enabled.

Migration Note: Migrated from platform channels to native Dart implementation. Uses ExtensionRepository for checking extension status. Behavior and signature remain identical for backward compatibility.

Android Reference: CometChat.isExtensionEnabled(String slug, CallbackListener<Boolean>)

Implementation

static Future<bool> isExtensionEnabled(String extensionId,
    {Function(bool)? onSuccess,
    Function(CometChatException excep)? onError}) async {
  try {
    // Validate parameters
    if (extensionId.isEmpty) {
      onError?.call(CometChatException(
          ErrorCode.errorEmptyExtensionSlug,
          ErrorMessage.errorMessageEmptyExtensionSlug,
          ErrorMessage.errorMessageEmptyExtensionSlug));
      return false;
    }

    // Get SDK instance
    final sdk = SdkRegistry.getInstance();

    // Call native Dart extension repository
    final isEnabled = await sdk.extensions.isExtensionEnabled(extensionId);

    // Call success callback
    if (onSuccess != null) onSuccess(isEnabled);
    return isEnabled;
  } 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 false;
}