WIP Relay editing UI
This commit is contained in:
@@ -3,34 +3,46 @@
|
||||
module Settings
|
||||
class NostrRelayStatusComponent < ViewComponent::Base
|
||||
def initialize(nip65_event:, relay_url: Setting.nostr_relay_url)
|
||||
@nip65_event = nip65_event
|
||||
@relay_url = relay_url
|
||||
@relay_host = relay_url.present? ? URI.parse(relay_url).host : nil
|
||||
@statuses = []
|
||||
|
||||
if nip65_event.present?
|
||||
@statuses.push({
|
||||
text: "You have a relay list configured",
|
||||
icon_name: "check-circle",
|
||||
icon_color: "emerald-500"
|
||||
})
|
||||
|
||||
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
|
||||
@statuses.push({
|
||||
text: "The <strong>#{@relay_host}</strong> relay is part of your relay list",
|
||||
icon_name: "check-circle",
|
||||
icon_color: "emerald-500"
|
||||
})
|
||||
else
|
||||
@text = "The Kosmos relay is missing from your relay list"
|
||||
@icon_name = "alert-octagon"
|
||||
@icon_color = "amber-500"
|
||||
@status = 1
|
||||
@statuses.push({
|
||||
text: "The <strong>#{@relay_host}</strong> relay is missing from your relay list",
|
||||
icon_name: "alert-octagon",
|
||||
icon_color: "amber-500"
|
||||
})
|
||||
end
|
||||
else
|
||||
@text = "We could not find a relay list for your public key"
|
||||
@icon_name = "alert-octagon"
|
||||
@icon_color = "amber-500"
|
||||
@status = 2
|
||||
@statuses.push({
|
||||
text: "We could not find a relay list for your public key",
|
||||
icon_name: "alert-octagon",
|
||||
icon_color: "amber-500"
|
||||
})
|
||||
end
|
||||
|
||||
@button_text = (nip65_event.present? ? "Edit relays" : "Set up relays")
|
||||
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] }
|
||||
nip65_event["tags"].select { |t| t[0] == "r" }.map { |t| t[1] }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user