muteConversations static method

Future<String?> muteConversations(
  1. List<MutedConversation> muteConversations, {
  2. dynamic onSuccess(
    1. String response
    )?,
  3. dynamic onError(
    1. CometChatException e
    )?,
})

Mutes the specified conversations for the logged-in user.

This method asynchronously sends a request to the CometChat server to mute the provided list of conversations. Upon a successful mute operation, onSuccess is invoked with a success response. If an error occurs, onError is called with a CometChatException.

Returns a Future<String?> which completes with a success response if the operation is successful, or null if an error occurs.

Implementation

static Future<String?> muteConversations(
    List<MutedConversation> muteConversations,
    {Function(String response)? onSuccess,
    Function(CometChatException e)? onError}) async {
  try {
    final sdk = SdkRegistry.getInstance();
    final conversationMaps = muteConversations.map((c) => c.toMap()).toList();
    await sdk.notificationsApi.muteConversations(conversationMaps);

    const result = 'Conversations muted successfully';
    if (onSuccess != null) onSuccess(result);
    return result;
  } catch (e) {
    _handleError(e, onError);
  }
  return null;
}