Class: Request

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations, Diaspora::Federated::Base
Defined in:
lib/diaspora/federated/request.rb

Overview

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

t
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

#aspectObject

Returns the value of attribute aspect


10
11
12
# File 'lib/diaspora/federated/request.rb', line 10

def aspect
  @aspect
end

#recipientObject

Returns the value of attribute recipient


10
11
12
# File 'lib/diaspora/federated/request.rb', line 10

def recipient
  @recipient
end

#senderObject

Returns the value of attribute sender


10
11
12
# File 'lib/diaspora/federated/request.rb', line 10

def sender
  @sender
end

Class Method Details

.diaspora_initialize(opts = {}) ⇒ Request

Note:

we should be using ActiveModel::Serialization for this

Initalize variables


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

def self.diaspora_initialize(opts = {})
  req = self.new
  req.sender = opts[:from]
  req.recipient = opts[:to]
  req.aspect = opts[:into]
  req
end

Instance Method Details

#diaspora_handleString

Alias of sender_handle


34
35
36
# File 'lib/diaspora/federated/request.rb', line 34

def diaspora_handle
  sender_handle
end

#notification_type(user, person) ⇒ Notifications::StartedSharing

Defines the abstract interface used in sending a corresponding [Notification] given the [Request]


60
61
62
# File 'lib/diaspora/federated/request.rb', line 60

def notification_type(user, person)
  Notifications::StartedSharing
end

#receive(user, person) ⇒ Request

Note:

A [Contact] may already exist if the [Request]'s recipient is sharing with the sender

Finds or initializes a corresponding [Contact], and will set Contact#sharing to true Follows back if user setting is set so


75
76
77
78
79
80
81
82
83
84
85
# File 'lib/diaspora/federated/request.rb', line 75

def receive(user, person)
  Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")

  contact = user.contacts.find_or_initialize_by_person_id(self.sender.id)
  contact.sharing = true
  contact.save
  
  user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !contact.receiving

  self
end

#recipient_handleString

Note:

Used for XML marshalling


49
50
51
# File 'lib/diaspora/federated/request.rb', line 49

def recipient_handle
  recipient.diaspora_handle
end

#recipient_handle=(recipient_handle) ⇒ Object


52
53
54
# File 'lib/diaspora/federated/request.rb', line 52

def recipient_handle= recipient_handle
  self.recipient = Person.where(:diaspora_handle => recipient_handle).first
end

#sender_handleString

Note:

Used for XML marshalling


40
41
42
# File 'lib/diaspora/federated/request.rb', line 40

def sender_handle
  sender.diaspora_handle
end

#sender_handle=(sender_handle) ⇒ Object


43
44
45
# File 'lib/diaspora/federated/request.rb', line 43

def sender_handle= sender_handle
  self.sender = Person.where(:diaspora_handle => sender_handle).first
end

#subscribers(user) ⇒ Array<Person>

Defines the abstract interface used in sending the [Request]


67
68
69
# File 'lib/diaspora/federated/request.rb', line 67

def subscribers(user)
  [self.recipient]
end