diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-08-19 12:35:23 -0700 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-08-19 12:35:23 -0700 |
commit | 992dbbd9fe619ab3002f7c0c552657da8269df49 (patch) | |
tree | 5ae59f108ffe8d208928e7d2c2265018e033ad26 /app/models | |
parent | a8a861ae2a122b310d1aca6f9f9b1d0601b8c49f (diff) | |
download | gitlab-ce-992dbbd9fe619ab3002f7c0c552657da8269df49.tar.gz |
Move `sent_notification!` out of Notify.
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/sent_notification.rb | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/app/models/sent_notification.rb b/app/models/sent_notification.rb index 23a1b19ea7c..460ca40be3f 100644 --- a/app/models/sent_notification.rb +++ b/app/models/sent_notification.rb @@ -9,8 +9,31 @@ 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) - find_by(reply_key: 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? |