Use a multi-step process, caching results in between, while informing the user about the current steps/progress
37 lines
1.1 KiB
Ruby
37 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
module Settings
|
|
class NostrRelayStatusComponent < ViewComponent::Base
|
|
def initialize(nip65_event:, relay_url: Setting.nostr_relay_url)
|
|
@relay_url = relay_url
|
|
|
|
if nip65_event.present?
|
|
if relay_urls(nip65_event).include?(@relay_url)
|
|
@text = "You have a relay list, and the Kosmos relay is part of it"
|
|
@icon_name = "check-circle"
|
|
@icon_color = "emerald-500"
|
|
@status = 0
|
|
else
|
|
@text = "The Kosmos relay is missing from your relay list"
|
|
@icon_name = "alert-octagon"
|
|
@icon_color = "amber-500"
|
|
@status = 1
|
|
end
|
|
else
|
|
@text = "We could not find a relay list for your public key"
|
|
@icon_name = "alert-octagon"
|
|
@icon_color = "amber-500"
|
|
@status = 2
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def relay_urls(nip65_event)
|
|
nip65_event["tags"].select{ |t| t[0] == "r" }.map{ |t| t[1] }
|
|
# @inbox_relay_urls = relay_tags&.select{ |t| t[2] == "read" }&.map{ |t| t[1] }
|
|
# @outbox_relay_urls = relay_tags&.select{ |t| t[2] != "read" }&.map{ |t| t[1] }
|
|
end
|
|
end
|
|
end
|