mirror of
https://github.com/nostr-protocol/nips.git
synced 2024-12-22 16:35:52 -05:00
77 lines
2.4 KiB
Markdown
77 lines
2.4 KiB
Markdown
|
|
NIP-25
|
|
======
|
|
|
|
Reactions
|
|
---------
|
|
|
|
`draft` `optional`
|
|
|
|
A reaction is a `kind 7` event that is used to react to other events.
|
|
|
|
The generic reaction, represented by the `content` set to a `+` string, SHOULD
|
|
be interpreted as a "like" or "upvote".
|
|
|
|
A reaction with `content` set to `-` SHOULD be interpreted as a "dislike" or
|
|
"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
|
|
separate tallies.
|
|
|
|
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",
|
|
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 "+".
|
|
|
|
Tags
|
|
----
|
|
|
|
The reaction event SHOULD include `e` and `p` tags from the note the user is
|
|
reacting to. 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.
|
|
|
|
The last `e` tag MUST be the `id` of the note that is being reacted to.
|
|
|
|
The last `p` tag MUST be the `pubkey` of the event being reacted to.
|
|
|
|
The reaction event MAY include a `k` tag with the stringified kind number
|
|
of the reacted event as its value.
|
|
|
|
Example code
|
|
|
|
```swift
|
|
func make_like_event(pubkey: String, privkey: String, liked: NostrEvent) -> NostrEvent {
|
|
var tags: [[String]] = liked.tags.filter {
|
|
tag in tag.count >= 2 && (tag[0] == "e" || tag[0] == "p")
|
|
}
|
|
tags.append(["e", liked.id])
|
|
tags.append(["p", liked.pubkey])
|
|
tags.append(["k", liked.kind])
|
|
let ev = NostrEvent(content: "+", pubkey: pubkey, kind: 7, tags: tags)
|
|
ev.calculate_id()
|
|
ev.sign(privkey: privkey)
|
|
return ev
|
|
}
|
|
```
|
|
|
|
Custom Emoji Reaction
|
|
---------------------
|
|
|
|
The client may specify a custom emoji ([NIP-30](30.md)) `:shortcode:` in the
|
|
reaction content. The client should refer to the emoji tag and render the
|
|
content as an emoji if shortcode is specified.
|
|
|
|
```json
|
|
{
|
|
"kind": 7,
|
|
"content": ":soapbox:",
|
|
"tags": [
|
|
["emoji", "soapbox", "https://gleasonator.com/emoji/Gleasonator/soapbox.png"]
|
|
],
|
|
"pubkey": "79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6",
|
|
"created_at": 1682790000
|
|
}
|
|
```
|
|
|
|
The content can be set only one `:shortcode:`. And emoji tag should be one.
|