notifier for the messages, we're so close
This commit is contained in:
parent
fca5310c77
commit
8bcf1b49c7
12 changed files with 183 additions and 3 deletions
|
|
@ -97,6 +97,24 @@ class Notifier < ActionMailer::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def private_message(recipient_id, sender_id, message_id)
|
||||||
|
@receiver = User.find_by_id(recipient_id)
|
||||||
|
@sender = Person.find_by_id(sender_id)
|
||||||
|
@message = Message.find_by_id(message_id)
|
||||||
|
@conversation = @message.conversation
|
||||||
|
@participants = @conversation.participants
|
||||||
|
|
||||||
|
|
||||||
|
log_mail(recipient_id, sender_id, 'private_message')
|
||||||
|
|
||||||
|
attachments.inline['logo_caps.png'] = ATTACHMENT
|
||||||
|
|
||||||
|
I18n.with_locale(@receiver.language) do
|
||||||
|
mail(:to => "\"#{@receiver.name}\" <#{@receiver.email}>",
|
||||||
|
:subject => I18n.t('notifier.private_message.subject', :name => @sender.name), :host => AppConfig[:pod_uri].host)
|
||||||
|
end
|
||||||
|
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} recipient_id=#{recipient_id} sender_id=#{sender_id}"
|
log_string = "event=mail mail_type=#{type} recipient_id=#{recipient_id} sender_id=#{sender_id}"
|
||||||
|
|
|
||||||
15
app/models/jobs/mail_private_message.rb
Normal file
15
app/models/jobs/mail_private_message.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
@ -67,6 +67,10 @@ class Message < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def notification_type(user, person)
|
||||||
|
Notifications::PrivateMessage
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def participant_of_parent_conversation
|
def participant_of_parent_conversation
|
||||||
if self.parent && !self.parent.participants.include?(self.author)
|
if self.parent && !self.parent.participants.include?(self.author)
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,9 @@ class Notification < ActiveRecord::Base
|
||||||
if target.respond_to? :notification_type
|
if target.respond_to? :notification_type
|
||||||
if note_type = target.notification_type(recipient, actor)
|
if note_type = target.notification_type(recipient, actor)
|
||||||
if target.is_a? Comment
|
if target.is_a? Comment
|
||||||
n = concatenate_or_create(recipient, target.post, actor, note_type)
|
n = note_type.concatenate_or_create(recipient, target.post, actor, note_type)
|
||||||
else
|
else
|
||||||
n = make_notification(recipient, target, actor, note_type)
|
n = note_type.make_notification(recipient, target, actor, note_type)
|
||||||
end
|
end
|
||||||
n.email_the_user(target, actor) if n
|
n.email_the_user(target, actor) if n
|
||||||
n.socket_to_user(recipient, :actor => actor) if n
|
n.socket_to_user(recipient, :actor => actor) if n
|
||||||
|
|
|
||||||
15
app/models/notifications/private_message.rb
Normal file
15
app/models/notifications/private_message.rb
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
class Notifications::PrivateMessage < Notification
|
||||||
|
def mail_job
|
||||||
|
Job::MailPrivateMessage
|
||||||
|
end
|
||||||
|
def translation_key
|
||||||
|
'private_message'
|
||||||
|
end
|
||||||
|
def self.make_notification(recipient, target, actor, notification_type)
|
||||||
|
n = notification_type.new(:target => target,
|
||||||
|
:recipient_id => recipient.id)
|
||||||
|
|
||||||
|
n.actors << actor
|
||||||
|
n
|
||||||
|
end
|
||||||
|
end
|
||||||
16
app/views/notifier/private_message.html.haml
Normal file
16
app/views/notifier/private_message.html.haml
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
%p
|
||||||
|
= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||||
|
%p
|
||||||
|
= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||||
|
= t('.private_message')
|
||||||
|
%p
|
||||||
|
= @message.text
|
||||||
|
%p
|
||||||
|
|
||||||
|
%br
|
||||||
|
= link_to t('.sign_in'), conversation_url(@cnv)
|
||||||
|
|
||||||
|
%br
|
||||||
|
= t('notifier.love')
|
||||||
|
%br
|
||||||
|
= t('notifier.diaspora')
|
||||||
8
app/views/notifier/private_message.text.haml
Normal file
8
app/views/notifier/private_message.text.haml
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
= t('notifier.hello', :name => @receiver.profile.first_name)
|
||||||
|
= "#{@sender.name} (#{@sender.diaspora_handle})"
|
||||||
|
= t('notifier.private_message.private_message')
|
||||||
|
|
||||||
|
= @message.text
|
||||||
|
|
||||||
|
= "#{t('notifier.love')} \n"
|
||||||
|
= t('notifier.diaspora')
|
||||||
|
|
@ -488,6 +488,10 @@ en:
|
||||||
subject: "%{name} has mentioned you on Diaspora*"
|
subject: "%{name} has mentioned you on Diaspora*"
|
||||||
mentioned: "mentioned you in a post:"
|
mentioned: "mentioned you in a post:"
|
||||||
sign_in: "Sign in to view it."
|
sign_in: "Sign in to view it."
|
||||||
|
private_message:
|
||||||
|
subject: "%{name} has sent you a private message yon Diaspora*"
|
||||||
|
private_message: "has sent you a private message:"
|
||||||
|
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."
|
||||||
|
|
|
||||||
|
|
@ -110,7 +110,38 @@ describe Notifier do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe ".private_message" do
|
||||||
|
before do
|
||||||
|
@user2 = bob
|
||||||
|
@participant_ids = @user2.contacts.map{|c| c.person.id} + [ @user2.person.id]
|
||||||
|
|
||||||
|
@create_hash = { :author => @user2.person, :participant_ids => @participant_ids ,
|
||||||
|
:subject => "cool stuff", :text => 'hey'}
|
||||||
|
|
||||||
|
@cnv = Conversation.create(@create_hash)
|
||||||
|
|
||||||
|
@mail = Notifier.private_message(user.id, @cnv.author.id, @cnv.id)
|
||||||
|
end
|
||||||
|
it 'goes to the right person' do
|
||||||
|
@mail.to.should == [user.email]
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the recipients in the body' do
|
||||||
|
@mail.body.encoded.include?(user.person.first_name).should be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the name of the sender in the body' do
|
||||||
|
@mail.body.encoded.include?(@cnv.author.name).should be true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'has the post text in the body' do
|
||||||
|
@mail.body.encoded.should include(@cnv.messages.first.text)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not include translation missing' do
|
||||||
|
@mail.body.encoded.should_not include("missing")
|
||||||
|
end
|
||||||
|
end
|
||||||
context "comments" 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)}
|
||||||
|
|
|
||||||
27
spec/models/jobs/mail_private_message.rb
Normal file
27
spec/models/jobs/mail_private_message.rb
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Job::MailPrivateMessage do
|
||||||
|
describe '#perfom_delegate' do
|
||||||
|
it 'should call .deliver on the notifier object' do
|
||||||
|
user1 = alice
|
||||||
|
user2 = bob
|
||||||
|
participant_ids = [user1.contacts.first.person.id, user1.person.id]
|
||||||
|
|
||||||
|
create_hash = { :author => user1.person, :participant_ids => participant_ids ,
|
||||||
|
:subject => "cool stuff", :text => 'hey'}
|
||||||
|
|
||||||
|
cnv = Conversation.create(create_hash)
|
||||||
|
message = cnv.messages.first
|
||||||
|
|
||||||
|
mail_mock = mock()
|
||||||
|
mail_mock.should_receive(:deliver)
|
||||||
|
Notifier.should_receive(:mentioned).with(user2.id, user1.person.id, message.id).and_return(mail_mock)
|
||||||
|
|
||||||
|
Job::MailMentioned.perform_delegate(user2.id, user1.person.id, message.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -44,7 +44,8 @@ describe Notification do
|
||||||
Notification.should_not_receive(:make_notificatin)
|
Notification.should_not_receive(:make_notificatin)
|
||||||
Notification.notify(@user, @sm, @person)
|
Notification.notify(@user, @sm, @person)
|
||||||
end
|
end
|
||||||
context 'with a request' do
|
|
||||||
|
context 'with a request' do
|
||||||
before do
|
before do
|
||||||
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
@request = Request.diaspora_initialize(:from => @user.person, :to => @user2.person, :into => @aspect)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
41
spec/models/notifications/private_message_spec.rb
Normal file
41
spec/models/notifications/private_message_spec.rb
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
# Copyright (c) 2010, Diaspora Inc. This file is
|
||||||
|
# licensed under the Affero General Public License version 3 or later. See
|
||||||
|
# the COPYRIGHT file.
|
||||||
|
|
||||||
|
require 'spec_helper'
|
||||||
|
|
||||||
|
describe Notifications::PrivateMessage do
|
||||||
|
before do
|
||||||
|
@user1 = alice
|
||||||
|
@user2 = bob
|
||||||
|
|
||||||
|
@create_hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.person.id],
|
||||||
|
:subject => "cool stuff", :text => "stuff"}
|
||||||
|
|
||||||
|
@cnv = Conversation.create(@create_hash)
|
||||||
|
@msg = @cnv.messages.first
|
||||||
|
end
|
||||||
|
|
||||||
|
describe '#make_notifiaction' do
|
||||||
|
it 'does not save the notification' do
|
||||||
|
lambda{
|
||||||
|
Notification.notify(@user2, @msg, @user1.person)
|
||||||
|
}.should_not change(Notification, :count)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'does email the user' do
|
||||||
|
opts = {
|
||||||
|
:actors => [@user1.person],
|
||||||
|
:recipient_id => @user2.id}
|
||||||
|
|
||||||
|
n = Notifications::PrivateMessage.new(opts)
|
||||||
|
Notifications::PrivateMessage.stub!(:make_notification).and_return(n)
|
||||||
|
Notification.notify(@user2, @msg, @user1.person)
|
||||||
|
n.stub!(:recipient).and_return @user2
|
||||||
|
|
||||||
|
@user2.should_receive(:mail)
|
||||||
|
n.email_the_user(@msg, @user1.person)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
Loading…
Reference in a new issue