also commented notification and sending ids into resque so that it works

This commit is contained in:
zhitomirskiyi 2011-01-06 15:56:03 -08:00
parent 27d8cc8003
commit 3fae950905
9 changed files with 119 additions and 37 deletions

View file

@ -14,6 +14,13 @@ module NotificationsHelper
else else
"#{translation} #{t('notifications.deleted')} #{t('notifications.post')}" "#{translation} #{t('notifications.deleted')} #{t('notifications.post')}"
end 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 else
end end
end end

View file

@ -46,10 +46,10 @@ class Notifier < ActionMailer::Base
:subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host) :subject => I18n.t('notifier.request_accepted.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
end 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) @receiver = User.find_by_id(recipient_id)
@sender = Person.find_by_id(sender_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') 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) :subject => I18n.t('notifier.comment_on_post.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
end 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 private
def log_mail recipient_id, sender_id, type 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}" log_string = "event=mail mail_type=#{type} db_name=#{MongoMapper.database.name} recipient_id=#{recipient_id} sender_id=#{sender_id}"

View file

@ -45,6 +45,8 @@ class Comment
def notification_type(user, person) def notification_type(user, person)
if self.post.diaspora_handle == user.diaspora_handle if self.post.diaspora_handle == user.diaspora_handle
return "comment_on_post" return "comment_on_post"
elsif self.post.comments.all(:diaspora_handle => user.diaspora_handle) != [] && self.diaspora_handle != user.diaspora_handle
return "also_commented"
else else
return false return false
end end

View file

@ -2,8 +2,8 @@ module Jobs
class MailCommentOnPost class MailCommentOnPost
extend ResqueJobLogging extend ResqueJobLogging
@queue = :mail @queue = :mail
def self.perform(recipient_id, sender_id, comment) def self.perform(recipient_id, sender_id, comment_id)
Notifier.comment_on_post(recipient_id, sender_id, comment).deliver Notifier.comment_on_post(recipient_id, sender_id, comment_id).deliver
end end
end end
end end

View file

@ -29,7 +29,7 @@ class Notification
:kind => kind, :kind => kind,
:person_id => person.id, :person_id => person.id,
:user_id => user.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.socket_to_uid(user) if n
n n
end end
@ -43,7 +43,9 @@ class Notification
when "request_accepted" when "request_accepted"
self.user.mail(Jobs::MailRequestAcceptance, self.user_id, self.person_id) self.user.mail(Jobs::MailRequestAcceptance, self.user_id, self.person_id)
when "comment_on_post" 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 end
end end

View file

@ -188,6 +188,7 @@ en:
request_accepted: "accepted your share request." request_accepted: "accepted your share request."
new_request: "offered to share with you." new_request: "offered to share with you."
comment_on_post: "commented on your" comment_on_post: "commented on your"
also_commented: "also commented on"
post: 'post' post: 'post'
deleted: 'deleted' deleted: 'deleted'
index: index:
@ -436,6 +437,10 @@ en:
subject: "%{name} has commented on your post." subject: "%{name} has commented on your post."
commented: "has commented on your post!" commented: "has commented on your post!"
sign_in: "Sign in to view it." 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: home:
show: show:
share_what_you_want: "Share what you want, with whom you want." share_what_you_want: "Share what you want, with whom you want."

View file

@ -81,11 +81,13 @@ describe Notifier do
end end
end end
describe "#comment_on_post" do context "comments" do
let!(:connect) { connect_users(user, aspect, user2, aspect2)} let!(:connect) { connect_users(user, aspect, user2, aspect2)}
let!(:sm) {user.post(:status_message, :message => "Sunny outside", :to => :all)} let!(:sm) {user.post(:status_message, :message => "Sunny outside", :to => :all)}
let!(:comment) { user2.comment("Totally is", :on => sm )} 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
let!(:comment_mail) {Notifier.comment_on_post(user.id, person.id, comment).deliver}
it 'goes to the right person' do it 'goes to the right person' do
comment_mail.to.should == [user.email] comment_mail.to.should == [user.email]
@ -102,5 +104,29 @@ describe Notifier do
it 'has the post link in the body' do it 'has the post link in the body' do
comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true comment_mail.body.encoded.include?("#{comment.post.id.to_s}").should be true
end end
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
end
end end
end end

View file

@ -57,22 +57,39 @@ describe Comment do
end end
describe 'comment#notification_type' do 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 before do
@not_your_post = user2.post(:status_message, :message => 'yo', :to => aspect2.id) @post2 = user2.post(:status_message, :message => 'yo', :to => aspect2.id)
@hello = user.post(:status_message, :message => "hello", :to => aspect.id) @post1 = user.post(:status_message, :message => "hello", :to => aspect.id)
@c11 = user2.comment "why so formal?", :on => @hello @c11 = user2.comment "why so formal?", :on => @post1
@c12 = user.comment "I simply felt like issuing a greeting. Do step off.", :on => @hello @c12 = user.comment "I simply felt like issuing a greeting. Do step off.", :on => @post1
@c12 = user2.comment "I simply felt like issuing a greeting. Do step off.", :on => @not_your_post @c22 = user2.comment "I simply felt like issuing a greeting. Do step off.", :on => @post2
end end
it "returns 'comment_on_post' if the comment is on a post you own" do 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' @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' do it 'returns false if the comment is not on a post you own and noone "also_commented"' do
@c11.notification_type(user2, user.person).should == false @c12.notification_type(user3, 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
end end

View file

@ -60,6 +60,14 @@ describe Diaspora::UserModules::Connecting do
Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id) Resque.should_receive(:enqueue).with(Jobs::MailRequestReceived, user.id, person.id)
user.receive_object(@r, person) user.receive_object(@r, person)
end 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 end
describe '#receive_request_acceptance' do describe '#receive_request_acceptance' do