Skip to content

Commit

Permalink
feat: process click
Browse files Browse the repository at this point in the history
  • Loading branch information
scmmishra committed Nov 4, 2024
1 parent 959001c commit 1362148
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/jobs/process_sns_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ def process_delivery
@email.update(status: "delivered", delivered_at: timestamp)
end

def process_click
data = @payload[:open]
timestamp = data.dig(:timestamp)
link = data.dig(:link)

@email.clicks.create(link: link, timestamp: timestamp)
@email.update(opened_at: timestamp) if @email.opened_at.nil?
end

def process_open
data = @payload[:open]
timestamp = data.dig(:timestamp)
Expand Down
1 change: 1 addition & 0 deletions app/models/email.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Email < ApplicationRecord
include Statusable

belongs_to :post
has_many :clicks, class_name: "EmailClick", dependent: :destroy
belongs_to :subscriber, optional: true

enum :status, { sent: "sent", delivered: "delivered", complained: "complained", bounced: "bounced" }
Expand Down

0 comments on commit 1362148

Please sign in to comment.