sendChatMessage method
- ChatId chatId, {
- ChatMessageText? text,
- List<
Attachment> ? attachments, - List<
ChatItem> repliesTo = const [],
Posts a new ChatMessage to the specified Chat by the authenticated MyUser.
For the posted ChatMessage to be meaningful, at least one of text
or
attachments
arguments must be specified and non-empty.
Specify repliesTo
argument if the posted ChatMessage is going to be a
reply to some other ChatItem.
Implementation
Future<void> sendChatMessage(
ChatId chatId, {
ChatMessageText? text,
List<Attachment>? attachments,
List<ChatItem> repliesTo = const [],
}) {
Log.debug(
'sendChatMessage($chatId, $text, $attachments, $repliesTo)',
'$runtimeType',
);
if (text?.val.isNotEmpty != true &&
attachments?.isNotEmpty != true &&
repliesTo.isNotEmpty) {
text ??= const ChatMessageText(' ');
} else if (text != null) {
text = ChatMessageText(text.val.trim());
if (text.val.length > ChatMessageText.maxLength) {
final List<ChatMessageText> chunks = text.split();
int i = 0;
return Future.forEach<ChatMessageText>(
chunks,
(text) => _chatRepository.sendChatMessage(
chatId,
text: text,
attachments: i++ != chunks.length - 1 ? null : attachments,
repliesTo: repliesTo,
),
);
}
}
return _chatRepository.sendChatMessage(
chatId,
text: text?.val.isEmpty == true ? null : text,
attachments: attachments,
repliesTo: repliesTo,
);
}