deleteChatMessage method
- ChatMessage message
override
Deletes the specified ChatMessage posted by the authenticated MyUser.
Implementation
@override
Future<void> deleteChatMessage(ChatMessage message) async {
Log.debug('deleteChatMessage($message)', '$runtimeType');
final RxChatImpl? chat = chats[message.chatId];
if (message.status.value != SendingStatus.sent) {
chat?.remove(message.id);
} else {
final Rx<ChatItem>? item = chat?.messages.firstWhereOrNull(
(e) => e.value.id == message.id,
);
if (item != null) {
chat?.messages.remove(item);
}
try {
await _graphQlProvider.deleteChatMessage(message.id);
if (item != null) {
chat?.remove(item.value.id);
}
} catch (_) {
if (item != null) {
chat?.messages.insertAfter(
item,
(e) => item.value.at.compareTo(e.value.at) == 1,
);
chat?.updateReads();
}
rethrow;
}
}
}