[refs #123] fix activity feed for commit comments; remove reply notification
This commit is contained in:
parent
46a5ab1c76
commit
dde81b5554
|
@ -32,25 +32,31 @@ class ActivityFeedObserver < ActiveRecord::Observer
|
|||
end
|
||||
|
||||
when 'Comment'
|
||||
subscribes = record.commentable.subscribes
|
||||
subscribes.each do |subscribe|
|
||||
if record.user_id != subscribe.user_id
|
||||
if record.reply? subscribe
|
||||
UserMailer.delay.new_comment_reply_notification(record, subscribe.user) if record.can_notify_on_reply?(subscribe)
|
||||
ActivityFeed.create(
|
||||
:user => subscribe.user,
|
||||
:kind => 'new_comment_reply_notification',
|
||||
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id}
|
||||
)
|
||||
else
|
||||
if record.commentable.class == Issue
|
||||
subscribes = record.commentable.subscribes.finder_hack
|
||||
subscribes.each do |subscribe|
|
||||
if record.user_id != subscribe.user_id
|
||||
UserMailer.delay.new_comment_notification(record, subscribe.user) if record.can_notify_on_new_comment?(subscribe)
|
||||
ActivityFeed.create(
|
||||
:user => subscribe.user,
|
||||
:kind => 'new_comment_notification',
|
||||
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title, :issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id}
|
||||
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :issue_title => record.commentable.title,
|
||||
:issue_serial_id => record.commentable.serial_id, :project_id => record.commentable.project.id}
|
||||
)
|
||||
end
|
||||
end
|
||||
elsif record.commentable.class == Grit::Commit
|
||||
subscribes = Subscribe.comment_subscribes(record).where(:status => true)
|
||||
subscribes.each do |subscribe|
|
||||
next if record.own_comment?(subscribe.user)
|
||||
UserMailer.delay.new_comment_notification(record, subscribe.user) if subscribe.user.notifier.can_notify
|
||||
ActivityFeed.create(
|
||||
:user => subscribe.user,
|
||||
:kind => 'new_comment_commit_notification',
|
||||
:data => {:user_name => subscribe.user.name, :comment_body => record.body, :commit_message => record.commentable.message.encode_to_default,
|
||||
:commit_id => record.commentable.id, :project_id => record.project.id}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
when 'GitHook'
|
||||
|
|
|
@ -10,7 +10,6 @@ class Comment < ActiveRecord::Base
|
|||
after_create :subscribe_on_reply, :unless => "commentable_type == 'Grit::Commit'"
|
||||
after_create :invoke_helper, :if => "commentable_type == 'Grit::Commit'"
|
||||
after_create :subscribe_users
|
||||
after_create {|comment| Subscribe.new_comment_notification(comment)}
|
||||
|
||||
def helper
|
||||
class_eval "def commentable; project.git_repository.commit('#{commentable_id}'); end" if commentable_type == 'Grit::Commit'
|
||||
|
@ -20,10 +19,6 @@ class Comment < ActiveRecord::Base
|
|||
user_id == user.id
|
||||
end
|
||||
|
||||
def reply?(subscribe)
|
||||
self.commentable.comments.exists?(:user_id => subscribe.user.id)
|
||||
end
|
||||
|
||||
def can_notify_on_reply?(subscribe)
|
||||
User.find(subscribe.user).notifier.new_comment_reply && User.find(subscribe.user).notifier.can_notify
|
||||
end
|
||||
|
|
|
@ -14,27 +14,6 @@ class Subscribe < ActiveRecord::Base
|
|||
Subscribe.where(:subscribeable_id => comment.commentable.id, :subscribeable_type => comment.commentable.class.name, :project_id => comment.project)
|
||||
end
|
||||
|
||||
def self.new_comment_notification(comment)
|
||||
commentable_class = comment.commentable.class
|
||||
Subscribe.new_comment_issue_notification(comment) if commentable_class == Issue
|
||||
Subscribe.new_comment_commit_notification(comment) if commentable_class == Grit::Commit
|
||||
end
|
||||
|
||||
def self.new_comment_issue_notification(comment)
|
||||
comment.commentable.subscribes.finder_hack.each do |subscribe|
|
||||
next if comment.own_comment?(subscribe.user) || !subscribe.user.notifier.can_notify
|
||||
UserMailer.delay.new_comment_notification(comment, subscribe.user) if subscribe.user.notifier.new_comment_reply
|
||||
end
|
||||
end
|
||||
|
||||
def self.new_comment_commit_notification(comment)
|
||||
subscribes = Subscribe.comment_subscribes(comment).where(:status => true)
|
||||
subscribes.each do |subscribe|
|
||||
next if comment.own_comment?(subscribe.user) || !subscribe.user.notifier.can_notify
|
||||
UserMailer.delay.new_comment_notification(comment, subscribe.user)
|
||||
end
|
||||
end
|
||||
|
||||
def self.subscribed_to_commit?(project, user, commit)
|
||||
subscribe = user.subscribes.where(:subscribeable_id => commit.id, :subscribeable_type => commit.class.name, :project_id => project.id).first
|
||||
return subscribe.subscribed? if subscribe # return status if already subscribe present
|
||||
|
@ -44,12 +23,10 @@ class Subscribe < ActiveRecord::Base
|
|||
(user.committer?(commit) && user.notifier.new_comment_commit_owner)
|
||||
end
|
||||
|
||||
|
||||
def self.subscribe_to_commit(options)
|
||||
Subscribe.set_subscribe_to_commit(options, true)
|
||||
end
|
||||
|
||||
|
||||
def self.unsubscribe_from_commit(options)
|
||||
Subscribe.set_subscribe_to_commit(options, false)
|
||||
end
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
%p== #{ t("notifications.bodies.new_comment_reply_notification.title", :user_name => user_name) }
|
||||
|
||||
%p= raw t("notifications.bodies.new_comment_reply_notification.content", {:issue_link => link_to(issue_title, project_issue_path(project_id, issue_serial_id))})
|
||||
|
||||
%p "#{ comment_body }"
|
|
@ -0,0 +1,5 @@
|
|||
%p== #{ t("notifications.bodies.new_commit_comment_notification.title", :user_name => user_name) }
|
||||
|
||||
%p= raw t("notifications.bodies.new_comment_notification.commit_content", {:commit_link => link_to(commit_message, commit_path(project_id, commit_id))})
|
||||
|
||||
%p "#{ comment_body }"
|
|
@ -1,9 +0,0 @@
|
|||
%p== Hello, #{@user.name}.
|
||||
|
||||
- #TODO hmm... this need to be refactored.
|
||||
%p Your comment into issue #{ link_to @comment.commentable.title, project_issue_url(@comment.commentable.project, @comment.commentable) } has been answered.
|
||||
|
||||
%p "#{ @comment.body }"
|
||||
|
||||
|
||||
%p== Support team «ROSA Build System»
|
|
@ -6,7 +6,8 @@ en:
|
|||
|
||||
notifications:
|
||||
subjects:
|
||||
new_comment_notification: New comment to your task
|
||||
new_comment_notification: New comment to task
|
||||
new_commit_comment_notification: New comment to commit
|
||||
new_issue_notification: New task added to project
|
||||
new_user_notification: Registered on project «%{ project_name }»
|
||||
issue_assign_notification: New task assigned
|
||||
|
@ -15,9 +16,7 @@ en:
|
|||
new_comment_notification:
|
||||
title: Hello, %{user_name}.
|
||||
content: To the issue %{issue_link} added a comment.
|
||||
new_comment_reply_notification:
|
||||
title: Hello, %{user_name}.
|
||||
content: Your comment into issue %{issue_link} has been answered.
|
||||
commit_content: To the commit %{commit_link} added a comment.
|
||||
new_issue_notification:
|
||||
title: Hello, %{user_name}.
|
||||
content: To project %{project_link} has been added an issue %{issue_link}
|
||||
|
|
|
@ -6,8 +6,8 @@ ru:
|
|||
|
||||
notifications:
|
||||
subjects:
|
||||
new_comment_notification: Новый комментарий к Вашей задаче
|
||||
new_comment_reply_notification: Новый комментарий к Вашей задаче
|
||||
new_comment_notification: Новый комментарий к задаче
|
||||
new_commit_comment_notification: Новый комментарий к коммиту
|
||||
new_issue_notification: Новая задача добавлена к проекту
|
||||
new_user_notification: Регистрация на проекте «%{ project_name }»
|
||||
issue_assign_notification: Вам назначили задачу
|
||||
|
@ -16,9 +16,7 @@ ru:
|
|||
new_comment_notification:
|
||||
title: Здравствуйте, %{user_name}.
|
||||
content: К задаче %{issue_link} был добавлен новый комментарий.
|
||||
new_comment_reply_notification:
|
||||
title: Здравствуйте, %{user_name}.
|
||||
content: На Ваш комментарий в задаче %{issue_link} был дан ответ.
|
||||
commit_content: К коммиту %{commit_link} был добавлен новый комментарий.
|
||||
new_issue_notification:
|
||||
title: Здравствуйте, %{user_name}.
|
||||
content: К проекту %{project_link} была добавлена задача %{issue_link}
|
||||
|
@ -30,5 +28,4 @@ ru:
|
|||
issue_assign_notification:
|
||||
title: Здравствуйте, %{user_name}.
|
||||
content: Вам была назначена задача %{issue_link}
|
||||
new_commit_comment_notification: Новый комментарий к коммиту
|
||||
invite_approve_notification: Приглашение в ABF
|
|
@ -949,7 +949,6 @@ en:
|
|||
new_issue_notification: New task added to project
|
||||
new_user_notification: Registered on project «%{ project_name }»
|
||||
issue_assign_notification: New task assigned
|
||||
new_commit_comment_notification: New comment to commit
|
||||
invite_approve_notification: Invitation to ABF
|
||||
|
||||
project:
|
||||
|
|
Loading…
Reference in New Issue