X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Factivity_pub%2Ftransmogrifier.ex;h=0a701334f00d08f7f57e2a8ac963e2e526414c2e;hb=e3508988283a0902a7e330995a0c224811956bce;hp=0bcd1db227ce62fcde9702d10e06fca21ca03485;hpb=2156de2feef373eecdf8e16f21ac7c4b1ee99995;p=akkoma diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex index 0bcd1db22..0a701334f 100644 --- a/lib/pleroma/web/activity_pub/transmogrifier.ex +++ b/lib/pleroma/web/activity_pub/transmogrifier.ex @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2020 Pleroma Authors +# Copyright © 2017-2021 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.ActivityPub.Transmogrifier do @@ -32,18 +32,18 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do """ def fix_object(object, options \\ []) do object - |> strip_internal_fields - |> fix_actor - |> fix_url - |> fix_attachments - |> fix_context + |> strip_internal_fields() + |> fix_actor() + |> fix_url() + |> fix_attachments() + |> fix_context() |> fix_in_reply_to(options) - |> fix_emoji - |> fix_tag - |> set_sensitive - |> fix_content_map - |> fix_addressing - |> fix_summary + |> fix_emoji() + |> fix_tag() + |> set_sensitive() + |> fix_content_map() + |> fix_addressing() + |> fix_summary() |> fix_type(options) end @@ -315,10 +315,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do tags = tag |> Enum.filter(fn data -> data["type"] == "Hashtag" and data["name"] end) - |> Enum.map(fn %{"name" => name} -> - name - |> String.slice(1..-1) - |> String.downcase() + |> Enum.map(fn + %{"name" => "#" <> hashtag} -> String.downcase(hashtag) + %{"name" => hashtag} -> String.downcase(hashtag) end) Map.put(object, "tag", tag ++ tags) @@ -653,7 +652,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do @spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil def get_obj_helper(id, options \\ []) do - case Object.normalize(id, true, options) do + options = Keyword.put(options, :fetch, true) + + case Object.normalize(id, options) do %Object{} = object -> {:ok, object} _ -> nil end @@ -672,7 +673,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do "actor" => attributed_to, "object" => data }) do - {:ok, Object.normalize(activity)} + {:ok, Object.normalize(activity, fetch: false)} else _ -> get_obj_helper(object_id) end @@ -763,7 +764,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do when activity_type in ["Create", "Listen"] do object = object_id - |> Object.normalize() + |> Object.normalize(fetch: false) |> Map.get(:data) |> prepare_object @@ -779,7 +780,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => object_id} = data) do object = object_id - |> Object.normalize() + |> Object.normalize(fetch: false) data = if Visibility.is_private?(object) && object.data["actor"] == ap_id do @@ -919,7 +920,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do defp build_emoji_tag({name, url}) do %{ - "icon" => %{"url" => url, "type" => "Image"}, + "icon" => %{"url" => "#{URI.encode(url)}", "type" => "Image"}, "name" => ":" <> name <> ":", "type" => "Emoji", "updated" => "1970-01-01T00:00:00Z", @@ -1008,7 +1009,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do def upgrade_user_from_ap_id(ap_id) do with %User{local: false} = user <- User.get_cached_by_ap_id(ap_id), - {:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id, force_http: true), + {:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id), {:ok, user} <- update_user(user, data) do TransmogrifierWorker.enqueue("user_upgrade", %{"user_id" => user.id}) {:ok, user}