deleteMessage static method

Future<void> deleteMessage(
  1. int messageId, {
  2. required dynamic onSuccess(
    1. BaseMessage message
    )?,
  3. required dynamic onError(
    1. 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 (p) {
    _errorCallbackHandler(null, p, null, onError);
  } catch (e) {
    _errorCallbackHandler(null, null, e, onError);
  }
}