diff --git a/app/models/jobs/receive_local_batch.rb b/app/models/jobs/receive_local_batch.rb new file mode 100644 index 0000000000000000000000000000000000000000..3439e1b1deffd72e94738e17b69b548227bae6cb --- /dev/null +++ b/app/models/jobs/receive_local_batch.rb @@ -0,0 +1,21 @@ +# 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 ReceiveLocalBatch < Base + require File.join(Rails.root, 'lib/postzord/receiver') + + @queue = :receive + def self.perform_delegate(author_id, post_id, recipient_user_ids) + end + def self.create_visibilities(post, recipient_user_ids) + aspects = Aspect.where(:user_id => recipient_user_ids).joins(:contacts).where(:contacts => {:person_id => post.author_id}).select('aspects.id') + aspects.each do |aspect| + PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id) + post.socket_to_user(aspect.user_id, :aspect_ids => [aspect.id]) if post.respond_to? :socket_to_user + end + end + end +end diff --git a/spec/models/jobs/receive_local_batch_spec.rb b/spec/models/jobs/receive_local_batch_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..d3ff0207ebb50bc8b1d8705b2640b3049bc7ad39 --- /dev/null +++ b/spec/models/jobs/receive_local_batch_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' +describe Job::ReceiveLocalBatch do + #takes author id, post id and array of receiving user ids + #for each recipient, it gets the aspects that the author is in + #Gets all the aspect ids, and inserts into post_visibilities for each aspect + #Then it sockets to those users + #And notifies mentioned people + before do + @post = alice.build_post(:status_message, :text => 'Hey Bob') + @post.save! + end + describe '.perform_delegate' do + it 'calls .create_visibilities' do + end + it 'sockets to users' do + end + it 'notifies mentioned users' do + end + end + describe '.create_visibilities' do + it 'creates a visibility for each user' do + PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_false + Job::ReceiveLocalBatch.create_visibilities(@post, [bob.id]) + PostVisibility.exists?(:aspect_id => bob.aspects.first, :post_id => @post.id).should be_true + end + end + describe '.socket_to_users' do + + end +end