mirror of
https://github.com/discourse/discourse.git
synced 2025-06-19 03:03:52 +08:00
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:
@ -236,16 +236,8 @@ class TopicView
|
|||||||
end
|
end
|
||||||
|
|
||||||
def image_url
|
def image_url
|
||||||
if @post_number > 1 && @desired_post.present?
|
url = desired_post&.image_url if @post_number > 1
|
||||||
if @desired_post.image_url.present?
|
url || @topic.image_url
|
||||||
@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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def filter_posts(opts = {})
|
def filter_posts(opts = {})
|
||||||
|
@ -706,4 +706,35 @@ describe TopicView do
|
|||||||
expect(topic_view.read_time).to eq(nil)
|
expect(topic_view.read_time).to eq(nil)
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
Reference in New Issue
Block a user