added the email notification, the notification is not persisted, fixed the receive callback spec
This commit is contained in:
parent
d38e3a6b29
commit
c252cfa025
10 changed files with 28 additions and 7 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def notification_type(user, person)
|
||||
Notifications::PrivateMessage
|
||||
Notifications::PrivateMessage unless user.person == person
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue