Class: Contact

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/contact.rb

Overview

The link between two actors

Each Contact has many ties, which determine the kind of the link through relations

Contacts and activities

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

Instance Method Summary collapse

Instance Attribute Details

#messageObject

Send a message when this contact is created or updated



18
19
20
# File 'app/models/contact.rb', line 18

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



130
131
132
133
134
135
136
# File 'app/models/contact.rb', line 130

def action
  if ties_count > 0 && relations.where(:type => ['Relation::Custom', 'Relation::Public']).any?
    'edit'
  else
    replied? ? 'reply' : 'new'
  end
end

#established?Boolean

Has this Contact any Tie?

Returns:

  • (Boolean)


94
95
96
# File 'app/models/contact.rb', line 94

def established?
  ties_count > 0
end

#inverse!Object

Find or create the inverse Contact



88
89
90
91
# File 'app/models/contact.rb', line 88

def inverse!
  inverse ||
    receiver.contact_to!(sender)
end

#receiver_subjectObject



78
79
80
# File 'app/models/contact.rb', line 78

def receiver_subject
  receiver.subject
end

#reflexive?Boolean

Does this Contact have the same sender and receiver?

Returns:

  • (Boolean)


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

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



116
117
118
119
120
# File 'app/models/contact.rb', line 116

def relation_ids=(ids)
  remove_follower(ids)

  association(:relations).ids_writer(ids)
end

#replied?Boolean

The Contact in the other way is established

Returns:

  • (Boolean)


99
100
101
102
# File 'app/models/contact.rb', line 99

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

#sender_subjectObject



74
75
76
# File 'app/models/contact.rb', line 74

def sender_subject
  sender.subject
end

#statusObject



138
139
140
141
142
143
144
145
# File 'app/models/contact.rb', line 138

def status
  case action
  when 'edit'
    ties.includes(:relation).map(&:relation_name).join(", ")
  else
    I18n.t("contact.#{ action }.link")
  end
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



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

def verb
  replied? ? "make-friend" : "follow"
end