Show images, video, and audio attachments to notices.

This commit is contained in:
Phil Hagelberg 2019-10-28 19:05:45 -07:00
parent 1d8950798c
commit 748d800acb
5 changed files with 50 additions and 8 deletions

View File

@ -19,6 +19,8 @@ defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
|> set_content(object)
|> set_link(activity.id)
|> set_published(object)
|> set_sensitive(object)
|> set_attachment(object.data["attachment"])
|> set_attachments(object)
end
@ -39,17 +41,23 @@ defmodule Pleroma.Web.StaticFE.ActivityRepresenter do
defp set_content(data, _), do: Map.put(data, :content, nil)
defp set_attachment(data, attachment), do: Map.put(data, :attachment, attachment)
defp set_link(data, activity_id),
do: Map.put(data, :link, Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, activity_id))
defp set_published(data, %Object{data: %{"published" => published}}),
do: Map.put(data, :published, published)
defp set_sensitive(data, %Object{data: %{"sensitive" => sensitive}}),
do: Map.put(data, :sensitive, sensitive)
# TODO: attachments
defp set_attachments(data, _), do: Map.put(data, :attachments, [])
def represent(activity_id) do
with %Activity{data: %{"type" => "Create"}} = activity <- Activity.get_by_id(activity_id),
with %Activity{data: %{"type" => "Create"}} = activity <-
Activity.get_by_id_with_object(activity_id),
true <- Visibility.is_public?(activity),
{:ok, %User{} = user} <- User.get_or_fetch(activity.data["actor"]) do
{:ok, prepare_activity(user, activity)}

View File

@ -8,10 +8,13 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
alias Pleroma.User
alias Pleroma.Web.MediaProxy
alias Pleroma.Formatter
alias Pleroma.Web.Metadata.Utils
alias Pleroma.Web.Router.Helpers
import Phoenix.HTML
@media_types ["image", "audio", "video"]
def emoji_for_user(%User{} = user) do
(user.source_data["tag"] || [])
|> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
@ -19,4 +22,8 @@ defmodule Pleroma.Web.StaticFE.StaticFEView do
{String.trim(name, ":"), url}
end)
end
def fetch_media_type(url) do
Utils.fetch_media_type(@media_types, url["mediaType"])
end
end

View File

@ -36,6 +36,11 @@
margin-right: 4px;
}
.activity-content img, video {
max-width: 800px;
max-height: 800px;
}
a {
color: white;
}

View File

@ -0,0 +1,8 @@
<%= case @mediaType do %>
<% "audio" -> %>
<audio src="<%= @url %>" controls="controls"></audio>
<% "video" -> %>
<video src="<%= @url %>" controls="controls"></video>
<% _ -> %>
<img src="<%= @url %>" alt="<%= @name %>" title="<%= @name %>">
<% end %>

View File

@ -1,15 +1,29 @@
<div class="activity">
<%= render("user_card.html", %{user: @data.user}) %>
<p class="pull-right">
<a href="<%= @data.link %>" class="activity-link"><%= @data.published %></a></p>
<div class="activity-content">
<%= if @data.title != "" do %>
<details>
<summary><%= raw @data.title %></summary>
<% end %>
<details>
<summary><%= raw @data.title %></summary>
<div class="e-content"><%= raw @data.content %></div>
</details>
<% else %>
<div class="e-content"><%= raw @data.content %></div>
<%= if @data.title != "" do %>
</details>
<% end %>
<p class="pull-right">
<a href="<%= @data.link %>" class="activity-link"><%= @data.published %></a></p>
<%= for %{"name" => name, "url" => [url | _]} <- @data.attachment do %>
<%= if @data.sensitive do %>
<details class="nsfw">
<summary>sensitive media</summary>
<div>
<%= render("_attachment.html", %{name: name, url: url["href"],
mediaType: fetch_media_type(url)}) %>
</div>
</details>
<% else %>
<%= render("_attachment.html", %{name: name, url: url["href"],
mediaType: fetch_media_type(url)}) %>
<% end %>
<% end %>
</div>
</div>