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.
-
#options_for_select ⇒ Object
Return an array of options suitable for the contact add button.
- #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
153 154 155 |
# File 'app/models/contact.rb', line 153 def action sent? ? 'edit' : ( replied? ? 'reply' : 'new' ) end |
#established? ⇒ Boolean
102 103 104 |
# File 'app/models/contact.rb', line 102 def established? ties_count > 0 end |
#inverse! ⇒ Object
Find or create the inverse Contact
96 97 98 99 |
# File 'app/models/contact.rb', line 96 def inverse! inverse || receiver.contact_to!(sender) end |
#options_for_select ⇒ Object
Return an array of options suitable for the contact add button
167 168 169 |
# File 'app/models/contact.rb', line 167 def sender.relation_customs.map{ |r| [ r.name, r.id ] } end |
#positive_replied? ⇒ Boolean
112 113 114 115 |
# File 'app/models/contact.rb', line 112 def positive_replied? inverse_id.present? && self.class.positive.where(:id => inverse.id).any? end |
#receiver_subject ⇒ Object
86 87 88 |
# File 'app/models/contact.rb', line 86 def receiver_subject receiver.subject end |
#reflexive? ⇒ Boolean
Does this Contact have the same sender and receiver?
91 92 93 |
# File 'app/models/contact.rb', line 91 def reflexive? sender_id == receiver_id end |
#replied? ⇒ Boolean
The Contact in the other way is established
107 108 109 110 |
# File 'app/models/contact.rb', line 107 def replied? inverse_id.present? && inverse.ties_count > 0 end |
#sender_subject ⇒ Object
82 83 84 |
# File 'app/models/contact.rb', line 82 def sender_subject sender.subject end |
#sent? ⇒ Boolean
141 142 143 |
# File 'app/models/contact.rb', line 141 def sent? ties_count > 0 && relations.where(:type => Relation.positive_names).any? end |
#status ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'app/models/contact.rb', line 157 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
128 129 130 131 |
# File 'app/models/contact.rb', line 128 def @user_author || end |
#user_author=(subject) ⇒ Object
Set who creates ties in behalf of a group or organization
134 135 136 |
# File 'app/models/contact.rb', line 134 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
121 122 123 |
# File 'app/models/contact.rb', line 121 def verb replied? ? "make-friend" : "follow" end |