mirror of
https://github.com/nostr-protocol/nips.git
synced 2026-07-22 07:48:25 +00:00
edit chat messages.
This commit is contained in:
45
C7.md
45
C7.md
@@ -6,6 +6,12 @@ Chats
|
||||
|
||||
`draft` `optional`
|
||||
|
||||
This NIP describes simple chat messages.
|
||||
|
||||
These messages behave like `kind:1` notes syntactically, but are intended to be used in the compĺetely different circumstance of sequential and localized group chats in which ordered consistency is expected, such as, for example, [NIP-29](29.md) rooms, in which a shared relay acts as the (temporary) single source of truth for all the chat messages.
|
||||
|
||||
## Definition
|
||||
|
||||
A chat message is a `kind 9` event.
|
||||
|
||||
```json
|
||||
@@ -16,6 +22,8 @@ A chat message is a `kind 9` event.
|
||||
}
|
||||
```
|
||||
|
||||
## Reply
|
||||
|
||||
A reply to a `kind 9` is an additional `kind 9` which quotes the parent using a `q` tag.
|
||||
|
||||
```json
|
||||
@@ -27,3 +35,40 @@ A reply to a `kind 9` is an additional `kind 9` which quotes the parent using a
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Edit
|
||||
|
||||
Because these messages are always received in order, an edit can just be another message in the stream that refers to a previous message.
|
||||
|
||||
The only difference between an edit and a normal message is that it will have a special `"edit"` tag (and an `EDIT` label prefixing the `content`) that allows clients to optionally parse it as a special edit action and have its changes applied to a previous message in the chat state. For that it uses a simple human-readable text-diff syntax in order to encode a "patch".
|
||||
|
||||
Simpler clients that do not want to support this can be just fine with just displaying the edits as normal text messages.
|
||||
|
||||
```json
|
||||
{
|
||||
"kind": 9,
|
||||
"content": "EDIT\n<patch-content>",
|
||||
"tags": [
|
||||
["e", <event-id-being-edited>],
|
||||
["edit"]
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
In which `<patch-content>` is formed by one or more lines of
|
||||
|
||||
```
|
||||
<index> -<number-of-characters-deleted> +<number-of-characters-inserted> <actual-characters-inserted>
|
||||
```
|
||||
|
||||
For example, if the original text was `Their should hire more internets to help them` and was edited to `They should hire more interns to help` the patch will be:
|
||||
|
||||
```
|
||||
0 -5 +4 They
|
||||
23 -9 +7 interns
|
||||
40 -5 +0
|
||||
```
|
||||
|
||||
The indexes and amounts refer to unicode characters, not bytes.
|
||||
|
||||
When generating these diffs clients should prefer to do it over full words instead of over characters, for readability.
|
||||
|
||||
Reference in New Issue
Block a user