1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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.
11 alias Pleroma.Object.Containment
14 alias Pleroma.Web.ActivityPub.ActivityPub
15 alias Pleroma.Web.ActivityPub.Utils
16 alias Pleroma.Web.ActivityPub.Visibility
17 alias Pleroma.Web.Federator
18 alias Pleroma.Workers.Transmogrifier, as: TransmogrifierWorker
23 require Pleroma.Constants
25 defdelegate worker_args(queue), to: Pleroma.Workers.Helper
28 Modifies an incoming AP object (mastodon format) to our internal format.
30 def fix_object(object, options \\ []) do
36 |> fix_in_reply_to(options)
46 def fix_summary(%{"summary" => nil} = object) do
48 |> Map.put("summary", "")
51 def fix_summary(%{"summary" => _} = object) do
52 # summary is present, nothing to do
56 def fix_summary(object) do
58 |> Map.put("summary", "")
61 def fix_addressing_list(map, field) do
63 is_binary(map[field]) ->
64 Map.put(map, field, [map[field]])
67 Map.put(map, field, [])
74 def fix_explicit_addressing(
75 %{"to" => to, "cc" => cc} = object,
81 |> Enum.filter(fn x -> x in explicit_mentions end)
85 |> Enum.filter(fn x -> x not in explicit_mentions end)
89 |> Enum.reject(fn x -> String.ends_with?(x, "/followers") and x != follower_collection end)
93 |> Map.put("to", explicit_to)
94 |> Map.put("cc", final_cc)
97 def fix_explicit_addressing(object, _explicit_mentions, _followers_collection), do: object
99 # if directMessage flag is set to true, leave the addressing alone
100 def fix_explicit_addressing(%{"directMessage" => true} = object), do: object
102 def fix_explicit_addressing(object) do
105 |> Utils.determine_explicit_mentions()
107 follower_collection = User.get_cached_by_ap_id(Containment.get_actor(object)).follower_address
109 explicit_mentions = explicit_mentions ++ [Pleroma.Constants.as_public(), follower_collection]
111 fix_explicit_addressing(object, explicit_mentions, follower_collection)
114 # if as:Public is addressed, then make sure the followers collection is also addressed
115 # so that the activities will be delivered to local users.
116 def fix_implicit_addressing(%{"to" => to, "cc" => cc} = object, followers_collection) do
117 recipients = to ++ cc
119 if followers_collection not in recipients do
121 Pleroma.Constants.as_public() in cc ->
122 to = to ++ [followers_collection]
123 Map.put(object, "to", to)
125 Pleroma.Constants.as_public() in to ->
126 cc = cc ++ [followers_collection]
127 Map.put(object, "cc", cc)
137 def fix_implicit_addressing(object, _), do: object
139 def fix_addressing(object) do
140 {:ok, %User{} = user} = User.get_or_fetch_by_ap_id(object["actor"])
141 followers_collection = User.ap_followers(user)
144 |> fix_addressing_list("to")
145 |> fix_addressing_list("cc")
146 |> fix_addressing_list("bto")
147 |> fix_addressing_list("bcc")
148 |> fix_explicit_addressing()
149 |> fix_implicit_addressing(followers_collection)
152 def fix_actor(%{"attributedTo" => actor} = object) do
154 |> Map.put("actor", Containment.get_actor(%{"actor" => actor}))
157 # Check for standardisation
158 # This is what Peertube does
159 # curl -H 'Accept: application/activity+json' $likes | jq .totalItems
160 # Prismo returns only an integer (count) as "likes"
161 def fix_likes(%{"likes" => likes} = object) when not is_map(likes) do
163 |> Map.put("likes", [])
164 |> Map.put("like_count", 0)
167 def fix_likes(object) do
171 def fix_in_reply_to(object, options \\ [])
173 def fix_in_reply_to(%{"inReplyTo" => in_reply_to} = object, options)
174 when not is_nil(in_reply_to) do
177 is_bitstring(in_reply_to) ->
180 is_map(in_reply_to) && is_bitstring(in_reply_to["id"]) ->
183 is_list(in_reply_to) && is_bitstring(Enum.at(in_reply_to, 0)) ->
184 Enum.at(in_reply_to, 0)
186 # Maybe I should output an error too?
191 object = Map.put(object, "inReplyToAtomUri", in_reply_to_id)
193 if Federator.allowed_incoming_reply_depth?(options[:depth]) do
194 case get_obj_helper(in_reply_to_id, options) do
195 {:ok, replied_object} ->
196 with %Activity{} = _activity <-
197 Activity.get_create_by_object_ap_id(replied_object.data["id"]) do
199 |> Map.put("inReplyTo", replied_object.data["id"])
200 |> Map.put("inReplyToAtomUri", object["inReplyToAtomUri"] || in_reply_to_id)
201 |> Map.put("conversation", replied_object.data["context"] || object["conversation"])
202 |> Map.put("context", replied_object.data["context"] || object["conversation"])
205 Logger.error("Couldn't fetch \"#{inspect(in_reply_to_id)}\", error: #{inspect(e)}")
210 Logger.error("Couldn't fetch \"#{inspect(in_reply_to_id)}\", error: #{inspect(e)}")
218 def fix_in_reply_to(object, _options), do: object
220 def fix_context(object) do
221 context = object["context"] || object["conversation"] || Utils.generate_context_id()
224 |> Map.put("context", context)
225 |> Map.put("conversation", context)
228 def fix_attachments(%{"attachment" => attachment} = object) when is_list(attachment) do
231 |> Enum.map(fn data ->
232 media_type = data["mediaType"] || data["mimeType"]
233 href = data["url"] || data["href"]
235 url = [%{"type" => "Link", "mediaType" => media_type, "href" => href}]
238 |> Map.put("mediaType", media_type)
239 |> Map.put("url", url)
243 |> Map.put("attachment", attachments)
246 def fix_attachments(%{"attachment" => attachment} = object) when is_map(attachment) do
247 Map.put(object, "attachment", [attachment])
251 def fix_attachments(object), do: object
253 def fix_url(%{"url" => url} = object) when is_map(url) do
255 |> Map.put("url", url["href"])
258 def fix_url(%{"type" => "Video", "url" => url} = object) when is_list(url) do
259 first_element = Enum.at(url, 0)
263 |> Enum.filter(fn x -> is_map(x) end)
264 |> Enum.filter(fn x -> x["mimeType"] == "text/html" end)
268 |> Map.put("attachment", [first_element])
269 |> Map.put("url", link_element["href"])
272 def fix_url(%{"type" => object_type, "url" => url} = object)
273 when object_type != "Video" and is_list(url) do
274 first_element = Enum.at(url, 0)
278 is_bitstring(first_element) -> first_element
279 is_map(first_element) -> first_element["href"] || ""
284 |> Map.put("url", url_string)
287 def fix_url(object), do: object
289 def fix_emoji(%{"tag" => tags} = object) when is_list(tags) do
290 emoji = tags |> Enum.filter(fn data -> data["type"] == "Emoji" and data["icon"] end)
294 |> Enum.reduce(%{}, fn data, mapping ->
295 name = String.trim(data["name"], ":")
297 mapping |> Map.put(name, data["icon"]["url"])
300 # we merge mastodon and pleroma emoji into a single mapping, to allow for both wire formats
301 emoji = Map.merge(object["emoji"] || %{}, emoji)
304 |> Map.put("emoji", emoji)
307 def fix_emoji(%{"tag" => %{"type" => "Emoji"} = tag} = object) do
308 name = String.trim(tag["name"], ":")
309 emoji = %{name => tag["icon"]["url"]}
312 |> Map.put("emoji", emoji)
315 def fix_emoji(object), do: object
317 def fix_tag(%{"tag" => tag} = object) when is_list(tag) do
320 |> Enum.filter(fn data -> data["type"] == "Hashtag" and data["name"] end)
321 |> Enum.map(fn data -> String.slice(data["name"], 1..-1) end)
323 combined = tag ++ tags
326 |> Map.put("tag", combined)
329 def fix_tag(%{"tag" => %{"type" => "Hashtag", "name" => hashtag} = tag} = object) do
330 combined = [tag, String.slice(hashtag, 1..-1)]
333 |> Map.put("tag", combined)
336 def fix_tag(%{"tag" => %{} = tag} = object), do: Map.put(object, "tag", [tag])
338 def fix_tag(object), do: object
340 # content map usually only has one language so this will do for now.
341 def fix_content_map(%{"contentMap" => content_map} = object) do
342 content_groups = Map.to_list(content_map)
343 {_, content} = Enum.at(content_groups, 0)
346 |> Map.put("content", content)
349 def fix_content_map(object), do: object
351 def fix_type(object, options \\ [])
353 def fix_type(%{"inReplyTo" => reply_id} = object, options) when is_binary(reply_id) do
355 if Federator.allowed_incoming_reply_depth?(options[:depth]) do
356 Object.normalize(reply_id, true)
359 if reply && (reply.data["type"] == "Question" and object["name"]) do
360 Map.put(object, "type", "Answer")
366 def fix_type(object, _), do: object
368 defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
369 with true <- id =~ "follows",
370 %User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
371 %Activity{} = activity <- Utils.fetch_latest_follow(follower, followed) do
378 defp mastodon_follow_hack(_, _), do: {:error, nil}
380 defp get_follow_activity(follow_object, followed) do
381 with object_id when not is_nil(object_id) <- Utils.get_ap_id(follow_object),
382 {_, %Activity{} = activity} <- {:activity, Activity.get_by_ap_id(object_id)} do
385 # Can't find the activity. This might a Mastodon 2.3 "Accept"
387 mastodon_follow_hack(follow_object, followed)
394 def handle_incoming(data, options \\ [])
396 # Flag objects are placed ahead of the ID check because Mastodon 2.8 and earlier send them
398 def handle_incoming(%{"type" => "Flag", "object" => objects, "actor" => actor} = data, _options) do
399 with context <- data["context"] || Utils.generate_context_id(),
400 content <- data["content"] || "",
401 %User{} = actor <- User.get_cached_by_ap_id(actor),
403 # Reduce the object list to find the reported user.
405 Enum.reduce_while(objects, nil, fn ap_id, _ ->
406 with %User{} = user <- User.get_cached_by_ap_id(ap_id) do
413 # Remove the reported user from the object list.
414 statuses <- Enum.filter(objects, fn ap_id -> ap_id != account.ap_id end) do
422 "cc" => [account.ap_id]
426 ActivityPub.flag(params)
430 # disallow objects with bogus IDs
431 def handle_incoming(%{"id" => nil}, _options), do: :error
432 def handle_incoming(%{"id" => ""}, _options), do: :error
433 # length of https:// = 8, should validate better, but good enough for now.
434 def handle_incoming(%{"id" => id}, _options) when not (is_binary(id) and length(id) > 8),
437 # TODO: validate those with a Ecto scheme
441 %{"type" => "Create", "object" => %{"type" => objtype} = object} = data,
444 when objtype in ["Article", "Note", "Video", "Page", "Question", "Answer"] do
445 actor = Containment.get_actor(data)
448 Map.put(data, "actor", actor)
451 with nil <- Activity.get_create_by_object_ap_id(object["id"]),
452 {:ok, %User{} = user} <- User.get_or_fetch_by_ap_id(data["actor"]) do
453 options = Keyword.put(options, :depth, (options[:depth] || 0) + 1)
454 object = fix_object(data["object"], options)
460 context: object["conversation"],
462 published: data["published"],
471 ActivityPub.create(params)
473 %Activity{} = activity -> {:ok, activity}
479 %{"type" => "Follow", "object" => followed, "actor" => follower, "id" => id} = data,
482 with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
483 {:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
484 {:ok, activity} <- ActivityPub.follow(follower, followed, id, false) do
485 with deny_follow_blocked <- Pleroma.Config.get([:user, :deny_follow_blocked]),
486 {_, false} <- {:user_blocked, User.blocks?(followed, follower) && deny_follow_blocked},
487 {_, false} <- {:user_locked, User.locked?(followed)},
488 {_, {:ok, follower}} <- {:follow, User.follow(follower, followed)},
490 {:follow_state_update, Utils.update_follow_state_for_all(activity, "accept")} do
491 ActivityPub.accept(%{
492 to: [follower.ap_id],
498 {:user_blocked, true} ->
499 {:ok, _} = Utils.update_follow_state_for_all(activity, "reject")
501 ActivityPub.reject(%{
502 to: [follower.ap_id],
508 {:follow, {:error, _}} ->
509 {:ok, _} = Utils.update_follow_state_for_all(activity, "reject")
511 ActivityPub.reject(%{
512 to: [follower.ap_id],
518 {:user_locked, true} ->
530 %{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data,
533 with actor <- Containment.get_actor(data),
534 {:ok, %User{} = followed} <- User.get_or_fetch_by_ap_id(actor),
535 {:ok, follow_activity} <- get_follow_activity(follow_object, followed),
536 {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "accept"),
537 %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
538 {:ok, _follower} = User.follow(follower, followed) do
539 ActivityPub.accept(%{
540 to: follow_activity.data["to"],
543 object: follow_activity.data["id"],
552 %{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data,
555 with actor <- Containment.get_actor(data),
556 {:ok, %User{} = followed} <- User.get_or_fetch_by_ap_id(actor),
557 {:ok, follow_activity} <- get_follow_activity(follow_object, followed),
558 {:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "reject"),
559 %User{local: true} = follower <- User.get_cached_by_ap_id(follow_activity.data["actor"]),
561 ActivityPub.reject(%{
562 to: follow_activity.data["to"],
565 object: follow_activity.data["id"],
568 User.unfollow(follower, followed)
577 %{"type" => "Like", "object" => object_id, "actor" => _actor, "id" => id} = data,
580 with actor <- Containment.get_actor(data),
581 {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
582 {:ok, object} <- get_obj_helper(object_id),
583 {:ok, activity, _object} <- ActivityPub.like(actor, object, id, false) do
591 %{"type" => "Announce", "object" => object_id, "actor" => _actor, "id" => id} = data,
594 with actor <- Containment.get_actor(data),
595 {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
596 {:ok, object} <- get_obj_helper(object_id),
597 public <- Visibility.is_public?(data),
598 {:ok, activity, _object} <- ActivityPub.announce(actor, object, id, false, public) do
606 %{"type" => "Update", "object" => %{"type" => object_type} = object, "actor" => actor_id} =
610 when object_type in ["Person", "Application", "Service", "Organization"] do
611 with %User{ap_id: ^actor_id} = actor <- User.get_cached_by_ap_id(object["id"]) do
612 {:ok, new_user_data} = ActivityPub.user_data_from_user_object(object)
614 banner = new_user_data[:info][:banner]
615 locked = new_user_data[:info][:locked] || false
619 |> Map.take([:name, :bio, :avatar])
620 |> Map.put(:info, %{banner: banner, locked: locked})
623 |> User.upgrade_changeset(update_data)
624 |> User.update_and_set_cache()
626 ActivityPub.update(%{
628 to: data["to"] || [],
629 cc: data["cc"] || [],
640 # TODO: We presently assume that any actor on the same origin domain as the object being
641 # deleted has the rights to delete that object. A better way to validate whether or not
642 # the object should be deleted is to refetch the object URI, which should return either
643 # an error or a tombstone. This would allow us to verify that a deletion actually took
646 %{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => _id} = data,
649 object_id = Utils.get_ap_id(object_id)
651 with actor <- Containment.get_actor(data),
652 {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
653 {:ok, object} <- get_obj_helper(object_id),
654 :ok <- Containment.contain_origin(actor.ap_id, object.data),
655 {:ok, activity} <- ActivityPub.delete(object, false) do
659 case User.get_cached_by_ap_id(object_id) do
660 %User{ap_id: ^actor} = user ->
675 "object" => %{"type" => "Announce", "object" => object_id},
681 with actor <- Containment.get_actor(data),
682 {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
683 {:ok, object} <- get_obj_helper(object_id),
684 {:ok, activity, _} <- ActivityPub.unannounce(actor, object, id, false) do
694 "object" => %{"type" => "Follow", "object" => followed},
700 with %User{local: true} = followed <- User.get_cached_by_ap_id(followed),
701 {:ok, %User{} = follower} <- User.get_or_fetch_by_ap_id(follower),
702 {:ok, activity} <- ActivityPub.unfollow(follower, followed, id, false) do
703 User.unfollow(follower, followed)
713 "object" => %{"type" => "Block", "object" => blocked},
719 with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
720 %User{local: true} = blocked <- User.get_cached_by_ap_id(blocked),
721 {:ok, %User{} = blocker} <- User.get_or_fetch_by_ap_id(blocker),
722 {:ok, activity} <- ActivityPub.unblock(blocker, blocked, id, false) do
723 User.unblock(blocker, blocked)
731 %{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = _data,
734 with true <- Pleroma.Config.get([:activitypub, :accept_blocks]),
735 %User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
736 {:ok, %User{} = blocker} = User.get_or_fetch_by_ap_id(blocker),
737 {:ok, activity} <- ActivityPub.block(blocker, blocked, id, false) do
738 User.unfollow(blocker, blocked)
739 User.block(blocker, blocked)
749 "object" => %{"type" => "Like", "object" => object_id},
755 with actor <- Containment.get_actor(data),
756 {:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
757 {:ok, object} <- get_obj_helper(object_id),
758 {:ok, activity, _, _} <- ActivityPub.unlike(actor, object, id, false) do
765 def handle_incoming(_, _), do: :error
767 def get_obj_helper(id, options \\ []) do
768 if object = Object.normalize(id, true, options), do: {:ok, object}, else: nil
771 def set_reply_to_uri(%{"inReplyTo" => in_reply_to} = object) when is_binary(in_reply_to) do
772 with false <- String.starts_with?(in_reply_to, "http"),
773 {:ok, %{data: replied_to_object}} <- get_obj_helper(in_reply_to) do
774 Map.put(object, "inReplyTo", replied_to_object["external_url"] || in_reply_to)
780 def set_reply_to_uri(obj), do: obj
782 # Prepares the object of an outgoing create activity.
783 def prepare_object(object) do
791 |> prepare_attachments
794 |> strip_internal_fields
795 |> strip_internal_tags
801 # internal -> Mastodon
804 def prepare_outgoing(%{"type" => "Create", "object" => object_id} = data) do
807 |> Object.normalize()
813 |> Map.put("object", object)
814 |> Map.merge(Utils.make_json_ld_header())
820 # Mastodon Accept/Reject requires a non-normalized object containing the actor URIs,
821 # because of course it does.
822 def prepare_outgoing(%{"type" => "Accept"} = data) do
823 with follow_activity <- Activity.normalize(data["object"]) do
825 "actor" => follow_activity.actor,
826 "object" => follow_activity.data["object"],
827 "id" => follow_activity.data["id"],
833 |> Map.put("object", object)
834 |> Map.merge(Utils.make_json_ld_header())
840 def prepare_outgoing(%{"type" => "Reject"} = data) do
841 with follow_activity <- Activity.normalize(data["object"]) do
843 "actor" => follow_activity.actor,
844 "object" => follow_activity.data["object"],
845 "id" => follow_activity.data["id"],
851 |> Map.put("object", object)
852 |> Map.merge(Utils.make_json_ld_header())
858 def prepare_outgoing(%{"type" => _type} = data) do
861 |> strip_internal_fields
862 |> maybe_fix_object_url
863 |> Map.merge(Utils.make_json_ld_header())
868 def maybe_fix_object_url(data) do
869 if is_binary(data["object"]) and not String.starts_with?(data["object"], "http") do
870 case get_obj_helper(data["object"]) do
871 {:ok, relative_object} ->
872 if relative_object.data["external_url"] do
875 |> Map.put("object", relative_object.data["external_url"])
881 Logger.error("Couldn't fetch #{data["object"]} #{inspect(e)}")
889 def add_hashtags(object) do
891 (object["tag"] || [])
893 # Expand internal representation tags into AS2 tags.
894 tag when is_binary(tag) ->
896 "href" => Pleroma.Web.Endpoint.url() <> "/tags/#{tag}",
901 # Do not process tags which are already AS2 tag objects.
902 tag when is_map(tag) ->
907 |> Map.put("tag", tags)
910 def add_mention_tags(object) do
913 |> Utils.get_notified_from_object()
914 |> Enum.map(fn user ->
915 %{"type" => "Mention", "href" => user.ap_id, "name" => "@#{user.nickname}"}
918 tags = object["tag"] || []
921 |> Map.put("tag", tags ++ mentions)
924 def add_emoji_tags(%User{info: %{"emoji" => _emoji} = user_info} = object) do
925 user_info = add_emoji_tags(user_info)
928 |> Map.put(:info, user_info)
931 # TODO: we should probably send mtime instead of unix epoch time for updated
932 def add_emoji_tags(%{"emoji" => emoji} = object) do
933 tags = object["tag"] || []
937 |> Enum.map(fn {name, url} ->
939 "icon" => %{"url" => url, "type" => "Image"},
940 "name" => ":" <> name <> ":",
942 "updated" => "1970-01-01T00:00:00Z",
948 |> Map.put("tag", tags ++ out)
951 def add_emoji_tags(object) do
955 def set_conversation(object) do
956 Map.put(object, "conversation", object["context"])
959 def set_sensitive(object) do
960 tags = object["tag"] || []
961 Map.put(object, "sensitive", "nsfw" in tags)
964 def set_type(%{"type" => "Answer"} = object) do
965 Map.put(object, "type", "Note")
968 def set_type(object), do: object
970 def add_attributed_to(object) do
971 attributed_to = object["attributedTo"] || object["actor"]
974 |> Map.put("attributedTo", attributed_to)
977 def add_likes(%{"id" => id, "like_count" => likes} = object) do
979 "id" => "#{id}/likes",
980 "first" => "#{id}/likes?page=1",
981 "type" => "OrderedCollection",
982 "totalItems" => likes
986 |> Map.put("likes", likes)
989 def add_likes(object) do
993 def prepare_attachments(object) do
995 (object["attachment"] || [])
996 |> Enum.map(fn data ->
997 [%{"mediaType" => media_type, "href" => href} | _] = data["url"]
998 %{"url" => href, "mediaType" => media_type, "name" => data["name"], "type" => "Document"}
1002 |> Map.put("attachment", attachments)
1005 defp strip_internal_fields(object) do
1010 "announcement_count",
1013 "deleted_activity_id"
1017 defp strip_internal_tags(%{"tag" => tags} = object) do
1020 |> Enum.filter(fn x -> is_map(x) end)
1023 |> Map.put("tag", tags)
1026 defp strip_internal_tags(object), do: object
1028 def perform(:user_upgrade, user) do
1029 # we pass a fake user so that the followers collection is stripped away
1030 old_follower_address = User.ap_followers(%User{nickname: user.nickname})
1035 where: ^old_follower_address in u.following,
1040 "array_replace(?,?,?)",
1042 ^old_follower_address,
1043 ^user.follower_address
1049 Repo.update_all(q, [])
1051 maybe_retire_websub(user.ap_id)
1056 where: ^old_follower_address in a.recipients,
1061 "array_replace(?,?,?)",
1063 ^old_follower_address,
1064 ^user.follower_address
1070 Repo.update_all(q, [])
1073 def upgrade_user_from_ap_id(ap_id) do
1074 with %User{local: false} = user <- User.get_cached_by_ap_id(ap_id),
1075 {:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id),
1076 already_ap <- User.ap_enabled?(user),
1077 {:ok, user} <- user |> User.upgrade_changeset(data) |> User.update_and_set_cache() do
1078 unless already_ap do
1079 %{"op" => "user_upgrade", "user_id" => user.id}
1080 |> TransmogrifierWorker.new(worker_args(:transmogrifier))
1086 %User{} = user -> {:ok, user}
1091 def maybe_retire_websub(ap_id) do
1092 # some sanity checks
1093 if is_binary(ap_id) && String.length(ap_id) > 8 do
1096 ws in Pleroma.Web.Websub.WebsubClientSubscription,
1097 where: fragment("? like ?", ws.topic, ^"#{ap_id}%")
1104 def maybe_fix_user_url(data) do
1105 if is_map(data["url"]) do
1106 Map.put(data, "url", data["url"]["href"])
1112 def maybe_fix_user_object(data) do
1114 |> maybe_fix_user_url