2014-03-11 07:39:25 +00:00
|
|
|
module Feed::Comment
|
2013-06-27 15:37:41 +01:00
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2014-03-17 20:18:46 +00:00
|
|
|
after_create :new_comment_notifications
|
2013-06-27 15:37:41 +01:00
|
|
|
# dont remove outdated issues link
|
|
|
|
after_update -> { Comment.create_link_on_issues_from_item(self) }
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def new_comment_notifications
|
2013-06-27 20:43:44 +01:00
|
|
|
return if automatic?
|
2013-06-27 15:37:41 +01:00
|
|
|
if issue_comment?
|
|
|
|
commentable.subscribes.each do |subscribe|
|
2014-03-17 20:18:46 +00:00
|
|
|
if user_id != subscribe.user_id && can_notify_on_new_comment?(subscribe)
|
|
|
|
UserMailer.new_comment_notification(self, subscribe.user_id).deliver
|
2013-06-27 17:18:53 +01:00
|
|
|
ActivityFeed.create(
|
2014-03-17 20:18:46 +00:00
|
|
|
{
|
|
|
|
user_id: subscribe.user_id,
|
|
|
|
kind: 'new_comment_notification',
|
|
|
|
data: {
|
|
|
|
user_name: user.name,
|
|
|
|
user_email: user.email,
|
|
|
|
user_id: user_id,
|
|
|
|
comment_body: body,
|
|
|
|
issue_title: commentable.title,
|
|
|
|
issue_serial_id: commentable.serial_id,
|
|
|
|
project_id: commentable.project.id,
|
|
|
|
comment_id: id,
|
|
|
|
project_name: project.name,
|
|
|
|
project_owner: project.owner.uname
|
|
|
|
}
|
|
|
|
}, without_protection: true
|
2013-06-27 17:18:53 +01:00
|
|
|
)
|
2013-06-27 15:37:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
elsif commit_comment?
|
2014-01-21 04:51:49 +00:00
|
|
|
Subscribe.comment_subscribes(self).where(status: true).each do |subscribe|
|
2014-03-17 20:18:46 +00:00
|
|
|
next if !subscribe.user_id || own_comment?(subscribe.user)
|
|
|
|
if subscribe.user.notifier.can_notify &&
|
|
|
|
( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) ||
|
|
|
|
(subscribe.user.commentor?(self.commentable) && subscribe.user.notifier.new_comment_commit_commentor) ||
|
2013-06-27 15:37:41 +01:00
|
|
|
(subscribe.user.committer?(self.commentable) && subscribe.user.notifier.new_comment_commit_owner) )
|
2014-03-17 20:18:46 +00:00
|
|
|
UserMailer.new_comment_notification(self, subscribe.user_id).deliver
|
2013-06-27 15:37:41 +01:00
|
|
|
end
|
2013-06-27 17:18:53 +01:00
|
|
|
ActivityFeed.create(
|
2014-03-17 20:18:46 +00:00
|
|
|
{
|
|
|
|
user_id: subscribe.user_id,
|
|
|
|
kind: 'new_comment_commit_notification',
|
|
|
|
data: {
|
|
|
|
user_name: user.name,
|
|
|
|
user_email: user.email,
|
|
|
|
user_id: user_id,
|
|
|
|
comment_body: body,
|
|
|
|
commit_message: commentable.message,
|
|
|
|
commit_id: commentable.id,
|
|
|
|
project_id: project.id,
|
|
|
|
comment_id: id,
|
|
|
|
project_name: project.name,
|
|
|
|
project_owner: project.owner.uname
|
|
|
|
}
|
|
|
|
}, without_protection: true
|
2013-06-27 17:18:53 +01:00
|
|
|
)
|
2013-06-27 15:37:41 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
Comment.create_link_on_issues_from_item(self)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_notify_on_new_comment?(subscribe)
|
2014-03-18 13:58:51 +00:00
|
|
|
notifier = SettingsNotifier.find_by user_id: subscribe.user_id
|
2014-03-17 20:18:46 +00:00
|
|
|
notifier && notifier.new_comment && notifier.can_notify
|
2013-06-27 15:37:41 +01:00
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
end
|