createMessage method

Future<Message> createMessage(
  1. Message msg, {
  2. ChatSilentNotification notification = const ChatSilentNotification(),
  3. VerifyToSendMessage? verifyToSend,
  4. OnDeniedToSendMessage? onDeniedToSend,
})

Implementation

Future<Message> createMessage(
  Message msg, {
  ChatSilentNotification notification = const ChatSilentNotification(),
  VerifyToSendMessage? verifyToSend,
  OnDeniedToSendMessage? onDeniedToSend,
}) async {
  final failed = msg.copyWith(status: MessageStatus.failed);
  if (me.isEmpty || msg.isEmpty) return failed;

  if (!isConnected && offlineQueueEnabled) {
    final target = room(msg.roomId);
    put(
      target.copyWith(
        lastMessage: msg.lastMessage(),
        lastMessageId: msg.id,
        lastMessageSenderId: me,
        lastMessageDeleted: false,
        updatedAt: ChatValueTimestamp.now(),
      ),
    );
    return enqueueMessage(
      msg,
      notification: notification,
      verifyToSend: verifyToSend,
      onDeniedToSend: onDeniedToSend,
    );
  }

  return sendNow(
    msg,
    notification: notification,
    verifyToSend: verifyToSend,
    onDeniedToSend: onDeniedToSend,
  );
}