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
| Parameter | Description |
|---|---|
newText *Type: stringDefault: 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 singleMessageobject.StreamUpdatesOn()checks message and message reaction-related updates on a list ofMessageobjects.
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 theOnMessageUpdatedevent 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) -
OnMessageUpdated1// event on the Message entity
2public event Action<Message> OnMessageUpdated;
3// needs a corresponding event handler
4void EventHandler(Message message) -
StreamUpdatesOn()(static) - returns all messages1Message.StreamUpdatesOn(
2 List<Message> messages,
3 Action<List<Message>> listener
4) -
StreamUpdatesOn()(static) - returns individual message with change type1Message.StreamUpdatesOn(
2 List<Message> messages,
3 Action<Message, ChatEntityChangeType> listener
4)
Input
| Parameter | Required in StreamUpdates() | Required in OnMessageUpdated | Required in StreamUpdatesOn() | Description |
|---|---|---|---|---|
streamType: boolDefault: n/a | Yes | n/a | n/a | Whether to start (true) or stop (false) listening to Message object updates. |
messagesType: List<Message>Default: n/a | No | No | Yes | List of Message objects for which you want to get updates. |
listenerType: 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. |
listenerType: 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()andOnMessageUpdatedGet message and message reaction-related updates for all messages published on the
supportchannel.1 -
StreamUpdatesOn()with individual message updatesGet message and message reaction-related updates for messages from the
supportchannel. The callback receives each updated message individually along with the change type.1