1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier do
7 A module to handle coding from internal to wire ActivityPub and back.
10 alias Pleroma.EarmarkRenderer
11 alias Pleroma.EctoType.ActivityPub.ObjectValidators
14 alias Pleroma.Object.Containment
17 alias Pleroma.Web.ActivityPub.ActivityPub
18 alias Pleroma.Web.ActivityPub.Builder
19 alias Pleroma.Web.ActivityPub.ObjectValidator
20 alias Pleroma.Web.ActivityPub.Pipeline
21 alias Pleroma.Web.ActivityPub.Utils
22 alias Pleroma.Web.ActivityPub.Visibility
23 alias Pleroma.Web.Federator
24 alias Pleroma.Workers.TransmogrifierWorker
29 require Pleroma.Constants
32 Modifies an incoming AP object (mastodon format) to our internal format.
34 def fix_object(object, options \\ []) do
36 |> strip_internal_fields
41 |> fix_in_reply_to(options)
51 def fix_summary(%{"summary" => nil} = object) do
52 Map.put(object, "summary", "")
55 def fix_summary(%{"summary" => _} = object) do
56 # summary is present, nothing to do
60 def fix_summary(object), do: Map.put(object, "summary", "")
62 def fix_addressing_list(map, field) do
67 Map.put(map, field, Enum.filter(addrs, &is_binary/1))
70 Map.put(map, field, [addrs])
73 Map.put(map, field, [])
77 def fix_explicit_addressing(
78 %{"to" => to, "cc" => cc} = object,
82 explicit_to = Enum.filter(to, fn x -> x in explicit_mentions end)
84 explicit_cc = Enum.filter(to, fn x -> x not in explicit_mentions end)
88 |> Enum.reject(fn x -> String.ends_with?(x, "/followers") and x != follower_collection end)
92 |> Map.put("to", explicit_to)
93 |> Map.put("cc", final_cc)
96 def fix_explicit_addressing(object, _explicit_mentions, _followers_collection), do: object
98 # if directMessage flag is set to true, leave the addressing alone
99 def fix_explicit_addressing(%{"directMessage" => true} = object), do: object
101 def fix_explicit_addressing(object) do
102 explicit_mentions = Utils.determine_explicit_mentions(object)
104 %User{follower_address: follower_collection} =
106 |> Containment.get_actor()
107 |> User.get_cached_by_ap_id()
112 Pleroma.Constants.as_public(),
116 fix_explicit_addressing(object, explicit_mentions, follower_collection)
119 # if as:Public is addressed, then make sure the followers collection is also addressed
120 # so that the activities will be delivered to local users.
121 def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collection) do
122 recipients = to ++ cc
124 if followers_collection not in recipients do
126 Pleroma.Constants.as_public() in cc ->
127 to = to ++ [followers_collection]
128 Map.put(object, "to", to)
130 Pleroma.Constants.as_public() in to ->
131 cc = cc ++ [followers_collection]
132 Map.put(object, "cc", cc)
142 def fix_implicit_addressing(object, _), do: object
144 def fix_addressing(object) do
145 {:ok, %User{} = user} = User.get_or_fetch_by_ap_id(object["actor"])
146 followers_collection = User.ap_followers(user)
149 |> fix_addressing_list("to")
150 |> fix_addressing_list("cc")
151 |> fix_addressing_list("bto")
152 |> fix_addressing_list("bcc")
153 |> fix_explicit_addressing()
154 |> fix_implicit_addressing(followers_collection)
157 def fix_actor(%{"attributedTo" => actor} = object) do
158 actor = Containment.get_actor(%{"actor" => actor})
160 # TODO: Remove actor field for Objects
162 |> Map.put("actor", actor)
163 |> Map.put("attributedTo", actor)
166 def fix_in_reply_to(object, options \\ [])
168 def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object, options)
169 when not is_nil(in_reply_to) do
170 in_reply_to_id = prepare_in_reply_to(in_reply_to)
171 object = Map.put(object, "inReplyToAtomUri", in_reply_to_id)
172 depth = (options[:depth] || 0) + 1
174 if Federator.allowed_thread_distance?(depth) do
175 with {:ok, replied_object} <- get_obj_helper(in_reply_to_id, options),
176 %Activity{} <- Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
178 |> Map.put("inReplyTo", replied_object.data["id"])
179 |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
180 |> Map.put("context", replied_object.data["context"] || object["conversation"])
181 |> Map.drop(["conversation"])
184 Logger.warn("Couldn't fetch #{inspect(in_reply_to_id)}, error: #{inspect(e)}")
192 def fix_in_reply_to(object, _options), do: object
194 defp prepare_in_reply_to(in_reply_to) do
196 is_bitstring(in_reply_to) ->
199 is_map(in_reply_to) && is_bitstring(in_reply_to["id"]) ->
202 is_list(in_reply_to) && is_bitstring(Enum.at(in_reply_to, 0)) ->
203 Enum.at(in_reply_to, 0)
210 def fix_context(object) do
211 context = object["context"] || object["conversation"] || Utils.generate_context_id()
214 |> Map.put("context", context)
215 |> Map.drop(["conversation"])
218 def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachment) do
220 Enum.map(attachment, fn data ->
223 is_list(data["url"]) -> List.first(data["url"])
224 is_map(data["url"]) -> data["url"]
230 is_map(url) && MIME.valid?(url["mediaType"]) -> url["mediaType"]
231 MIME.valid?(data["mediaType"]) -> data["mediaType"]
232 MIME.valid?(data["mimeType"]) -> data["mimeType"]
238 is_map(url) && is_binary(url["href"]) -> url["href"]
239 is_binary(data["url"]) -> data["url"]
240 is_binary(data["href"]) -> data["href"]
248 "type" => Map.get(url || %{}, "type", "Link")
250 |> Maps.put_if_present("mediaType", media_type)
253 "url" => [attachment_url],
254 "type" => data["type"] || "Document"
256 |> Maps.put_if_present("mediaType", media_type)
257 |> Maps.put_if_present("name", data["name"])
264 Map.put(object, "attachment", attachments)
267 def fix_attachments(%{"attachment" => attachment} = object) when is_map(attachment) do
269 |> Map.put("attachment", [attachment])
273 def fix_attachments(object), do: object
275 def fix_url(%{"url" => url} = object) when is_map(url) do
276 Map.put(object, "url", url["href"])
279 def fix_url(%{"type" => object_type, "url" => url} = object)
280 when object_type in ["Video", "Audio"] and is_list(url) do
282 Enum.find(url, fn x ->
283 media_type = x["mediaType"] || x["mimeType"] || ""
285 is_map(x) and String.starts_with?(media_type, ["audio/", "video/"])
289 Enum.find(url, fn x -> is_map(x) and (x["mediaType"] || x["mimeType"]) == "text/html" end)
292 |> Map.put("attachment", [attachment])
293 |> Map.put("url", link_element["href"])
296 def fix_url(%{"type" => object_type, "url" => url} = object)
297 when object_type != "Video" and is_list(url) do
298 first_element = Enum.at(url, 0)
302 is_bitstring(first_element) -> first_element
303 is_map(first_element) -> first_element["href"] || ""
307 Map.put(object, "url", url_string)
310 def fix_url(object), do: object
312 def fix_emoji(%{"tag" => tags} = object) when is_list(tags) do
315 |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)
316 |> Enum.reduce(%{}, fn data, mapping ->
317 name = String.trim(data["name"], ":")
319 Map.put(mapping, name, data["icon"]["url"])
322 # we merge mastodon and pleroma emoji into a single mapping, to allow for both wire formats
323 emoji = Map.merge(object["emoji"] || %{}, emoji)
325 Map.put(object, "emoji", emoji)
328 def fix_emoji(%{"tag" => %{"type" => "Emoji"} = tag} = object) do
329 name = String.trim(tag["name"], ":")
330 emoji = %{name => tag["icon"]["url"]}
332 Map.put(object, "emoji", emoji)
335 def fix_emoji(object), do: object
337 def fix_tag(%{"tag" => tag} = object) when is_list(tag) do
340 |> Enum.filter(fn data -> data["type"] == "Hashtag" and data["name"] end)
341 |> Enum.map(fn data -> String.slice(data["name"], 1..-1) end)
343 Map.put(object, "tag", tag ++ tags)
346 def fix_tag(%{"tag" => %{"type" => "Hashtag", "name" => hashtag} = tag} = object) do
347 combined = [tag, String.slice(hashtag, 1..-1)]
349 Map.put(object, "tag", combined)
352 def fix_tag(%{"tag" => %{} = tag} = object), do: Map.put(object, "tag", [tag])
354 def fix_tag(object), do: object
356 # content map usually only has one language so this will do for now.
357 def fix_content_map(%{"contentMap" => content_map} = object) do
358 content_groups = Map.to_list(content_map)
359 {_, content} = Enum.at(content_groups, 0)
361 Map.put(object, "content", content)
364 def fix_content_map(object), do: object
366 def fix_type(object, options \\ [])
368 def fix_type(%{"inReplyTo" => reply_id, "name" => _} = object, options)
369 when is_binary(reply_id) do
370 with true <- Federator.allowed_thread_distance?(options[:depth]),
371 {:ok, %{data: %{"type" => "Question"} = _} = _} <- get_obj_helper(reply_id, options) do
372 Map.put(object, "type", "Answer")
378 def fix_type(object, _), do: object
380 defp fix_content(%{"mediaType" => "text/markdown", "content" => content} = object)
381 when is_binary(content) do
384 |> Earmark.as_html!(%Earmark.Options{renderer: EarmarkRenderer})
385 |> Pleroma.HTML.filter_tags()
387 Map.merge(object, %{"content" => html_content, "mediaType" => "text/html"})
390 defp fix_content(object), do: object
392 # Reduce the object list to find the reported user.
393 defp get_reported(objects) do
394 Enum.reduce_while(objects, nil, fn ap_id, _ ->
395 with %User{} = user <- User.get_cached_by_ap_id(ap_id) do
403 # Compatibility wrapper for Mastodon votes
404 defp handle_create(%{"object" => %{"type" => "Answer"}} = data, _user) do
405 handle_incoming(data)
408 defp handle_create(%{"object" => object} = data, user) do
413 context: object["context"],
415 published: data["published"],
423 |> ActivityPub.create()
426 def handle_incoming(data, options \\ [])
428 # Flag objects are placed ahead of the ID check because Mastodon 2.8 and earlier send them
430 def handle_incoming(%{"type" => "Flag", "object" => objects, "actor" => actor} = data, _options) do
431 with context <- data["context"] || Utils.generate_context_id(),
432 content <- data["content"] || "",
433 %User{} = actor <- User.get_cached_by_ap_id(actor),
434 # Reduce the object list to find the reported user.
435 %User{} = account <- get_reported(objects),
436 # Remove the reported user from the object list.
437 statuses <- Enum.filter(objects, fn ap_id -> ap_id != account.ap_id end) do
444 additional: %{"cc" => [account.ap_id]}
446 |> ActivityPub.flag()
450 # disallow objects with bogus IDs
451 def handle_incoming(%{"id" => nil}, _options), do: :error
452 def handle_incoming(%{"id" => ""}, _options), do: :error
453 # length of https:// = 8, should validate better, but good enough for now.
454 def handle_incoming(%{"id" => id}, _options) when is_binary(id) and byte_size(id) < 8,
457 # TODO: validate those with a Ecto scheme
461 %{"type" => "Create", "object" => %{"type" => objtype} = object} = data,
464 when objtype in ["Article", "Event", "Note", "Video", "Page", "Audio"] do
465 actor = Containment.get_actor(data)
467 with nil <- Activity.get_create_by_object_ap_id(object["id"]),
468 {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(actor) do
471 |> Map.put("object", fix_object(object, options))
472 |> Map.put("actor", actor)
475 with {:ok, created_activity} <- handle_create(data, user) do
476 reply_depth = (options[:depth] || 0) + 1
478 if Federator.allowed_thread_distance?(reply_depth) do
479 for reply_id <- replies(object) do
480 Pleroma.Workers.RemoteFetcherWorker.enqueue("fetch_remote", %{
482 "depth" => reply_depth
487 {:ok, created_activity}
490 %Activity{} = activity -> {:ok, activity}
496 %{"type" => "Listen", "object" => %{"type" => "Audio"} = object} = data,
499 actor = Containment.get_actor(data)
502 Map.put(data, "actor", actor)
505 with {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(data["actor"]) do
506 reply_depth = (options[:depth] || 0) + 1
507 options = Keyword.put(options, :depth, reply_depth)
508 object = fix_object(object, options)
516 published: data["published"],
517 additional: Map.take(data, ["cc", "id"])
520 ActivityPub.listen(params)
526 @misskey_reactions %{
540 @doc "Rewrite misskey likes into EmojiReacts"
544 "_misskey_reaction" => reaction
549 |> Map.put("type", "EmojiReact")
550 |> Map.put("content", @misskey_reactions[reaction] || reaction)
551 |> handle_incoming(options)
555 %{"type" => "Create", "object" => %{"type" => objtype}} = data,
558 when objtype in ["Question", "Answer", "ChatMessage"] do
559 with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
560 {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
565 def handle_incoming(%{"type" => type} = data, _options)
566 when type in ~w{Like EmojiReact Announce} do
567 with :ok <- ObjectValidator.fetch_actor_and_object(data),
568 {:ok, activity, _meta} <-
569 Pipeline.common_pipeline(data, local: false) do
577 %{"type" => type} = data,
580 when type in ~w{Update Block Follow Accept Reject} do
581 with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
582 {:ok, activity, _} <-
583 Pipeline.common_pipeline(data, local: false) do
589 %{"type" => "Delete"} = data,
592 with {:ok, activity, _} <-
593 Pipeline.common_pipeline(data, local: false) do
596 {:error, {:validate_object, _}} = e ->
597 # Check if we have a create activity for this
598 with {:ok, object_id} <- ObjectValidators.ObjectID.cast(data["object"]),
599 %Activity{data: %{"actor" => actor}} <-
600 Activity.create_by_object_ap_id(object_id) |> Repo.one(),
601 # We have one, insert a tombstone and retry
602 {:ok, tombstone_data, _} <- Builder.tombstone(actor, object_id),
603 {:ok, _tombstone} <- Object.create(tombstone_data) do
604 handle_incoming(data)
614 "object" => %{"type" => "Follow", "object" => followed},
620 with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
621 {:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
622 {:ok, activity} <- ActivityPub.unfollow(follower, followed, id, false) do
623 User.unfollow(follower, followed)
633 "object" => %{"type" => type}
637 when type in ["Like", "EmojiReact", "Announce", "Block"] do
638 with {:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
643 # For Undos that don't have the complete object attached, try to find it in our database.
651 when is_binary(object) do
652 with %Activity{data: data} <- Activity.get_by_ap_id(object) do
654 |> Map.put("object", data)
655 |> handle_incoming(options)
664 "actor" => origin_actor,
665 "object" => origin_actor,
666 "target" => target_actor
670 with %User{} = origin_user <- User.get_cached_by_ap_id(origin_actor),
671 {:ok, %User{} = target_user} <- User.get_or_fetch_by_ap_id(target_actor),
672 true <- origin_actor in target_user.also_known_as do
673 ActivityPub.move(origin_user, target_user, false)
679 def handle_incoming(_, _), do: :error
681 @spec get_obj_helper(String.t(), Keyword.t()) :: {:ok, Object.t()} | nil
682 def get_obj_helper(id, options \\ []) do
683 case Object.normalize(id, true, options) do
684 %Object{} = object -> {:ok, object}
689 @spec get_embedded_obj_helper(String.t() | Object.t(), User.t()) :: {:ok, Object.t()} | nil
690 def get_embedded_obj_helper(%{"attributedTo" => attributed_to, "id" => object_id} = data, %User{
693 when attributed_to == ap_id do
694 with {:ok, activity} <-
699 "actor" => attributed_to,
702 {:ok, Object.normalize(activity)}
704 _ -> get_obj_helper(object_id)
708 def get_embedded_obj_helper(object_id, _) do
709 get_obj_helper(object_id)
712 def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do
713 with false <- String.starts_with?(in_reply_to, "http"),
714 {:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do
715 Map.put(object, "inReplyTo", replied_to_object["external_url"] || in_reply_to)
721 def set_reply_to_uri(obj), do: obj
724 Serialized Mastodon-compatible `replies` collection containing _self-replies_.
725 Based on Mastodon's ActivityPub::NoteSerializer#replies.
727 def set_replies(obj_data) do
729 with limit when limit > 0 <-
730 Pleroma.Config.get([:activitypub, :note_replies_output_limit], 0),
731 %Object{} = object <- Object.get_cached_by_ap_id(obj_data["id"]) do
733 |> Object.self_replies()
734 |> select([o], fragment("?->>'id'", o.data))
741 set_replies(obj_data, replies_uris)
744 defp set_replies(obj, []) do
748 defp set_replies(obj, replies_uris) do
749 replies_collection = %{
750 "type" => "Collection",
751 "items" => replies_uris
754 Map.merge(obj, %{"replies" => replies_collection})
757 def replies(%{"replies" => %{"first" => %{"items" => items}}}) when not is_nil(items) do
761 def replies(%{"replies" => %{"items" => items}}) when not is_nil(items) do
765 def replies(_), do: []
767 # Prepares the object of an outgoing create activity.
768 def prepare_object(object) do
775 |> prepare_attachments
779 |> strip_internal_fields
780 |> strip_internal_tags
786 # internal -> Mastodon
789 def prepare_outgoing(%{"type" => activity_type, "object" => object_id} = data)
790 when activity_type in ["Create", "Listen"] do
793 |> Object.normalize()
799 |> Map.put("object", object)
800 |> Map.merge(Utils.make_json_ld_header())
806 def prepare_outgoing(%{"type" => "Announce", "actor" => ap_id, "object" => object_id} = data) do
809 |> Object.normalize()
812 if Visibility.is_private?(object) && object.data["actor"] == ap_id do
813 data |> Map.put("object", object |> Map.get(:data) |> prepare_object)
815 data |> maybe_fix_object_url
820 |> strip_internal_fields
821 |> Map.merge(Utils.make_json_ld_header())
827 # Mastodon Accept/Reject requires a non-normalized object containing the actor URIs,
828 # because of course it does.
829 def prepare_outgoing(%{"type" => "Accept"} = data) do
830 with follow_activity <- Activity.normalize(data["object"]) do
832 "actor" => follow_activity.actor,
833 "object" => follow_activity.data["object"],
834 "id" => follow_activity.data["id"],
840 |> Map.put("object", object)
841 |> Map.merge(Utils.make_json_ld_header())
847 def prepare_outgoing(%{"type" => "Reject"} = data) do
848 with follow_activity <- Activity.normalize(data["object"]) do
850 "actor" => follow_activity.actor,
851 "object" => follow_activity.data["object"],
852 "id" => follow_activity.data["id"],
858 |> Map.put("object", object)
859 |> Map.merge(Utils.make_json_ld_header())
865 def prepare_outgoing(%{"type" => _type} = data) do
868 |> strip_internal_fields
869 |> maybe_fix_object_url
870 |> Map.merge(Utils.make_json_ld_header())
875 def maybe_fix_object_url(%{"object" => object} = data) when is_binary(object) do
876 with false <- String.starts_with?(object, "http"),
877 {:fetch, {:ok, relative_object}} <- {:fetch, get_obj_helper(object)},
878 %{data: %{"external_url" => external_url}} when not is_nil(external_url) <-
880 Map.put(data, "object", external_url)
883 Logger.error("Couldn't fetch #{object} #{inspect(e)}")
891 def maybe_fix_object_url(data), do: data
893 def add_hashtags(object) do
895 (object["tag"] || [])
897 # Expand internal representation tags into AS2 tags.
898 tag when is_binary(tag) ->
900 "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
905 # Do not process tags which are already AS2 tag objects.
906 tag when is_map(tag) ->
910 Map.put(object, "tag", tags)
913 # TODO These should be added on our side on insertion, it doesn't make much
914 # sense to regenerate these all the time
915 def add_mention_tags(object) do
916 to = object["to"] || []
917 cc = object["cc"] || []
918 mentioned = User.get_users_from_set(to ++ cc, local_only: false)
920 mentions = Enum.map(mentioned, &build_mention_tag/1)
922 tags = object["tag"] || []
923 Map.put(object, "tag", tags ++ mentions)
926 defp build_mention_tag(%{ap_id: ap_id, nickname: nickname} = _) do
927 %{"type" => "Mention", "href" => ap_id, "name" => "@#{nickname}"}
930 def take_emoji_tags(%User{emoji: emoji}) do
933 |> Enum.map(&build_emoji_tag/1)
936 # TODO: we should probably send mtime instead of unix epoch time for updated
937 def add_emoji_tags(%{"emoji" => emoji} = object) do
938 tags = object["tag"] || []
940 out = Enum.map(emoji, &build_emoji_tag/1)
942 Map.put(object, "tag", tags ++ out)
945 def add_emoji_tags(object), do: object
947 defp build_emoji_tag({name, url}) do
949 "icon" => %{"url" => url, "type" => "Image"},
950 "name" => ":" <> name <> ":",
952 "updated" => "1970-01-01T00:00:00Z",
957 def set_conversation(object) do
958 Map.put(object, "conversation", object["context"])
961 def set_sensitive(%{"sensitive" => true} = object) do
965 def set_sensitive(object) do
966 tags = object["tag"] || []
967 Map.put(object, "sensitive", "nsfw" in tags)
970 def set_type(%{"type" => "Answer"} = object) do
971 Map.put(object, "type", "Note")
974 def set_type(object), do: object
976 def add_attributed_to(object) do
977 attributed_to = object["attributedTo"] || object["actor"]
978 Map.put(object, "attributedTo", attributed_to)
982 def prepare_attachments(%{"type" => "ChatMessage"} = object), do: object
984 def prepare_attachments(object) do
987 |> Map.get("attachment", [])
988 |> Enum.map(fn data ->
989 [%{"mediaType" => media_type, "href" => href} | _] = data["url"]
993 "mediaType" => media_type,
994 "name" => data["name"],
999 Map.put(object, "attachment", attachments)
1002 def strip_internal_fields(object) do
1003 Map.drop(object, Pleroma.Constants.object_internal_fields())
1006 defp strip_internal_tags(%{"tag" => tags} = object) do
1007 tags = Enum.filter(tags, fn x -> is_map(x) end)
1009 Map.put(object, "tag", tags)
1012 defp strip_internal_tags(object), do: object
1014 def perform(:user_upgrade, user) do
1015 # we pass a fake user so that the followers collection is stripped away
1016 old_follower_address = User.ap_followers(%User{nickname: user.nickname})
1020 where: ^old_follower_address in a.recipients,
1025 "array_replace(?,?,?)",
1027 ^old_follower_address,
1028 ^user.follower_address
1033 |> Repo.update_all([])
1036 def upgrade_user_from_ap_id(ap_id) do
1037 with %User{local: false} = user <- User.get_cached_by_ap_id(ap_id),
1038 {:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id),
1039 {:ok, user} <- update_user(user, data) do
1040 TransmogrifierWorker.enqueue("user_upgrade", %{"user_id" => user.id})
1043 %User{} = user -> {:ok, user}
1048 defp update_user(user, data) do
1050 |> User.remote_user_changeset(data)
1051 |> User.update_and_set_cache()
1054 def maybe_fix_user_url(%{"url" => url} = data) when is_map(url) do
1055 Map.put(data, "url", url["href"])
1058 def maybe_fix_user_url(data), do: data
1060 def maybe_fix_user_object(data), do: maybe_fix_user_url(data)