Skip to content

Commit

Permalink
FIX: Minor Twitter onebox improvements (discourse#22387)
Browse files Browse the repository at this point in the history
  • Loading branch information
jancernik authored Jul 3, 2023
1 parent de192b1 commit 77732cd
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
5 changes: 5 additions & 0 deletions app/assets/stylesheets/common/base/onebox.scss
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ aside.onebox.twitterstatus .onebox-body {
margin-right: 0.25em;
}
}

.is-reply {
color: var(--primary-medium);
margin-right: 0.25em;
}
}

// Onebox - Imgur/Flickr - Album
Expand Down
7 changes: 7 additions & 0 deletions lib/onebox/engine/twitter_status_onebox.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def retweets
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
if twitter_api_credentials_present? && quoted_tweet_author.present?
quoted_tweet_author[:name]
Expand Down Expand Up @@ -216,6 +222,7 @@ def data
avatar: avatar,
likes: likes,
retweets: retweets,
is_reply: is_reply,
quoted_text: quoted_text,
quoted_full_name: quoted_full_name,
quoted_screen_name: quoted_screen_name,
Expand Down
5 changes: 5 additions & 0 deletions lib/onebox/templates/twitterstatus.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
<div class="twitter-screen-name"><a href="{{link}}" target="_blank" rel="noopener">@{{screen_name}}</a></div>

<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>
{{#quoted_text}}
<div class="quoted">
Expand Down
14 changes: 8 additions & 6 deletions lib/twitter_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ def prettify_tweet(tweet)
text = tweet[:data][:text].dup.to_s
if (entities = tweet[:data][:entities]) && (urls = entities[:urls])
urls.each do |url|
text.gsub!(
url[:url],
"<a target='_blank' href='#{url[:expanded_url]}'>#{url[:display_url]}</a>",
)
if !url[:display_url].start_with?("pic.twitter.com")
text.gsub!(
url[:url],
"<a target='_blank' href='#{url[:expanded_url]}'>#{url[:display_url]}</a>",
)
else
text.gsub!(url[:url], "")
end
end
end

text = link_hashtags_in link_handles_in text

result = Rinku.auto_link(text, :all, 'target="_blank"').to_s

if tweet[:includes] && media = tweet[:includes][:media]
Expand Down

0 comments on commit 77732cd

Please sign in to comment.