Newer
Older
# licensed under the Affero General Public License version 3 or later. See
Daniel Vincent Grippi
a validé
class Request < ActiveRecord::Base
maxwell
a validé
require File.join(Rails.root, 'lib/diaspora/webhooks')
require File.join(Rails.root, 'lib/postzord/dispatch')
maxwell
a validé
include Diaspora::Webhooks
include ROXML
xml_accessor :sender_handle
xml_accessor :recipient_handle
belongs_to :sender, :class_name => 'Person'
belongs_to :recipient, :class_name => 'Person'
belongs_to :aspect
validates_uniqueness_of :sender_id, :scope => :recipient_id
validates_presence_of :sender, :recipient
validate :not_friending_yourself
danielvincent
a validé
def self.diaspora_initialize(opts = {})
self.new(:sender => opts[:from],
:recipient => opts[:to],
:aspect => opts[:into])
maxwell
a validé
end
Raphael
a validé
Request.new(
:sender => accepting_user.person,
:recipient => self.sender
Raphael
a validé
)
def diaspora_handle
sender_handle
end
sender.diaspora_handle
end
def sender_handle= sender_handle
self.sender = Person.where(:diaspora_handle => sender_handle).first
end
def recipient_handle
recipient.diaspora_handle
end
def recipient_handle= recipient_handle
self.recipient = Person.where(:diaspora_handle => recipient_handle).first
if Contact.unscoped.where(:user_id => user.id, :person_id => person.id).first
Notifications::RequestAccepted
Notifications::NewRequest
end
def receive(user, person)
Rails.logger.info("event=receive payload_type=request sender=#{self.sender} to=#{self.recipient}")
user.receive_contact_request(self)
Raphael
a validé
private
if sender && recipient && Contact.where(:user_id => self.recipient.owner_id, :person_id => self.sender.id).count > 0
errors[:base] << 'You have already connected to this person'
Raphael
a validé
end
end
def not_friending_yourself
if self.recipient == self.sender
errors[:base] << 'You can not friend yourself'
end
end