From 0d10303a76c35d95b84bbcca2d54d0b99bcec432 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Fri, 8 May 2026 23:56:31 -0300 Subject: edit chat messages. --- C7.md | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'C7.md') diff --git a/C7.md b/C7.md index 0d94f18..b1e1c8c 100644 --- a/C7.md +++ b/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", + "tags": [ + ["e", ], + ["edit"] + ] +} +``` + +In which `` is formed by one or more lines of + +``` + - + +``` + +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. -- cgit v1.2.3