Manage masage 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 EditMessageText()
method.
Method signature
This method takes the following parameters:
message.EditMessageText(string newText)
Input
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
newText | string | Yes | n/a | New/updated text that you want to add in place of the existing message. |
Output
This method doesn't return any data.
Basic usage
Correct the number of the support ticket you sent to 78398
.
message.EditMessageText("Your ticket number is 78398")
Get message updates
These methods let you receive updates when specific messages and related message reactions are added, edited, or removed on other clients:
StartListeningForUpdates()
— listen forMessage
object update information.OnMessageUpdated
— add a single event handler to a singleMessage
object update.AddListenerToMessagesUpdate()
— add a single event handler to eachMessage
object update from the provided list.
Method signature
These methods take the following parameters:
-
StartListeningForUpdates()
message.StartListeningForUpdates()
-
OnMessageUpdated
// event on the user entity
public event Action<Message> OnMessageUpdated;
// needs a corresponding event handler
void EventHandler(Message message) -
AddListenerToMessagesUpdate()
chat.AddListenerToMessagesUpdate(
string channelId,
List<string> messageTimeTokens,
Action<Message> listener
)
Input
Parameter | Type | Required in StartListeningForUpdates | Required in OnMessageUpdated | Required in AddListenerToMessagesUpdate() | Default | Description |
---|---|---|---|---|---|---|
message | Message | No | Yes | No | n/a | The message object to handle the update event for. |
channelId | string | No | No | Yes | n/a | The channel ID for which to check the update events. |
messageTimeTokens | List<string> | No | Yes | n/a | List of timetokens of messages for which to check the update events. | |
listener | Action<Message> | No | Yes | Yes | n/a | The definition of the custom behavior to be executed when detecting message changes. |
Output
These operations don't return any data.
Basic usage
-
StartListeningForUpdates()
andOnMessageUpdated
Get message and message reaction-related updates for all messages published on the
support
channel.if (chat.TryGetChannel("support", out var channel))
{
Console.WriteLine($"Found channel with name {channel.Name}");
};
message.StartListeningForUpdates();
message.OnMessageUpdated += OnMessageUpdatedHandler; // or use lambda
void OnMessageUpdatedHandler(Message message)
{
Console.WriteLine($"Message updated");
} -
AddListenerToMessagesUpdate()
Get message and message reaction-related updates for 10 historical messages older than the timetoken
15343325214676133
published on thesupport
channel.
show all 25 linesif (chat.TryGetChannel("support", out var channel))
{
Console.WriteLine($"Found channel with name {channel.Name}");
};
var messages = channel.GetMessageHistory(startTimetoken: "15343325214676133", count: 10);
List<string> timetokens = new List<string>();
// get the timetokens
for (int i = 0; i < messages.Count; i++)
{
// Get the time token of the current message
string timeToken = messages[i].TimeToken;