diff options
author | Jason Robinson <mail@jasonrobinson.me> | 2015-07-17 16:59:27 +0300 |
---|---|---|
committer | Jason Robinson <mail@jasonrobinson.me> | 2015-07-18 21:29:31 +0300 |
commit | bdf6c717729e0752f450cdd7592a49b2b2f39439 (patch) | |
tree | d26bc55aa3ddac65e94f39c9700da3ebf1a0e666 /app/workers | |
parent | 0e439f6c1c66e46457bd26ff640c2278e53d9b9b (diff) |
Implement social relay functionality
* .well-known/social-relay - to serve subscription preferences to relays
* Workers.deferred_dispatch relay carbon copy functionality for outbound sending
See discussion here: https://www.loomio.org/d/9vpoe0UR/public-post-federation#comment-730911 and spec here: https://wiki.diasporafoundation.org/Relay_servers_for_public_posts
Diffstat (limited to 'app/workers')
-rw-r--r-- | app/workers/deferred_dispatch.rb | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/app/workers/deferred_dispatch.rb b/app/workers/deferred_dispatch.rb index 46fa894c3..fb5d4a311 100644 --- a/app/workers/deferred_dispatch.rb +++ b/app/workers/deferred_dispatch.rb @@ -10,14 +10,38 @@ 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)) + 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 + rescue ActiveRecord::RecordNotFound # The target got deleted before the job was run + end + + def add_additional_subscribers(object, object_class_name, opts) + if AppConfig.relay.outbound.send? && + object_class_name == "StatusMessage" && + object.respond_to?(:public?) && object.public? + handle_relay(opts) + end if opts[:additional_subscribers].present? - opts[:additional_subscribers] = Person.where(:id => opts[:additional_subscribers]) + opts[:additional_subscribers] = Person.where(id: opts[:additional_subscribers]) end + end - Postzord::Dispatcher.build(user, object, opts).post - rescue ActiveRecord::RecordNotFound # The target got deleted before the job was run + def handle_relay(opts) + relay_person = Person.find_by diaspora_handle: AppConfig.relay.outbound.handle.to_s + if relay_person + add_person_to_subscribers(opts, relay_person) + else + # Skip this message for relay and just queue a webfinger fetch for the relay handle + Workers::FetchWebfinger.perform_async(AppConfig.relay.outbound.handle) + end + end + + def add_person_to_subscribers(opts, person) + opts[:additional_subscribers] ||= [] + opts[:additional_subscribers] << person.id end end end |