Merge pull request #1132 from metamaps/feature/mod.follow
add active scope to follows model
This commit is contained in:
commit
f323796030
6 changed files with 27 additions and 9 deletions
|
@ -11,6 +11,10 @@ class Follow < ApplicationRecord
|
||||||
|
|
||||||
after_create :add_subsetting
|
after_create :add_subsetting
|
||||||
|
|
||||||
|
scope :active, -> {
|
||||||
|
where(muted: false)
|
||||||
|
}
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def add_subsetting
|
def add_subsetting
|
||||||
|
|
|
@ -58,8 +58,8 @@ class User < ApplicationRecord
|
||||||
admin: admin }
|
admin: admin }
|
||||||
if (_options[:follows])
|
if (_options[:follows])
|
||||||
json['follows'] = {
|
json['follows'] = {
|
||||||
topics: following.where(muted: false, followed_type: 'Topic').to_a.map(&:followed_id),
|
topics: following.active.where(followed_type: 'Topic').to_a.map(&:followed_id),
|
||||||
maps: following.where(muted: false, followed_type: 'Map').to_a.map(&:followed_id)
|
maps: following.active.where(followed_type: 'Map').to_a.map(&:followed_id)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
if (_options[:follow_settings])
|
if (_options[:follow_settings])
|
||||||
|
|
|
@ -8,7 +8,9 @@ class FollowService
|
||||||
return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason)
|
return if (reason == 'created' || reason == 'contributed') && !should_auto_follow(entity, user, reason)
|
||||||
|
|
||||||
follow = Follow.where(followed: entity, user: user).first_or_create
|
follow = Follow.where(followed: entity, user: user).first_or_create
|
||||||
follow.update_attribute('muted', false)
|
unless follow.update(muted: false)
|
||||||
|
raise follow.errors.full_messages.join("\n")
|
||||||
|
end
|
||||||
if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason)
|
if FollowReason::REASONS.include?(reason) && !follow.follow_reason.read_attribute(reason)
|
||||||
follow.follow_reason.update_attribute(reason, true)
|
follow.follow_reason.update_attribute(reason, true)
|
||||||
end
|
end
|
||||||
|
@ -16,7 +18,11 @@ class FollowService
|
||||||
|
|
||||||
def unfollow(entity, user)
|
def unfollow(entity, user)
|
||||||
follow = Follow.where(followed: entity, user: user).first
|
follow = Follow.where(followed: entity, user: user).first
|
||||||
follow.update_attribute('muted', true)
|
if follow
|
||||||
|
unless follow.update(muted: true)
|
||||||
|
raise follow.errors.full_messages.join("\n")
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_reason(entity, user, reason)
|
def remove_reason(entity, user, reason)
|
||||||
|
|
|
@ -53,8 +53,7 @@ class NotificationService
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.notify_followers(entity, event_type, event, reason_filter = nil, exclude_follows = nil)
|
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 = entity.follows.active.where.not(user_id: event.user.id)
|
||||||
follows = follows.where(muted: false)
|
|
||||||
|
|
||||||
if !exclude_follows.nil?
|
if !exclude_follows.nil?
|
||||||
follows = follows.where.not(id: exclude_follows)
|
follows = follows.where.not(id: exclude_follows)
|
||||||
|
|
9
config/initializers/delayed_job.rb
Normal file
9
config/initializers/delayed_job.rb
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
Delayed::Worker.class_eval do
|
||||||
|
|
||||||
|
def handle_failed_job_with_notification(job, error)
|
||||||
|
handle_failed_job_without_notification(job, error)
|
||||||
|
ExceptionNotifier.notify_exception(error)
|
||||||
|
end
|
||||||
|
alias_method_chain :handle_failed_job, :notification
|
||||||
|
|
||||||
|
end
|
|
@ -5,7 +5,7 @@ namespace :metamaps do
|
||||||
end
|
end
|
||||||
|
|
||||||
def summarize_map_activity
|
def summarize_map_activity
|
||||||
Follow.where(followed_type: 'Map').find_each do |follow|
|
Follow.active.where(followed_type: 'Map').find_each do |follow|
|
||||||
map = follow.followed
|
map = follow.followed
|
||||||
user = follow.user
|
user = follow.user
|
||||||
# add logging and rescue-ing
|
# add logging and rescue-ing
|
||||||
|
|
Loading…
Add table
Reference in a new issue