Nostr.Event.SimpleGroups (Nostr Lib v0.2.1) (event) (nip51)

View Source

Simple Groups List (Kind 10009)

A list of NIP-29 groups the user is in. Contains references to groups via group tags (group id + relay URL + optional name) and r tags for relays.

Defined in NIP 51 https://github.com/nostr-protocol/nips/blob/master/51.md

Summary

Functions

Creates a new simple groups list (kind 10009).

Parses a kind 10009 event into a SimpleGroups struct.

Types

group_entry()

@type group_entry() :: %{id: binary(), relay: URI.t(), name: binary() | nil}

t()

@type t() :: %Nostr.Event.SimpleGroups{
  event: Nostr.Event.t(),
  groups: [group_entry()],
  relays: [URI.t()]
}

Functions

create(groups, opts \\ [])

@spec create([map() | tuple()], Keyword.t()) :: t()

Creates a new simple groups list (kind 10009).

Arguments

  • groups - List of group entries (see formats below)
  • opts - Optional event arguments, including :relays for r tags

Group Entry Formats

Groups can be specified as:

  • %{id: "group-id", relay: "wss://relay.com"} - Map with id and relay
  • %{id: "group-id", relay: "wss://relay.com", name: "Group Name"} - With optional name
  • {"group-id", "wss://relay.com"} - Tuple format
  • {"group-id", "wss://relay.com", "Group Name"} - Tuple with name

Options

  • :relays - List of relay URLs to include as r tags
  • :pubkey - Event author pubkey
  • :created_at - Event timestamp

Example

SimpleGroups.create([
  %{id: "group1", relay: "wss://relay.com"},
  {"group2", "wss://other-relay.com", "My Group"}
], relays: ["wss://relay.com", "wss://other-relay.com"])

parse(event)

@spec parse(Nostr.Event.t()) :: t()

Parses a kind 10009 event into a SimpleGroups struct.