From 86b37466d56e3465633fb30cd3e903fb5d96e404 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 1 Jun 2016 17:15:37 +0200 Subject: [PATCH] add DeferredRetraction worker --- app/workers/deferred_retraction.rb | 17 +++++++++++++++++ lib/diaspora/federated/retraction.rb | 11 ++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 app/workers/deferred_retraction.rb diff --git a/app/workers/deferred_retraction.rb b/app/workers/deferred_retraction.rb new file mode 100644 index 000000000..7c1425f4f --- /dev/null +++ b/app/workers/deferred_retraction.rb @@ -0,0 +1,17 @@ +# Copyright (c) 2010-2011, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +module Workers + class DeferredRetraction < Base + sidekiq_options queue: :dispatch + + def perform(user_id, retraction_data, recipient_ids) + user = User.find(user_id) + subscribers = Person.where(id: recipient_ids) + object = Retraction.new(retraction_data.deep_symbolize_keys, subscribers) + + Diaspora::Federation::Dispatcher.build(user, object).dispatch + end + end +end diff --git a/lib/diaspora/federated/retraction.rb b/lib/diaspora/federated/retraction.rb index 277f5c228..277616cad 100644 --- a/lib/diaspora/federated/retraction.rb +++ b/lib/diaspora/federated/retraction.rb @@ -10,6 +10,11 @@ class Retraction attr_accessor :person, :object, :subscribers + def initialize(data, subscribers) + @data = data + @subscribers = subscribers + end + def subscribers unless self.type == 'Person' @subscribers ||= object.subscribers @@ -22,7 +27,7 @@ class Retraction end def self.for(object) - retraction = self.new + retraction = new({}, []) if object.is_a? User retraction.post_guid = object.person.guid retraction.type = object.person.class.to_s @@ -39,6 +44,10 @@ class Retraction @target ||= self.type.constantize.where(:guid => post_guid).first end + def defer_dispatch(user) + Workers::DeferredRetraction.perform_async(user.id, data, subscribers.map(&:id)) + end + def perform receiving_user logger.debug "Performing retraction for #{post_guid}"