From 2c3a2543599d18792dfe6c03743395d5dbdbf7ff Mon Sep 17 00:00:00 2001 From: evazion Date: Fri, 14 Oct 2022 18:59:35 -0500 Subject: [PATCH] posts: choose better images for opengraph previews. When choosing the Open Graph image (the preview image shown when a Danbooru link is posted on Discord or social media), choose the safest image with the highest score, rather than the image with the highest favcount. --- app/logical/post_sets/post.rb | 3 +-- app/models/post.rb | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index 355be2c32..c79753bb5 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -129,8 +129,7 @@ module PostSets end def best_post - # be smarter about this in the future - posts.reject(&:is_deleted).select(&:visible?).max_by(&:fav_count) + posts.reject(&:is_deleted).select(&:visible?).max_by { |post| [-post.rating_id, post.score] } end def pending_bulk_update_requests diff --git a/app/models/post.rb b/app/models/post.rb index 10f873f3a..1c539799d 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -305,6 +305,11 @@ class Post < ApplicationRecord flags.join(" ") end + # g => 0, s => 1, q => 2, e => 3 + def rating_id + RATINGS.keys.index(rating) + end + def pretty_rating RATINGS.fetch(rating) end