[sorting query builder] Adjust filtering
This commit is contained in:
parent
5b4b633702
commit
852d2f78e9
@ -44,9 +44,10 @@ class Api::V1::Timelines::ExploreController < Api::BaseController
|
|||||||
|
|
||||||
def explore_statuses
|
def explore_statuses
|
||||||
if current_account
|
if current_account
|
||||||
SortingQueryBuilder.new.call(@sort_type, nil, params[:page]).reject {|status|
|
SortingQueryBuilder.new.call(@sort_type, nil, params[:page], current_account)
|
||||||
FeedManager.instance.filter?(:home, status, current_account.id)
|
.reject {|status|
|
||||||
}
|
FeedManager.instance.filter?(:home, status, current_account.id)
|
||||||
|
}
|
||||||
else
|
else
|
||||||
page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min
|
page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min
|
||||||
SortingQueryBuilder.new.call(@sort_type, nil, page)
|
SortingQueryBuilder.new.call(@sort_type, nil, page)
|
||||||
|
@ -43,7 +43,7 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
|
|||||||
'top_yearly',
|
'top_yearly',
|
||||||
'top_all_time',
|
'top_all_time',
|
||||||
].include? params[:sort_by]
|
].include? params[:sort_by]
|
||||||
|
|
||||||
if @collection_type === 'featured' && (@sort_type == 'newest' || @sort_type == 'recent')
|
if @collection_type === 'featured' && (@sort_type == 'newest' || @sort_type == 'recent')
|
||||||
@sort_type = 'hot'
|
@sort_type = 'hot'
|
||||||
end
|
end
|
||||||
@ -66,9 +66,9 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
|
|||||||
elsif @collection_type == 'member' && !current_account.nil?
|
elsif @collection_type == 'member' && !current_account.nil?
|
||||||
@groupIds = current_account.groups.pluck(:id)
|
@groupIds = current_account.groups.pluck(:id)
|
||||||
end
|
end
|
||||||
|
|
||||||
if current_account
|
if current_account
|
||||||
SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page]).reject {|status|
|
SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page], current_account).reject {|status|
|
||||||
FeedManager.instance.filter?(:home, status, current_account.id)
|
FeedManager.instance.filter?(:home, status, current_account.id)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -51,7 +51,7 @@ class Api::V1::Timelines::GroupController < Api::BaseController
|
|||||||
|
|
||||||
def group_statuses
|
def group_statuses
|
||||||
if current_account
|
if current_account
|
||||||
SortingQueryBuilder.new.call(@sort_type, @group, params[:page]).reject {|status|
|
SortingQueryBuilder.new.call(@sort_type, @group, params[:page], current_account).reject {|status|
|
||||||
FeedManager.instance.filter?(:home, status, current_account.id)
|
FeedManager.instance.filter?(:home, status, current_account.id)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class SortingQueryBuilder < BaseService
|
class SortingQueryBuilder < BaseService
|
||||||
def call(sort_type, group = nil, page = 1)
|
def call(sort_type, group = nil, page = 1, account = nil)
|
||||||
limit = 20
|
limit = 20
|
||||||
|
|
||||||
min_likes = 5
|
min_likes = 5
|
||||||
@ -44,6 +44,8 @@ class SortingQueryBuilder < BaseService
|
|||||||
query = query.with_public_visibility if group.nil?
|
query = query.with_public_visibility if group.nil?
|
||||||
query = query.where('statuses.created_at > ?', date_limit)
|
query = query.where('statuses.created_at > ?', date_limit)
|
||||||
query = query.where(group: group) unless group.nil?
|
query = query.where(group: group) unless group.nil?
|
||||||
|
query = query.excluding_blocked_reblogs(account) unless account.nil?
|
||||||
|
query = query.not_excluded_by_account(current_account) unless account.nil?
|
||||||
query = query.page(page.to_i)
|
query = query.page(page.to_i)
|
||||||
query = query.per(limit)
|
query = query.per(limit)
|
||||||
return query
|
return query
|
||||||
@ -55,6 +57,8 @@ class SortingQueryBuilder < BaseService
|
|||||||
query = query.where('status_stats.reblogs_count > ?', min_reblogs) unless sort_type == 'recent'
|
query = query.where('status_stats.reblogs_count > ?', min_reblogs) unless sort_type == 'recent'
|
||||||
query = query.where('status_stats.favourites_count > ?', min_likes) unless sort_type == 'recent'
|
query = query.where('status_stats.favourites_count > ?', min_likes) unless sort_type == 'recent'
|
||||||
query = query.joins(:status)
|
query = query.joins(:status)
|
||||||
|
query = query.excluding_blocked_reblogs(account) unless account.nil?
|
||||||
|
query = query.not_excluded_by_account(current_account) unless account.nil?
|
||||||
query = query.where('statuses.reblog_of_id IS NULL')
|
query = query.where('statuses.reblog_of_id IS NULL')
|
||||||
query = query.where('statuses.in_reply_to_id IS NULL')
|
query = query.where('statuses.in_reply_to_id IS NULL')
|
||||||
query = query.where('statuses.group_id': group) unless group.nil?
|
query = query.where('statuses.group_id': group) unless group.nil?
|
||||||
|
Loading…
Reference in New Issue
Block a user