2022-07-30 12:34:04 -04:00
NIP-25
======
Reactions
---------
2023-11-15 19:42:51 -05:00
`draft` `optional`
2022-07-30 12:34:04 -04:00
2024-09-10 11:43:25 -04:00
A reaction is a `kind 7` event that is used to indicate user reactions to other events. A
2024-09-10 12:33:03 -04:00
reaction's `content` field MUST include user-generated-content indicating the value of the
reaction.
2022-07-30 12:34:04 -04:00
2024-09-10 11:36:03 -04:00
A reaction with `content` set to `+` or an empty string MUST be interpreted as a "like" or "upvote".
A reaction with `content` set to `-` MUST be interpreted as a "dislike" or "downvote".
2022-07-30 12:34:04 -04:00
2024-09-10 11:36:03 -04:00
A reaction with `content` set to an emoji or [NIP-30 ](30.md ) custom emoji SHOULD NOT be interpreted
as a "like" or "dislike". Clients MAY instead display this emoji reaction on the post.
2022-07-30 12:34:04 -04:00
Tags
----
2024-06-06 07:57:35 -04:00
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.
2022-07-30 12:34:04 -04:00
2024-06-06 07:57:35 -04:00
The last `e` tag MUST be the `id` of the note that is being reacted to.
2022-07-30 12:34:04 -04:00
2024-06-06 07:57:35 -04:00
The last `p` tag MUST be the `pubkey` of the event being reacted to.
2024-05-04 16:35:39 -04:00
2024-06-06 07:57:35 -04:00
The `a` tag MUST contain the coordinates (`kind:pubkey:d-tag`) of the replaceable being reacted to.
2022-07-30 12:34:04 -04:00
2024-09-10 11:40:02 -04:00
The reaction event SHOULD include a `k` tag with the stringified kind number of the reacted event as
its value, and a `c` tag with the reaction's `content` so that reactions can be indexed and filtered.
2023-10-11 07:55:27 -04:00
2022-07-30 12:34:04 -04:00
Example code
```swift
func make_like_event(pubkey: String, privkey: String, liked: NostrEvent) -> NostrEvent {
2024-06-06 07:57:35 -04:00
var tags: [[String]] = liked.tags.filter {
tag in tag.count >= 2 & & (tag[0] == "e" || tag[0] == "p")
}
2022-07-30 12:34:04 -04:00
tags.append(["e", liked.id])
tags.append(["p", liked.pubkey])
2023-10-11 07:55:27 -04:00
tags.append(["k", liked.kind])
2022-10-30 11:34:14 -04:00
let ev = NostrEvent(content: "+", pubkey: pubkey, kind: 7, tags: tags)
2022-07-30 12:34:04 -04:00
ev.calculate_id()
ev.sign(privkey: privkey)
return ev
}
2023-07-10 11:15:34 -04:00
```
2024-08-08 11:36:08 -04:00
Reactions to a website
---------------------
If the target of the reaction is a website, the reaction MUST be a `kind 17` event and MUST include an `r` tag with the website's URL.
2024-09-03 13:11:31 -04:00
```jsonc
2024-08-08 11:36:08 -04:00
{
"kind": 17,
"content": "⭐",
"tags": [
["r", "https://example.com/"]
],
2024-09-03 13:11:31 -04:00
// other fields...
2024-08-08 11:36:08 -04:00
}
```
URLs SHOULD be [normalized ](https://datatracker.ietf.org/doc/html/rfc3986#section-6 ), so that reactions to the same website are not omitted from queries.
A fragment MAY be attached to the URL, to react to a section of the page.
It should be noted that a URL with a fragment is not considered to be the same URL as the original.
2023-07-10 11:15:34 -04:00
Custom Emoji Reaction
---------------------
2023-07-13 20:08:03 -04:00
The client may specify a custom emoji ([NIP-30](30.md)) `:shortcode:` in the
2023-07-10 11:15:34 -04:00
reaction content. The client should refer to the emoji tag and render the
content as an emoji if shortcode is specified.
2024-09-03 13:11:31 -04:00
```jsonc
2023-07-10 11:15:34 -04:00
{
"kind": 7,
"content": ":soapbox:",
"tags": [
["emoji", "soapbox", "https://gleasonator.com/emoji/Gleasonator/soapbox.png"]
],
2024-09-03 13:11:31 -04:00
// other fields...
2023-07-10 11:15:34 -04:00
}
```
The content can be set only one `:shortcode:` . And emoji tag should be one.