diaspora/app/models/jobs/receive_local_batch.rb
2011-03-22 13:44:55 -07:00

40 lines
1.5 KiB
Ruby

# 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(post_id, recipient_user_ids)
post = Post.find(post_id)
create_visibilities(post, recipient_user_ids)
socket_to_users(post, recipient_user_ids) if post.respond_to?(:socket_to_user)
notify_mentioned_users(post)
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.user_id')
Rails.logger.info(:event => :rlb_aspects, :aspect_ids => aspects.map{|a| a.id}.join(','))
aspects.each do |aspect|
begin
PostVisibility.create(:aspect_id => aspect.id, :post_id => post.id)
rescue ActiveRecord::RecordNotUnique => e
Rails.logger.info(:event => :unexpected_pv, :aspect_id => aspect.id, :post_id => post.id)
#The post was already visible to that aspect
end
end
end
def self.socket_to_users(post, recipient_user_ids)
recipient_user_ids.each do |id|
post.socket_to_user(id)
end
end
def self.notify_mentioned_users(post)
post.mentions.each do |mention|
mention.notify_recipient
end
end
end
end