sendChatMessage method Null safety

Future<ChatMessage> sendChatMessage(
  1. {required String message,
  2. ParticipantId? recipient}
)

Sends a message to the this CallClient's current room. If a recipient is not specified, the message is sent to the whole room.

Once successfully posted, the resulting message will be emitted as a AppMessageReceived-event with the message's local-field set to true.

Implementation

Future<ChatMessage> sendChatMessage({required String message, ParticipantId? recipient}) async {
  final chatMessage = ChatMessage(
    fromParticipantId: participants.local.id,
    fromParticipantName: participants.local.info.username ?? 'Guest',
    // The backend strips microseconds so we do the same so we can compare the timestamps later.
    date: DateTime.fromMillisecondsSinceEpoch(
      DateTime.now().millisecondsSinceEpoch,
    ).toUtc(),
    message: message,
    local: true,
    room: 'main-room',
  );
  await _platformBridge.sendChatMessage(_native, chatMessage, recipient);
  _eventsController.add(Event.appMessageReceived(message: AppMessage.chatMessage(message: chatMessage)));
  return chatMessage;
}