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

ParameterTypeRequiredDefaultDescription
newTextstringYesn/aNew/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 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:

  • 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

ParameterTypeRequired in StartListeningForUpdatesRequired in OnMessageUpdatedRequired in AddListenerToMessagesUpdate()DefaultDescription
messageMessageNoYesNon/aThe message object to handle the update event for.
channelIdstringNoNoYesn/aThe channel ID for which to check the update events.
messageTimeTokensList<string>NoYesn/aList of timetokens of messages for which to check the update events.
listenerAction<Message>NoYesYesn/aThe definition of the custom behavior to be executed when detecting message changes.

Output

These operations don't return any data.

Basic usage

  • StartListeningForUpdates() 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.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 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