WIP fetch relays and profile with ruby

This commit is contained in:
2024-10-16 13:32:15 +02:00
parent a08a4746f7
commit 5283f6fce7
4 changed files with 57 additions and 9 deletions

View File

@@ -0,0 +1,38 @@
module NostrManager
class DiscoverUserProfile < NostrManagerService
MAX_EVENTS = 3
def initialize(pubkey:)
@pubkey = pubkey
@relays = Setting.nostr_discovery_relays
end
def call
received_events = 0
profile_events = []
filter = Nostr::Filter.new(
authors: [@pubkey],
kinds: [0],
limit: 1,
)
@relays.each do |url|
event = NostrManager::FetchLatestEvent.call(filter: filter, relay_url: url)
if event.present?
profile_events << event if profile_events.none? { |e| e["id"] == event["id"] }
received_events += 1
end
if received_events >= MAX_EVENTS
puts "Found #{MAX_EVENTS} events, ending the search"
break
end
end
latest_event = profile_events.min_by { |e| e["created_at"] }
puts latest_event.inspect
end
end
end