Class: Activity
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Activity
- Includes:
- NotificationsHelper
- Defined in:
- app/models/activity.rb
Overview
Activities follow the Activity Streams standard.
Every Activity has an #author, #user_author and #owner
- author
-
Is the subject that originated the activity. The entity that posted something, liked, etc..
- user_author
-
The User logged in when the Activity was created. If the User has not changed the session to represent other entity (a Group for example), the user_author will be the same as the author.
- owner
-
The subject whose wall was posted or comment was liked, etc..
Audiences and visibility
Each activity is attached to one or more relations, which define the subject that can reach the activity
In the case of a public relation everyone will be able to see the activity.
In the case of custom relations, only the subjects that have a Tie with that relation (in other words, the contacts that have been added as friends with that relation} will be able to reach the Activity
Instance Method Summary collapse
-
#audience ⇒ Object
The Actors this activity is shared with.
-
#audience_in_words(subject, options = {}) ⇒ Object
The Relation with which activity is shared.
-
#author_subject ⇒ Object
The subject author.
-
#comments ⇒ Object
The comments about this activity.
-
#direct_activity_object ⇒ Object
The first activity object of this activity.
-
#direct_object ⇒ Object
The first object of this activity.
-
#liked_by(user) ⇒ Object
:nodoc:.
-
#liked_by?(user) ⇒ Boolean
Does user like this activity?.
-
#likes ⇒ Object
The ‘like’ qualifications emmited to this activities.
-
#new_like(subject, user) ⇒ Object
Build a new children activity where subject like this.
- #notificable? ⇒ Boolean
- #notify ⇒ Object
-
#owner_subject ⇒ Object
The subject owner.
-
#participants ⇒ Object
A list of participants.
-
#public? ⇒ Boolean
Is this activity public?.
-
#receiver ⇒ Object
The wall where the activity is shown belongs to receiver.
-
#receiver_subject ⇒ Object
The wall where the activity is shown belongs to the receiver.
-
#reflexive? ⇒ Boolean
Does this Activity have the same sender and receiver?.
-
#represented_author? ⇒ Boolean
Is the author represented in this Activity?.
-
#same_thread ⇒ Object
This and related activities.
-
#sender ⇒ Object
The Actor author of this activity.
-
#sender_subject ⇒ Object
The Subject author of this activity.
-
#stream_content ⇒ Object
TODO: detailed description of activity.
-
#stream_title ⇒ Object
Title for activity streams.
-
#title(view) ⇒ Object
The title for this activity in the stream.
-
#user_author_subject ⇒ Object
The subject user actor.
-
#verb ⇒ Object
The name of the verb of this activity.
-
#verb=(name) ⇒ Object
Set the name of the verb of this activity.
Methods included from NotificationsHelper
#description_of, #locale_as, #notification_url_of, #title_of
Instance Method Details
#audience ⇒ Object
The Actors this activity is shared with
273 274 275 276 277 278 279 280 |
# File 'app/models/activity.rb', line 273 def audience raise "Cannot get the audience of a public activity!" if public? [ , , owner ].uniq | Actor. joins(:received_ties). merge(Tie.where(:relation_id => relation_ids)) end |
#audience_in_words(subject, options = {}) ⇒ Object
The Relation with which activity is shared
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'app/models/activity.rb', line 283 def audience_in_words(subject, = {}) [:details] ||= :full public_relation = relations.select{ |r| r.is_a?(Relation::Public) } visibility, audience = if public_relation.present? [ :public, nil ] else visible_relations = relations.select{ |r| r.actor_id == Actor.normalize_id(subject)} if visible_relations.present? [ :visible, visible_relations.map(&:name).uniq.join(", ") ] else [ :hidden, relations.map(&:actor).map(&:name).uniq.join(", ") ] end end I18n.t "activity.audience.#{ visibility }.#{ [:details] }", :audience => audience end |
#author_subject ⇒ Object
The subject author
93 94 95 |
# File 'app/models/activity.rb', line 93 def .subject end |
#comments ⇒ Object
The comments about this activity
150 151 152 |
# File 'app/models/activity.rb', line 150 def comments children.includes(:activity_objects).where('activity_objects.object_type' => "Comment") end |
#direct_activity_object ⇒ Object
The first activity object of this activity
184 185 186 187 |
# File 'app/models/activity.rb', line 184 def direct_activity_object @direct_activity_object ||= activity_objects.first end |
#direct_object ⇒ Object
The first object of this activity
190 191 192 193 |
# File 'app/models/activity.rb', line 190 def direct_object @direct_object ||= direct_activity_object.try(:object) end |
#liked_by(user) ⇒ Object
:nodoc:
159 160 161 |
# File 'app/models/activity.rb', line 159 def liked_by(user) #:nodoc: likes.(user) end |
#liked_by?(user) ⇒ Boolean
Does user like this activity?
164 165 166 |
# File 'app/models/activity.rb', line 164 def liked_by?(user) liked_by(user).present? end |
#likes ⇒ Object
The ‘like’ qualifications emmited to this activities
155 156 157 |
# File 'app/models/activity.rb', line 155 def likes children.joins(:activity_verb).where('activity_verbs.name' => "like") end |
#new_like(subject, user) ⇒ Object
Build a new children activity where subject like this
169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'app/models/activity.rb', line 169 def new_like(subject, user) a = children.new :verb => "like", :author_id => Actor.normalize_id(subject), :user_author_id => Actor.normalize_id(user), :owner_id => owner_id, :relation_ids => self.relation_ids if direct_activity_object.present? a.activity_objects << direct_activity_object end a end |
#notificable? ⇒ Boolean
234 235 236 |
# File 'app/models/activity.rb', line 234 def notificable? is_root? or ['post','update'].include?(root.verb) end |
#notify ⇒ Object
238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'app/models/activity.rb', line 238 def notify return true unless notificable? #Avaible verbs: follow, like, make-friend, post, update if direct_object.is_a? Comment participants.each do |p| p.notify(notification_subject, "Youre not supposed to see this", self) unless p == sender end elsif ['like','follow','make-friend','post','update'].include? verb and !reflexive? receiver.notify(notification_subject, "Youre not supposed to see this", self) end true end |
#owner_subject ⇒ Object
The subject owner
98 99 100 |
# File 'app/models/activity.rb', line 98 def owner_subject owner.subject end |
#participants ⇒ Object
A list of participants
253 254 255 256 257 258 259 |
# File 'app/models/activity.rb', line 253 def participants parts=Set.new same_thread.map{|a| a.activity_objects.first}.each do |ao| parts << ao. if ao.respond_to? :author and !ao..nil? end parts end |
#public? ⇒ Boolean
Is this activity public?
268 269 270 |
# File 'app/models/activity.rb', line 268 def public? relation_ids.include? Relation::Public.instance.id end |
#receiver ⇒ Object
The wall where the activity is shown belongs to receiver
This method provides the Actor. Use #receiver_subject for the Subject (User, Group, etc..)
137 138 139 |
# File 'app/models/activity.rb', line 137 def receiver owner end |
#receiver_subject ⇒ Object
145 146 147 |
# File 'app/models/activity.rb', line 145 def receiver_subject owner_subject end |
#reflexive? ⇒ Boolean
Does this Activity have the same sender and receiver?
108 109 110 |
# File 'app/models/activity.rb', line 108 def reflexive? == owner_id end |
#represented_author? ⇒ Boolean
Is the author represented in this Activity?
113 114 115 |
# File 'app/models/activity.rb', line 113 def != end |
#same_thread ⇒ Object
This and related activities
262 263 264 265 |
# File 'app/models/activity.rb', line 262 def same_thread return [self] if is_root? [parent] + siblings end |
#sender ⇒ Object
121 122 123 |
# File 'app/models/activity.rb', line 121 def sender end |
#sender_subject ⇒ Object
129 130 131 |
# File 'app/models/activity.rb', line 129 def sender_subject end |
#stream_content ⇒ Object
TODO: detailed description of activity
230 231 232 |
# File 'app/models/activity.rb', line 230 def stream_content stream_title end |
#stream_title ⇒ Object
Title for activity streams
216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'app/models/activity.rb', line 216 def stream_title # FIXMEEEEEEEEEEEEEEEEE object = ( direct_object.present? ? ( direct_object.is_a?(SocialStream::Models::Subject) ? direct_object.name : direct_object.title ) : receiver.name ) I18n.t "activity.stream.title.#{ verb }", :author => sender_subject.name, :activity_object => object end |
#title(view) ⇒ Object
The title for this activity in the stream
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'app/models/activity.rb', line 196 def title view case verb when "follow", "make-friend", "like" I18n.t "activity.verb.#{ verb }.#{ receiver.subject_type }.title", :subject => view.link_name(sender_subject), :contact => view.link_name(receiver_subject) when "post", "update" if sender == receiver view.link_name sender_subject else I18n.t "activity.verb.post.title.other_wall", :sender => view.link_name(sender_subject), :receiver => view.link_name(receiver_subject) end else "Must define activity title" end.html_safe end |
#user_author_subject ⇒ Object
The subject user actor
103 104 105 |
# File 'app/models/activity.rb', line 103 def .subject end |
#verb ⇒ Object
The name of the verb of this activity
83 84 85 |
# File 'app/models/activity.rb', line 83 def verb activity_verb.name end |
#verb=(name) ⇒ Object
Set the name of the verb of this activity
88 89 90 |
# File 'app/models/activity.rb', line 88 def verb=(name) self.activity_verb = ActivityVerb[name] end |