sendMessage method

Future<void> sendMessage({
  1. required String id,
  2. required String channelName,
  3. required String message,
  4. required String messageType,
})

Implementation

Future<void> sendMessage(
    {required String id,
    required String channelName,
    required String message,
    required String messageType}) async {
  final request = SendMessageRequest(
      messageType: messageType, message: message, conversationId: id);
  //log(request.toString());
  ConversationMessage unsentMessage = ConversationMessage(
    message: message,
    messageType: messageType,
    uid: id,
    messageFrom: 'company',
    createdAt: DateTime.now(),
    updatedAt: DateTime.now(),
    timestamp: DateTime.now().toString(),
    platform: 'Bodsquare platform',
    status: 'offline',
  );

  await addOfflineMessage(unsentMessage);

  textMessageController.clear();
  final response = channelName.toLowerCase() == 'twitter'
      ? await _conversationRepository.sendTwitterMessage(request)
      : channelName.toLowerCase() == 'facebook'
          ? await _conversationRepository.sendFacebookMessage(request)
          : channelName.toLowerCase() == 'instagram'
              ? await _conversationRepository.sendInstagramMessage(request)
              : const ConversationModel();

  if (response.status == 'success') {
    // _conversationsService.conversation.value = response;
    await getSingleConversation(
      id,
    );
    // getAllConversations();
    // await getOfflineMessage(id);
  } else {
    _loadingService.showError(
      'unable to send message...',
    );
  }
  // getAllConversations();
}