diff options
Diffstat (limited to 'C7.md')
| -rw-r--r-- | C7.md | 45 |
1 files changed, 45 insertions, 0 deletions
| @@ -6,6 +6,12 @@ Chats | |||
| 6 | 6 | ||
| 7 | `draft` `optional` | 7 | `draft` `optional` |
| 8 | 8 | ||
| 9 | This NIP describes simple chat messages. | ||
| 10 | |||
| 11 | 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. | ||
| 12 | |||
| 13 | ## Definition | ||
| 14 | |||
| 9 | A chat message is a `kind 9` event. | 15 | A chat message is a `kind 9` event. |
| 10 | 16 | ||
| 11 | ```json | 17 | ```json |
| @@ -16,6 +22,8 @@ A chat message is a `kind 9` event. | |||
| 16 | } | 22 | } |
| 17 | ``` | 23 | ``` |
| 18 | 24 | ||
| 25 | ## Reply | ||
| 26 | |||
| 19 | A reply to a `kind 9` is an additional `kind 9` which quotes the parent using a `q` tag. | 27 | A reply to a `kind 9` is an additional `kind 9` which quotes the parent using a `q` tag. |
| 20 | 28 | ||
| 21 | ```json | 29 | ```json |
| @@ -27,3 +35,40 @@ A reply to a `kind 9` is an additional `kind 9` which quotes the parent using a | |||
| 27 | ] | 35 | ] |
| 28 | } | 36 | } |
| 29 | ``` | 37 | ``` |
| 38 | |||
| 39 | ## Edit | ||
| 40 | |||
| 41 | Because these messages are always received in order, an edit can just be another message in the stream that refers to a previous message. | ||
| 42 | |||
| 43 | 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". | ||
| 44 | |||
| 45 | Simpler clients that do not want to support this can be just fine with just displaying the edits as normal text messages. | ||
| 46 | |||
| 47 | ```json | ||
| 48 | { | ||
| 49 | "kind": 9, | ||
| 50 | "content": "EDIT\n<patch-content>", | ||
| 51 | "tags": [ | ||
| 52 | ["e", <event-id-being-edited>], | ||
| 53 | ["edit"] | ||
| 54 | ] | ||
| 55 | } | ||
| 56 | ``` | ||
| 57 | |||
| 58 | In which `<patch-content>` is formed by one or more lines of | ||
| 59 | |||
| 60 | ``` | ||
| 61 | <index> -<number-of-characters-deleted> +<number-of-characters-inserted> <actual-characters-inserted> | ||
| 62 | ``` | ||
| 63 | |||
| 64 | 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: | ||
| 65 | |||
| 66 | ``` | ||
| 67 | 0 -5 +4 They | ||
| 68 | 23 -9 +7 interns | ||
| 69 | 40 -5 +0 | ||
| 70 | ``` | ||
| 71 | |||
| 72 | The indexes and amounts refer to unicode characters, not bytes. | ||
| 73 | |||
| 74 | When generating these diffs clients should prefer to do it over full words instead of over characters, for readability. | ||