b0deafc53e
* all the good changes * follows * dont send duplicates * remove follow_type for now * dont add all the extra stuff we're not implementing yet * refactor * lots of fixes * Delete activity.html.erb * Delete activity.text.erb * Update 20170209215819_create_follows.rb * Update schema.rb * Update mapping.rb * Update mailboxer.rb
35 lines
990 B
Ruby
35 lines
990 B
Ruby
# frozen_string_literal: true
|
|
class FollowService
|
|
|
|
|
|
def self.follow(entity, user, reason)
|
|
|
|
#return unless is_tester(user)
|
|
|
|
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
|
|
end
|
|
|
|
def self.unfollow(entity, user)
|
|
Follow.where(followed: entity, user: user).destroy_all
|
|
end
|
|
|
|
def self.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
|
|
end
|
|
end
|
|
|
|
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
|
|
end
|