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 object of choices suitable for the contact add button.
-
#options_for_select_type ⇒ Object
Options for select are simple or multiple.
- #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
170 171 172 |
# File 'app/models/contact.rb', line 170 def action sent? ? 'edit' : ( replied? ? 'reply' : 'new' ) end |
#established? ⇒ Boolean
119 120 121 |
# File 'app/models/contact.rb', line 119 def established? ties_count > 0 end |
#inverse! ⇒ Object
Find or create the inverse Contact
113 114 115 116 |
# File 'app/models/contact.rb', line 113 def inverse! inverse || receiver.contact_to!(sender) end |
#options_for_select ⇒ Object
Return an object of choices suitable for the contact add button
185 186 187 |
# File 'app/models/contact.rb', line 185 def sender. end |
#options_for_select_type ⇒ Object
Options for select are simple or multiple
191 192 193 |
# File 'app/models/contact.rb', line 191 def sender. end |
#positive_replied? ⇒ Boolean
129 130 131 132 |
# File 'app/models/contact.rb', line 129 def positive_replied? inverse_id.present? && self.class.positive.where(:id => inverse.id).any? end |
#receiver_subject ⇒ Object
103 104 105 |
# File 'app/models/contact.rb', line 103 def receiver_subject receiver.subject end |
#reflexive? ⇒ Boolean
Does this Contact have the same sender and receiver?
108 109 110 |
# File 'app/models/contact.rb', line 108 def reflexive? sender_id == receiver_id end |
#replied? ⇒ Boolean
The Contact in the other way is established
124 125 126 127 |
# File 'app/models/contact.rb', line 124 def replied? inverse_id.present? && inverse.ties_count > 0 end |
#sender_subject ⇒ Object
99 100 101 |
# File 'app/models/contact.rb', line 99 def sender_subject sender.subject end |
#sent? ⇒ Boolean
158 159 160 |
# File 'app/models/contact.rb', line 158 def sent? ties_count > 0 && relations.where(:type => Relation.positive_names).any? end |
#status ⇒ Object
174 175 176 177 178 179 180 181 |
# File 'app/models/contact.rb', line 174 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
145 146 147 148 |
# File 'app/models/contact.rb', line 145 def @user_author || end |
#user_author=(subject) ⇒ Object
Set who creates ties in behalf of a group or organization
151 152 153 |
# File 'app/models/contact.rb', line 151 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
138 139 140 |
# File 'app/models/contact.rb', line 138 def verb replied? ? "make-friend" : "follow" end |