add active scope to follows model
This commit is contained in:
parent
8af66b1b2c
commit
5af2b8f216
4 changed files with 10 additions and 7 deletions
|
@ -10,7 +10,11 @@ class Follow < ApplicationRecord
|
|||
validates :user, uniqueness: { scope: :followed, message: 'This entity is already followed by this user' }
|
||||
|
||||
after_create :add_subsetting
|
||||
|
||||
|
||||
scope :active, -> {
|
||||
where(muted: false)
|
||||
}
|
||||
|
||||
private
|
||||
|
||||
def add_subsetting
|
||||
|
|
|
@ -58,8 +58,8 @@ class User < ApplicationRecord
|
|||
admin: admin }
|
||||
if (_options[:follows])
|
||||
json['follows'] = {
|
||||
topics: following.where(muted: false, followed_type: 'Topic').to_a.map(&:followed_id),
|
||||
maps: following.where(muted: false, followed_type: 'Map').to_a.map(&:followed_id)
|
||||
topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id),
|
||||
maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id)
|
||||
}
|
||||
end
|
||||
if (_options[:follow_settings])
|
||||
|
|
|
@ -8,7 +8,7 @@ class FollowService
|
|||
return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason)
|
||||
|
||||
follow = Follow.where(followed: entity, user: user).first_or_create
|
||||
follow.update_attribute('muted', false)
|
||||
follow.update(muted: false)
|
||||
if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason)
|
||||
follow.follow_reason.update_attribute(reason, true)
|
||||
end
|
||||
|
@ -16,7 +16,7 @@ class FollowService
|
|||
|
||||
def unfollow(entity, user)
|
||||
follow = Follow.where(followed: entity, user: user).first
|
||||
follow.update_attribute('muted', true)
|
||||
follow.update(muted: true)
|
||||
end
|
||||
|
||||
def remove_reason(entity, user, reason)
|
||||
|
|
|
@ -53,8 +53,7 @@ class NotificationService
|
|||
end
|
||||
|
||||
def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil)
|
||||
follows = entity.follows.where.not(user_id: event.user.id)
|
||||
follows = follows.where(muted: false)
|
||||
follows = entity.follows.active.where.not(user_id: event.user.id)
|
||||
|
||||
if !exclude_follows.nil?
|
||||
follows = follows.where.not(id: exclude_follows)
|
||||
|
|
Loading…
Reference in a new issue