diff --git a/app/models/conversation.rb b/app/models/conversation.rb index a1e40665d..785e80628 100644 --- a/app/models/conversation.rb +++ b/app/models/conversation.rb @@ -65,7 +65,8 @@ class Conversation < ActiveRecord::Base end self.messages.each do |msg| msg.conversation_id = cnv.id - msg.receive(user, person) + received_msg = msg.receive(user, person) + Notification.notify(user, received_msg, person) if msg.respond_to?(:notification_type) end end end diff --git a/app/models/jobs/mail_private_message.rb b/app/models/jobs/mail_private_message.rb index 232ed9a61..d372d990a 100644 --- a/app/models/jobs/mail_private_message.rb +++ b/app/models/jobs/mail_private_message.rb @@ -7,9 +7,7 @@ module Job class MailPrivateMessage < Base @queue = :mail def self.perform_delegate(recipient_id, actor_id, target_id) - Notifier.private_message( recipient_id, actor_id, target_id).deliver - end end end diff --git a/app/models/message.rb b/app/models/message.rb index c4d41bb0c..abebfc04d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -68,7 +68,7 @@ class Message < ActiveRecord::Base end def notification_type(user, person) - Notifications::PrivateMessage + Notifications::PrivateMessage unless user.person == person end private diff --git a/app/views/notifier/private_message.html.haml b/app/views/notifier/private_message.html.haml index f6d6b48c6..18c1b335f 100644 --- a/app/views/notifier/private_message.html.haml +++ b/app/views/notifier/private_message.html.haml @@ -3,12 +3,14 @@ %p = "#{@sender.name} (#{@sender.diaspora_handle})" = t('.private_message') +%p + = t('.message_subject', :subject => @conversation.subject) %p = @message.text %p %br - = link_to t('.sign_in'), conversation_url(@cnv) + = link_to t('.sign_in'), conversation_url(@conversation) %br = t('notifier.love') diff --git a/app/views/notifier/private_message.text.haml b/app/views/notifier/private_message.text.haml index d86a91780..58419ab2c 100644 --- a/app/views/notifier/private_message.text.haml +++ b/app/views/notifier/private_message.text.haml @@ -2,6 +2,7 @@ = "#{@sender.name} (#{@sender.diaspora_handle})" = t('notifier.private_message.private_message') += t('notifier.private_message.message_subject', :subject => @conversation.subject) = @message.text = "#{t('notifier.love')} \n" diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 8131d11b0..a5f0f617e 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -493,6 +493,7 @@ en: private_message: subject: "%{name} has sent you a private message yon Diaspora*" private_message: "has sent you a private message:" + message_subject: "Subject: %{subject}" sign_in: "Sign in to view it." home: show: diff --git a/spec/mailers/notifier_spec.rb b/spec/mailers/notifier_spec.rb index 9ce3bd699..b2ed38bb3 100644 --- a/spec/mailers/notifier_spec.rb +++ b/spec/mailers/notifier_spec.rb @@ -120,7 +120,7 @@ describe Notifier do @cnv = Conversation.create(@create_hash) - @mail = Notifier.private_message(user.id, @cnv.author.id, @cnv.id) + @mail = Notifier.private_message(user.id, @cnv.author.id, @cnv.messages.first.id) end it 'goes to the right person' do @mail.to.should == [user.email] @@ -134,6 +134,10 @@ describe Notifier do @mail.body.encoded.include?(@cnv.author.name).should be true end + it 'has the conversation subject in the body' do + @mail.body.encoded.should include(@cnv.subject) + end + it 'has the post text in the body' do @mail.body.encoded.should include(@cnv.messages.first.text) end diff --git a/spec/models/conversation_spec.rb b/spec/models/conversation_spec.rb index 9bfa725bd..89ac00a30 100644 --- a/spec/models/conversation_spec.rb +++ b/spec/models/conversation_spec.rb @@ -83,6 +83,10 @@ describe Conversation do it 'does not save before receive' do Diaspora::Parser.from_xml(@xml).persisted?.should be_false end + it 'notifies for the message' do + Notification.should_receive(:notify).once + Diaspora::Parser.from_xml(@xml).receive(@user1, @user2.person) + end end end end diff --git a/spec/models/message_spec.rb b/spec/models/message_spec.rb index 99aca42df..859900f4b 100644 --- a/spec/models/message_spec.rb +++ b/spec/models/message_spec.rb @@ -20,7 +20,16 @@ describe Message do it 'validates that the author is a participant in the conversation' do msg = Message.new(:text => 'yo', :author => eve.person, :conversation_id => @cnv.id) - pp msg.valid? + end + + describe '#notification_type' do + it 'does not return anything for the author' do + @message.notification_type(@user1, @user1.person).should be_nil + end + + it 'returns private mesage for an actual receiver' do + @message.notification_type(@user2, @user1.person).should == Notifications::PrivateMessage + end end describe '#before_create' do diff --git a/spec/shared_behaviors/relayable.rb b/spec/shared_behaviors/relayable.rb index ba809119a..f6cc2d1a3 100644 --- a/spec/shared_behaviors/relayable.rb +++ b/spec/shared_behaviors/relayable.rb @@ -68,6 +68,7 @@ describe Diaspora::Relayable do it 'calls after_receive callback' do @object_by_recipient.should_receive(:after_receive) + @object_by_recipient.class.stub(:where).and_return([@object_by_recipient]) @object_by_recipient.receive(@local_luke, @local_leia.person) end end