ChannelFileMessageSendWsRequest constructor Null safety

ChannelFileMessageSendWsRequest(
  1. {required String channelUrl,
  2. required FileMessageParams params,
  3. required String? requestId,
  4. List? thumbnails,
  5. bool? requireAuth}
)

Implementation

ChannelFileMessageSendWsRequest({
  required String channelUrl,
  required FileMessageParams params,
  required String? requestId,
  List<dynamic>? thumbnails,
  bool? requireAuth,
}) : super() {
  payload.addAll({
    'channel_url': channelUrl,
    if (requireAuth != null) 'require_auth': requireAuth,
    'url': params.uploadFile.url,
    'name': params.uploadFile.name,
    'type': params.uploadFile.mimeType,
    'size': params.uploadFile.fileSize,
    'custom': params.data,
    'custom_type': params.customType,
  });

  if (params.pushOption == PushNotificationDeliveryOption.suppress) {
    payload['push_option'] = params.pushOption.asString();
  }

  payload['mention_type'] = params.mentionType?.asString();
  if (params.mentionType == MentionType.users) {
    payload['mentioned_user_ids'] = params.mentionedUserIds;
  }

  payload['thumbnails'] = thumbnails;
  payload['created_at'] = DateTime.now().millisecondsSinceEpoch;
  payload['metaarray'] = params.metaArrays?.map((e) => e.toJson()).toList();

  if (params.parentMessageId != null) {
    payload['parent_message_id'] = params.parentMessageId;
    payload['root_message_id'] = params.parentMessageId;
  }
  payload.removeWhere((key, value) => value == null);
}