upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/C7.md
blob: b1e1c8cab0aa832586827f4e019c98dfec463667 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
NIP-C7
======

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
{
  "kind": 9,
  "content": "GM",
  "tags": []
}
```

## Reply

A reply to a `kind 9` is an additional `kind 9` which quotes the parent using a `q` tag.

```json
{
  "kind": 9,
  "content": "nostr:nevent1...\nyes",
  "tags": [
    ["q", <event-id>, <relay-url>, <pubkey>]
  ]
}
```

## 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.