Welcome to mirror list, hosted at ThFree Co, Russian Federation.

service_user.rb « models « app - github.com/diaspora/diaspora.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f1ce222ac88ac84f83bcad79dbdb11810426ff8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
class ServiceUser < ActiveRecord::Base

  belongs_to :person
  belongs_to :contact
  belongs_to :service
  belongs_to :request
  belongs_to :invitation

  before_save :attach_local_models

  private
  def attach_local_models
    service_for_uid = Services::Facebook.where(:type => service.type.to_s, :uid => self.uid).first
    if !service_for_uid.blank? && (service_for_uid.user.person.profile.searchable)
      self.person = service_for_uid.user.person 
    else
      self.person = nil
    end

    if self.person
      self.contact = self.service.user.contact_for(self.person)
      self.request = Request.where(:recipient_id => self.service.user.person.id,
                                   :sender_id => self.person_id).first
    end

    self.invitation = Invitation.joins(:recipient).where(:sender_id => self.service.user_id,
                                                            :users => {:invitation_service => self.service.provider,
                                                                       :invitation_identifier => self.uid}).first
  end
end