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 EditMessageText() method.

Method signature

This method takes the following parameters:

message.EditMessageText(string newText)

Input

* required
ParameterDescription
newText *
Type: string
Default:
n/a
New/updated text that you want to add in place of the existing message.

Output

An awaitable Task.

Basic usage

Correct the number of the support ticket you sent to 78398.

await 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:

  • SetListeningForUpdates() — listen for Message object update information.
  • OnMessageUpdated — add a single event handler to a single Message object update.
  • AddListenerToMessagesUpdate() — add a single event handler to each Message object update from the provided list.

Method signature

These methods take the following parameters:

  • SetListeningForUpdates()

    message.SetListeningForUpdates(bool listen)
  • 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

ParameterRequired in SetListeningForUpdatesRequired in OnMessageUpdatedRequired in AddListenerToMessagesUpdate()Description
listen
Type: bool
Default:
n/a
Yes
n/a
n/a
Whether to listen to Message updates from server.
channelId
Type: string
Default:
n/a
No
No
Yes
The channel ID for which to check the update events.
messageTimeTokens
Type: List<string>
Default:
List of timetokens of messages for which to check the update events.
No
Yes
n/a
listener
Type: Action<Message>
Default:
n/a
No
Yes
Yes
The definition of the custom behavior to be executed when detecting message changes.

Output

These methods don't return anything.

Basic usage

  • SetListeningForUpdates() and OnMessageUpdated

    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.SetListeningForUpdates(true);
    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 the support channel.

    if (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;

    show all 25 lines
Last updated on