inital commit for mailqueue

This commit is contained in:
zhitomirskiyi 2010-11-04 12:04:07 -07:00 committed by maxwell
parent 693847480b
commit d793bdc3c7
7 changed files with 23 additions and 7 deletions

View file

@ -5,6 +5,7 @@ class Notifier < ActionMailer::Base
ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png") ATTACHMENT = File.read("#{Rails.root}/public/images/diaspora_white_on_grey.png")
def new_request(recipient, sender) def new_request(recipient, sender)
puts "I'm in new request"
@receiver = recipient @receiver = recipient
@sender = sender @sender = sender
attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT attachments.inline['diaspora_white_on_grey.png'] = ATTACHMENT
@ -22,4 +23,13 @@ class Notifier < ActionMailer::Base
mail(:to => "#{recipient.real_name} <#{recipient.email}>", mail(:to => "#{recipient.real_name} <#{recipient.email}>",
:subject => "#{@sender.real_name} has accepted your friend request on Diaspora*", :host => APP_CONFIG[:terse_pod_url]) :subject => "#{@sender.real_name} has accepted your friend request on Diaspora*", :host => APP_CONFIG[:terse_pod_url])
end end
def self.send_request_accepted!(user, person, aspect)
Notifier.async.request_accepted(user, person, aspect ).deliver.commit!
end
def self.send_new_request!(user, person)
Notifier.async.new_request(user, person).deliver.commit!
end
end end

View file

@ -67,7 +67,7 @@ module Diaspora
Rails.logger.info("#{self.real_name}'s friend request has been accepted") Rails.logger.info("#{self.real_name}'s friend request has been accepted")
friend_request.destroy friend_request.destroy
original_request.destroy original_request.destroy
Notifier.request_accepted(self, friend_request.person, destination_aspect) Notifier.send_request_accepted!(self, friend_request.person, destination_aspect)
#this is a new friend request #this is a new friend request
elsif !request_from_me?(friend_request) elsif !request_from_me?(friend_request)
@ -75,7 +75,7 @@ module Diaspora
self.save self.save
Rails.logger.info("#{self.real_name} has received a friend request") Rails.logger.info("#{self.real_name} has received a friend request")
friend_request.save friend_request.save
Notifier.new_request(self, friend_request.person).deliver Notifier.send_new_request!(self, friend_request.person)
else else
raise "#{self.real_name} is trying to receive a friend request from himself." raise "#{self.real_name} is trying to receive a friend request from himself."
end end

2
script/mail_worker.rb Normal file
View file

@ -0,0 +1,2 @@
require File.dirname(__FILE__) + '/../config/environment'
Magent::Processor.new(Magent::AsyncChannel.new(:default)).run!

View file

@ -50,4 +50,5 @@ fi
mkdir -p -v log/thin/ mkdir -p -v log/thin/
bundle exec ruby ./script/websocket_server.rb& bundle exec ruby ./script/websocket_server.rb&
bundle exec ruby ./script/mail_worker.rb&
bundle exec thin start $args bundle exec thin start $args

View file

@ -39,11 +39,12 @@ def process_message
else else
EM::Timer.new(1){process_message} EM::Timer.new(1){process_message}
end end
end end
begin begin
EM.run { EM.run {
Diaspora::WebSocket.initialize_channels Diaspora::WebSocket.initialize_channels
EventMachine::WebSocket.start( EventMachine::WebSocket.start(

View file

@ -18,6 +18,7 @@ describe Diaspora::UserModules::Friending do
let(:user2) { make_user } let(:user2) { make_user }
let(:aspect2) { user2.aspects.create(:name => "aspect two") } let(:aspect2) { user2.aspects.create(:name => "aspect two") }
context 'friend requesting' do context 'friend requesting' do
it "should assign a request to a aspect for the user that sent it out" do it "should assign a request to a aspect for the user that sent it out" do
aspect.requests.size.should == 0 aspect.requests.size.should == 0
@ -87,7 +88,7 @@ describe Diaspora::UserModules::Friending do
end end
it 'should send an email on acceptance if a friend request' do it 'should send an email on acceptance if a friend request' do
Notifier.should_receive(:request_accepted) Notifier.should_receive(:send_request_accepted!)
request = user.send_friend_request_to(user2.person, aspect) request = user.send_friend_request_to(user2.person, aspect)
user.receive_friend_request(request.reverse_for(user2)) user.receive_friend_request(request.reverse_for(user2))
end end
@ -133,9 +134,7 @@ describe Diaspora::UserModules::Friending do
end end
it 'sends an email to the receiving user' do it 'sends an email to the receiving user' do
mail_obj = mock("mailer") Notifier.should_receive(:send_new_request!).and_return(true)
mail_obj.should_receive(:deliver)
Notifier.should_receive(:new_request).and_return(mail_obj)
user.receive @req_xml, person_one user.receive @req_xml, person_one
end end
end end

View file

@ -33,6 +33,9 @@ RSpec.configure do |config|
EventMachine::HttpRequest.any_instance.stubs(:get) EventMachine::HttpRequest.any_instance.stubs(:get)
DatabaseCleaner.clean DatabaseCleaner.clean
UserFixer.load_user_fixtures UserFixer.load_user_fixtures
Notifier.stub!(:send_request_accepted!).and_return(true)
Notifier.stub!(:send_new_request!).and_return(true)
end end
end end