fetchSilentModeForConversations method Null safety

Future<Map<String, ChatSilentModeResult>> fetchSilentModeForConversations(
  1. List<ChatConversation> conversations
)

Obtain the DND Settings of specified conversations in batches.

Param conversations The conversation list.

Return key is conversation id and the value is silent mode.

Throws A description of the exception. See {@link ChatError}.

Implementation

Future<Map<String, ChatSilentModeResult>> fetchSilentModeForConversations(
  List<ChatConversation> conversations,
) async {
  Map<String, int> req = {};
  for (var item in conversations) {
    req[item.id] = conversationTypeToInt(item.type);
  }
  Map result = await _channel.invokeMethod(
    ChatMethodKeys.fetchSilentModeForConversations,
    req,
  );
  try {
    ChatError.hasErrorFromResult(result);
    Map<String, ChatSilentModeResult> ret = {};
    Map? tmpMap = result[ChatMethodKeys.fetchSilentModeForConversations];
    if (tmpMap != null) {
      for (var item in tmpMap.entries) {
        if (item.key is String && item.value is Map) {
          ret[item.key] = ChatSilentModeResult.fromJson(item.value);
        }
      }
    }
    return ret;
  } on ChatError catch (e) {
    throw e;
  }
}