On this page

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:

1message.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<ChatOperationResult>.

Sample code

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

1

Get 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 single Message object.
  • StreamUpdatesOn() checks message and message reaction-related updates on a list of Message objects.

Both methods accept a callback function as an argument. The Chat SDK invokes this callback whenever someone adds, edits, or removes 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 actions event listener to receive all messageAction events of type added or removed.

Change types

For details on ChatEntityChangeType values (Updated and Deleted) and their meaning, see Change types. Note that messages always return ChatEntityChangeType.Updated (even for soft deletes).

Stream update behavior
  • StreamUpdates() enables listening for updates on a single message. Use the OnMessageUpdated event to handle changes.
  • StreamUpdatesOn() has two overloads:
    • StreamUpdatesOn(List<Message>, Action<List<Message>>) returns the complete list of messages you're monitoring each time any change occurs to any of them.
    • StreamUpdatesOn(List<Message>, Action<Message, ChatEntityChangeType>) returns only the specific message that was updated along with the type of change.
Hard deletion callbacks

Messages currently don't receive hard deletion callbacks. Only soft deletes (using Delete(soft: true)) will yield a callback with ChatEntityChangeType.Updated. Hard deletes remove the message entirely without triggering update events.

Method naming

Earlier versions used SetListeningForUpdates() to enable streaming. This method has been superseded by StreamUpdates(), though it remains available for backward compatibility.

Method signature

These methods take the following parameters:

  • StreamUpdates()

    1message.StreamUpdates(bool stream)
  • OnMessageUpdated

    1// event on the Message entity
    2public event Action<Message> OnMessageUpdated;
    3// needs a corresponding event handler
    4void EventHandler(Message message)
  • StreamUpdatesOn() (static) - returns all messages

    1Message.StreamUpdatesOn(
    2 List<Message> messages,
    3 Action<List<Message>> listener
    4)
  • StreamUpdatesOn() (static) - returns individual message with change type

    1Message.StreamUpdatesOn(
    2 List<Message> messages,
    3 Action<Message, ChatEntityChangeType> listener
    4)

Input

ParameterRequired in StreamUpdates()Required in OnMessageUpdatedRequired in StreamUpdatesOn()Description
stream
Type: bool
Default:
n/a
Yes
n/a
n/a
Whether to start (true) or stop (false) listening to Message object updates.
messages
Type: List<Message>
Default:
n/a
No
No
Yes
List of Message objects for which you want to get updates.
listener
Type: Action<List<Message>>
Default:
n/a
No
No
Yes (first overload)
Callback that receives the complete list of all messages being monitored each time any change occurs.
listener
Type: Action<Message, ChatEntityChangeType>
Default:
n/a
No
No
Yes (second overload)
Callback that receives the specific message that was updated. Note: The change type is currently always ChatEntityChangeType.Updated for messages.

Output

These methods don't return a value. Updates are delivered through event handlers or callback functions.

Sample code

  • StreamUpdates() and OnMessageUpdated

    Get message and message reaction-related updates for all messages published on the support channel.

    1
    
  • StreamUpdatesOn() with individual message updates

    Get message and message reaction-related updates for messages from the support channel. The callback receives each updated message individually along with the change type.

    1
    
Last updated on