Class: Retraction

Inherits:
Object
  • Object
show all
Includes:
Diaspora::Federated::Base
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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::Federated::Base

included

Instance Attribute Details

#objectObject

Returns the value of attribute object


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

def object
  @object
end

#personObject

Returns the value of attribute person


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

def person
  @person
end

#subscribers(user) ⇒ Object

Returns the value of attribute subscribers


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

def subscribers
  @subscribers
end

Class Method Details

.for(object) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/diaspora/federated/retraction.rb', line 24

def self.for(object)
  retraction = self.new
  if object.is_a? User
    retraction.post_guid = object.person.guid
    retraction.type = object.person.class.to_s
  else
    retraction.post_guid = object.guid
    retraction.type = object.class.to_s
    retraction.object = object
  end
  retraction.diaspora_handle = object.diaspora_handle
  retraction
end

Instance Method Details

#perform(receiving_user) ⇒ Object


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

def perform receiving_user
  Rails.logger.debug "Performing retraction for #{post_guid}"

  self.target.destroy if self.target
  Rails.logger.info("event=retraction status=complete type=#{self.type} guid=#{self.post_guid}")
end

#receive(user, person) ⇒ Object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/diaspora/federated/retraction.rb', line 49

def receive(user, person)
  if self.type == 'Person'
    unless self.person.guid.to_s == self.post_guid.to_s
      Rails.logger.info("event=receive status=abort reason='sender is not the person he is trying to retract' recipient=#{self.diaspora_handle} sender=#{self.person.diaspora_handle} payload_type=#{self.class} retraction_type=person")
      return
    end
    user.disconnected_by(self.target)
  elsif self.target.nil? || self.target.author != self.person
    Rails.logger.info("event=retraction status=abort reason='no post found authored by retractor' sender=#{person.diaspora_handle} post_guid=#{post_guid}")
  else
    self.perform(user)
  end
  self
end

#targetObject


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

def target
  @target ||= self.type.constantize.where(:guid => post_guid).first
end