sendMessage method

dynamic sendMessage({
  1. required ChatModal chatModal,
  2. required Map otherUserObject,
  3. required bool isBlocked,
  4. required List deviceIdList,
  5. String? notificationTitle,
  6. String? notificationMessage,
})

to send a message call this function

Implementation

sendMessage({
  required ChatModal chatModal,
  required Map otherUserObject,
  required bool isBlocked,
  required List deviceIdList,
  String? notificationTitle,
  String? notificationMessage,
}) async
{
  // String chatId = FirebaseChatServices.getSessionId(chatModal.to);
  int messageId = chatModal.createdAt.millisecondsSinceEpoch;
  customPrint('The notification message is $notificationMessage');
  // Map<int, ChatModal> innerMap = {};
  chatModal.fromServer = false;
  var chats = tempChats[chatId] ?? {};
  chatModal.id = messageId.toString();
  customPrint('The message is of this message is $messageId');
  chats[messageId] = chatModal;
  // Map<int, ChatModal> message =
  tempChats[chatId] = chats;

  notifyListeners();

  if (chatModal.messageType == MessageType.image) {
    chatModal.message =
        await MediaUploadService.uploadImageAndGetUrl(
          chatModal.message,
          onProgress: (progress) {
            customPrint(
              'The old value and new value is ${chatModal.progress?.value} and new $progress',
            );
            chatModal.progress?.value = (progress * 100).toInt();
          },
        );

    customPrint('the download url is ${chatModal.message}');

    customPrint(
      "the message type is ${chatModal.messageType}::::::::::${chatModal.message}",
    );
  }
  else if (chatModal.messageType == MessageType.video) {
    customPrint(
      "the message  ${chatModal.messageType}:::::::${chatModal.message}",
    );

    // chatModal.message = f.path;
    customPrint("adtadtdatdatdtadatdtadta::::::::::${chatModal.message}");
    File compressedFile = await compressVideo(path: chatModal.message);

    if (chatModal.thumbnail != null) {
      File t = File(chatModal.thumbnail!);
      // chatModal.thumbnail = await NewestWebServices.uploadImageAndGetUrl(t.path, onProgress: (progress){
      // })??'invalid';

      MediaUploadService.uploadImageAndGetUrl(
        t.path,
        onProgress: (progress) {},
      ).then((value) {
        chatModal.thumbnail = value;
      });
    }

    chatModal.message =
        await MediaUploadService.uploadImageAndGetUrl(
          compressedFile.path,
          onProgress: (progress) {
            customPrint(
              'The old value and new value is ${chatModal.progress?.value} and new $progress',
            );
            chatModal.progress?.value = (progress * 100).toInt();
          },
        );

    // addToLocalMessage();
    chatModal.fromServer = true;
    customPrint(
      'the complete chat modal is  ${chatModal.fromServer} ${chatModal.toJson()}',
    );
    customPrint(
      'the download url is ${chatModal.message}....\nthumbnail: ${chatModal.thumbnail}',
    );
  }
  customPrint(
    " the message is ${chatModal.messageType} : ${chatModal.message}",
  );
  await FirebaseChatServices(
    userData: currentUserModal
  ).sendMessage(
    chatModal,
    // chatListModal: chatListModal,
    chatCollection: chatCollectionReference,
    chatId: chatId,
    // notificationMessage: notificationMessage,
    //
    // notificationTitle: notificationTitle,
    // otherUserObject: otherUserObject,
    // deviceIdList: deviceIdList,
    // isBlocked: isBlocked, chatCollection: chatCollectionReference,
    messageType: chatModal.messageType,
  );

  customLogs('Manish: removing chat id $chatId');
  customPrint('sfsa ${tempChats[chatId]}');

  tempChats[chatId]?.remove(messageId);
  customPrint('sfsa  after${tempChats[chatId]}');
  notifyListeners();
}