FIX: Don’t use `user_generated` images as avatar images in Oneboxed Twitter content (#13712)
By default, Twitter will return the URL for the avatar image of the tweet poster as the `og:image` value. However, if the `user_generated` attribute is true, we should not use this as the avatar URL as this will be an URL of an image in the tweet itself (e.g., an image belonging to a tweeted news story).
This commit is contained in:
parent
53fe8b2e77
commit
a64aea38b7
|
@ -23,7 +23,7 @@ module Onebox
|
||||||
html.css('meta').each do |m|
|
html.css('meta').each do |m|
|
||||||
if m.attribute('property') && m.attribute('property').to_s.match(/^og:/i)
|
if m.attribute('property') && m.attribute('property').to_s.match(/^og:/i)
|
||||||
m_content = m.attribute('content').to_s.strip
|
m_content = m.attribute('content').to_s.strip
|
||||||
m_property = m.attribute('property').to_s.gsub('og:', '')
|
m_property = m.attribute('property').to_s.gsub('og:', '').gsub(':', '_')
|
||||||
twitter_data[m_property.to_sym] = m_content
|
twitter_data[m_property.to_sym] = m_content
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -100,7 +100,7 @@ module Onebox
|
||||||
if twitter_api_credentials_present?
|
if twitter_api_credentials_present?
|
||||||
access(:user, :profile_image_url_https).sub('normal', '400x400')
|
access(:user, :profile_image_url_https).sub('normal', '400x400')
|
||||||
elsif twitter_data[:image]
|
elsif twitter_data[:image]
|
||||||
twitter_data[:image]
|
twitter_data[:image] unless twitter_data[:image_user_generated]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -74,6 +74,23 @@ describe Onebox::Engine::TwitterStatusOnebox do
|
||||||
let(:retweets_count) { "201" }
|
let(:retweets_count) { "201" }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
shared_context "featured image info" do
|
||||||
|
before do
|
||||||
|
@link = "https://twitter.com/codinghorror/status/1409351083177046020"
|
||||||
|
@onebox_fixture = "twitterstatus_featured_image"
|
||||||
|
|
||||||
|
stub_request(:get, @link.downcase).to_return(status: 200, body: onebox_response(@onebox_fixture))
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:full_name) { "Jeff Atwood" }
|
||||||
|
let(:screen_name) { "codinghorror" }
|
||||||
|
let(:avatar) { "" }
|
||||||
|
let(:timestamp) { "3:02 PM - 27 Jun 2021" }
|
||||||
|
let(:link) { @link }
|
||||||
|
let(:favorite_count) { "90" }
|
||||||
|
let(:retweets_count) { "0" }
|
||||||
|
end
|
||||||
|
|
||||||
shared_examples "includes quoted tweet data" do
|
shared_examples "includes quoted tweet data" do
|
||||||
it 'includes quoted tweet' do
|
it 'includes quoted tweet' do
|
||||||
expect(html).to include("If you bought a ticket for tonight’s @Metallica show at Stade de France, you have helped")
|
expect(html).to include("If you bought a ticket for tonight’s @Metallica show at Stade de France, you have helped")
|
||||||
|
@ -115,6 +132,18 @@ describe Onebox::Engine::TwitterStatusOnebox do
|
||||||
it_behaves_like '#to_html'
|
it_behaves_like '#to_html'
|
||||||
it_behaves_like "includes quoted tweet data"
|
it_behaves_like "includes quoted tweet data"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with a featured image tweet" do
|
||||||
|
let(:tweet_content) do
|
||||||
|
"My first text message from my child! A moment that shall live on in infamy!"
|
||||||
|
end
|
||||||
|
|
||||||
|
include_context "featured image info"
|
||||||
|
include_context "engines"
|
||||||
|
|
||||||
|
it_behaves_like "an engine"
|
||||||
|
it_behaves_like '#to_html'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with twitter client" do
|
context "with twitter client" do
|
||||||
|
|
Loading…
Reference in New Issue