2017-02-11 05:20:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
class FollowService
|
2017-02-12 03:56:07 +00:00
|
|
|
class << self
|
|
|
|
def follow(entity, user, reason)
|
2017-02-11 05:20:42 +00:00
|
|
|
|
2017-02-12 03:56:07 +00:00
|
|
|
return unless is_tester(user)
|
2017-02-11 05:20:42 +00:00
|
|
|
|
2017-02-12 03:56:07 +00:00
|
|
|
follow = Follow.where(followed: entity, user: user).first_or_create
|
|
|
|
if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason)
|
|
|
|
follow.follow_reason.update_attribute(reason, true)
|
|
|
|
end
|
2017-02-11 05:20:42 +00:00
|
|
|
end
|
2017-02-12 03:56:07 +00:00
|
|
|
|
|
|
|
def unfollow(entity, user)
|
|
|
|
Follow.where(followed: entity, user: user).destroy_all
|
|
|
|
end
|
|
|
|
|
|
|
|
def remove_reason(entity, user, reason)
|
|
|
|
return unless FollowReason::REASONS.include?(reason)
|
|
|
|
follow = Follow.where(followed: entity, user: user).first
|
|
|
|
if follow
|
|
|
|
follow.follow_reason.update_attribute(reason, false)
|
|
|
|
if !follow.follow_reason.has_reason
|
|
|
|
follow.destroy
|
|
|
|
end
|
2017-02-11 05:20:42 +00:00
|
|
|
end
|
|
|
|
end
|
2017-02-12 03:56:07 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def is_tester(user)
|
|
|
|
%w(connorturland@gmail.com devin@callysto.com chessscholar@gmail.com solaureum@gmail.com ishanshapiro@gmail.com).include?(user.email)
|
|
|
|
end
|
2017-02-11 05:20:42 +00:00
|
|
|
end
|
|
|
|
end
|