Allow non-members to publish zap receipts for members #197

Merged
raucao merged 12 commits from feature/strfry_zap_receipts into master 2024-06-22 17:52:03 +00:00
2 changed files with 32 additions and 3 deletions
Showing only changes of commit 87d900b627 - Show all commits

View File

@@ -5,11 +5,19 @@ class WellKnownController < ApplicationController
@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 }
}
if Setting.nostr_relay_url
res[:relays] = {
@user.nostr_pubkey => [ Setting.nostr_relay_url ]
}
end
respond_to do |format|
format.json do
render json: {
names: { "#{@user.cn}": @user.nostr_pubkey }
}.to_json
render json: res.to_json
end
end
end

View File

@@ -45,6 +45,27 @@ RSpec.describe "Well-known URLs", type: :request do
expect(res["names"].keys.size).to eq(1)
expect(res["names"]["bobdylan"]).to eq(user.nostr_pubkey)
end
context "without relay configured" do
it "does not include a recommended relay" do
get "/.well-known/nostr.json?name=bobdylan"
res = JSON.parse(response.body)
expect(res["relays"]).to be_nil
end
end
context "with relay configured" do
before do
Setting.nostr_relay_url = "wss://nostr.kosmos.org"
end
it "includes a recommended relay" do
get "/.well-known/nostr.json?name=bobdylan"
res = JSON.parse(response.body)
expect(res["relays"][user.nostr_pubkey].length).to eq(1)
expect(res["relays"][user.nostr_pubkey].first).to eq("wss://nostr.kosmos.org")
end
end
end
end
end