Fetch user relays, synchronously
This commit is contained in:
33
app/services/nostr_manager/discover_user_relays.rb
Normal file
33
app/services/nostr_manager/discover_user_relays.rb
Normal file
@@ -0,0 +1,33 @@
|
||||
module NostrManager
|
||||
class DiscoverUserRelays < NostrManagerService
|
||||
def initialize(pubkey:)
|
||||
@pubkey = pubkey
|
||||
@relays = Setting.nostr_discovery_relays
|
||||
# @relays = %w[
|
||||
# wss://nostr.kosmos.org
|
||||
# wss://purplepag.es
|
||||
# wss://relay.nostr.band
|
||||
# wss://njump.me
|
||||
# ]
|
||||
end
|
||||
|
||||
def call
|
||||
nip65_events = []
|
||||
user_relays = []
|
||||
filter = Nostr::Filter.new(
|
||||
authors: [@pubkey],
|
||||
kinds: [10002],
|
||||
limit: 1,
|
||||
)
|
||||
|
||||
@relays.each do |url|
|
||||
event = NostrManager::FetchLatestEvent.call(filter: filter, relay_url: url)
|
||||
if event.present? && user_relays.detect { |r| r[:id] == event["id"] }.nil?
|
||||
user_relays << { id: event["id"], created_at: event["created_at"] }
|
||||
end
|
||||
end
|
||||
|
||||
puts user_relays.inspect
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user