diff options
Diffstat (limited to '25.md')
| -rw-r--r-- | 25.md | 46 |
1 files changed, 35 insertions, 11 deletions
| @@ -5,9 +5,9 @@ NIP-25 | |||
| 5 | Reactions | 5 | Reactions |
| 6 | --------- | 6 | --------- |
| 7 | 7 | ||
| 8 | `draft` `optional` `author:jb55` | 8 | `draft` `optional` |
| 9 | 9 | ||
| 10 | A reaction is a `kind 7` note that is used to react to other notes. | 10 | A reaction is a `kind 7` event that is used to react to other events. |
| 11 | 11 | ||
| 12 | The generic reaction, represented by the `content` set to a `+` string, SHOULD | 12 | The generic reaction, represented by the `content` set to a `+` string, SHOULD |
| 13 | be interpreted as a "like" or "upvote". | 13 | be interpreted as a "like" or "upvote". |
| @@ -18,32 +18,56 @@ downvote or dislike on a post. A client MAY also choose to tally likes against | |||
| 18 | dislikes in a reddit-like system of upvotes and downvotes, or display them as | 18 | dislikes in a reddit-like system of upvotes and downvotes, or display them as |
| 19 | separate tallies. | 19 | separate tallies. |
| 20 | 20 | ||
| 21 | The `content` MAY be an emoji, in this case it MAY be interpreted as a "like" or "dislike", | 21 | The `content` MAY be an emoji, or [NIP-30](30.md) custom emoji in this case it MAY be interpreted as a "like" or "dislike", |
| 22 | or the client MAY display this emoji reaction on the post. | 22 | or the client MAY display this emoji reaction on the post. If the `content` is an empty string then the client should |
| 23 | consider it a "+". | ||
| 23 | 24 | ||
| 24 | Tags | 25 | Tags |
| 25 | ---- | 26 | ---- |
| 26 | 27 | ||
| 27 | The reaction event SHOULD include `e` and `p` tags from the note the user is | 28 | The reaction event SHOULD include `e` and `p` tags from the note the user is reacting to (and optionally `a` tags if the target is a replaceable event). This allows users to be notified of reactions to posts they were mentioned in. Including the `e` tags enables clients to pull all the reactions associated with individual posts or all the posts in a thread. `a` tags enables clients to seek reactions for all versions of a replaceable event. |
| 28 | reacting to. This allows users to be notified of reactions to posts they were | ||
| 29 | mentioned in. Including the `e` tags enables clients to pull all the reactions | ||
| 30 | associated with individual posts or all the posts in a thread. | ||
| 31 | 29 | ||
| 32 | The last `e` tag MUST be the `id` of the note that is being reacted to. | 30 | The last `e` tag MUST be the `id` of the note that is being reacted to. |
| 33 | 31 | ||
| 34 | The last `p` tag MUST be the `pubkey` of the event being reacted to. | 32 | The last `p` tag MUST be the `pubkey` of the event being reacted to. |
| 35 | 33 | ||
| 34 | The `a` tag MUST contain the coordinates (`kind:pubkey:d-tag`) of the replaceable being reacted to. | ||
| 35 | |||
| 36 | The reaction event MAY include a `k` tag with the stringified kind number of the reacted event as its value. | ||
| 37 | |||
| 36 | Example code | 38 | Example code |
| 37 | 39 | ||
| 38 | ```swift | 40 | ```swift |
| 39 | func make_like_event(pubkey: String, privkey: String, liked: NostrEvent) -> NostrEvent { | 41 | func make_like_event(pubkey: String, privkey: String, liked: NostrEvent) -> NostrEvent { |
| 40 | var tags: [[String]] = liked.tags.filter { | 42 | var tags: [[String]] = liked.tags.filter { |
| 41 | tag in tag.count >= 2 && (tag[0] == "e" || tag[0] == "p") | 43 | tag in tag.count >= 2 && (tag[0] == "e" || tag[0] == "p") |
| 42 | } | 44 | } |
| 43 | tags.append(["e", liked.id]) | 45 | tags.append(["e", liked.id]) |
| 44 | tags.append(["p", liked.pubkey]) | 46 | tags.append(["p", liked.pubkey]) |
| 47 | tags.append(["k", liked.kind]) | ||
| 45 | let ev = NostrEvent(content: "+", pubkey: pubkey, kind: 7, tags: tags) | 48 | let ev = NostrEvent(content: "+", pubkey: pubkey, kind: 7, tags: tags) |
| 46 | ev.calculate_id() | 49 | ev.calculate_id() |
| 47 | ev.sign(privkey: privkey) | 50 | ev.sign(privkey: privkey) |
| 48 | return ev | 51 | return ev |
| 49 | } | 52 | } |
| 53 | ``` | ||
| 54 | |||
| 55 | Custom Emoji Reaction | ||
| 56 | --------------------- | ||
| 57 | |||
| 58 | The client may specify a custom emoji ([NIP-30](30.md)) `:shortcode:` in the | ||
| 59 | reaction content. The client should refer to the emoji tag and render the | ||
| 60 | content as an emoji if shortcode is specified. | ||
| 61 | |||
| 62 | ```json | ||
| 63 | { | ||
| 64 | "kind": 7, | ||
| 65 | "content": ":soapbox:", | ||
| 66 | "tags": [ | ||
| 67 | ["emoji", "soapbox", "https://gleasonator.com/emoji/Gleasonator/soapbox.png"] | ||
| 68 | ], | ||
| 69 | ...other fields | ||
| 70 | } | ||
| 71 | ``` | ||
| 72 | |||
| 73 | The content can be set only one `:shortcode:`. And emoji tag should be one. | ||