diff app/views/tweets/_tweet.html.erb @ 234:7a773720d81f legit-client

Totally legit client
author nanaya <me@nanaya.net>
date Fri, 14 Jul 2023 22:42:20 +0900
parents 12287b32fbda
children 961d362e42c7
line wrap: on
line diff
--- a/app/views/tweets/_tweet.html.erb	Fri Jul 14 01:45:40 2023 +0900
+++ b/app/views/tweets/_tweet.html.erb	Fri Jul 14 22:42:20 2023 +0900
@@ -1,34 +1,32 @@
-<% if tweet.retweeted_status.present? %>
+<% if tweet[:retweet].present? %>
   <p>
-    <%= link_to status_url(tweet.retweeted_status) do %>
+    <%= link_to status_url(tweet[:retweet]) do %>
       <em>Retweeted:</em>
     <% end %>
   </p>
 
-  <%= render "tweet", :tweet => tweet.retweeted_status, :with_time => true %>
-<% else%>
+  <%= render "tweet", :tweet => tweet[:retweet], :with_time => true %>
+<% else %>
   <% if defined?(with_time) && with_time %>
     <p>
-      <small>Originally tweeted at <%= tweet.created_at.rfc822 %></small>
+      <small>Originally tweeted at <%= tweet[:created_at].rfc822 %></small>
     </p>
   <% end %>
 
-  <% if tweet.in_reply_to_status_id.present? %>
+  <% if tweet[:reply_to_id].present? %>
     <p>
       <small>
         Replying to
-        <%= link_to 'tweet', status_url_base(tweet.in_reply_to_screen_name, tweet.in_reply_to_status_id) %>
-        by <%= link_to tweet.in_reply_to_screen_name, "https://twitter.com/#{tweet.in_reply_to_screen_name}" %>
+        <%= link_to 'tweet', status_url_base(tweet[:reply_to_username], tweet[:reply_to_id]) %>
+        by <%= link_to "@#{tweet[:reply_to_username]}", "https://twitter.com/#{tweet[:reply_to_username]}" %>
       </small>
     </p>
   <% end %>
 
   <p>
-    <%# FIXME: Twitter gem doesn't support extended mode when writing this %>
     <%= auto_link(expand_url(
-          tweet.full_text_extended,
-          tweet.attrs[:entities][:urls],
-          tweet.attrs[:entities][:media]
+          tweet[:message],
+          { **tweet[:entity_urls], **tweet[:entity_media] }
         ))
         .gsub("\n", "<br />")
         .html_safe
@@ -36,31 +34,36 @@
   </p>
 
   <p>
-    <%= link_to "https://twitter.com/#{tweet.user.screen_name}" do %>
-      <%= image_tag tweet.user.profile_image_url_https.to_s, :alt => "profile image for #{tweet.user.name.printable}" %>
-      <%= tweet.user.name.printable -%>
+    <%= link_to "https://twitter.com/#{tweet[:user][:username]}" do %>
+      <%= image_tag tweet[:user][:avatar_url].to_s, :alt => "profile image for #{tweet[:user][:name].printable}" %>
+      <%= tweet[:user][:name].printable -%>
     <% end %>
   </p>
 
   <p>
-    <% tweet.media.each_with_index do |media, i| %>
-      <% if media.is_a? Twitter::Media::Photo %>
-        <%= link_to "#{media.media_url_https}?name=orig" do %>
-          <%= image_tag "#{media.media_url_https}?name=small", :alt => "attachment #{i + 1}" -%>
+    <% tweet[:entity_media].each do |_short_url, media| %>
+      <% if media[:type] == 'photo' %>
+        <%= link_to "#{media[:url]}?name=orig" do %>
+          <%= image_tag "#{media[:url]}?name=small", :alt => "attachment #{media[:id]}" -%>
         <% end %>
-      <% elsif media.is_a? Twitter::Media::Video %>
-        <%= video_tag media.video_info.variants
-          .select { |i| i.bitrate.is_a? Integer }
-          .sort_by { |i| -i.bitrate }
-          .map(&:url), width: '100%', controls: true
+      <% elsif media[:type] == 'video' %>
+        <%= video_tag media[:variants]
+          .sort_by { |variant| -variant[:bitrate] }
+          .map { |variant| variant[:url] }, width: '100%', controls: true
         %>
       <% end %>
     <% end %>
   </p>
 
-  <% if tweet.quoted_status.present? %>
+  <% if tweet[:quote_id].present? %>
     <blockquote>
-      <%= render "tweet", :tweet => tweet.quoted_status, :with_time => true %>
+      <% if tweet[:quote].present? %>
+        <%= render "tweet", :tweet => tweet[:quote], :with_time => true %>
+      <% else %>
+        <%= link_to status_url_base(nil, tweet[:quote_id]) do %>
+          <em>Preview not available, view tweet directly.</em>
+        <% end %>
+      <% end %>
     </blockquote>
   <% end %>
 <% end %>