editChatMessage method
- ChatMessage item, {
- ChatMessageTextInput? text,
- ChatMessageAttachmentsInput? attachments,
- ChatMessageRepliesInput? repliesTo,
Edits the specified ChatMessage posted by the authenticated MyUser.
Implementation
Future<void> editChatMessage(
ChatMessage item, {
ChatMessageTextInput? text,
ChatMessageAttachmentsInput? attachments,
ChatMessageRepliesInput? repliesTo,
}) async {
Log.debug('editChatMessage($item, $text)', '$runtimeType');
if (text?.changed?.val.trim() == item.text?.val.trim()) {
text = null;
} else if (text != null) {
text = ChatMessageTextInput(
text.changed?.val.trim().isEmpty != false
? null
: ChatMessageText(text.changed!.val.trim()),
);
}
if (item.attachments
.map((e) => e.id)
.sameAs(attachments?.changed.map((e) => e.id))) {
attachments = null;
}
if (item.repliesTo
.map((e) => e.original?.id)
.sameAs(repliesTo?.changed.map((e) => e))) {
repliesTo = null;
}
if ((text?.changed ?? item.text)?.val.isEmpty != false &&
(attachments?.changed ?? item.attachments).isEmpty &&
(repliesTo?.changed ?? item.repliesTo).isNotEmpty) {
text = const ChatMessageTextInput(ChatMessageText(' '));
}
if (text != null || attachments != null || repliesTo != null) {
return _chatRepository.editChatMessage(
item,
text: text,
attachments: attachments,
repliesTo: repliesTo,
);
}
}