Class: Contact

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/contact.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

Instance Method Details

#contactsObject


73
74
75
76
77
78
79
80
81
82
# File 'app/models/contact.rb', line 73

def contacts
  people = Person.arel_table
  incoming_aspects = Aspect.where(
    :user_id => self.person.owner_id,
    :contacts_visible => true).joins(:contacts).where(
      :contacts => {:person_id => self.user.person_id}).select('aspects.id')
  incoming_aspect_ids = incoming_aspects.map{|a| a.id}
  similar_contacts = Person.joins(:contacts => :aspect_memberships).where(
    :aspect_memberships => {:aspect_id => incoming_aspect_ids}).where(people[:id].not_eq(self.user.person.id)).select('DISTINCT people.*')
end

#destroy_notificationsObject


50
51
52
53
54
55
# File 'app/models/contact.rb', line 50

def destroy_notifications
  Notification.where(:target_type => "Person",
                     :target_id => person_id,
                     :recipient_id => user_id,
                     :type => "Notifications::StartedSharing").destroy_all
end

#dispatch_requestObject


57
58
59
60
61
# File 'app/models/contact.rb', line 57

def dispatch_request
  request = self.generate_request
  Postzord::Dispatcher.build(self.user, request).post
  request
end

#generate_requestObject


63
64
65
66
67
# File 'app/models/contact.rb', line 63

def generate_request
  Request.diaspora_initialize(:from => self.user.person,
              :to => self.person,
              :into => aspects.first)
end

#in_aspect?(aspect) ⇒ Boolean


88
89
90
91
92
93
94
95
96
# File 'app/models/contact.rb', line 88

def in_aspect? aspect
  if aspect_memberships.loaded?
    aspect_memberships.detect{ |am| am.aspect_id == aspect.id }
  elsif aspects.loaded?
    aspects.detect{ |a| a.id == aspect.id }
  else
    AspectMembership.exists?(:contact_id => self.id, :aspect_id => aspect.id)
  end
end

#mutual?Boolean


84
85
86
# File 'app/models/contact.rb', line 84

def mutual?
  self.sharing && self.receiving
end

#receive_shareable(shareable) ⇒ Object


69
70
71
# File 'app/models/contact.rb', line 69

def receive_shareable(shareable)
  ShareVisibility.create!(:shareable_id => shareable.id, :shareable_type => shareable.class.base_class.to_s, :contact_id => self.id)
end