added 260907 version of worker toolkit

This commit is contained in:
2026-09-08 20:30:51 -04:00
parent cbd3f0f8ca
commit 97aca37663
1283 changed files with 142951 additions and 0 deletions

View File

@@ -0,0 +1,43 @@
class DiscussionPosts < AdditionalPosts
attr_accessor :params, :user
TOP_POSTS_DAYS = 7
TOP_POSTS_COUNT = 5
def initialize(params, user)
@params = params
@user = user
end
def show_list
return Post.none unless params
@posts = Post.accessible_by(current_ability).where(_type: "Post")
@posts = @posts.fts(params[:query]) if params[:query].present?
@posts = if params[:id].present? && Post::TOPIC_TYPES.include?(params[:type])
@posts.where("#{params[:type]}_ids": params[:id].to_i)
elsif params[:following].present?
@posts.by_followings(user.topic_following)
else
@posts
end
end
def full_top_post_list
Post.accessible_by(current_ability)
.where(_type: "Post")
.by_followings(user.topic_following)
.where(:created_at.gte => TOP_POSTS_DAYS.days.ago)
.order(comment_reaction_count: :desc)
end
def refined_top_list
posts = full_top_post_list.limit(TOP_POSTS_COUNT)
if Array(posts).size == TOP_POSTS_COUNT
posts
else
posts + add_last_new_posts(TOP_POSTS_COUNT - Array(posts).size, posts.map(&:_id))
end
end
end