2022-07-30 09:34:04 -07:00
NIP-25
======
Reactions
---------
2023-11-15 21:42:51 -03:00
`draft` `optional`
2022-07-30 09:34:04 -07:00
2023-10-11 20:55:27 +09:00
A reaction is a `kind 7` event that is used to react to other events.
2022-07-30 09:34:04 -07:00
2022-07-31 12:44:40 -07:00
The generic reaction, represented by the `content` set to a `+` string, SHOULD
be interpreted as a "like" or "upvote".
2022-07-30 09:34:04 -07:00
2023-01-01 02:15:08 -05:00
A reaction with `content` set to `-` SHOULD be interpreted as a "dislike" or
2022-07-30 10:09:33 -07:00
"downvote". It SHOULD NOT be counted as a "like", and MAY be displayed as a
downvote or dislike on a post. A client MAY also choose to tally likes against
dislikes in a reddit-like system of upvotes and downvotes, or display them as
2023-04-07 17:38:03 +05:30
separate tallies.
2022-07-30 10:09:33 -07:00
2023-07-06 17:22:42 +09:00
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",
2023-08-10 15:48:53 -05:00
or the client MAY display this emoji reaction on the post. If the `content` is an empty string then the client should
consider it a "+".
2022-07-30 09:34:04 -07:00
Tags
----
2025-02-26 17:06:35 -03:00
There MUST be always an `e` tag set to the `id` of the event that is being reacted to. The `e` tag SHOULD include a relay hint pointing to a relay where the event being reacted to can be found. If a client decides to include other `e` , which not recommended, the target event `id` should be last of the `e` tags.
2022-07-30 09:34:04 -07:00
2025-02-26 17:06:35 -03:00
The SHOULD be a `p` tag set to the `pubkey` of the event being reacted to. If a client decides to include other `p` tags, which not recommended, the target event `pubkey` should be last the `p` tags.
2022-07-30 09:34:04 -07:00
2025-02-26 17:06:35 -03:00
If the event being reacted to is an addressable event, an `a` SHOULD be included together with the `e` tag, it must be set to the coordinates (`kind:pubkey:d-tag` ) of the event being reacted to.
2024-05-04 16:35:39 -04:00
2025-02-26 17:06:35 -03:00
The reaction SHOULD include a `k` tag with the stringified kind number of the reacted event as its value.
2022-07-30 09:34:04 -07:00
2025-02-26 17:06:35 -03:00
**Example code**
2022-07-30 09:34:04 -07:00
```swift
func make_like_event(pubkey: String, privkey: String, liked: NostrEvent) -> NostrEvent {
2025-02-26 17:06:35 -03:00
tags.append(["e", liked.id, liked.source_relays.first ?? ""])
2022-07-30 09:34:04 -07:00
tags.append(["p", liked.pubkey])
2025-02-26 17:06:35 -03:00
tags.append(["k", String(liked.kind)])
2022-10-30 08:34:14 -07:00
let ev = NostrEvent(content: "+", pubkey: pubkey, kind: 7, tags: tags)
2022-07-30 09:34:04 -07:00
ev.calculate_id()
ev.sign(privkey: privkey)
return ev
}
2023-07-11 00:15:34 +09:00
```
2024-08-09 00:36:08 +09: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 20:41:31 +03:30
```jsonc
2024-08-09 00:36:08 +09:00
{
"kind": 17,
"content": "⭐",
"tags": [
["r", "https://example.com/"]
],
2024-09-03 20:41:31 +03:30
// other fields...
2024-08-09 00:36:08 +09: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-11 00:15:34 +09:00
Custom Emoji Reaction
---------------------
2023-07-14 09:08:03 +09:00
The client may specify a custom emoji ([NIP-30 ](30.md )) `:shortcode:` in the
2023-07-11 00:15:34 +09: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 20:41:31 +03:30
```jsonc
2023-07-11 00:15:34 +09:00
{
"kind": 7,
"content": ":soapbox:",
"tags": [
["emoji", "soapbox", "https://gleasonator.com/emoji/Gleasonator/soapbox.png"]
],
2024-09-03 20:41:31 +03:30
// other fields...
2023-07-11 00:15:34 +09:00
}
```
The content can be set only one `:shortcode:` . And emoji tag should be one.