postChatMessage method
- ChatId chatId, {
- ChatMessageText? text,
- List<
AttachmentId> ? attachments, - List<
ChatItemId> 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.
To attach some Attachments to the posted ChatMessage, first, they
should be uploaded with Mutation.uploadAttachment, and then use the
returned AttachmentIds in attachments argument of this mutation.
Specify repliesTo argument of this mutations if the posted ChatMessage
is going to be a reply to some other ChatItem.
Authentication
Mandatory.
Result
Only the following ChatEvent may be produced on success:
Non-idempotent
Each time creates a new unique ChatMessage, producing a new ChatEvent.
Implementation
Future<ChatEventsVersionedMixin?> postChatMessage(
ChatId chatId, {
ChatMessageText? text,
List<AttachmentId>? attachments,
List<ChatItemId> repliesTo = const [],
}) async {
Log.debug(
'postChatMessage($chatId, $text, $attachments, $repliesTo)',
'$runtimeType',
);
final variables = PostChatMessageArguments(
chatId: chatId,
text: text,
attachments: attachments,
repliesTo: repliesTo,
);
final QueryResult result = await client.mutate(
MutationOptions(
operationName: 'PostChatMessage',
document: PostChatMessageMutation(variables: variables).document,
variables: variables.toJson(),
),
onException: (data) => PostChatMessageException(
(PostChatMessage$Mutation.fromJson(data).postChatMessage
as PostChatMessage$Mutation$PostChatMessage$PostChatMessageError)
.code,
),
);
return PostChatMessage$Mutation.fromJson(result.data!).postChatMessage
as PostChatMessage$Mutation$PostChatMessage$ChatEventsVersioned;
}