add DeferredRetraction worker
This commit is contained in:
parent
ecbf5fa3e7
commit
86b37466d5
2 changed files with 27 additions and 1 deletions
17
app/workers/deferred_retraction.rb
Normal file
17
app/workers/deferred_retraction.rb
Normal file
|
|
@ -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
|
||||||
|
|
@ -10,6 +10,11 @@ class Retraction
|
||||||
|
|
||||||
attr_accessor :person, :object, :subscribers
|
attr_accessor :person, :object, :subscribers
|
||||||
|
|
||||||
|
def initialize(data, subscribers)
|
||||||
|
@data = data
|
||||||
|
@subscribers = subscribers
|
||||||
|
end
|
||||||
|
|
||||||
def subscribers
|
def subscribers
|
||||||
unless self.type == 'Person'
|
unless self.type == 'Person'
|
||||||
@subscribers ||= object.subscribers
|
@subscribers ||= object.subscribers
|
||||||
|
|
@ -22,7 +27,7 @@ class Retraction
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.for(object)
|
def self.for(object)
|
||||||
retraction = self.new
|
retraction = new({}, [])
|
||||||
if object.is_a? User
|
if object.is_a? User
|
||||||
retraction.post_guid = object.person.guid
|
retraction.post_guid = object.person.guid
|
||||||
retraction.type = object.person.class.to_s
|
retraction.type = object.person.class.to_s
|
||||||
|
|
@ -39,6 +44,10 @@ class Retraction
|
||||||
@target ||= self.type.constantize.where(:guid => post_guid).first
|
@target ||= self.type.constantize.where(:guid => post_guid).first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def defer_dispatch(user)
|
||||||
|
Workers::DeferredRetraction.perform_async(user.id, data, subscribers.map(&:id))
|
||||||
|
end
|
||||||
|
|
||||||
def perform receiving_user
|
def perform receiving_user
|
||||||
logger.debug "Performing retraction for #{post_guid}"
|
logger.debug "Performing retraction for #{post_guid}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue