summaryrefslogtreecommitdiff
path: root/app/models/sent_notification.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-08-19 12:35:23 -0700
committerDouwe Maan <douwe@gitlab.com>2015-08-19 12:35:23 -0700
commit992dbbd9fe619ab3002f7c0c552657da8269df49 (patch)
tree5ae59f108ffe8d208928e7d2c2265018e033ad26 /app/models/sent_notification.rb
parenta8a861ae2a122b310d1aca6f9f9b1d0601b8c49f (diff)
downloadgitlab-ce-992dbbd9fe619ab3002f7c0c552657da8269df49.tar.gz
Move `sent_notification!` out of Notify.
Diffstat (limited to 'app/models/sent_notification.rb')
-rw-r--r--app/models/sent_notification.rb27
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?