Class: Postzord::Receiver::Private

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

Methods inherited from Postzord::Receiver

#author_does_not_match_xml_author?, #perform!

Constructor Details

#initialize(user, opts = {}) ⇒ Private


7
8
9
10
11
12
13
14
15
16
# File 'lib/postzord/receiver/private.rb', line 7

def initialize(user, opts={})
  @user = user
  @user_person = @user.person
  @salmon_xml = opts[:salmon_xml]

  @sender = opts[:person] || Webfinger.new(self.salmon.author_id).fetch
  @author = @sender

  @object = opts[:object]
end

Instance Method Details

#parse_and_receive(xml) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/postzord/receiver/private.rb', line 33

def parse_and_receive(xml)
  @object ||= Diaspora::Parser.from_xml(xml)
  return  if @object.nil?

  FEDERATION_LOGGER.info("user:#{@user.id} starting private receive from person:#{@sender.guid}")

  if self.validate_object
    set_author!
    receive_object
    FEDERATION_LOGGER.info("object received: [#{@object.class}#{@object.respond_to?(:text) ? ":'#{@object.text}'" : ''}]")
  else
    FEDERATION_LOGGER.error("failed to receive object from #{@object.author}: #{@object.inspect}")
    raise "not a valid object:#{@object.inspect}"
  end
end

#receive!Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/postzord/receiver/private.rb', line 18

def receive!
  begin 
    if @sender && self.salmon.verified_for_key?(@sender.public_key)
      parse_and_receive(salmon.parsed_data)
    else
      FEDERATION_LOGGER.info("event=receive status=abort recipient=#{@user.diaspora_handle} sender=#{@salmon.author_id} reason='not_verified for key'")
      false
    end
  rescue => e
    #this sucks
    FEDERATION_LOGGER.error("Failure to receive #{@object.class} from sender:#{@sender.id} for user:#{@user.id}: #{e.message}\n#{@object.inspect}")
    raise e
  end
end

#receive_objectObject


50
51
52
53
54
55
# File 'lib/postzord/receiver/private.rb', line 50

def receive_object
  obj = @object.receive(@user, @author)
  Notification.notify(@user, obj, @author) if obj.respond_to?(:notification_type)
  FEDERATION_LOGGER.info("user:#{@user.id} successfully received private post from person #{@sender.guid}: #{@object.inspect}")
  obj
end