Class: SocialActivity

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_activities(subject, verb, object, options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/app/models/social_activity.rb', line 27

def self.create_activities(subject, verb, object, options = {})
  activities = []
  owners = [ subject, object ]
  owners.concat(options[:additional_recipients]) if options[:additional_recipients]
  owners.concat(subject.incoming_social_connections.collect {|i| i.source })
  owners.concat(object.incoming_social_connections.collect {|i| i.source })

  owners.uniq.each do |owner|
    activities << SocialActivity.create(:owner => owner,
                                        :subject => subject,
                                        :verb => verb,
                                        :target => object,
                                        :options_as_json => options.to_json)
  end
  activities
end

.exists(subject, verb, object) ⇒ Object



50
51
52
53
54
55
# File 'lib/app/models/social_activity.rb', line 50

def self.exists(subject, verb, object)
  SocialActivity.where('subject_id = ? and subject_type = ? and verb = ? ' +
                       'and target_id = ? and target_type = ?',
                       subject.id, subject.class.name, verb, object.id,
                       object.class.name).exists?
end

.objects_by_verb_count(object, verb) ⇒ Object



57
58
59
60
61
62
# File 'lib/app/models/social_activity.rb', line 57

def self.objects_by_verb_count(object, verb)
  SocialActivity.where('target_id = ? and target_type = ? and verb = ? ' +
                       'and owner_id = ? and owner_type = ?',
                       object.id, object.class.name, verb, object.id,
                       object.class.name).count
end

.unseen_activities(for_whom) ⇒ Object



44
45
46
47
48
# File 'lib/app/models/social_activity.rb', line 44

def self.unseen_activities(for_whom)
  SocialActivity.where('owner_id = ? and owner_type = ? and unseen = ?',
                       for_whom.id, for_whom.class.name,
                       true).order("created_at DESC")
end

Instance Method Details

#consumeObject



15
16
17
18
# File 'lib/app/models/social_activity.rb', line 15

def consume
  self.unseen = false
  self.save
end

#optionsObject



7
8
9
# File 'lib/app/models/social_activity.rb', line 7

def options
  JSON.parse options_as_json
end

#to_sObject



11
12
13
# File 'lib/app/models/social_activity.rb', line 11

def to_s
  "SocialActivity #{subject} #{verb} #{target} (owned by #{owner})"
end