Updating messages
Since PubNub stores all messages in a time-series database, it doesn’t expose an API to directly update a message. However, clients can update messages by passing another version of the message using the Message Reactions feature.
User ID / UUID
User ID is also referred to as UUID
/uuid
in some APIs and server responses but holds the value of the userId
parameter you set during initialization.
Update a message
Use the addMessageAction
method to update a published message after it has been published by adding an action to it.
- JavaScript
- Swift
- Java
- Unity
pubnub.addMessageAction(
{
channel: 'main'
messageTimetoken: '15610547826970040',
action: {
type: 'updated',
value: 'Hello World! (fixed typo)',
},
},
function(status, response) {
}
);
extension MyAppMessageAction: MessageAction {}
let action = MyAppMessageAction(type: "updated", value: "Hello World! (fixed typo)")
pubnub.addMessageAction(
channel: "main",
message: action,
messageTimetoken: 15610547826970040
) { result in
switch result {
case let .success(response):
print("Successfully Message Reaction Add Response: \(response)")
case let .failure(error):
print("Error from failed response: \(error.localizedDescription)")
}
show all 16 linespubnub.addMessageAction()
.channel("main")
.messageAction(new PNMessageAction()
.setType("updated")
.setValue("Hello World! (fixed typo)")
.setMessageTimetoken(15610547826970040L)
)
.async(result -> {
result.onSuccess(res -> {
System.out.println(res.getType());
System.out.println(res.getValue());
System.out.println(res.getUuid());
System.out.println(res.getActionTimetoken());
System.out.println(res.getMessageTimetoken());
}).onFailure(exception -> {
show all 18 linesMessageActionAdd messageAct = new MessageActionAdd();
messageAct.ActionType = "updated";
messageAct.ActionValue = "Hello World! (fixed typo)";
pubnub.AddMessageActions().Channel("main").MessageAction(messageAct).MessageTimetoken(15610547826970040).Async((result, status) => {
if (!status.Error) {
Debug.Log("result.ActionTimetoken: " + result.ActionTimetoken);
Debug.Log("result.ActionType: " + result.ActionType);
Debug.Log("result.ActionValue: " + result.ActionValue);
Debug.Log("result.MessageTimetoken: " + result.MessageTimetoken);
Debug.Log("result.UserID: " + result.UserId);
} else {
Debug.Log(status.Error);
Debug.Log(status.ErrorData.Info);
}
show all 16 linesMessage update event
PubNub triggers events when messages are updated using message reactions. Clients subscribed to the channel will receive these events.
{
"channel":"main",
"subscription":null,
"timetoken":"15610547826970040",
"publisher":"user-1",
"message":{
"source":"actions",
"version":"1.0",
"action":"added",
"data":{
"type":"updated",
"value":"Hello World! (fixed typo)",
"messageTimetoken":"15610547826970040",
"actionTimetoken":"15610547826999081"
}
show all 17 lines