Finish receive local batch job
This commit is contained in:
parent
72523cc7f9
commit
d2cdc20e2b
2 changed files with 41 additions and 2 deletions
|
|
@ -8,7 +8,11 @@ module Job
|
||||||
require File.join(Rails.root, 'lib/postzord/receiver')
|
require File.join(Rails.root, 'lib/postzord/receiver')
|
||||||
|
|
||||||
@queue = :receive
|
@queue = :receive
|
||||||
def self.perform_delegate(author_id, post_id, recipient_user_ids)
|
def self.perform_delegate(post_id, recipient_user_ids)
|
||||||
|
post = Post.find(post_id)
|
||||||
|
create_visibilities(post, recipient_user_ids)
|
||||||
|
socket_to_users(post, recipient_user_ids)
|
||||||
|
notify_mentioned_users(post)
|
||||||
end
|
end
|
||||||
def self.create_visibilities(post, recipient_user_ids)
|
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.user_id')
|
aspects = Aspect.where(:user_id => recipient_user_ids).joins(:contacts).where(:contacts => {:person_id => post.author_id}).select('aspects.id, aspects.user_id')
|
||||||
|
|
@ -17,5 +21,15 @@ module Job
|
||||||
post.socket_to_user(aspect.user_id, :aspect_ids => [aspect.id]) if post.respond_to? :socket_to_user
|
post.socket_to_user(aspect.user_id, :aspect_ids => [aspect.id]) if post.respond_to? :socket_to_user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
def self.socket_to_users(post, recipient_user_ids)
|
||||||
|
recipient_user_ids.each do |id|
|
||||||
|
SocketsController.new.outgoing(id, post)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
def self.notify_mentioned_users(post)
|
||||||
|
post.mentions.each do |mention|
|
||||||
|
mention.notify_recipient
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,16 @@ describe Job::ReceiveLocalBatch do
|
||||||
end
|
end
|
||||||
describe '.perform_delegate' do
|
describe '.perform_delegate' do
|
||||||
it 'calls .create_visibilities' do
|
it 'calls .create_visibilities' do
|
||||||
|
Job::ReceiveLocalBatch.should_receive(:create_visibilities).with(@post, [bob.id])
|
||||||
|
Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
|
||||||
end
|
end
|
||||||
it 'sockets to users' do
|
it 'sockets to users' do
|
||||||
|
Job::ReceiveLocalBatch.should_receive(:socket_to_users).with(@post, [bob.id])
|
||||||
|
Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
|
||||||
end
|
end
|
||||||
it 'notifies mentioned users' do
|
it 'notifies mentioned users' do
|
||||||
|
Job::ReceiveLocalBatch.should_receive(:notify_mentioned_users).with(@post)
|
||||||
|
Job::ReceiveLocalBatch.perform_delegate(@post.id, [bob.id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe '.create_visibilities' do
|
describe '.create_visibilities' do
|
||||||
|
|
@ -25,6 +31,25 @@ describe Job::ReceiveLocalBatch do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
describe '.socket_to_users' do
|
describe '.socket_to_users' do
|
||||||
|
before do
|
||||||
|
@controller = mock()
|
||||||
|
SocketsController.stub(:new).and_return(@controller)
|
||||||
|
end
|
||||||
|
it 'sockets to each user' do
|
||||||
|
@controller.should_receive(:outgoing).with(bob.id, @post)
|
||||||
|
Job::ReceiveLocalBatch.socket_to_users(@post, [bob.id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
describe '.notify_mentioned_users' do
|
||||||
|
it 'calls notify person for a mentioned person' do
|
||||||
|
@post = alice.build_post(:status_message, :text => "Hey @{Bob; #{bob.diaspora_handle}}")
|
||||||
|
@post.save!
|
||||||
|
Notification.should_receive(:notify).with(bob, anything, alice.person)
|
||||||
|
Job::ReceiveLocalBatch.notify_mentioned_users(@post)
|
||||||
|
end
|
||||||
|
it 'does not call notify person for a non-mentioned person' do
|
||||||
|
Notification.should_not_receive(:notify)
|
||||||
|
Job::ReceiveLocalBatch.notify_mentioned_users(@post)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue