View Source NostrBasics.Models.ContactList (NostrBasics v0.1.5)

Represents a nostr user's contact list... and relays...

Note that, strangely, the pubkey's relays are stored in that structure even if it has nothing to do with a contact list at all.

Link to this section Summary

Functions

Converts an %Event{} into a %ContactList{}

Converts an %ContactList{} into an %Event{}

Link to this section Types

@type t() :: %NostrBasics.Models.ContactList{
  contacts: term(),
  pubkey: term(),
  relays: term()
}

Link to this section Functions

Link to this function

add(contact_list, pubkey)

View Source
@spec from_event(NostrBasics.Event.t()) :: {:ok, t()} | {:error, String.t()}

Converts an %Event{} into a %ContactList{}

examples

Examples

iex> %NostrBasics.Event{
...>   id: "811574fe1f5b49e301b8a554d71f7a63314efc540b1778e2ad813a564b12739b",
...>   pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
...>   created_at: ~U[2023-02-11 13:15:17Z],
...>   kind: 3,
...>   tags: [["p", "5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2", ""]],
...>   content: ~s({"wss://nos.lol":{"write":false,"read":true}}),
...>   sig: <<0xc177a56607ef5f5d137478aeca851791a35514f5ad55f8e0e3901f561c004cc1d15a1b048a03c6f4b01e5c675ecd132fb0b5a2cc3cc7562e848fe5a968c658c5::512>>
...> }
...> |> NostrBasics.Models.ContactList.from_event
{
  :ok,
  %NostrBasics.Models.ContactList{
    pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
    contacts: [
      %NostrBasics.Models.Contact{
        pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
        main_relay: "",
        petname: nil
      }
    ],
    relays: [%{url: "wss://nos.lol", read?: true, write?: false}]
  }
}
Link to this function

remove(contact_list, pubkey_to_remove)

View Source
@spec to_event(t()) :: NostrBasics.Event.t()

Converts an %ContactList{} into an %Event{}

examples

Examples

iex> %NostrBasics.Models.ContactList{ ...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>, ...> contacts: [ ...> %NostrBasics.Models.Contact{ ...> pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>, ...> main_relay: "", ...> petname: nil ...> } ...> ], ...> relays: [%{url: "wss://nos.lol", read?: true, write?: false}] ...> } ...> |> NostrBasics.Models.ContactList.to_event ...> |> Map.put(:created_at, ~U[2023-02-13 14:09:30.382207Z]) %NostrBasics.Event{

pubkey: <<0x5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2::256>>,
kind: 3,
created_at: ~U[2023-02-13 14:09:30.382207Z],
tags: [
  ["p", "5ab9f2efb1fda6bc32696f6f3fd715e156346175b93b6382099d23627693c3f2", ""]
],
content: ~s({"wss://nos.lol":{"read":true,"write":false}})

}