2025-01-20 16:50:51 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
|
|
module DiscourseRewind
|
|
|
|
|
module Action
|
|
|
|
|
class BestPosts < BaseReport
|
|
|
|
|
def call
|
|
|
|
|
best_posts =
|
|
|
|
|
Post
|
|
|
|
|
.where(user_id: user.id)
|
|
|
|
|
.where(created_at: date)
|
|
|
|
|
.where(deleted_at: nil)
|
|
|
|
|
.where("post_number > 1")
|
2025-11-19 09:36:08 +10:00
|
|
|
.order("like_count DESC NULLS LAST, created_at ASC")
|
2025-01-20 16:50:51 +01:00
|
|
|
.limit(3)
|
2025-11-19 09:36:08 +10:00
|
|
|
.select(:post_number, :topic_id, :like_count, :reply_count, :raw, :cooked)
|
|
|
|
|
.map do |post|
|
|
|
|
|
{
|
|
|
|
|
post_number: post.post_number,
|
|
|
|
|
topic_id: post.topic_id,
|
|
|
|
|
like_count: post.like_count,
|
|
|
|
|
reply_count: post.reply_count,
|
|
|
|
|
excerpt:
|
|
|
|
|
post.excerpt(200, { strip_links: true, remap_emoji: true, keep_images: true }),
|
|
|
|
|
}
|
|
|
|
|
end
|
2025-01-20 16:50:51 +01:00
|
|
|
|
|
|
|
|
{ data: best_posts, identifier: "best-posts" }
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|