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:
jbrw
2021-07-13 14:54:28 -04:00
committed by GitHub
parent 53fe8b2e77
commit a64aea38b7
3 changed files with 4180 additions and 2 deletions

View File

@ -23,7 +23,7 @@ module Onebox
html.css('meta').each do |m|
if m.attribute('property') && m.attribute('property').to_s.match(/^og:/i)
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
end
end
@ -100,7 +100,7 @@ module Onebox
if twitter_api_credentials_present?
access(:user, :profile_image_url_https).sub('normal', '400x400')
elsif twitter_data[:image]
twitter_data[:image]
twitter_data[:image] unless twitter_data[:image_user_generated]
end
end