rosa-build/lib/modules/observers/activity_feed/comment.rb

69 lines
2.7 KiB
Ruby
Raw Normal View History

# -*- encoding : utf-8 -*-
module Modules::Observers::ActivityFeed::Comment
extend ActiveSupport::Concern
included do
after_commit :new_comment_notifications, :on => :create, :unless => :automatic?
# dont remove outdated issues link
after_update -> { Comment.create_link_on_issues_from_item(self) }
end
private
def new_comment_notifications
if issue_comment?
commentable.subscribes.each do |subscribe|
if user_id != subscribe.user_id
UserMailer.new_comment_notification(self, subscribe.user).deliver if can_notify_on_new_comment?(subscribe)
2013-06-27 17:18:53 +01:00
ActivityFeed.create(
:user => subscribe.user,
: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
}
)
end
end
elsif commit_comment?
Subscribe.comment_subscribes(self).where(:status => true).each do |subscribe|
next if own_comment?(subscribe.user)
if subscribe.user.notifier.can_notify and
( (subscribe.project.owner?(subscribe.user) && subscribe.user.notifier.new_comment_commit_repo_owner) or
(subscribe.user.commentor?(self.commentable) && subscribe.user.notifier.new_comment_commit_commentor) or
(subscribe.user.committer?(self.commentable) && subscribe.user.notifier.new_comment_commit_owner) )
UserMailer.new_comment_notification(self, subscribe.user).deliver
end
2013-06-27 17:18:53 +01:00
ActivityFeed.create(
:user => subscribe.user,
: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}
)
end
end
Comment.create_link_on_issues_from_item(self)
end
def can_notify_on_new_comment?(subscribe)
User.find(subscribe.user).notifier.new_comment && User.find(subscribe.user).notifier.can_notify
end
end