Respect new Lightning notification settings
This commit is contained in:
parent
5348a229a6
commit
1685d6ecf8
@ -7,14 +7,14 @@ class WebhooksController < ApplicationController
|
||||
def lndhub
|
||||
@user = User.find_by!(ln_account: @payload[:user_login])
|
||||
|
||||
if zap = @user.zaps.find_by(payment_request: @payload[:payment_request])
|
||||
if @zap = @user.zaps.find_by(payment_request: @payload[:payment_request])
|
||||
zap_receipt = NostrManager::CreateZapReceipt.call(
|
||||
zap: zap,
|
||||
zap: @zap,
|
||||
paid_at: Time.parse(@payload[:settled_at]).to_i,
|
||||
preimage: @payload[:preimage]
|
||||
)
|
||||
zap.update! receipt: zap_receipt.to_h
|
||||
NostrManager::PublishZapReceipt.call(zap: zap)
|
||||
@zap.update! receipt: @zap_receipt.to_h
|
||||
NostrManager::PublishZapReceipt.call(zap: @zap)
|
||||
end
|
||||
|
||||
send_notifications
|
||||
@ -41,7 +41,16 @@ class WebhooksController < ApplicationController
|
||||
end
|
||||
|
||||
def send_notifications
|
||||
case @user.preferences[:lightning_notify_sats_received]
|
||||
return if @payload[:amount] < @user.preferences[:lightning_notify_min_sats]
|
||||
|
||||
if @user.preferences[:lightning_notify_only_with_message]
|
||||
return if @payload[:memo].blank?
|
||||
end
|
||||
|
||||
target = @zap.present? ? @user.preferences[:lightning_notify_zap_received] :
|
||||
@user.preferences[:lightning_notify_sats_received]
|
||||
|
||||
case target
|
||||
when "xmpp"
|
||||
notify_xmpp
|
||||
when "email"
|
||||
|
@ -101,6 +101,34 @@ RSpec.describe "Webhooks", type: :request do
|
||||
expect(args[3]["params"]["amount_sats"]).to eq(12300)
|
||||
end
|
||||
end
|
||||
|
||||
describe "minimum threshold amount not reached" do
|
||||
before do
|
||||
user.update! preferences: {
|
||||
lightning_notify_sats_received: "xmpp",
|
||||
lightning_notify_min_sats: 21000
|
||||
}
|
||||
end
|
||||
|
||||
it "does not send a notification" do
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
expect(enqueued_jobs.size).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
describe "no memo/description/message" do
|
||||
before do
|
||||
user.update! preferences: {
|
||||
lightning_notify_sats_received: "xmpp",
|
||||
lightning_notify_only_with_message: true
|
||||
}
|
||||
end
|
||||
|
||||
it "does not send a notification" do
|
||||
post "/webhooks/lndhub", params: payload.merge({ memo: "" }).to_json
|
||||
expect(enqueued_jobs.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "Valid payload for zap transaction" do
|
||||
@ -149,6 +177,17 @@ RSpec.describe "Webhooks", type: :request do
|
||||
expect(NostrManager::PublishZapReceipt).to receive(:call).with(zap: zap)
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
end
|
||||
|
||||
context "with notifications disabled for zaps" do
|
||||
before do
|
||||
user.update! preferences: { lightning_notify_zap_received: "disabled" }
|
||||
end
|
||||
|
||||
it "does not send a notification" do
|
||||
post "/webhooks/lndhub", params: payload.to_json
|
||||
expect(enqueued_jobs.size).to eq(0)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user