getMutedConversations static method

Future<List<MutedConversation>> getMutedConversations({
  1. dynamic onSuccess(
    1. List<MutedConversation> mutedConversations
    )?,
  2. dynamic onError(
    1. CometChatException e
    )?,
})

Retrieves a list of conversations that have been muted by the logged-in user.

This method makes an asynchronous call to the CometChat server to fetch all muted conversations. Upon successful retrieval, onSuccess is invoked with a list of MutedConversation objects. If an error occurs, onError is called with a CometChatException.

Returns a Future<List<MutedConversation>> which completes with the list of muted conversations, or an empty list if an error occurs.

Implementation

static Future<List<MutedConversation>> getMutedConversations(
    {Function(List<MutedConversation> mutedConversations)? onSuccess,
    Function(CometChatException e)? onError}) async {
  List<MutedConversation> mutedConversations = [];
  try {
    final sdk = SdkRegistry.getInstance();
    final response = await sdk.notificationsApi.getMutedConversations();
    final data = response['data'] as Map<String, dynamic>;
    final mutedConversationsJson = data['mutedConversations'] as List? ?? [];

    for (final item in mutedConversationsJson) {
      mutedConversations
          .add(MutedConversation.fromMap(item as Map<String, dynamic>));
    }

    if (onSuccess != null) onSuccess(mutedConversations);
    return mutedConversations;
  } catch (e) {
    _handleError(e, onError);
  }
  return mutedConversations;
}