mirror of
https://ghfast.top/https://github.com/discourse/discourse-follow.git
synced 2026-07-15 11:36:38 +08:00
25 lines
903 B
Ruby
25 lines
903 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Follow::UserExtension
|
|
def self.prepended(base)
|
|
base.has_many :follower_relations, class_name: "UserFollower", dependent: :delete_all
|
|
base.has_many :followers,
|
|
->(user) {
|
|
if !user.allow_people_to_follow_me ||
|
|
user.user_option&.hide_profile_and_presence
|
|
where("1=0")
|
|
end
|
|
},
|
|
through: :follower_relations,
|
|
source: :follower_user
|
|
|
|
base.has_many :following_relations,
|
|
class_name: "UserFollower",
|
|
foreign_key: :follower_id,
|
|
dependent: :delete_all
|
|
base.has_many :following,
|
|
-> { UserFollower.filter_opted_out_users(self) },
|
|
through: :following_relations,
|
|
source: :followed_user
|
|
end
|
|
end
|