Packages

Connect to the nostr network with Elixir

Current section

Files

Jump to
nostr lib nostr client subscriptions profile_subscription.ex
Raw

lib/nostr/client/subscriptions/profile_subscription.ex

defmodule Nostr.Client.Subscriptions.ProfileSubscription do
use GenServer
alias Nostr.RelaySocket
alias Nostr.Event.Types.EndOfStoredEvents
def start_link([relay_pids, pubkey, subscriber]) do
GenServer.start_link(__MODULE__, %{
relay_pids: relay_pids,
pubkey: pubkey,
subscriber: subscriber
})
end
@impl true
def init(%{relay_pids: relay_pids, pubkey: pubkey} = state) do
relay_pids
|> Enum.map(fn relay_pid ->
RelaySocket.subscribe_profile(relay_pid, pubkey)
end)
{:ok, state}
end
@impl true
def handle_info(profile, %{subscriber: subscriber} = state) do
send(subscriber, profile)
{:noreply, state}
end
@impl true
def handle_info(%EndOfStoredEvents{}, state) do
## nothing to do
{:noreply, state}
end
end