Files
akkounts/app/components/settings/nostr_edit_relays_component.rb
raucao d288a69d5e
CI / Test (pull_request) Successful in 1m18s
Badge every auto-added relay and the auto-added display name
When no relay list exists, all recommended relays are now marked as added, not just the site relay, with a short note explaining the default list. The profile editor likewise marks the display name as added when it is filled in from the account display name.
2026-11-28 15:14:38 +04:00

36 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module Settings
class NostrEditRelaysComponent < ViewComponent::Base
def initialize(nip65_event: nil)
@nip65_event = nip65_event
@relays = build_relays
end
private
def build_relays
site_relay = Setting.nostr_relay_url
normalized_site_relay = NostrManagerService.normalize_url(site_relay)
if @nip65_event.blank?
relays = Setting.nostr_discovery_relays.map { |url| { url: url, marker: nil, added: true } }
if site_relay.present?
relays.reject! { |r| NostrManagerService.normalize_url(r[:url]) == normalized_site_relay }
relays.unshift({ url: site_relay, marker: nil, added: true })
end
relays
else
existing = @nip65_event["tags"]
.select { |t| t.is_a?(Array) && t[0] == "r" }
.map { |t| { url: t[1], marker: t[2], added: false } }
if site_relay.present? && existing.none? { |r| NostrManagerService.normalize_url(r[:url]) == normalized_site_relay }
existing.unshift({ url: site_relay, marker: nil, added: true })
end
existing
end
end
end
end