sendFiles method

Future<void> sendFiles(
  1. ChatId id,
  2. PerformDropEvent event
)

Sends the dropped files of event to the Chat identified by its id.

Implementation

Future<void> sendFiles(ChatId id, PerformDropEvent event) async {
  final List<Attachment> attachments = [];

  // Populate attachments with dropped files.
  for (final DropItem item in event.session.items) {
    final PlatformFile? file = await item.dataReader?.asPlatformFile();
    if (file != null) {
      if (file.size >= MessageFieldController.maxAttachmentSize) {
        MessagePopup.error('err_size_too_big'.l10n);
        continue;
      }

      attachments.add(
        LocalAttachment(
          NativeFile.fromPlatformFile(file),
          status: SendingStatus.sending,
        ),
      );
    }
  }

  if (attachments.isNotEmpty) {
    attachments.whereType<LocalAttachment>().forEach(
      _chatService.uploadAttachment,
    );

    await _chatService.sendChatMessage(id, attachments: attachments);
  }
}