Merge branch 'features/validators-video' into 'develop'
authorrinpatch <rinpatch@sdf.org>
Wed, 16 Sep 2020 13:36:27 +0000 (13:36 +0000)
committerrinpatch <rinpatch@sdf.org>
Wed, 16 Sep 2020 13:36:27 +0000 (13:36 +0000)
Pipeline Ingestion: Video and Article

See merge request pleroma/pleroma!2908

1  2 
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/transmogrifier.ex

index 5aac3f53b020c63ef76154854bbf33fa60c9229c,3ab0457375a333a554ebe644abf458372ec7c872..f5cbb3e01922ad91568fd940a220dc0112ad1525
@@@ -84,7 -84,7 +84,7 @@@ defmodule Pleroma.Web.ActivityPub.Activ
  
    defp increase_replies_count_if_reply(_create_data), do: :noop
  
-   @object_types ~w[ChatMessage Question Answer Audio Event]
+   @object_types ~w[ChatMessage Question Answer Audio Video Event Article]
    @spec persist(map(), keyword()) :: {:ok, Activity.t() | Object.t()}
    def persist(%{"type" => type} = object, meta) when type in @object_types do
      with {:ok, object} <- Object.create(object) do
    end
  
    defp restrict_replies(query, %{
 -         reply_filtering_user: user,
 +         reply_filtering_user: %User{} = user,
           reply_visibility: "self"
         }) do
      from(
    end
  
    defp restrict_replies(query, %{
 -         reply_filtering_user: user,
 +         reply_filtering_user: %User{} = user,
           reply_visibility: "following"
         }) do
      from(
index 8fe430644de3c23eff23492e73d97fcf8a9f0d60,80f529704e31ea888d10db8af1e16d38225ac85e..fcca014f01d548f0302e2f0f08bcb2d938219cce
@@@ -7,7 -7,6 +7,6 @@@ defmodule Pleroma.Web.ActivityPub.Trans
    A module to handle coding from internal to wire ActivityPub and back.
    """
    alias Pleroma.Activity
-   alias Pleroma.EarmarkRenderer
    alias Pleroma.EctoType.ActivityPub.ObjectValidators
    alias Pleroma.Maps
    alias Pleroma.Object
@@@ -45,7 -44,6 +44,6 @@@
      |> fix_addressing
      |> fix_summary
      |> fix_type(options)
-     |> fix_content
    end
  
    def fix_summary(%{"summary" => nil} = object) do
      Map.put(object, "url", url["href"])
    end
  
-   def fix_url(%{"type" => "Video", "url" => url} = object) when is_list(url) do
-     attachment =
-       Enum.find(url, fn x ->
-         media_type = x["mediaType"] || x["mimeType"] || ""
-         is_map(x) and String.starts_with?(media_type, "video/")
-       end)
-     link_element =
-       Enum.find(url, fn x -> is_map(x) and (x["mediaType"] || x["mimeType"]) == "text/html" end)
-     object
-     |> Map.put("attachment", [attachment])
-     |> Map.put("url", link_element["href"])
-   end
-   def fix_url(%{"type" => object_type, "url" => url} = object)
-       when object_type != "Video" and is_list(url) do
+   def fix_url(%{"url" => url} = object) when is_list(url) do
      first_element = Enum.at(url, 0)
  
      url_string =
    def fix_emoji(%{"tag" => tags} = object) when is_list(tags) do
      emoji =
        tags
 -      |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)
 +      |> Enum.filter(fn data -> is_map(data) and data["type"] == "Emoji" and data["icon"] end)
        |> Enum.reduce(%{}, fn data, mapping ->
          name = String.trim(data["name"], ":")
  
  
    def fix_type(object, _), do: object
  
-   defp fix_content(%{"mediaType" => "text/markdown", "content" => content} = object)
-        when is_binary(content) do
-     html_content =
-       content
-       |> Earmark.as_html!(%Earmark.Options{renderer: EarmarkRenderer})
-       |> Pleroma.HTML.filter_tags()
-     Map.merge(object, %{"content" => html_content, "mediaType" => "text/html"})
-   end
-   defp fix_content(object), do: object
    # Reduce the object list to find the reported user.
    defp get_reported(objects) do
      Enum.reduce_while(objects, nil, fn ap_id, _ ->
          %{"type" => "Create", "object" => %{"type" => objtype} = object} = data,
          options
        )
-       when objtype in ~w{Article Note Video Page} do
+       when objtype in ~w{Note Page} do
      actor = Containment.get_actor(data)
  
      with nil <- Activity.get_create_by_object_ap_id(object["id"]),
          %{"type" => "Create", "object" => %{"type" => objtype}} = data,
          _options
        )
-       when objtype in ~w{Question Answer ChatMessage Audio Event} do
+       when objtype in ~w{Question Answer ChatMessage Audio Video Event Article} do
+     data = Map.put(data, "object", strip_internal_fields(data["object"]))
      with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
           {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
        {:ok, activity}