[group_collection] Change to -my groups- timeline

This commit is contained in:
Fosco Marotto 2021-01-23 03:13:47 -05:00
parent 3719a6cfd7
commit 958e8aad3a
4 changed files with 61 additions and 8 deletions

View File

@ -24,7 +24,7 @@ class Api::V1::StatusesController < Api::BaseController
def comments
descendants_results = @status.descendants(CONTEXT_LIMIT, current_account, nil, nil)
loaded_descendants = cache_collection(descendants_results, Status)
@context = Context.new(descendants: loaded_descendants)
statuses = [@status] + @context.descendants
@ -51,6 +51,7 @@ class Api::V1::StatusesController < Api::BaseController
def create
markdown = status_params[:markdown] unless status_params[:markdown] === status_params[:status]
@status = PostStatusService.new.call(current_user.account,
text: status_params[:status],
markdown: markdown,

View File

@ -64,13 +64,13 @@ class Api::V1::Timelines::GroupCollectionController < Api::BaseController
if @collection_type == 'featured'
@groupIds = FetchGroupsService.new.call("featured")
elsif @collection_type == 'member' && !current_account.nil?
@groupIds = current_account.groups.pluck(:id)
# @groupIds = current_account.groups.pluck(:id)
return SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page], current_account.id, "group_collection")
end
if current_account
SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page]).reject {|status|
FeedManager.instance.filter?(:home, status, current_account.id)
}
SortingQueryBuilder.new.call(@sort_type, @groupIds, params[:page])
# .reject {|status| FeedManager.instance.filter?(:home, status, current_account.id)}
else
return []
# page = [params[:page].to_i.abs, MIN_UNAUTHENTICATED_PAGES].min

View File

@ -1,24 +1,29 @@
# frozen_string_literal: true
class SortingQueryBuilder < BaseService
def call(sort_type, group = nil, page = 1)
def call(sort_type, group = nil, page = 1, account_id = nil, source = nil)
limit = 20
min_likes = 5
min_reblogs = 2
min_replies = 1
date_limit = 5.years.ago
pure_limit = "NOW() - INTERVAL '1 year'"
max_page = 8
case sort_type
when 'hot'
date_limit = 8.hours.ago
pure_limit = "NOW() - INTERVAL '8 hours'"
when 'top_today'
date_limit = 24.hours.ago
pure_limit = "NOW() - INTERVAL '24 hours'"
when 'top_weekly'
date_limit = 7.days.ago
pure_limit = "NOW() - INTERVAL '7 days'"
when 'top_monthly'
date_limit = 30.days.ago
pure_limit = "NOW() - INTERVAL '30 days'"
when 'top_yearly'
date_limit = 1.year.ago
end
@ -39,7 +44,54 @@ class SortingQueryBuilder < BaseService
return []
end
if source == 'group_collection'
return [] if account_id.nil?
query = "
select q.* from (
select s.*
from statuses s
join group_accounts ga
on s.group_id = ga.group_id
and ga.account_id = #{account_id} "
query += "
join status_stats ss
on s.id = ss.status_id " if sort_type != 'newest'
query += "
where "
query += "
ss.updated_at > #{pure_limit} " if sort_type == 'recent'
query += "
s.created_at > #{pure_limit} " if sort_type != 'recent'
query += "
and s.reply is false
and s.reblog_of_id is null "
if sort_type != 'newest'
query += "
order by ss.favourites_count desc, ss.reblogs_count desc, ss.replies_count desc "
else
query += "
order by s.created_at desc "
end
query += "limit #{limit} "
if page.to_i > 1
query += "offset #{page.to_i * limit}"
end
query += "
) q
left join custom_filters cf
on cf.account_id = #{account_id}
and q.text like '%' || cf.phrase || '%'
where cf.id is null
"
return Status.find_by_sql query
end
if sort_type == 'newest'
query = Status.without_replies.without_reblogs
query = query.with_public_visibility if group.nil?
query = query.where('statuses.created_at > ?', date_limit)

View File

@ -36,8 +36,8 @@ class HomeFeed < Feed
or s.account_id in (select target_account_id from follows where account_id = #{@id})
)
and s.account_id not in (select target_account_id from mutes where account_id = #{@id})
and reblog.account_id not in (select target_account_id from mutes where account_id = #{@id})
and reblog.account_id not in (select target_account_id from blocks where account_id = #{@id})
and (reblog.id is null or reblog.account_id not in (select target_account_id from mutes where account_id = #{@id}))
and (reblog.id is null or reblog.account_id not in (select target_account_id from blocks where account_id = #{@id}))
#{pagination_max}
#{pagination_min}
order by s.created_at desc