resendItem method

Future<void> resendItem(
  1. ChatItem item
)

Resends the specified ChatItem.

Implementation

Future<void> resendItem(ChatItem item) async {
  if (item.status.value == SendingStatus.error) {
    if (item is ChatMessage) {
      final double donation = item.donations.fold(
        0,
        (a, b) => a + b.amount.val,
      );

      if (donation != 0) {
        if (_walletService.balance.value.sum.val < donation) {
          return _showBalanceExceeded();
        }
      }
    }

    await _chatService
        .resendChatItem(item)
        .then(
          (_) => AudioUtils.once(AudioSource.asset('audio/message_sent.mp3')),
        )
        .onError<PostChatMessageException>(
          (_, _) => _showBlockedPopup(),
          test: (e) => e.code == PostChatMessageErrorCode.blocked,
        )
        .onError<PostChatMessageException>(
          (_, _) => _showBalanceExceeded(),
          test: (e) => e.code == PostChatMessageErrorCode.notEnoughFunds,
        )
        .onError<PostChatMessageException>(
          (_, _) => _showDonationsDisabled(),
          test: (e) => e.code == PostChatMessageErrorCode.disabledDonation,
        )
        .onError<UploadAttachmentException>((e, _) => MessagePopup.error(e))
        .onError<ConnectionException>((_, _) {});
  }
}