Class: Postzord::Receiver::Public

Inherits:
Postzord::Receiver show all
Defined in:
lib/postzord/receiver/public.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

Instance Method Summary collapse

Methods inherited from Postzord::Receiver

#author_does_not_match_xml_author?, #perform!

Constructor Details

#initialize(xml) ⇒ Public


9
10
11
12
13
14
# File 'lib/postzord/receiver/public.rb', line 9

def initialize(xml)
  @salmon = Salmon::Slap.from_xml(xml)
  @author = Webfinger.new(@salmon.author_id).fetch

  FEDERATION_LOGGER.info("Receiving public object from person:#{@author.id}")
end

Instance Attribute Details

#authorObject

Returns the value of attribute author


7
8
9
# File 'lib/postzord/receiver/public.rb', line 7

def author
  @author
end

#salmonObject

Returns the value of attribute salmon


7
8
9
# File 'lib/postzord/receiver/public.rb', line 7

def salmon
  @salmon
end

Instance Method Details

#receive!void


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/postzord/receiver/public.rb', line 22

def receive!
  return false unless verified_signature?
  # return false unless account_deletion_is_from_author

  return false unless save_object

  FEDERATION_LOGGER.info("received a #{@object.inspect}")
  if @object.respond_to?(:relayable?)
    receive_relayable
  elsif @object.is_a?(AccountDeletion)
    #nothing
  elsif @object.is_a?(SignedRetraction) # feels like a hack
    self.recipient_user_ids.each do |user_id|
      user = User.where(id: user_id).first
      @object.perform user if user
    end
  else
    Workers::ReceiveLocalBatch.perform_async(@object.class.to_s, @object.id, self.recipient_user_ids)
    true
  end
end

#receive_relayableObject


45
46
47
48
49
50
51
52
53
54
# File 'lib/postzord/receiver/public.rb', line 45

def receive_relayable
  if @object.parent_author.local?
    # receive relayable object only for the owner of the parent object
    @object.receive(@object.parent_author.owner, @author)
  end
  # notify everyone who can see the parent object
  receiver = Postzord::Receiver::LocalBatch.new(@object, self.recipient_user_ids)
  receiver.notify_users
  @object
end

#recipient_user_idsArray<Integer>


66
67
68
# File 'lib/postzord/receiver/public.rb', line 66

def recipient_user_ids
  User.all_sharing_with_person(@author).select('users.id').map!{ |u| u.id }
end

#save_objectObject


57
58
59
60
61
62
63
# File 'lib/postzord/receiver/public.rb', line 57

def save_object
  @object = Diaspora::Parser::from_xml(@salmon.parsed_data)
  raise "Object is not public" if object_can_be_public_and_it_is_not?
  raise Diaspora::AuthorXMLAuthorMismatch if author_does_not_match_xml_author?
  @object.save! if @object && @object.respond_to?(:save!)
  @object
end

#verified_signature?Boolean


17
18
19
# File 'lib/postzord/receiver/public.rb', line 17

def verified_signature?
  @salmon.verified_for_key?(@author.public_key)
end

#xml_authorObject


70
71
72
73
74
75
76
77
# File 'lib/postzord/receiver/public.rb', line 70

def xml_author
  if @object.respond_to?(:relayable?)
    #this is public, so it would only be owners sending us other people comments etc
     @object.parent_author.local? ? @object.diaspora_handle : @object.parent_diaspora_handle
  else
    @object.diaspora_handle
  end
end