view app/views/tweets/_tweet.html.erb @ 252:151bc6d97d39

Include pinned tweet
author nanaya <me@nanaya.net>
date Tue, 17 Oct 2023 00:04:11 +0900
parents be0b78fb5f57
children d726e8b92dd1
line wrap: on
line source

<% if tweet[:retweet].present? %>
  <p><em>Retweeted:</em></p>

  <%= render "tweet", :tweet => tweet[:retweet], :with_time => true %>
<% else %>
  <% if defined?(with_time) && with_time %>
    <p>
      <small>
        Originally <%= link_to 'tweeted', status_url(tweet) %> at <%= tweet[:created_at].rfc822 %>
      </small>
    </p>
  <% end %>

  <% if tweet[:reply_to_id].present? %>
    <p>
      <small>
        Replying to
        <%= 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>
    <%= auto_link(expand_url(
          tweet[:message],
          { **tweet[:entity_urls], **tweet[:entity_media] }
        ))
        .gsub("\n", "<br />")
        .html_safe
      %>
  </p>

  <p>
    <%= 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[:entity_media].each do |_short_url, media| %>
      <% if media[:type] == 'photo' %>
        <%= link_to "#{media[:image_url]}?name=orig" do %>
          <%= image_tag "#{media[:image_url]}?name=small", :alt => "attachment #{media[:id]}" -%>
        <% end %>
      <% 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[:quote_id].present? %>
    <blockquote>
      <% 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 %>