Class: Contact
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Contact
- 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
-
#message ⇒ Object
Send a message when this contact is created or updated.
Instance Method Summary collapse
- #action ⇒ Object
- #established? ⇒ Boolean
-
#inverse! ⇒ Object
Find or create the inverse Contact.
- #receiver_subject ⇒ Object
-
#reflexive? ⇒ Boolean
Does this Contact have the same sender and receiver?.
-
#relation_ids=(ids) ⇒ Object
has_many collection=objects method does not trigger destroy callbacks, so follower_count will not be updated.
-
#replied? ⇒ Boolean
The Contact in the other way is established.
- #sender_subject ⇒ Object
- #status ⇒ Object
-
#verb ⇒ Object
The ActivityVerb corresponding to this Contact.
Instance Attribute Details
#message ⇒ Object
Send a message when this contact is created or updated
18 19 20 |
# File 'app/models/contact.rb', line 18 def @message end |
Instance Method Details
#action ⇒ Object
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 reject relation.
The contact’s action is edit
when it has any Tie with a custom relation or a public relation
130 131 132 133 134 135 136 |
# File 'app/models/contact.rb', line 130 def action if ties_count > 0 && relations.where(:type => ['Relation::Custom', 'Relation::Public']).any? 'edit' else replied? ? 'reply' : 'new' end end |
#established? ⇒ Boolean
94 95 96 |
# File 'app/models/contact.rb', line 94 def established? ties_count > 0 end |
#inverse! ⇒ Object
Find or create the inverse Contact
88 89 90 91 |
# File 'app/models/contact.rb', line 88 def inverse! inverse || receiver.contact_to!(sender) end |
#receiver_subject ⇒ Object
78 79 80 |
# File 'app/models/contact.rb', line 78 def receiver_subject receiver.subject end |
#reflexive? ⇒ Boolean
Does this Contact have the same sender and receiver?
83 84 85 |
# File 'app/models/contact.rb', line 83 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
116 117 118 119 120 |
# File 'app/models/contact.rb', line 116 def relation_ids=(ids) remove_follower(ids) association(:relations).ids_writer(ids) end |
#replied? ⇒ Boolean
The Contact in the other way is established
99 100 101 102 |
# File 'app/models/contact.rb', line 99 def replied? inverse_id.present? && inverse.ties_count > 0 end |
#sender_subject ⇒ Object
74 75 76 |
# File 'app/models/contact.rb', line 74 def sender_subject sender.subject end |
#status ⇒ Object
138 139 140 141 142 143 144 145 |
# File 'app/models/contact.rb', line 138 def status case action when 'edit' ties.includes(:relation).map(&:relation_name).join(", ") else I18n.t("contact.#{ action }.link") end end |
#verb ⇒ Object
The ActivityVerb corresponding to this Contact. If this contact is pending, the other one was establised already, so this is going to “make-friend”. If it is not pending, the contact in the other way was not established, so this is following
108 109 110 |
# File 'app/models/contact.rb', line 108 def verb replied? ? "make-friend" : "follow" end |