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 a Tie. When Alice adds Bob as contact, a new Tie is created with the Contact from Alice to Bob and the Relation that Alice chose.
Inverse Contacts
Alice has a Contact to Bob. The inverse is the Contact from Bob to Alice. Inverse contacts are used to check if contacts are replied, for instance, if Bob added Alice as contact after she did so.
Again, the Contact from Bob to Alice must have positive ties to be active.
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?.
-
#replied? ⇒ Boolean
The Contact in the other way is established.
- #sender_subject ⇒ Object
-
#sent? ⇒ Boolean
The sender of this Contact has establised positive sent to the receiver.
- #status ⇒ Object
-
#user_author ⇒ Object
Record who creates ties in behalf of a group or organization.
-
#user_author=(subject) ⇒ Object
Set who creates ties in behalf of a group or organization.
-
#verb ⇒ Object
The ActivityVerb corresponding to this Contact.
Instance Attribute Details
#message ⇒ Object
Send a message when this contact is created or updated
20 21 22 |
# File 'app/models/contact.rb', line 20 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
154 155 156 |
# File 'app/models/contact.rb', line 154 def action sent? ? 'edit' : ( replied? ? 'reply' : 'new' ) end |
#established? ⇒ Boolean
103 104 105 |
# File 'app/models/contact.rb', line 103 def established? ties_count > 0 end |
#inverse! ⇒ Object
Find or create the inverse Contact
97 98 99 100 |
# File 'app/models/contact.rb', line 97 def inverse! inverse || receiver.contact_to!(sender) end |
#positive_replied? ⇒ Boolean
113 114 115 116 |
# File 'app/models/contact.rb', line 113 def positive_replied? inverse_id.present? && self.class.positive.where(:id => inverse.id).any? end |
#receiver_subject ⇒ Object
87 88 89 |
# File 'app/models/contact.rb', line 87 def receiver_subject receiver.subject end |
#reflexive? ⇒ Boolean
Does this Contact have the same sender and receiver?
92 93 94 |
# File 'app/models/contact.rb', line 92 def reflexive? sender_id == receiver_id end |
#replied? ⇒ Boolean
The Contact in the other way is established
108 109 110 111 |
# File 'app/models/contact.rb', line 108 def replied? inverse_id.present? && inverse.ties_count > 0 end |
#sender_subject ⇒ Object
83 84 85 |
# File 'app/models/contact.rb', line 83 def sender_subject sender.subject end |
#sent? ⇒ Boolean
142 143 144 |
# File 'app/models/contact.rb', line 142 def sent? ties_count > 0 && relations.where(:type => Relation.positive_names).any? end |
#status ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'app/models/contact.rb', line 158 def status case action when 'edit' ties.includes(:relation).map(&:relation_name).join(", ") else I18n.t("contact.#{ action }.link") end end |
#user_author ⇒ Object
Record who creates ties in behalf of a group or organization
Defaults to the sender actor, if it is a user
129 130 131 132 |
# File 'app/models/contact.rb', line 129 def @user_author || end |
#user_author=(subject) ⇒ Object
Set who creates ties in behalf of a group or organization
135 136 137 |
# File 'app/models/contact.rb', line 135 def subject @user_author = (subject.nil? ? nil : Actor.normalize(subject)) 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
122 123 124 |
# File 'app/models/contact.rb', line 122 def verb replied? ? "make-friend" : "follow" end |