Class: Socializer::ActivityObject
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Socializer::ActivityObject
- Defined in:
- app/models/socializer/activity_object.rb
Instance Attribute Summary collapse
-
#object_ids ⇒ Object
Returns the value of attribute object_ids.
-
#scope ⇒ Object
Returns the value of attribute scope.
Class Method Summary collapse
-
.attribute_type_of(*args) ⇒ Object
define a class macro for setting comparaison with activitable_type.
Instance Method Summary collapse
- #increment_unread_notifications_count ⇒ Object
- #like!(person) ⇒ Object
-
#likes ⇒ Object
REFACTOR: DRY this up.
- #share! ⇒ Object
- #unlike!(person) ⇒ Object
Instance Attribute Details
#object_ids ⇒ Object
Returns the value of attribute object_ids.
3 4 5 |
# File 'app/models/socializer/activity_object.rb', line 3 def object_ids @object_ids end |
#scope ⇒ Object
Returns the value of attribute scope.
3 4 5 |
# File 'app/models/socializer/activity_object.rb', line 3 def scope @scope end |
Class Method Details
.attribute_type_of(*args) ⇒ Object
define a class macro for setting comparaison with activitable_type
28 29 30 31 32 |
# File 'app/models/socializer/activity_object.rb', line 28 def self.attribute_type_of(*args) args.each do |type| define_method("#{type}?") { activitable_type == "Socializer::#{type.capitalize}" } end end |
Instance Method Details
#increment_unread_notifications_count ⇒ Object
104 105 106 |
# File 'app/models/socializer/activity_object.rb', line 104 def increment_unread_notifications_count increment!(:unread_notifications_count) end |
#like!(person) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'app/models/socializer/activity_object.rb', line 55 def like!(person) activity = Activity.create! do |a| a.actor_id = person.activity_object.id a.activity_object_id = id a.verb = Verb.find_or_create_by(name: 'like') end Audience.create!(privacy_level: :public, activity_id: activity.id) increment_like_count end |
#likes ⇒ Object
REFACTOR: DRY this up. Reduce database calls TODO: Rename this method to liked_by
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/models/socializer/activity_object.rb', line 38 def likes people = [] query = Activity.joins { verb }.where { activity_object_id.eq(my { id }) } activities_likes = query.where { verb.name.eq('like') } activities_likes.each do |activity| people.push activity.actor end activities_unlikes = query.where { verb.name.eq('unlike') } activities_unlikes.each do |activity| people.delete_at people.index(activity.actor) end people end |
#share! ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/models/socializer/activity_object.rb', line 79 def share! public = Socializer::Audience.privacy_level.find_value(:public).value.to_s circles = Socializer::Audience.privacy_level.find_value(:circles).value.to_s activity = Activity.new do |a| a.actor_id = actor_id a.activity_object_id = id a.verb = Verb.find_or_create_by(name: 'share') end # REFACTOR: remove duplication if scope == public || scope == circles activity.audiences.build(privacy_level: scope) else object_ids.each do |object_id| activity.audiences.build do |a| a.privacy_level = :limited a.activity_object_id = object_id end end end activity.save! end |
#unlike!(person) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/models/socializer/activity_object.rb', line 67 def unlike!(person) activity = Activity.create! do |a| a.actor_id = person.activity_object.id a.activity_object_id = id a.verb = Verb.find_or_create_by(name: 'unlike') end Audience.create!(privacy_level: :public, activity_id: activity.id) decrement_like_count end |