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: 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
These methods let you receive updates when specific messages and related message reactions are added, edited, or removed on other clients:
SetListeningForUpdates()
— 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:
-
SetListeningForUpdates()
1message.SetListeningForUpdates(bool listen)
-
OnMessageUpdated
1// event on the user entity
2public event Action<Message> OnMessageUpdated;
3// needs a corresponding event handler
4void EventHandler(Message message) -
AddListenerToMessagesUpdate()
1chat.AddListenerToMessagesUpdate(
2 string channelId,
3 List<string> messageTimeTokens,
4 Action<Message> listener
5)
Input
Parameter | Required in SetListeningForUpdates | Required in OnMessageUpdated | Required 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: n/a | No | No | Yes | List of timetokens of messages for which to check the update events. |
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.
Sample code
-
SetListeningForUpdates()
andOnMessageUpdated
Get message and message reaction-related updates for all messages published on the
support
channel.1
-
AddListenerToMessagesUpdate()
Get message and message reaction-related updates for 10 historical messages older than the timetoken
15343325214676133
published on thesupport
channel.1