Class: Contact

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/contact.rb

Overview

The link between two actors

Each Contact has many ties, which determine the kind of the link through relations

Contacts and activities

Each Activity is attached to a Contact. When Alice post in Bob’s wall, the Activity is attached to the Contact from Alice to Bob

  • The sender of the Contact is the author of the Activity. It is the user that uploads a resource to the website or the social entity that originates the Activity (for example: add as contact).

  • The receiver Actor of the Contact is the receiver of the Activity. The Activity will appear in the wall of the receiver, depending on the permissions

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#messageObject

Send a message when this contact is created or updated



18
19
20
# File 'app/models/contact.rb', line 18

def message
  @message
end

Instance Method Details

#actionObject

Is this Contact new or edit for subject ?

action is new when, despite of being created, it has not ties or it has a Tie with a public relation.

The contact’s action is edit when it has any Tie with a custom relation



110
111
112
113
114
115
116
# File 'app/models/contact.rb', line 110

def action
  if ties_count > 0 && relations.where(:type => 'Relation::Custom').any?
    'edit'
  else
    'new'
  end
end

#inverse!Object

Find or create the inverse Contact



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

def inverse!
  inverse ||
    receiver.contact_to!(sender)
end

#pending?Boolean

Is not the inverse of this Contact

Returns:

  • (Boolean)


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

def pending?
  inverse &&
    inverse.ties_count > 0
end

#receiver_subjectObject



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

def receiver_subject
  receiver.try(:subject)
end

#reflexive?Boolean

Does this Contact have the same sender and receiver?

Returns:

  • (Boolean)


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

def reflexive?
  sender_id == receiver_id
end

#relation_ids=(ids) ⇒ Object

has_many collection=objects method does not trigger destroy callbacks, so follower_count will not be updated

We need to update that status here



97
98
99
100
101
# File 'app/models/contact.rb', line 97

def relation_ids=(ids)
  remove_follower(ids)

  association(:relations).ids_writer(ids)
end

#sender_subjectObject



62
63
64
# File 'app/models/contact.rb', line 62

def sender_subject
  sender.try(:subject)
end

#verbObject

The ActivityVerb corresponding to this Contact, depending on if it is pending or already replied



89
90
91
# File 'app/models/contact.rb', line 89

def verb
  pending? ? "follow" : "make-friend"
end