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



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

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

#established?Boolean

Has this Contact any Tie?

Returns:

  • (Boolean)


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

def established?
  ties_count > 0
end

#inverse!Object

Find or create the inverse Contact



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

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

#positive_replied?Boolean

Returns:

  • (Boolean)


110
111
112
113
# File 'app/models/contact.rb', line 110

def positive_replied?
  inverse_id.present? &&
    self.class.positive.where(:id => inverse.id).any?
end

#receiver_subjectObject



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

def receiver_subject
  receiver.subject
end

#reflexive?Boolean

Does this Contact have the same sender and receiver?

Returns:

  • (Boolean)


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

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



127
128
129
130
# File 'app/models/contact.rb', line 127

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)


105
106
107
108
# File 'app/models/contact.rb', line 105

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

#sender_subjectObject



80
81
82
# File 'app/models/contact.rb', line 80

def sender_subject
  sender.subject
end

#statusObject



148
149
150
151
152
153
154
155
# File 'app/models/contact.rb', line 148

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



119
120
121
# File 'app/models/contact.rb', line 119

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