docbrown/app/labor/follow_checker.rb
Ben Halpern c76abbbdb3
Allow users to follow podcasts (#2690)
* Allow users to follow podcasts

* Only display podcasts user follows

* Add main_color_hex to factory

* Fix podcast test and modify styles

* Fix tests

* Remove weird test
2019-05-04 15:30:40 -04:00

24 lines
871 B
Ruby

class FollowChecker
attr_accessor :follower, :followable_type, :followable_id
def initialize(follower, followable_type, followable_id)
@follower = follower
@followable_type = followable_type
@followable_id = followable_id
end
def cached_follow_check
Rails.cache.fetch("user-#{follower.id}-#{follower.updated_at}/is_following_#{followable_type}_#{followable_id}", expires_in: 20.hours) do
followable = if followable_type == "Tag"
Tag.find(followable_id)
elsif followable_type == "Organization"
Organization.find(followable_id)
elsif followable_type == "Podcast"
Podcast.find(followable_id)
else
User.find(followable_id)
end
follower.following?(followable)
end
end
end