Add support for Lightning Zaps #190

Merged
raucao merged 25 commits from feature/170-nostr_zaps into master 2024-06-03 16:44:49 +00:00
4 changed files with 42 additions and 6 deletions
Showing only changes of commit 48041630ca - Show all commits

View File

@@ -169,6 +169,9 @@ class Setting < RailsSettings::Base
field :nostr_public_key, type: :string,
default: ENV["NOSTR_PUBLIC_KEY"].presence
field :nostr_zaps_relay_limit, type: :integer,
default: 12
#
# OpenCollective
#

View File

@@ -7,8 +7,7 @@ module NostrManager
def call
tags = parse_tags(@zap.request_event.tags)
# TODO limit to 15 or so relays
tags[:relays].each do |relay_url|
tags[:relays].take(Setting.nostr_zaps_relay_limit).each do |relay_url|
if @delayed
NostrPublishEventJob.perform_later(event: @zap.receipt, relay: relay_url)
else

View File

@@ -19,5 +19,15 @@
title: "Public key",
description: "The corresponding public key of the accounts service"
) %>
<% end %>
</ul>
</section>
<section>
<h3>Zaps</h3>
<ul role="list">
<%= render FormElements::FieldsetResettableSettingComponent.new(
key: :nostr_zaps_relay_limit,
title: "Relay limit",
description: "The maximum number of relays to publish zap receipts to"
) %>
</ul>
<% end %>

View File

@@ -6,11 +6,35 @@ RSpec.describe NostrManager::PublishZapReceipt, type: :model do
describe "Default/delayed execution" do
it "publishes zap receipts to all requested relays" do
2.times do
expect(NostrPublishEventJob).to receive(:perform_later).and_return(true)
end
expect(NostrPublishEventJob).to receive(:perform_later)
.exactly(2).times.and_return(true)
described_class.call(zap: zap)
end
context "with a long relay list" do
before do
relays = zap.request["tags"].find { |t| t.first == "relays" }
[
"wss://aegonstargaryen.example.com", "wss://visenya.example.com",
"wss://rhaenys.example.com", "wss://housevelaryon.example.com",
"wss://aemond.example.com", "wss://jaehaerys.example.com",
"wss://daenerys.example.com", "wss://corlys.example.com",
"wss://laenor.example.com", "wss://alysanne.example.com",
"wss://balerion.example.com", "wss://meraxes.example.com",
"wss://vhaegar.example.com", "wss://vermax.example.com",
"wss://caraxes.example.com"
].each do |url|
relays << url
end
end
it "limits publishing attempts to the first 12 relays" do
expect(NostrPublishEventJob).to receive(:perform_later)
.exactly(12).times.and_return(true)
described_class.call(zap: zap)
end
end
end
end