Class: Contact

Inherits:
ActiveRecord::Base
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#messageObject

Send a message when this contact is created or updated



20
21
22
# File 'app/models/contact.rb', line 20

def message
  @message
end

Instance Method Details

#actionObject

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

Has this Contact any Tie?

Returns:

  • (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_selectObject

Return an array of options suitable for the contact add button



167
168
169
# File 'app/models/contact.rb', line 167

def options_for_select
  sender.relation_customs.map{ |r| [ r.name, r.id ] }
end

#positive_replied?Boolean

Returns:

  • (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_subjectObject



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?

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


107
108
109
110
# File 'app/models/contact.rb', line 107

def replied?
  inverse_id.present? &&
    inverse.ties_count > 0
end

#sender_subjectObject



82
83
84
# File 'app/models/contact.rb', line 82

def sender_subject
  sender.subject
end

#sent?Boolean

The sender of this Contact has establised positive sent to the receiver

That means that there exists at least one Tie with a positive relation within them

Returns:

  • (Boolean)


141
142
143
# File 'app/models/contact.rb', line 141

def sent?
  ties_count > 0 && relations.where(:type => Relation.positive_names).any?
end

#statusObject



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_authorObject

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
  @user_author ||
    build_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 user_author= subject
  @user_author = (subject.nil? ? nil : Actor.normalize(subject))
end

#verbObject

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