From dde81b55544c40a31af6f6be448b748abae8f118 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Sat, 25 Feb 2012 00:25:35 +0600 Subject: [PATCH] [refs #123] fix activity feed for commit comments; remove reply notification --- app/models/activity_feed_observer.rb | 30 +++++++++++-------- app/models/comment.rb | 5 ---- app/models/subscribe.rb | 23 -------------- .../_new_comment_reply_notification.haml | 5 ---- .../_new_commit_comment_notification.haml | 5 ++++ .../new_comment_reply_notification.en.haml | 9 ------ config/locales/activity_feed.en.yml | 7 ++--- config/locales/activity_feed.ru.yml | 9 ++---- config/locales/en.yml | 1 - 9 files changed, 29 insertions(+), 65 deletions(-) delete mode 100644 app/views/activity_feeds/partials/_new_comment_reply_notification.haml create mode 100644 app/views/activity_feeds/partials/_new_commit_comment_notification.haml delete mode 100644 app/views/user_mailer/new_comment_reply_notification.en.haml diff --git a/app/models/activity_feed_observer.rb b/app/models/activity_feed_observer.rb index b4e5fb348..6092ddea3 100644 --- a/app/models/activity_feed_observer.rb +++ b/app/models/activity_feed_observer.rb @@ -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' diff --git a/app/models/comment.rb b/app/models/comment.rb index e6a72f83e..0cde4b217 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -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 diff --git a/app/models/subscribe.rb b/app/models/subscribe.rb index a8fd5cc31..9779af5a3 100644 --- a/app/models/subscribe.rb +++ b/app/models/subscribe.rb @@ -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 diff --git a/app/views/activity_feeds/partials/_new_comment_reply_notification.haml b/app/views/activity_feeds/partials/_new_comment_reply_notification.haml deleted file mode 100644 index a9f040c38..000000000 --- a/app/views/activity_feeds/partials/_new_comment_reply_notification.haml +++ /dev/null @@ -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 }" diff --git a/app/views/activity_feeds/partials/_new_commit_comment_notification.haml b/app/views/activity_feeds/partials/_new_commit_comment_notification.haml new file mode 100644 index 000000000..32826e333 --- /dev/null +++ b/app/views/activity_feeds/partials/_new_commit_comment_notification.haml @@ -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 }" diff --git a/app/views/user_mailer/new_comment_reply_notification.en.haml b/app/views/user_mailer/new_comment_reply_notification.en.haml deleted file mode 100644 index b2838b2e0..000000000 --- a/app/views/user_mailer/new_comment_reply_notification.en.haml +++ /dev/null @@ -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» diff --git a/config/locales/activity_feed.en.yml b/config/locales/activity_feed.en.yml index cc3307d17..0794427a7 100644 --- a/config/locales/activity_feed.en.yml +++ b/config/locales/activity_feed.en.yml @@ -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} diff --git a/config/locales/activity_feed.ru.yml b/config/locales/activity_feed.ru.yml index 2ac9486cc..256a8d7bb 100644 --- a/config/locales/activity_feed.ru.yml +++ b/config/locales/activity_feed.ru.yml @@ -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 \ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index fda62af7e..d4c08478c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: