Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/pages/docs/messages/updates-deletes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ meta_description: "Update and delete messages published to a channel, and retrie
Message updates and deletes are currently Experimental, meaning the API or behaviour may change in response to customer feedback without a major SDK release.
</Aside>

You can update and delete messages that have been published to a channel, for usecases such as:
You can update and delete messages that have been published to a channel, for use cases such as:

* **Message editing** - allow users to edit their messages in chat-like applications
* **Content moderation** - remove or edit inappropriate content after publication
* **Gradual message building** - a message can be published while still unfinished, and then repeatedly edited with more complete information, so that someone querying history once the message is complete will only see the final version

Updating or deleting a message does not modify any messages that have been received by subscribing clients in-place: a given Message obect is immutable. Rather, it publishes a new message to the channel, with an action of `message.update` or `message.delete`, with the same `serial` as the original message, that subscribing clients can see and act on.
Updating or deleting a message does not modify any messages that have been received by subscribing clients in-place: a given Message object is immutable. Rather, it publishes a new message to the channel, with an action of `message.update` or `message.delete`, with the same `serial` as the original message, that subscribing clients can see and act on.

It also replaces the original message in message history, so history queries will see the latest version of the message (but in the place in history of the original).

Expand Down Expand Up @@ -49,7 +49,7 @@ const realtime = new Ably.Realtime({ key: '{{API_KEY}}' });
// This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
const channel = realtime.channels.get('updates:example');

// First subscribe to a messages
// First subscribe to messages
await channel.subscribe((msg) => {
if (msg.data === 'original-data') {
// Publish an update
Expand Down Expand Up @@ -79,7 +79,7 @@ const realtime = new Ably.Realtime({ key: '{{API_KEY}}' });
// This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
const channel = realtime.channels.get('updates:example');

// First subscribe to a messages
// First subscribe to messages
await channel.subscribe((msg) => {
if (msg.data === 'original-data') {
// Publish an update
Expand Down Expand Up @@ -132,7 +132,7 @@ When updating a message, you can optionally provide metadata about the update op
| description | A description of why the update was made. | String |
| metadata | Additional metadata about the update operation. | Object |

This metadata will end up in the message's `version` property. See [Message version structure](http://localhost:8000/docs/messages/updates-deletes#version-structure) for what this looks like.
This metadata will end up in the message's `version` property. See [Message version structure](/docs/messages/updates-deletes#version-structure) for what this looks like.

## Delete a message <a id="delete"/>

Expand All @@ -150,7 +150,7 @@ const realtime = new Ably.Realtime({ key: '{{API_KEY}}' });
// This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
const channel = realtime.channels.get('updates:example');

// First subscribe to a messages
// First subscribe to messages
await channel.subscribe((msg) => {
if (msg.data === 'original-data') {
// Publish a delete
Expand All @@ -159,7 +159,7 @@ await channel.subscribe((msg) => {

// Second way: publish a new Message using the serial
const msg2 = { serial: msg.serial };
await channel.updateMessage(msg2, { description: 'reason for second update' });
await channel.deleteMessage(msg2, { description: 'reason for second delete' });
}
});

Expand All @@ -175,7 +175,7 @@ const realtime = new Ably.Realtime({ key: '{{API_KEY}}' });
// This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
const channel = realtime.channels.get('updates:example');

// First subscribe to a messages
// First subscribe to messages
await channel.subscribe((msg) => {
if (msg.data === 'original-data') {
// Publish a delete
Expand All @@ -184,7 +184,7 @@ await channel.subscribe((msg) => {

// Second way: publish a new Message using the serial
const msg2 = { serial: msg.serial };
await channel.updateMessage(msg2, { description: 'reason for second update' });
await channel.deleteMessage(msg2, { description: 'reason for second delete' });
}
});

Expand Down Expand Up @@ -223,7 +223,7 @@ When deleting a message, you can optionally provide metadata:
| description | A description of why the delete was made. | String |
| metadata | Additional metadata about the delete operation. | Object |

This metadata will end up in the message's `version` property. See [Message version structure](http://localhost:8000/docs/messages/updates-deletes#version-structure) for what this looks like.
This metadata will end up in the message's `version` property. See [Message version structure](/docs/messages/updates-deletes#version-structure) for what this looks like.

## Get the latest version of a message <a id="get"/>

Expand Down