diff --git a/app/helpers/notifications_helper.rb b/app/helpers/notifications_helper.rb index 7b0ef659f4c68705c77d73edbd5327a11ad4076d..a6570468ac0d7aa512afd65799f2577b80e5b00e 100644 --- a/app/helpers/notifications_helper.rb +++ b/app/helpers/notifications_helper.rb @@ -14,6 +14,13 @@ module NotificationsHelper else "#{translation} #{t('notifications.deleted')} #{t('notifications.post')}" end + when 'also_commented' + comment = Comment.first(:id => note.target_id) + if comment + "#{translation} #{link_to t('notifications.post'), object_path(comment.post)}".html_safe + else + "#{translation} #{t('notifications.deleted')} #{t('notifications.post')}" + end else end end diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 48a428ab5fe01c106ba2bba0f7e31794af434dc6..f1b0664e84692d102da66be8e2072b2a76132913 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -46,10 +46,10 @@ class Notifier < ActionMailer::Base :subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host) end - def comment_on_post(recipient_id, sender_id, comment) + def comment_on_post(recipient_id, sender_id, comment_id) @receiver = User.find_by_id(recipient_id) @sender = Person.find_by_id(sender_id) - @comment = comment + @comment = Comment.find_by_id(comment_id) log_mail(recipient_id, sender_id, 'comment_on_post') @@ -59,6 +59,21 @@ class Notifier < ActionMailer::Base :subject => I18n.t('notifier.comment_on_post.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host) end + def also_commented(recipient_id, sender_id, comment_id) + @receiver = User.find_by_id(recipient_id) + @sender = Person.find_by_id(sender_id) + @comment = Comment.find_by_id(comment_id) + @post_author_name = @comment.post.person.name + + + log_mail(recipient_id, sender_id, 'comment_on_post') + + attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT + + mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>", + :subject => I18n.t('notifier.also_commented.subject', :name => @sender.name, :post_author => @post_author_name ), :host => AppConfig[:pod_uri].host) + end + private def log_mail recipient_id, sender_id, type log_string = "event=mail mail_type=#{type} db_name=#{MongoMapper.database.name} recipient_id=#{recipient_id} sender_id=#{sender_id}" diff --git a/app/models/comment.rb b/app/models/comment.rb index c2d3f29779ad85485837c87cd1cc5fbdecc68880..eceb4d8e7321734d0579895a101da06713bfb471 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -45,6 +45,8 @@ class Comment def notification_type(user, person) if self.post.diaspora_handle == user.diaspora_handle return "comment_on_post" + elsif self.post.comments.all(:diaspora_handle => user.diaspora_handle) != [] && self.diaspora_handle != user.diaspora_handle + return "also_commented" else return false end diff --git a/app/models/jobs/mail_comment_on_post.rb b/app/models/jobs/mail_comment_on_post.rb index a6a75a5c5c77a1d27439821e59b2e078e5bad550..89585fe86950ef9b9e9c93bf4bb24132ccb00e35 100644 --- a/app/models/jobs/mail_comment_on_post.rb +++ b/app/models/jobs/mail_comment_on_post.rb @@ -2,8 +2,8 @@ module Jobs class MailCommentOnPost extend ResqueJobLogging @queue = :mail - def self.perform(recipient_id, sender_id, comment) - Notifier.comment_on_post(recipient_id, sender_id, comment).deliver + def self.perform(recipient_id, sender_id, comment_id) + Notifier.comment_on_post(recipient_id, sender_id, comment_id).deliver end end end diff --git a/app/models/notification.rb b/app/models/notification.rb index b8f8f2e2f041a208abce7c81c2380c471dbadf89..c3849f7cdaeecbb5efa167942fd49d1449a57c78 100644 --- a/app/models/notification.rb +++ b/app/models/notification.rb @@ -29,7 +29,7 @@ class Notification :kind => kind, :person_id => person.id, :user_id => user.id) - n.email_the_user(object) unless user.disable_mail || !n + n.email_the_user(object) if n n.socket_to_uid(user) if n n end @@ -43,7 +43,9 @@ class Notification when "request_accepted" self.user.mail(Jobs::MailRequestAcceptance, self.user_id, self.person_id) when "comment_on_post" - self.user.mail(Jobs::MailCommentOnPost, self.user_id, self.person_id, object) + self.user.mail(Jobs::MailCommentOnPost, self.user_id, self.person_id, object.id) + when "also_commented" + self.user.mail(Jobs::MailAlsoCommented, self.user_id, self.person_id, object.id) end end end diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index a887a55933fc7ec0c7b61bc34c2cb8d50be3a40b..24b16d056c2a6d3a6461df9e4f5ee4d54a6acf14 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -188,6 +188,7 @@ en: request_accepted: "accepted your share request." new_request: "offered to share with you." comment_on_post: "commented on your" + also_commented: "also commented on" post: 'post' deleted: 'deleted' index: @@ -436,6 +437,10 @@ en: subject: "%{name} has commented on your post." commented: "has commented on your post!" sign_in: "Sign in to view it." + also_commented: + subject: "%{name} has also commented." + commented: "has also commented on %{post_author}'s post:" + sign_in: "Sign in to view it." home: show: share_what_you_want: "Share what you want, with whom you want." diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 6f34431fbb9129f8e8cf9b28c1fdebd62a777bff..f5b8d9e0c4e4cb7132f04ad7884485dd58888a6a 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -81,26 +81,52 @@ describe Notifier do end end - describe "#comment_on_post" do + context "comments" do let!(:connect) { connect_users(user, aspect, user2, aspect2)} let!(:sm) {user.post(:status_message, :message => "Sunny outside", :to => :all)} let!(:comment) { user2.comment("Totally is", :on => sm )} - let!(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment)} + describe "#comment_on_post" do - it 'goes to the right person' do - comment_mail.to.should == [user.email] - end + let!(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment).deliver} - it 'has the receivers name in the body' do - comment_mail.body.encoded.include?(user.person.profile.first_name).should be true - end + it 'goes to the right person' do + comment_mail.to.should == [user.email] + end + + it 'has the receivers name in the body' do + comment_mail.body.encoded.include?(user.person.profile.first_name).should be true + end + + it 'has the name of person commenting' do + comment_mail.body.encoded.include?(person.name).should be true + end + + it 'has the post link in the body' do + comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true + end - it 'has the name of person commenting' do - comment_mail.body.encoded.include?(person.name).should be true end + describe "#also commented" do + + let!(:comment_mail) {Notifier.also_commented(user.id, person.id, comment)} + + it 'goes to the right person' do + comment_mail.to.should == [user.email] + end + + it 'has the receivers name in the body' do + comment_mail.body.encoded.include?(user.person.profile.first_name).should be true + end + + it 'has the name of person commenting' do + comment_mail.body.encoded.include?(person.name).should be true + end + + it 'has the post link in the body' do + comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true + end - it 'has the post link in the body' do - comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true end + end end diff --git a/spec/models/comment_spec.rb b/spec/models/comment_spec.rb index a109b9499bf3c99da34e9ff4d455a011c74e2496..05c30280c561ec00d3ed45e90fcefc902f7e396a 100644 --- a/spec/models/comment_spec.rb +++ b/spec/models/comment_spec.rb @@ -54,26 +54,43 @@ describe Comment do user2.person.id => user2.person, } end + end + + describe 'comment#notification_type' do + let(:user3) {make_user} + let(:aspect3) {user3.aspects.create(:name => "Faces")} + let!(:connecting2) { connect_users(user, aspect, user3, aspect3) } + before do + @post2 = user2.post(:status_message, :message => 'yo', :to => aspect2.id) + @post1 = user.post(:status_message, :message => "hello", :to => aspect.id) + @c11 = user2.comment "why so formal?", :on => @post1 + @c12 = user.comment "I simply felt like issuing a greeting. Do step off.", :on => @post1 + @c22 = user2.comment "I simply felt like issuing a greeting. Do step off.", :on => @post2 end - describe 'comment#notification_type' do - before do - @not_your_post = user2.post(:status_message, :message => 'yo', :to => aspect2.id) - @hello = user.post(:status_message, :message => "hello", :to => aspect.id) - @c11 = user2.comment "why so formal?", :on => @hello - @c12 = user.comment "I simply felt like issuing a greeting. Do step off.", :on => @hello - @c12 = user2.comment "I simply felt like issuing a greeting. Do step off.", :on => @not_your_post + it "returns 'comment_on_post' if the comment is on a post you own" do + @c11.notification_type(user, user2.person).should == 'comment_on_post' + end - end + it 'returns false if the comment is not on a post you own and noone "also_commented"' do + @c12.notification_type(user3, user.person).should == false + end - it "returns 'comment_on_post' if the comment is on a post you own" do - @c11.notification_type(user, user2.person).should == 'comment_on_post' - - end - it 'returns false if the comment is not on a post you own' do - @c11.notification_type(user2, user.person).should == false - end + + context "also commented" do + before do + @c13 = user3.comment "I also commented on the first user's post", :on => @post1 + end + + it 'does not return also commented if the user commented' do + @c13.notification_type(user3, user.person).should == false + end + + it "returns 'also_commented' if another person commented on a post you commented on" do + @c13.notification_type(user2, user.person).should == 'also_commented' + end + end end diff --git a/spec/models/user/connecting_spec.rb b/spec/models/user/connecting_spec.rb index 819b8ae3dd964f82e0f9a33a538c4a2776073474..42fa524ad803687e13e3c540f6d8d67b8b02aa86 100644 --- a/spec/models/user/connecting_spec.rb +++ b/spec/models/user/connecting_spec.rb @@ -60,6 +60,14 @@ describe Diaspora::UserModules::Connecting do Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id) user.receive_object(@r, person) end + + it 'should not lock the connection after ignore' do + user.send_friend_request_to(user2, aspect) + user2.pending_request.count.should == 1 + user2.ignore_request(user2.pending_requests.first) + user.send_friend_request_to(user2, aspect) + user2.pending_request.count.should == 1 + end end describe '#receive_request_acceptance' do