Class: Retraction

Inherits:
Object
  • Object
show all
Includes:
Diaspora::Federated::Base, Diaspora::Logging
Defined in:
lib/diaspora/federated/retraction.rb

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Direct Known Subclasses

ContactRetraction

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Federated::Base

#object_to_receive

Constructor Details

#initialize(data, subscribers, target = nil) ⇒ Retraction

Returns a new instance of Retraction.


13
14
15
16
17
# File 'lib/diaspora/federated/retraction.rb', line 13

def initialize(data, subscribers, target=nil)
  @data = data
  @subscribers = subscribers
  @target = target
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data


11
12
13
# File 'lib/diaspora/federated/retraction.rb', line 11

def data
  @data
end

#subscribersObject (readonly)

Returns the value of attribute subscribers


11
12
13
# File 'lib/diaspora/federated/retraction.rb', line 11

def subscribers
  @subscribers
end

Class Method Details

.entity_classObject


19
20
21
# File 'lib/diaspora/federated/retraction.rb', line 19

def self.entity_class
  DiasporaFederation::Entities::Retraction
end

.for(target) ⇒ Object


32
33
34
35
# File 'lib/diaspora/federated/retraction.rb', line 32

def self.for(target)
  federation_retraction_data = retraction_data_for(target)
  new(federation_retraction_data, target.subscribers.select(&:remote?), target)
end

.retraction_data_for(target) ⇒ Object


23
24
25
26
27
28
29
30
# File 'lib/diaspora/federated/retraction.rb', line 23

def self.retraction_data_for(target)
  DiasporaFederation::Entities::Retraction.new(
    target_guid: target.guid,
    target:      Diaspora::Federation::Entities.related_entity(target),
    target_type: Diaspora::Federation::Mappings.entity_name_for(target),
    author:      target.diaspora_handle
  ).to_h
end

Instance Method Details

#defer_dispatch(user, include_target_author = true) ⇒ Object


37
38
39
40
# File 'lib/diaspora/federated/retraction.rb', line 37

def defer_dispatch(user, include_target_author=true)
  subscribers = dispatch_subscribers(include_target_author)
  Workers::DeferredRetraction.perform_async(user.id, self.class.to_s, data, subscribers.map(&:id), service_opts(user))
end

#performObject


42
43
44
45
46
# File 'lib/diaspora/federated/retraction.rb', line 42

def perform
  logger.debug "Performing retraction for #{target.class.base_class}:#{target.guid}"
  target.destroy!
  logger.info "event=retraction status=complete target=#{data[:target_type]}:#{data[:target_guid]}"
end

#public?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/diaspora/federated/retraction.rb', line 48

def public?
  data[:target][:public]
end