Class: Contact
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Contact
- Defined in:
- app/models/contact.rb
Overview
A Contact is an ordered pair of Actors, and therefore two Subjects.
Contacts are created at convenience (in the case of suggestions, for instance), and they do not mean that there is a real link between those two Subjects. Link existance is stored as Ties.
Contacts and activities
WARNING: This will be change soon to direct references to author, owner and user_author, in the same way as ActivityObject
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.
- #positive_replied? ⇒ Boolean
- #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
25 26 27 |
# File 'app/models/contact.rb', line 25 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
147 148 149 150 151 152 153 |
# File 'app/models/contact.rb', line 147 def action if ties_count > 0 && relations.where(:type => Relation.positive_names).any? 'edit' else replied? ? 'reply' : 'new' end end |
#established? ⇒ Boolean
107 108 109 |
# File 'app/models/contact.rb', line 107 def established? ties_count > 0 end |
#inverse! ⇒ Object
Find or create the inverse Contact
101 102 103 104 |
# File 'app/models/contact.rb', line 101 def inverse! inverse || receiver.contact_to!(sender) end |
#positive_replied? ⇒ Boolean
117 118 119 120 |
# File 'app/models/contact.rb', line 117 def positive_replied? inverse_id.present? && self.class.positive.where(:id => inverse.id).any? end |
#receiver_subject ⇒ Object
91 92 93 |
# File 'app/models/contact.rb', line 91 def receiver_subject receiver.subject end |
#reflexive? ⇒ Boolean
Does this Contact have the same sender and receiver?
96 97 98 |
# File 'app/models/contact.rb', line 96 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
134 135 136 137 |
# File 'app/models/contact.rb', line 134 def relation_ids=(ids) remove_follower(ids) association(:relations).ids_writer(ids) end |
#replied? ⇒ Boolean
The Contact in the other way is established
112 113 114 115 |
# File 'app/models/contact.rb', line 112 def replied? inverse_id.present? && inverse.ties_count > 0 end |
#sender_subject ⇒ Object
87 88 89 |
# File 'app/models/contact.rb', line 87 def sender_subject sender.subject end |
#status ⇒ Object
155 156 157 158 159 160 161 162 |
# File 'app/models/contact.rb', line 155 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
126 127 128 |
# File 'app/models/contact.rb', line 126 def verb replied? ? "make-friend" : "follow" end |