This commit is contained in:
Roman Chvanikov 2020-12-09 01:18:05 +03:00
parent 8a7b081966
commit dbaa15232b
3 changed files with 11 additions and 6 deletions

View File

@ -26,7 +26,9 @@ defmodule Pleroma.Media do
timestamps()
end
def create_from_object_data(%{"url" => [url]} = data, %{user: user} = _opts) do
def create_from_object_data(%{"url" => [url]} = data, %{user: user} = opts) do
object_id = get_in(opts, [:object, "id"])
%Media{}
|> changeset(%{
href: url["href"],
@ -35,7 +37,8 @@ defmodule Pleroma.Media do
name: data["name"],
blurhash: nil,
meta: %{},
user_id: user.id
user_id: user.id,
object_id: object_id
})
|> Repo.insert()
end

View File

@ -164,7 +164,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
defp maybe_update_media(%Object{data: %{"attachment" => []}}), do: :ok
defp maybe_update_media(%Object{id: id, data: %{"attachment" => attachments}}) do
defp maybe_update_media(%Object{data: %{"id" => id, "attachment" => attachments}}) do
Enum.each(attachments, fn data ->
with %{"id" => media_id} <- data do
media_id

View File

@ -9,6 +9,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
alias Pleroma.Activity
alias Pleroma.EctoType.ActivityPub.ObjectValidators
alias Pleroma.Maps
alias Pleroma.Media
alias Pleroma.Object
alias Pleroma.Object.Containment
alias Pleroma.Repo
@ -272,9 +273,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def fix_attachments(object), do: object
def fix_media(%{"attachment" => [_ | _] = attachments} = object) do
Enum.each(attachments, fn attachment ->
IO.inspect({:fix_media, %{attachment: attachment, object: object}})
end)
Enum.each(
attachments,
&Media.create_from_object_data(&1, %{user: User.get_by_ap_id(object.actor), object: object})
)
object
end