FIX: Minor Twitter onebox improvements (#22387)

This commit is contained in:
Jan Cernik 2023-07-03 19:53:12 -03:00 committed by GitHub
parent de192b1fbd
commit 77732cd2b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25 additions and 6 deletions

View File

@ -679,6 +679,11 @@ aside.onebox.twitterstatus .onebox-body {
margin-right: 0.25em; margin-right: 0.25em;
} }
} }
.is-reply {
color: var(--primary-medium);
margin-right: 0.25em;
}
} }
// Onebox - Imgur/Flickr - Album // Onebox - Imgur/Flickr - Album

View File

@ -141,6 +141,12 @@ module Onebox
end end
end end
def is_reply
if twitter_api_credentials_present?
raw.dig(:data, :referenced_tweets)&.any? { |tweet| tweet.dig(:type) == "replied_to" }
end
end
def quoted_full_name def quoted_full_name
if twitter_api_credentials_present? && quoted_tweet_author.present? if twitter_api_credentials_present? && quoted_tweet_author.present?
quoted_tweet_author[:name] quoted_tweet_author[:name]
@ -216,6 +222,7 @@ module Onebox
avatar: avatar, avatar: avatar,
likes: likes, likes: likes,
retweets: retweets, retweets: retweets,
is_reply: is_reply,
quoted_text: quoted_text, quoted_text: quoted_text,
quoted_full_name: quoted_full_name, quoted_full_name: quoted_full_name,
quoted_screen_name: quoted_screen_name, quoted_screen_name: quoted_screen_name,

View File

@ -3,6 +3,11 @@
<div class="twitter-screen-name"><a href="{{link}}" target="_blank" rel="noopener">@{{screen_name}}</a></div> <div class="twitter-screen-name"><a href="{{link}}" target="_blank" rel="noopener">@{{screen_name}}</a></div>
<div class="tweet"> <div class="tweet">
{{#is_reply}}
<span class="is-reply">
<svg class="fa d-icon d-icon-reply svg-icon svg-string" xmlns="http://www.w3.org/2000/svg"><use href="#reply"></use></svg>
</span>
{{/is_reply}}
<span class="tweet-description">{{{tweet}}}</span> <span class="tweet-description">{{{tweet}}}</span>
{{#quoted_text}} {{#quoted_text}}
<div class="quoted"> <div class="quoted">

View File

@ -15,15 +15,17 @@ class TwitterApi
text = tweet[:data][:text].dup.to_s text = tweet[:data][:text].dup.to_s
if (entities = tweet[:data][:entities]) && (urls = entities[:urls]) if (entities = tweet[:data][:entities]) && (urls = entities[:urls])
urls.each do |url| urls.each do |url|
text.gsub!( if !url[:display_url].start_with?("pic.twitter.com")
url[:url], text.gsub!(
"<a target='_blank' href='#{url[:expanded_url]}'>#{url[:display_url]}</a>", url[:url],
) "<a target='_blank' href='#{url[:expanded_url]}'>#{url[:display_url]}</a>",
)
else
text.gsub!(url[:url], "")
end
end end
end end
text = link_hashtags_in link_handles_in text text = link_hashtags_in link_handles_in text
result = Rinku.auto_link(text, :all, 'target="_blank"').to_s result = Rinku.auto_link(text, :all, 'target="_blank"').to_s
if tweet[:includes] && media = tweet[:includes][:media] if tweet[:includes] && media = tweet[:includes][:media]