Delete messages
Delete()
either permanently removes a historical message from Message Persistence or marks it as IsDeleted
parameter (if you remove the message with the soft option).
Requires Message Persistence configuration
To manage messages, you must enable Message Persistence for your app's keyset in the Admin Portal. To delete messages from PubNub storage, you must also mark the Enable Delete-From-History option.
Method signature
This method takes the following parameters:
message.Delete(bool soft)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
soft | boolean | Yes | false | Define if you want to permanently remove message data. By default, the message data gets permanently deleted from Message Persistence. If you set this parameter to true , the Message object gets the IsDeleted status and you can still restore/get its data. |
Output
This method doesn't return any data.
Basic usage
Delete the message with the 16200000000000001
timetoken from the support
channel.
// reference the "channel" object
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
};
// invoke the method on the "channel" object
List<Message> messages = channel.GetMessageHistory(startTimetoken: "16200000000000000", endTimetoken: "16200000000000001", count: 1);
var message = messages[0];
// permanently remove the message
message.Delete(false);
Other examples
Archive (soft delete) the message with the 16200000000000001
timetoken from the support
channel, keeping its data in Message Persistence.
// reference the "channel" object
if (!chat.TryGetChannel("support", out var channel))
{
Console.WriteLine("Couldn't find channel!");
return;
}
// invoke the method on the "channel" object
List<Message> messages = channel.GetMessageHistory(startTimetoken: "16200000000000000", endTimetoken: "16200000000000001", count: 1);
var message = messages[0];
// soft delete the message
message.Delete(soft: true);