deleteMessage static method
Future<void>
deleteMessage(
- int messageId, {
- required dynamic onSuccess(
- BaseMessage message
- required dynamic onError(
- CometChatException excep
Deletes the message with specified messageId
.
you get an object of the BaseMessage class, with the deletedAt field set with the timestamp of the time the message was deleted. Also, the deletedBy field is set. These two fields can be used to identify if the message is deleted while iterating through a list of messages.
Messages can be deleted only when logged-in user is the sender.
method could throw PlatformException with error codes specifying the cause
Implementation
static Future<void> deleteMessage(int messageId, {required Function(BaseMessage message)? onSuccess, required Function(CometChatException excep)? onError}) async {
try {
final res = await channel.invokeMethod('deleteMessage', {
'messageId': messageId,
});
BaseMessage message = BaseMessage.fromMap(res);
if(onSuccess != null) onSuccess(message);
return res;
} on PlatformException catch (platformException) {
if(onError != null) onError(CometChatException(platformException.code, platformException.details, platformException.message));
} catch (e) {
debugPrint("Error: $e");
if(onError != null) onError(CometChatException(ErrorCode.errorUnhandledException, e.toString() , e.toString()));
}
}