diff options
Diffstat (limited to '17.md')
| -rw-r--r-- | 17.md | 51 |
1 files changed, 47 insertions, 4 deletions
| @@ -8,7 +8,11 @@ Private Direct Messages | |||
| 8 | 8 | ||
| 9 | This NIP defines an encrypted direct messaging scheme using [NIP-44](44.md) encryption and [NIP-59](59.md) seals and gift wraps. | 9 | This NIP defines an encrypted direct messaging scheme using [NIP-44](44.md) encryption and [NIP-59](59.md) seals and gift wraps. |
| 10 | 10 | ||
| 11 | ## Direct Message Kind | 11 | ## Message kinds |
| 12 | |||
| 13 | Each of these message kinds can be gift-wrapped as described afterwards. Clients have to first unwrap them to then see their kinds. | ||
| 14 | |||
| 15 | ### Direct Message Kind | ||
| 12 | 16 | ||
| 13 | Kind `14` is a chat message. `p` tags identify one or more receivers of the message. | 17 | Kind `14` is a chat message. `p` tags identify one or more receivers of the message. |
| 14 | 18 | ||
| @@ -31,7 +35,7 @@ Kind `14` is a chat message. `p` tags identify one or more receivers of the mess | |||
| 31 | 35 | ||
| 32 | `.content` MUST be plain text. Fields `id` and `created_at` are required. | 36 | `.content` MUST be plain text. Fields `id` and `created_at` are required. |
| 33 | 37 | ||
| 34 | An `e` tag denotes the direct parent message this post is replying to. | 38 | An `e` tag denotes the direct parent message this post is replying to. |
| 35 | 39 | ||
| 36 | `q` tags MAY be used when citing events in the `.content` with [NIP-21](21.md). | 40 | `q` tags MAY be used when citing events in the `.content` with [NIP-21](21.md). |
| 37 | 41 | ||
| @@ -41,7 +45,7 @@ An `e` tag denotes the direct parent message this post is replying to. | |||
| 41 | 45 | ||
| 42 | Kind `14`s MUST never be signed. If it is signed, the message might leak to relays and become **fully public**. | 46 | Kind `14`s MUST never be signed. If it is signed, the message might leak to relays and become **fully public**. |
| 43 | 47 | ||
| 44 | ## File Message Kind | 48 | ### File Message Kind |
| 45 | 49 | ||
| 46 | ```jsonc | 50 | ```jsonc |
| 47 | { | 51 | { |
| @@ -59,7 +63,6 @@ Kind `14`s MUST never be signed. If it is signed, the message might leak to rela | |||
| 59 | ["decryption-key", "<decryption-key>"], | 63 | ["decryption-key", "<decryption-key>"], |
| 60 | ["decryption-nonce", "<decryption-nonce>"], | 64 | ["decryption-nonce", "<decryption-nonce>"], |
| 61 | ["x", "<the SHA-256 hexencoded string of the file>"], | 65 | ["x", "<the SHA-256 hexencoded string of the file>"], |
| 62 | // rest of tags... | ||
| 63 | ], | 66 | ], |
| 64 | "content": "<file-url>" | 67 | "content": "<file-url>" |
| 65 | } | 68 | } |
| @@ -82,6 +85,46 @@ Kind `15` is used for sending encrypted file event messages: | |||
| 82 | 85 | ||
| 83 | Just like kind `14`, kind `15`s MUST never be signed. | 86 | Just like kind `14`, kind `15`s MUST never be signed. |
| 84 | 87 | ||
| 88 | ### "Seen" event | ||
| 89 | |||
| 90 | An event of kind `30016` that CAN be emitted automatically by a client whenever a chat window is displayed to the user, even if the user hasn't acted on it. | ||
| 91 | |||
| 92 | ```jsonc | ||
| 93 | { | ||
| 94 | "id": "<usual hash>", | ||
| 95 | "pubkey": "<sender-pubkey>", | ||
| 96 | "created_at": "<current-time>", | ||
| 97 | "kind": 30016, | ||
| 98 | "tags": [ | ||
| 99 | ["d", "<subject>"], | ||
| 100 | ["seen", "<latest_message_id>", "<previous_id>", "<...>"] | ||
| 101 | ], | ||
| 102 | "content": "" | ||
| 103 | } | ||
| 104 | ``` | ||
| 105 | |||
| 106 | - `d` must be set to the conversation subject, or it can be empty or omitted in the most common case of a `<subject>` not existing. | ||
| 107 | - `seen` must be set to the id of the last messages seen. It can contain any number of ids, ordered from the newest to the oldest. | ||
| 108 | |||
| 109 | This event SHOULD be discarded whenever a new event is received for the same conversation. | ||
| 110 | |||
| 111 | Any messages with timestamp before the last item in the `seen` array are assumed to have been seen. | ||
| 112 | |||
| 113 | If there is a gap in the `seen` array that indicates a message may have been missed for whatever reason. | ||
| 114 | |||
| 115 | For example: | ||
| 116 | |||
| 117 | - `alice` sends message `aaaa` | ||
| 118 | - `alice` sends message `bbbb` | ||
| 119 | - `alice` sends message `cccc` | ||
| 120 | - `bob` sends event with `["seen", "bbbb", "aaaa"]` | ||
| 121 | - at this point `alice`'s client should display `aaaa` and `bbbb` as seen, `cccc` as unseen | ||
| 122 | - `alice` sends message `dddd` | ||
| 123 | - `alice` sends message `eeee`, which is lost due to relay malfunction | ||
| 124 | - `alice` sends message `ffff` | ||
| 125 | - `bob` sends event with `["seen", "ffff", "dddd", "cccc"]` | ||
| 126 | - at this point `alice`'s client should display all messages as seen, except for `eeee` which should be displayed with an error indicator | ||
| 127 | |||
| 85 | ## Chat Rooms | 128 | ## Chat Rooms |
| 86 | 129 | ||
| 87 | The set of `pubkey` + `p` tags defines a chat room. If a new `p` tag is added or a current one is removed, a new room is created with a clean message history. | 130 | The set of `pubkey` + `p` tags defines a chat room. If a new `p` tag is added or a current one is removed, a new room is created with a clean message history. |