diff --git a/app/models/jobs/receive_local.rb b/app/models/jobs/receive_local.rb new file mode 100644 index 000000000..ebe84bbdc --- /dev/null +++ b/app/models/jobs/receive_local.rb @@ -0,0 +1,11 @@ +module Jobs + class ReceiveLocal + @queue = :receive_local + def self.perform(user_id, person_id, object_type, object_id) + user = User.find(user_id) + person = Person.find(person_id) + object = eval("#{object_type}.first(:id => \"#{object_id}\")") + user.receive_object(object, person) + end + end +end diff --git a/app/models/user.rb b/app/models/user.rb index f3eb0367b..b3dae8374 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -189,7 +189,6 @@ class User def push_to_aspects(post, aspects) #send to the aspects - # target_aspect_ids = aspects.map {|a| a.id} target_contacts = Contact.all(:aspect_ids.in => target_aspect_ids, :pending => false) @@ -211,7 +210,12 @@ class User # calling nil? performs a necessary evaluation. if person.owner_id Rails.logger.info("event=push_to_person route=local sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}") - Resque.enqueue(Jobs::Receive, person.owner_id, post.to_diaspora_xml, self.person.id) + + if post.is_a?(Post) || post.is_a?(Comment) + Resque.enqueue(Jobs::ReceiveLocal, person.owner_id, self.person.id, post.class.to_s, post.id) + else + Resque.enqueue(Jobs::Receive, person.owner_id, post.to_diaspora_xml, self.person.id) + end else xml = salmon.xml_for person Rails.logger.info("event=push_to_person route=remote sender=#{self.diaspora_handle} recipient=#{person.diaspora_handle} payload_type=#{post.class}") diff --git a/spec/models/jobs/receive_local.rb b/spec/models/jobs/receive_local.rb new file mode 100644 index 000000000..e90d872f3 --- /dev/null +++ b/spec/models/jobs/receive_local.rb @@ -0,0 +1,39 @@ +require 'spec_helper' + +describe Jobs::ReceiveLocal do + before do + @user1 = make_user + @user2 = make_user + @status = Factory(:status_message) + @status_type = @status.class.to_s + + User.stub(:find){ |id| + if id == @user1.id + @user1 + else + nil + end + } + + Person.stub(:find){ |id| + if id == @user2.person.id + @user2.person + else + nil + end + } + + StatusMessage.stub(:find){ |id| + if id == @status.id + @status + else + nil + end + } + end + + it 'calls receive_object' do + @user1.should_receive(:receive_object).with(@status, @user2.person).and_return(true) + Jobs::ReceiveLocal.perform(@user1.id, @user2.person.id, @status_type, @status.id) + end +end diff --git a/spec/models/user/posting_spec.rb b/spec/models/user/posting_spec.rb index 15ec8c601..7aaa0d9ce 100644 --- a/spec/models/user/posting_spec.rb +++ b/spec/models/user/posting_spec.rb @@ -129,6 +129,7 @@ describe User do let!(:aspect4) { user4.aspects.create(:name => 'heroes') } let!(:post) { user.build_post :status_message, :message => "hey" } + let!(:request) { Request.instantiate(:from => user3.person, :to => user4.person) } before do connect_users(user, aspect, user2, aspect2) @@ -174,8 +175,13 @@ describe User do @salmon = user.salmon(post) @xml = post.to_diaspora_xml end - it 'enqueues receive for local contacts' do - Resque.should_receive(:enqueue).with(Jobs::Receive, user2.id, @xml, user.person.id) + it 'enqueues receive for requests and retractions for local contacts' do + xml = request.to_diaspora_xml + Resque.should_receive(:enqueue).with(Jobs::Receive, user2.id, xml, user.person.id) + user.push_to_person(@salmon, request, user2.person) + end + it 'enqueues receive for requests and retractions for local contacts' do + Resque.should_receive(:enqueue).with(Jobs::ReceiveLocal, user2.id, user.person.id, post.class.to_s, post.id) user.push_to_person(@salmon, post, user2.person) end it 'calls the MessageHandler for remote contacts' do