WIP Refactor stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-10-18 18:15:52 +02:00
parent 04a9061663
commit 79ef9fa6d5
7 changed files with 97 additions and 88 deletions

View File

@@ -1,36 +1,21 @@
module NostrManager
class DiscoverUserProfile < NostrManagerService
MAX_EVENTS = 2
def initialize(pubkey:, relays: nil)
@pubkey = pubkey
@relays = relays.present? ? 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
profile_events.min_by { |e| e["created_at"] }
NostrManager::FetchLatestEvent.call(
relays: @relays,
filter: filter
)
end
end
end