WIP Edit nostr profile
This commit is contained in:
parent
10d29b6fab
commit
9866cd0404
@ -0,0 +1,44 @@
|
|||||||
|
<div class="w-[72vw] md:w-[500px]">
|
||||||
|
<header class="absolute z-10 h-36 sm:h-44 inset-x-1 top-1 rounded-t
|
||||||
|
bg-cover bg-center bg-gray-50"
|
||||||
|
style="background-image: url('<%= @profile["banner"]%>');">
|
||||||
|
<div class="inline-block z-20 size-28 sm:size-32 ml-4 mt-16 sm:mt-20">
|
||||||
|
<% if @profile["picture"].present? %>
|
||||||
|
<img src="<%= @profile["picture"] %>"
|
||||||
|
class="inline-block size:28 sm:size-32 rounded-full border-2 border-white" />
|
||||||
|
<% else %>
|
||||||
|
<span class="inline-block size:28 sm:size-32 overflow-hidden rounded-full border-2 border-white bg-gray-100">
|
||||||
|
<svg class="size-full text-gray-300" fill="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path d="M24 20.993V24H0v-2.996A14.977 14.977 0 0112.004 15c4.904 0 9.26 2.354 11.996 5.993zM16.002 8.999a4 4 0 11-8 0 4 4 0 018 0z" />
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
<main class="mt-44 sm:mt-52">
|
||||||
|
<%= form_for(@user, url: setting_path(:nostr), html: { :method => :put }) do |f| %>
|
||||||
|
<%= render FormElements::FieldsetComponent.new(tag: "div", title: "Display name") do %>
|
||||||
|
<%= f.text_field :display_name, value: @display_name, class: "w-full sm:w-3/5" %>
|
||||||
|
<% if @validation_errors.present? && @validation_errors[:display_name].present? %>
|
||||||
|
<p class="error-msg mt-2"><%= @validation_errors[:display_name].first %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<%= render FormElements::FieldsetComponent.new(tag: "div", title: "Nostr address (NIP-05)") do %>
|
||||||
|
<%= f.text_field :nip05_address, value: @profile["nip05"], class: "w-full sm:w-3/5" %>
|
||||||
|
<% if @validation_errors.present? && @validation_errors[:nip05_address].present? %>
|
||||||
|
<p class="error-msg mt-2"><%= @validation_errors[:nip05_address].first %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<%= render FormElements::FieldsetComponent.new(tag: "div", title: "Ligtning address for Zaps") do %>
|
||||||
|
<%= f.text_field :lud16_address, value: @profile["lud16"], class: "w-full sm:w-3/5" %>
|
||||||
|
<% if @validation_errors.present? && @validation_errors[:lud16_address].present? %>
|
||||||
|
<p class="error-msg mt-2"><%= @validation_errors[:lud16_address].first %></p>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
</main>
|
||||||
|
<footer>
|
||||||
|
<%# <%= @profile.inspect %>
|
||||||
|
<%# <%= @profile_event.inspect %>
|
||||||
|
</footer>
|
||||||
|
</div>
|
28
app/components/settings/nostr_edit_profile_component.rb
Normal file
28
app/components/settings/nostr_edit_profile_component.rb
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module Settings
|
||||||
|
class NostrEditProfileComponent < ViewComponent::Base
|
||||||
|
def initialize(user:, profile_event:)
|
||||||
|
if profile_event.present?
|
||||||
|
@user = user
|
||||||
|
@profile_event = profile_event
|
||||||
|
@profile = JSON.parse(profile_event["content"])
|
||||||
|
@display_name = @profile["display_name"] || @profile["displayName"]
|
||||||
|
|
||||||
|
if @profile["nip05"].present? && @profile["nip05"] == @user.address
|
||||||
|
# "Your profile's Nostr address is set to <strong>#{ user_address }</strong>"
|
||||||
|
else
|
||||||
|
# "Your profile's Nostr address is not set to <strong>#{ user_address }</strong> yet"
|
||||||
|
end
|
||||||
|
|
||||||
|
if @profile["lud16"].present? && @profile["lud16"] == @user.address
|
||||||
|
# "Your profile's Lightning address is set to <strong>#{ user_address }</strong>"
|
||||||
|
else
|
||||||
|
# "Your profile's Lightning address is not set to <strong>#{ user_address }</strong> yet"
|
||||||
|
end
|
||||||
|
else
|
||||||
|
# "We could not find a profile for your public key"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
@ -5,3 +5,17 @@
|
|||||||
icon_color: status[:icon_color]
|
icon_color: status[:icon_color]
|
||||||
) %>
|
) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if @status == 1 %>
|
||||||
|
<p class="mt-8">
|
||||||
|
<button class="btn-md btn-blue">
|
||||||
|
Edit my profile
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
<% elsif @status == 2 %>
|
||||||
|
<p class="mt-8">
|
||||||
|
<button class="btn-md btn-blue">
|
||||||
|
Create my profile
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
@ -2,3 +2,17 @@
|
|||||||
text: @text,
|
text: @text,
|
||||||
icon_name: @icon_name,
|
icon_name: @icon_name,
|
||||||
icon_color: @icon_color) %>
|
icon_color: @icon_color) %>
|
||||||
|
|
||||||
|
<% if @status == 1 %>
|
||||||
|
<p class="mt-8">
|
||||||
|
<button class="btn-md btn-blue">
|
||||||
|
Add the relay to my list
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
<% elsif @status == 2 %>
|
||||||
|
<p class="mt-8">
|
||||||
|
<button class="btn-md btn-blue">
|
||||||
|
Set up default relays
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
<% end %>
|
||||||
|
@ -8,15 +8,18 @@ module Settings
|
|||||||
@text = "You have a relay list, and the Kosmos relay is part of it"
|
@text = "You have a relay list, and the Kosmos relay is part of it"
|
||||||
@icon_name = "check-circle"
|
@icon_name = "check-circle"
|
||||||
@icon_color = "emerald-500"
|
@icon_color = "emerald-500"
|
||||||
|
@status = 0
|
||||||
else
|
else
|
||||||
@text = "The Kosmos relay is missing from your relay list"
|
@text = "The Kosmos relay is missing from your relay list"
|
||||||
@icon_name = "alert-octagon"
|
@icon_name = "alert-octagon"
|
||||||
@icon_color = "amber-500"
|
@icon_color = "amber-500"
|
||||||
|
@status = 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@text = "We could not find a relay list for your public key"
|
@text = "We could not find a relay list for your public key"
|
||||||
@icon_name = "alert-octagon"
|
@icon_name = "alert-octagon"
|
||||||
@icon_color = "amber-500"
|
@icon_color = "amber-500"
|
||||||
|
@status = 2
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -137,20 +137,22 @@ class SettingsController < ApplicationController
|
|||||||
if @user.nostr_pubkey.present?
|
if @user.nostr_pubkey.present?
|
||||||
outbox_relay_urls = nil
|
outbox_relay_urls = nil
|
||||||
|
|
||||||
if @nip65_event = NostrManager::DiscoverUserRelays.call(pubkey: @user.nostr_pubkey)
|
# if @nip65_event = NostrManager::DiscoverUserRelays.call(pubkey: @user.nostr_pubkey)
|
||||||
relay_tags = @nip65_event["tags"].select{ |t| t[0] == "r" }
|
# relay_tags = @nip65_event["tags"].select{ |t| t[0] == "r" }
|
||||||
outbox_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
|
||||||
|
|
||||||
@profile = NostrManager::DiscoverUserProfile.call(
|
# @profile = NostrManager::DiscoverUserProfile.call(
|
||||||
pubkey: @user.nostr_pubkey,
|
# pubkey: @user.nostr_pubkey,
|
||||||
relays: outbox_relay_urls
|
# relays: outbox_relay_urls
|
||||||
)
|
# )
|
||||||
|
@profile = {"content"=>"{\"name\":\"jimmy\",\"picture\":\"https://storage.kosmos.org/jimmy/public/shares/241028-1117-tony.jpg\",\"banner\":\"https://storage.kosmos.org/raucao/public/shares/240604-1517-1500x500.jpg\",\"nip05\":\"jimmy@kosmos.org\",\"lud16\":\"jimmy@kosmos.org\",\"pubkey\":\"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3\",\"display_name\":\"Jimmy\",\"displayName\":\"Jimmy\",\"about\":\"I don't exist. Follow at your own peril.\"}", "created_at"=>1730114246, "id"=>"6b15b1308a61ee837bd3b50319978314650e435891c259f4ea499f819f35a4f6", "kind"=>0, "pubkey"=>"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3", "sig"=>"4f681f4b95646bbf88a6eae9ca92c0f2ce5effecfa017556a23490f91a99243aedf81d956ee2466ed64fecb9a03b6b89cd80ff116df0178830977e203867d7ae", "tags"=>[]}
|
||||||
|
# @profile = {"content"=>"{\"name\":\"jimmy\",\"nip05\":\"jimmy@kosmos.org\",\"lud16\":\"jimmy@kosmos.org\",\"pubkey\":\"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3\",\"display_name\":\"Jimmy\",\"displayName\":\"Jimmy\",\"about\":\"I don't exist. Follow at your own peril.\"}", "created_at"=>1730114246, "id"=>"6b15b1308a61ee837bd3b50319978314650e435891c259f4ea499f819f35a4f6", "kind"=>0, "pubkey"=>"07e188a1ff87ce171d517b8ed2bb7a31b1d3453a0db3b15379ec07b724d232f3", "sig"=>"4f681f4b95646bbf88a6eae9ca92c0f2ce5effecfa017556a23490f91a99243aedf81d956ee2466ed64fecb9a03b6b89cd80ff116df0178830977e203867d7ae", "tags"=>[]}
|
||||||
else
|
else
|
||||||
@relays, @profile = [nil, nil]
|
@relays, @profile = [nil, nil]
|
||||||
end
|
end
|
||||||
|
|
||||||
render partial: 'nostr_user_relays'
|
render partial: 'nostr_user_metadata'
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module NostrManager
|
module NostrManager
|
||||||
class FetchEvent < NostrManagerService
|
class FetchEvent < NostrManagerService
|
||||||
TIMEOUT = 1
|
TIMEOUT = 10
|
||||||
|
|
||||||
def initialize(filter:, relay_url:)
|
def initialize(filter:, relay_url:)
|
||||||
@filter = filter
|
@filter = filter
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
module NostrManager
|
module NostrManager
|
||||||
class FetchLatestEvent < NostrManagerService
|
class FetchLatestEvent < NostrManagerService
|
||||||
TIMEOUT = 5
|
TIMEOUT = 20
|
||||||
|
|
||||||
def initialize(relays:, filter:, max_events: 2)
|
def initialize(relays:, filter:, max_events: 2)
|
||||||
@relays = relays
|
@relays = relays
|
||||||
|
27
app/views/settings/_nostr_user_metadata.html.erb
Normal file
27
app/views/settings/_nostr_user_metadata.html.erb
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<%= turbo_frame_tag "nostr_user_metadata" do %>
|
||||||
|
<section>
|
||||||
|
<h3>Relays</h3>
|
||||||
|
<%= render Settings::NostrRelayStatusComponent.new(
|
||||||
|
nip65_event: @nip65_event
|
||||||
|
) %>
|
||||||
|
</section>
|
||||||
|
|
||||||
|
<section>
|
||||||
|
<h3>Profile</h3>
|
||||||
|
<%= render Settings::NostrProfileStatusComponent.new(
|
||||||
|
profile_event: @profile,
|
||||||
|
user_address: current_user.address
|
||||||
|
) %>
|
||||||
|
<div class="mt-8" data-controller="modal" data-action="keydown.esc->modal#close">
|
||||||
|
<button data-action="click->modal#open" class="btn-md btn-blue w-full sm:w-auto">
|
||||||
|
Edit profile
|
||||||
|
</button>
|
||||||
|
<%= render ModalComponent.new(show_close_button: false) do %>
|
||||||
|
<%= render Settings::NostrEditProfileComponent.new(
|
||||||
|
user: current_user,
|
||||||
|
profile_event: @profile
|
||||||
|
) %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
|
<% end %>
|
@ -1,15 +0,0 @@
|
|||||||
<%= turbo_frame_tag "nostr_user_metadata" do %>
|
|
||||||
<section>
|
|
||||||
<h3>Relays</h3>
|
|
||||||
<%= render Settings::NostrRelayStatusComponent.new(
|
|
||||||
nip65_event: @nip65_event
|
|
||||||
) %>
|
|
||||||
</section>
|
|
||||||
<section>
|
|
||||||
<h3>Profile</h3>
|
|
||||||
<%= render Settings::NostrProfileStatusComponent.new(
|
|
||||||
profile_event: @profile,
|
|
||||||
user_address: current_user.address
|
|
||||||
) %>
|
|
||||||
</section>
|
|
||||||
<% end %>
|
|
3
app/views/shared/nostr/_edit_user_profile.html.erb
Normal file
3
app/views/shared/nostr/_edit_user_profile.html.erb
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<div>
|
||||||
|
<%= profile.inspect %>
|
||||||
|
</div>
|
Loading…
x
Reference in New Issue
Block a user