UX: Do not use avatars as fallback opengraph images for replies (#8605)

People rarely want to have their avatars show up as the preview image on social media platforms. Instead, we should fall back to the site opengraph image.
This commit is contained in:
David Taylor 2019-12-20 13:17:14 +00:00 committed by GitHub
parent b47b1d8af8
commit 61919ad39f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View File

@ -236,16 +236,8 @@ class TopicView
end
def image_url
if @post_number > 1 && @desired_post.present?
if @desired_post.image_url.present?
@desired_post.image_url
elsif @desired_post.user
# show poster avatar
@desired_post.user.avatar_template_url.gsub("{size}", "200")
end
else
@topic.image_url
end
url = desired_post&.image_url if @post_number > 1
url || @topic.image_url
end
def filter_posts(opts = {})

View File

@ -706,4 +706,35 @@ describe TopicView do
expect(topic_view.read_time).to eq(nil)
end
end
describe '#image_url' do
let!(:post1) { Fabricate(:post, topic: topic) }
let!(:post2) { Fabricate(:post, topic: topic) }
let!(:post3) { Fabricate(:post, topic: topic).tap { |p| p.update_column(:image_url, "post3_image.png") }.reload }
def topic_view_for_post(post_number)
TopicView.new(topic.id, evil_trout, post_number: post_number)
end
context "when op has an image" do
before do
topic.update_column(:image_url, "op_image.png")
post1.update_column(:image_url, "op_image.png")
end
it "uses the topic image as a fallback when posts have no image" do
expect(topic_view_for_post(1).image_url).to eq("op_image.png")
expect(topic_view_for_post(2).image_url).to eq("op_image.png")
expect(topic_view_for_post(3).image_url).to eq("post3_image.png")
end
end
context "when op has no image" do
it "returns nil when posts have no image" do
expect(topic_view_for_post(1).image_url).to eq(nil)
expect(topic_view_for_post(2).image_url).to eq(nil)
expect(topic_view_for_post(3).image_url).to eq("post3_image.png")
end
end
end
end