Manage message updates
Edit messages and receive events whenever someone edits them.
Requires Message Persistence
To manage messages in PubNub storage, you must enable Message Persistence for your app's keyset in the Admin Portal.
Edit messages
Change the content of the existing message to a new one using the EditText() method.
Method signature
- Blueprint
- C++ / Input parameters
Message->EditText(FString NewText);
| Parameter | Description |
|---|---|
newText *Type: stringDefault: n/a | New/updated text that you want to add in place of the existing message. |
Output
This method doesn't return anything.
Sample code
Correct the number of the support ticket you sent to 78398.
#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
FString Timetoken = "16200000000000001";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken);
show all 16 linesGet message updates
You can receive updates when specific messages and related message reactions are added, edited, or removed on other clients using the following methods:
StreamUpdates()checks message and message reaction-related updates on a singleMessageobject.StreamUpdatesOn()checks message and message reaction-related updates on a list ofMessageobjects.
Both methods accept a callback function as an argument. The Unreal Chat SDK invokes this callback whenever someone adds, edits or deletes a message, or adds or removes a message reaction to/from the specific message(s).
Underneath, these methods subscribe the current user to a channel and add a message reactions event listener to receive all messageAction events of type added or removed. These methods also return the unsubscribe function you can invoke to stop receiving messageAction events and unsubscribe from the channel.
Method signature
- Blueprint
- C++ / Input parameters
-
StreamUpdates()Message->StreamUpdates(FOnPubnubMessageStreamUpdateReceived MessageUpdateCallback); -
StreamUpdatesOn()Message->StreamUpdatesOn(
TArray<UPubnubMessage*> Messages,
FOnPubnubMessageStreamUpdateReceived MessageUpdateCallback
);
| Parameter | Required in StreamUpdates() | Required in StreamUpdatesOn() | Description |
|---|---|---|---|
MessagesType: TArray<UPubnubMessage*>Default: n/a | No | Yes | Array of Message objects for which you want to get updates. |
MessageUpdateCallbackType: FOnPubnubMessageStreamUpdateReceivedDefault: n/a | Yes | Yes | Callback function passed as a parameter to both methods. It defines the custom behavior to be executed when detecting channel metadata changes. |
Output
| Type | Description |
|---|---|
UPubnubCallbackStop* | Object on which you can call Stop() to stop receiving updates. |
Sample code
-
StreamUpdates()Get message and message reaction-related updates for the message with the timetoken
16200000000000000published on thesupportchannel.
show all 21 lines#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
FString Timetoken = "16200000000000000";
// Fetch the message
UPubnubMessage* Message = Channel->GetMessage(Timetoken); -
StreamUpdatesOn()Get message and message reaction-related updates for several messages published on the
supportchannel.
show all 23 lines#include "Kismet/GameplayStatics.h"
#include "PubnubChatSubsystem.h"
UGameInstance* GameInstance = UGameplayStatics::GetGameInstance(this);
UPubnubChatSubsystem* PubnubChatSubsystem = GameInstance->GetSubsystem<UPubnubChatSubsystem>();
UPubnubChat* Chat = PubnubChatSubsystem ->InitChat("demo", "demo", "my_user");
UPubnubChannel* Channel = Chat->GetChannel("support");
// Get the channels and save the reference
UPubnubMessage* Message1 = Channel->GetMessage("16200000000000000");
UPubnubMessage* Message2 = Channel->GetMessage("16200000000000001");
TArray<UPubnubMessage*> Messages;
Messages.Add(Message1);
Other examples
-
StreamUpdates()Stop listening to updates for the message with the timetoken
16200000000000000published on thesupportchannel.auto StopUpdates = Message->StreamUpdates(StreamUpdatesResponse);
StopUpdates->Stop(); -
StreamUpdatesOn()Stop listening to updates for the last ten messages published on the
supportchannel.auto StopUpdates = Message->StreamUpdatesOn(Messages, MessagesStreamUpdatesResponse);
StopUpdates->Stop();