Delete messages
Delete() either permanently removes a historical message from Message Persistence (DeleteMessageHard()) or marks it as deleted if you use the soft delete option (DeleteMessage()).
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.
Mark message as deleted (soft delete)
Method signature
This method applies to the Message object the deleted status so you can still restore/get its data.
- Blueprint
- C++ / Input parameters
1// soft delete
2Message->DeleteMessage();
Output
| Type | Description | 
|---|---|
| UPubnubMessage* | An updated message instance with an added deletedaction type. | 
Sample code
Soft delete the message with the 16200000000000001 timetoken from the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15
Delete a message (hard delete)
Method signature
This method permanently removes a message from Message Persistence.
- Blueprint
- C++ / Input parameters
1// hard delete
2Message->DeleteMessageHard();
Output
| Type | Description | 
|---|---|
| bool | Whether or not the deletion was successful. | 
Sample code
Permanently delete the message with the 16200000000000001 timetoken from the support channel.
1#include "Kismet/GameplayStatics.h"
2#include "PubnubChatSubsystem.h"
3
4UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
5UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
6
7UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
8
9UPubnubChannel* Channel = Chat->GetChannel("support");
10
11FString Timetoken = "16200000000000001";
12
13// Fetch the message
14UPubnubMessage* Message = Channel->GetMessage(Timetoken);
15