Add support for integrated Nostr relay service #198

Merged
raucao merged 8 commits from feature/own_relay into feature/strfry_zap_receipts 2024-06-22 17:51:42 +00:00
2 changed files with 15 additions and 4 deletions
Showing only changes of commit f401a03590 - Show all commits

View File

@ -9,15 +9,13 @@ class WellKnownController < ApplicationController
if params[:name] == "_"
# pubkey for the primary domain without a username (e.g. kosmos.org)
res = { names: { "_": Setting.nostr_public_key } }
res[:relays] = { "_" => [ relay_url ] } if relay_url
else
@user = User.where(cn: params[:name], ou: domain).first
http_status :not_found and return if @user.nil? || @user.nostr_pubkey.blank?
res = { names: { @user.cn => @user.nostr_pubkey } }
end
if relay_url
res[:relays] = { @user.nostr_pubkey => [ relay_url ] }
res[:relays] = { @user.nostr_pubkey => [ relay_url ] } if relay_url
end
respond_to do |format|

View File

@ -75,6 +75,19 @@ RSpec.describe "Well-known URLs", type: :request do
expect(res["names"]["_"]).to eq(Setting.nostr_public_key)
end
context "with relay configured" do
before do
Setting.nostr_relay_url = "wss://nostr.kosmos.org"
end
it "returns the pubkey and relay" do
get "/.well-known/nostr.json?name=_"
res = JSON.parse(response.body)
expect(res["relays"]["_"].length).to eq(1)
expect(res["relays"]["_"].first).to eq("wss://nostr.kosmos.org")
end
end
context "nostr service integration not enabled" do
before do
Setting.nostr_enabled = false