Commit 992dbbd9 authored by Douwe Maan's avatar Douwe Maan

Move `sent_notification!` out of Notify.

parent a8a861ae
......@@ -9,7 +9,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
sent_notification!(@issue, recipient_id)
SentNotification.record(@issue, recipient_id, reply_key)
end
def reassigned_issue_email(recipient_id, issue_id, previous_assignee_id, updated_by_user_id)
......@@ -22,7 +22,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
sent_notification!(@issue, recipient_id)
SentNotification.record(@issue, recipient_id, reply_key)
end
def closed_issue_email(recipient_id, issue_id, updated_by_user_id)
......@@ -35,7 +35,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
sent_notification!(@issue, recipient_id)
SentNotification.record(@issue, recipient_id, reply_key)
end
def issue_status_changed_email(recipient_id, issue_id, status, updated_by_user_id)
......@@ -49,7 +49,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
sent_notification!(@issue, recipient_id)
SentNotification.record(@issue, recipient_id, reply_key)
end
end
end
......@@ -11,7 +11,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
sent_notification!(@merge_request, recipient_id)
SentNotification.record(@merge_request, recipient_id, reply_key)
end
def reassigned_merge_request_email(recipient_id, merge_request_id, previous_assignee_id, updated_by_user_id)
......@@ -26,7 +26,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
sent_notification!(@merge_request, recipient_id)
SentNotification.record(@merge_request, recipient_id, reply_key)
end
def closed_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
......@@ -41,7 +41,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
sent_notification!(@merge_request, recipient_id)
SentNotification.record(@merge_request, recipient_id, reply_key)
end
def merged_merge_request_email(recipient_id, merge_request_id, updated_by_user_id)
......@@ -55,7 +55,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
sent_notification!(@merge_request, recipient_id)
SentNotification.record(@merge_request, recipient_id, reply_key)
end
def merge_request_status_email(recipient_id, merge_request_id, status, updated_by_user_id)
......@@ -71,7 +71,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
sent_notification!(@merge_request, recipient_id)
SentNotification.record(@merge_request, recipient_id, reply_key)
end
end
end
......@@ -12,7 +12,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@commit.title} (#{@commit.short_id})"))
sent_notification!(@commit, recipient_id)
SentNotification.record(@commit, recipient_id, reply_key)
end
def note_issue_email(recipient_id, note_id)
......@@ -27,7 +27,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@issue.title} (##{@issue.iid})"))
sent_notification!(@issue, recipient_id)
SentNotification.record(@issue, recipient_id, reply_key)
end
def note_merge_request_email(recipient_id, note_id)
......@@ -43,7 +43,7 @@ module Emails
to: recipient(recipient_id),
subject: subject("#{@merge_request.title} (##{@merge_request.iid})"))
sent_notification!(@merge_request, recipient_id)
SentNotification.record(@merge_request, recipient_id, reply_key)
end
end
end
......@@ -33,27 +33,6 @@ class Notify < BaseMailer
allowed_domains
end
def sent_notification!(noteable, recipient_id)
return unless reply_key
noteable_id = nil
commit_id = nil
if noteable.is_a?(Commit)
commit_id = noteable.id
else
noteable_id = noteable.id
end
SentNotification.create(
project: noteable.project,
noteable_type: noteable.class.name,
noteable_id: noteable_id,
commit_id: commit_id,
recipient_id: recipient_id,
reply_key: reply_key
)
end
private
def can_send_from_user_email?(sender)
......
......@@ -9,10 +9,33 @@ class SentNotification < ActiveRecord::Base
validates :noteable_id, presence: true, unless: :for_commit?
validates :commit_id, presence: true, if: :for_commit?
def self.for(reply_key)
class << self
def for(reply_key)
find_by(reply_key: reply_key)
end
def record(noteable, recipient_id, reply_key)
return unless reply_key
noteable_id = nil
commit_id = nil
if noteable.is_a?(Commit)
commit_id = noteable.id
else
noteable_id = noteable.id
end
create(
project: noteable.project,
noteable_type: noteable.class.name,
noteable_id: noteable_id,
commit_id: commit_id,
recipient_id: recipient_id,
reply_key: reply_key
)
end
end
def for_commit?
noteable_type == "Commit"
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment