first structure of Diaspora::Federation::Dispatcher
This commit is contained in:
parent
83f5662d62
commit
596659a78f
2 changed files with 50 additions and 3 deletions
|
|
@ -10,10 +10,8 @@ module Workers
|
|||
user = User.find(user_id)
|
||||
object = object_class_name.constantize.find(object_id)
|
||||
opts = HashWithIndifferentAccess.new(opts)
|
||||
opts[:services] = user.services.where(type: opts.delete(:service_types))
|
||||
|
||||
add_additional_subscribers(object, object_class_name, opts)
|
||||
Postzord::Dispatcher.build(user, object, opts).post
|
||||
Diaspora::Federation::Dispatcher.build(user, object, opts).dispatch
|
||||
rescue ActiveRecord::RecordNotFound # The target got deleted before the job was run
|
||||
end
|
||||
|
||||
|
|
|
|||
49
lib/diaspora/federation/dispatcher.rb
Normal file
49
lib/diaspora/federation/dispatcher.rb
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
module Diaspora
|
||||
module Federation
|
||||
class Dispatcher
|
||||
include Diaspora::Logging
|
||||
|
||||
def initialize(sender, object, opts={})
|
||||
@sender = sender
|
||||
@object = object
|
||||
@opts = opts
|
||||
end
|
||||
|
||||
def self.build(sender, object, opts={})
|
||||
new(sender, object, opts)
|
||||
end
|
||||
|
||||
def self.defer_dispatch(sender, object, opts={})
|
||||
Workers::DeferredDispatch.perform_async(sender.id, object.class.to_s, object.id, opts)
|
||||
end
|
||||
|
||||
def dispatch
|
||||
deliver_to_services
|
||||
deliver_to_subscribers
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
attr_reader :sender, :object, :opts
|
||||
|
||||
def deliver_to_services
|
||||
# TODO: pubsubhubbub, relay, social-network-services
|
||||
end
|
||||
|
||||
def deliver_to_subscribers
|
||||
local_people, remote_people = object.subscribers.partition(&:local?)
|
||||
|
||||
deliver_to_local(local_people) unless local_people.empty?
|
||||
deliver_to_remote(remote_people) unless remote_people.empty?
|
||||
end
|
||||
|
||||
def deliver_to_local(people)
|
||||
Workers::ReceiveLocal.perform_async(object.class.to_s, object.id, people.map(&:owner_id))
|
||||
end
|
||||
|
||||
def deliver_to_remote(people)
|
||||
# TODO: send to remote hosts
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue