Nostr.NIP36 (Nostr Lib v0.2.0) (nip36)
View SourceNIP-36: Sensitive Content / Content Warning
The content-warning tag enables users to specify if event content needs approval
before being shown. Clients can hide the content until the user acts on it.
Tag Format
["content-warning", "<optional reason>"]Examples
# Extract warning from tags
NIP36.from_tags(event.tags)
# => "Spoilers" | true | nil
# Build a warning tag
NIP36.to_tag("NSFW")
# => %Tag{type: :"content-warning", data: "NSFW"}
# Check if event has warning
NIP36.has_warning?(event)
# => true | falseSee: https://github.com/nostr-protocol/nips/blob/master/36.md
Summary
Functions
Adds a content warning tag to an event.
Extracts content warning from a list of tags.
Checks if an event or list of tags has a content warning.
Removes content warning from an event.
Builds a content-warning tag.
Types
@type warning() :: binary() | true | nil
Content warning value.
nil- no content warningtrue- content warning present but no reason givenbinary()- content warning with reason string
Functions
@spec add_warning(Nostr.Event.t(), binary() | true) :: Nostr.Event.t()
Adds a content warning tag to an event.
If the event already has a content-warning tag, it is replaced.
Examples
iex> event = %Event{tags: []}
iex> NIP36.add_warning(event, "Spoilers").tags
[%Tag{type: :"content-warning", data: "Spoilers", info: []}]
iex> event = %Event{tags: []}
iex> NIP36.add_warning(event).tags
[%Tag{type: :"content-warning", data: "", info: []}]
@spec from_tags([Nostr.Tag.t()]) :: warning()
Extracts content warning from a list of tags.
Returns:
- The reason string if present and non-empty
trueif the tag is present but has no reasonnilif no content-warning tag exists
Examples
iex> tags = [%Tag{type: :"content-warning", data: "Spoilers"}]
iex> NIP36.from_tags(tags)
"Spoilers"
iex> tags = [%Tag{type: :"content-warning", data: ""}]
iex> NIP36.from_tags(tags)
true
iex> NIP36.from_tags([])
nil
@spec has_warning?(Nostr.Event.t() | [Nostr.Tag.t()]) :: boolean()
Checks if an event or list of tags has a content warning.
Examples
iex> NIP36.has_warning?(%Event{tags: [%Tag{type: :"content-warning", data: ""}]})
true
iex> NIP36.has_warning?([%Tag{type: :p, data: "pubkey"}])
false
@spec remove_warning(Nostr.Event.t()) :: Nostr.Event.t()
Removes content warning from an event.
Examples
iex> tags = [%Tag{type: :"content-warning", data: "test"}]
iex> event = %Event{tags: tags}
iex> NIP36.remove_warning(event).tags
[]
@spec to_tag(warning()) :: Nostr.Tag.t() | nil
Builds a content-warning tag.
Examples
iex> NIP36.to_tag("NSFW")
%Tag{type: :"content-warning", data: "NSFW", info: []}
iex> NIP36.to_tag(true)
%Tag{type: :"content-warning", data: "", info: []}
iex> NIP36.to_tag(nil)
nil