Class: Contact

Inherits:
ApplicationRecord show all
Includes:
Diaspora::Federated::Base
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.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_or_update_sharing_contact(recipient, sender) ⇒ Object

creates or updates a contact with active sharing flag. Returns nil if already sharing.


80
81
82
83
84
85
86
87
# File 'app/models/contact.rb', line 80

def self.create_or_update_sharing_contact(recipient, sender)
  contact = recipient.contacts.find_or_initialize_by(person_id: sender.id)

  return if contact.sharing

  contact.update(sharing: true)
  contact
end

Instance Method Details

#destroy_notificationsObject


41
42
43
44
45
46
47
48
# File 'app/models/contact.rb', line 41

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

#in_aspect?(aspect) ⇒ Boolean

Returns:

  • (Boolean)

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

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

Returns:

  • (Boolean)

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

def mutual?
  sharing && receiving
end

#object_to_receiveObject

object for local recipients


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

def object_to_receive
  Contact.create_or_update_sharing_contact(person.owner, user.person)
end

#receive(_recipient_user_ids) ⇒ Object

Follows back if user setting is set so


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

def receive(_recipient_user_ids)
  user.share_with(person, user.auto_follow_back_aspect) if user.auto_follow_back && !receiving
end

#subscribersArray<Person>

Returns The recipient of the contact.

Returns:

  • (Array<Person>)

    The recipient of the contact


75
76
77
# File 'app/models/contact.rb', line 75

def subscribers
  [person]
end