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.ActivityPub do
7 alias Pleroma.Instances
8 alias Pleroma.Notification
10 alias Pleroma.Pagination
14 alias Pleroma.Web.ActivityPub.MRF
15 alias Pleroma.Web.ActivityPub.Transmogrifier
16 alias Pleroma.Web.Federator
17 alias Pleroma.Web.OStatus
18 alias Pleroma.Web.WebFinger
21 import Pleroma.Web.ActivityPub.Utils
22 import Pleroma.Web.ActivityPub.Visibility
26 @httpoison Application.get_env(:pleroma, :httpoison)
28 # For Announce activities, we filter the recipients based on following status for any actors
29 # that match actual users. See issue #164 for more information about why this is necessary.
30 defp get_recipients(%{"type" => "Announce"} = data) do
33 actor = User.get_cached_by_ap_id(data["actor"])
37 |> Enum.filter(fn recipient ->
38 case User.get_cached_by_ap_id(recipient) do
43 User.following?(user, actor)
50 defp get_recipients(%{"type" => "Create"} = data) do
53 actor = data["actor"] || []
54 recipients = (to ++ cc ++ [actor]) |> Enum.uniq()
58 defp get_recipients(data) do
65 defp check_actor_is_active(actor) do
66 if not is_nil(actor) do
67 with user <- User.get_cached_by_ap_id(actor),
68 false <- user.info.deactivated do
78 defp check_remote_limit(%{"object" => %{"content" => content}}) when not is_nil(content) do
79 limit = Pleroma.Config.get([:instance, :remote_limit])
80 String.length(content) <= limit
83 defp check_remote_limit(_), do: true
85 def increase_note_count_if_public(actor, object) do
86 if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
89 def decrease_note_count_if_public(actor, object) do
90 if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
93 def increase_replies_count_if_reply(%{
94 "object" => %{"inReplyTo" => reply_ap_id} = object,
97 if is_public?(object) do
98 Activity.increase_replies_count(reply_ap_id)
99 Object.increase_replies_count(reply_ap_id)
103 def increase_replies_count_if_reply(_create_data), do: :noop
105 def decrease_replies_count_if_reply(%Object{
106 data: %{"inReplyTo" => reply_ap_id} = object
108 if is_public?(object) do
109 Activity.decrease_replies_count(reply_ap_id)
110 Object.decrease_replies_count(reply_ap_id)
114 def decrease_replies_count_if_reply(_object), do: :noop
116 def insert(map, local \\ true, fake \\ false) when is_map(map) do
117 with nil <- Activity.normalize(map),
118 map <- lazy_put_activity_defaults(map, fake),
119 :ok <- check_actor_is_active(map["actor"]),
120 {_, true} <- {:remote_limit_error, check_remote_limit(map)},
121 {:ok, map} <- MRF.filter(map),
122 {recipients, _, _} = get_recipients(map),
123 {:fake, false, map, recipients} <- {:fake, fake, map, recipients},
124 {:ok, object} <- insert_full_object(map) do
126 Repo.insert(%Activity{
130 recipients: recipients
133 # Splice in the child object if we have one.
135 if !is_nil(object) do
136 Map.put(activity, :object, object)
142 Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
145 Notification.create_notifications(activity)
149 %Activity{} = activity ->
152 {:fake, true, map, recipients} ->
153 activity = %Activity{
157 recipients: recipients,
161 Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
169 def stream_out(activity) do
170 public = "https://www.w3.org/ns/activitystreams#Public"
172 if activity.data["type"] in ["Create", "Announce", "Delete"] do
173 Pleroma.Web.Streamer.stream("user", activity)
174 Pleroma.Web.Streamer.stream("list", activity)
176 if Enum.member?(activity.data["to"], public) do
177 Pleroma.Web.Streamer.stream("public", activity)
180 Pleroma.Web.Streamer.stream("public:local", activity)
183 if activity.data["type"] in ["Create"] do
184 activity.data["object"]
185 |> Map.get("tag", [])
186 |> Enum.filter(fn tag -> is_bitstring(tag) end)
187 |> Enum.each(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end)
189 if activity.data["object"]["attachment"] != [] do
190 Pleroma.Web.Streamer.stream("public:media", activity)
193 Pleroma.Web.Streamer.stream("public:local:media", activity)
198 if !Enum.member?(activity.data["cc"] || [], public) &&
201 User.get_by_ap_id(activity.data["actor"]).follower_address
203 do: Pleroma.Web.Streamer.stream("direct", activity)
208 def create(%{to: to, actor: actor, context: context, object: object} = params, fake \\ false) do
209 additional = params[:additional] || %{}
210 # only accept false as false value
211 local = !(params[:local] == false)
212 published = params[:published]
216 %{to: to, actor: actor, published: published, context: context, object: object},
219 {:ok, activity} <- insert(create_data, local, fake),
220 {:fake, false, activity} <- {:fake, fake, activity},
221 _ <- increase_replies_count_if_reply(create_data),
222 # Changing note count prior to enqueuing federation task in order to avoid
223 # race conditions on updating user.info
224 {:ok, _actor} <- increase_note_count_if_public(actor, activity),
225 :ok <- maybe_federate(activity) do
228 {:fake, true, activity} ->
233 def accept(%{to: to, actor: actor, object: object} = params) do
234 # only accept false as false value
235 local = !(params[:local] == false)
237 with data <- %{"to" => to, "type" => "Accept", "actor" => actor.ap_id, "object" => object},
238 {:ok, activity} <- insert(data, local),
239 :ok <- maybe_federate(activity) do
244 def reject(%{to: to, actor: actor, object: object} = params) do
245 # only accept false as false value
246 local = !(params[:local] == false)
248 with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object},
249 {:ok, activity} <- insert(data, local),
250 :ok <- maybe_federate(activity) do
255 def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
256 # only accept false as false value
257 local = !(params[:local] == false)
266 {:ok, activity} <- insert(data, local),
267 :ok <- maybe_federate(activity) do
272 # TODO: This is weird, maybe we shouldn't check here if we can make the activity.
274 %User{ap_id: ap_id} = user,
275 %Object{data: %{"id" => _}} = object,
279 with nil <- get_existing_like(ap_id, object),
280 like_data <- make_like_data(user, object, activity_id),
281 {:ok, activity} <- insert(like_data, local),
282 {:ok, object} <- add_like_to_object(activity, object),
283 :ok <- maybe_federate(activity) do
284 {:ok, activity, object}
286 %Activity{} = activity -> {:ok, activity, object}
287 error -> {:error, error}
297 with %Activity{} = like_activity <- get_existing_like(actor.ap_id, object),
298 unlike_data <- make_unlike_data(actor, like_activity, activity_id),
299 {:ok, unlike_activity} <- insert(unlike_data, local),
300 {:ok, _activity} <- Repo.delete(like_activity),
301 {:ok, object} <- remove_like_from_object(like_activity, object),
302 :ok <- maybe_federate(unlike_activity) do
303 {:ok, unlike_activity, like_activity, object}
310 %User{ap_id: _} = user,
311 %Object{data: %{"id" => _}} = object,
316 with true <- is_public?(object),
317 announce_data <- make_announce_data(user, object, activity_id, public),
318 {:ok, activity} <- insert(announce_data, local),
319 {:ok, object} <- add_announce_to_object(activity, object),
320 :ok <- maybe_federate(activity) do
321 {:ok, activity, object}
323 error -> {:error, error}
333 with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object),
334 unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id),
335 {:ok, unannounce_activity} <- insert(unannounce_data, local),
336 :ok <- maybe_federate(unannounce_activity),
337 {:ok, _activity} <- Repo.delete(announce_activity),
338 {:ok, object} <- remove_announce_from_object(announce_activity, object) do
339 {:ok, unannounce_activity, object}
345 def follow(follower, followed, activity_id \\ nil, local \\ true) do
346 with data <- make_follow_data(follower, followed, activity_id),
347 {:ok, activity} <- insert(data, local),
348 :ok <- maybe_federate(activity) do
353 def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
354 with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
355 {:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
356 unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
357 {:ok, activity} <- insert(unfollow_data, local),
358 :ok <- maybe_federate(activity) do
363 def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
364 user = User.get_cached_by_ap_id(actor)
365 to = (object.data["to"] || []) ++ (object.data["cc"] || [])
367 with {:ok, object, activity} <- Object.delete(object),
373 "deleted_activity_id" => activity && activity.id
375 {:ok, activity} <- insert(data, local),
376 _ <- decrease_replies_count_if_reply(object),
377 # Changing note count prior to enqueuing federation task in order to avoid
378 # race conditions on updating user.info
379 {:ok, _actor} <- decrease_note_count_if_public(user, object),
380 :ok <- maybe_federate(activity) do
385 def block(blocker, blocked, activity_id \\ nil, local \\ true) do
386 ap_config = Application.get_env(:pleroma, :activitypub)
387 unfollow_blocked = Keyword.get(ap_config, :unfollow_blocked)
388 outgoing_blocks = Keyword.get(ap_config, :outgoing_blocks)
390 with true <- unfollow_blocked do
391 follow_activity = fetch_latest_follow(blocker, blocked)
393 if follow_activity do
394 unfollow(blocker, blocked, nil, local)
398 with true <- outgoing_blocks,
399 block_data <- make_block_data(blocker, blocked, activity_id),
400 {:ok, activity} <- insert(block_data, local),
401 :ok <- maybe_federate(activity) do
408 def unblock(blocker, blocked, activity_id \\ nil, local \\ true) do
409 with %Activity{} = block_activity <- fetch_latest_block(blocker, blocked),
410 unblock_data <- make_unblock_data(blocker, blocked, block_activity, activity_id),
411 {:ok, activity} <- insert(unblock_data, local),
412 :ok <- maybe_federate(activity) do
426 # only accept false as false value
427 local = !(params[:local] == false)
428 forward = !(params[:forward] == false)
430 additional = params[:additional] || %{}
442 Map.merge(additional, %{"to" => [], "cc" => [account.ap_id]})
444 Map.merge(additional, %{"to" => [], "cc" => []})
447 with flag_data <- make_flag_data(params, additional),
448 {:ok, activity} <- insert(flag_data, local),
449 :ok <- maybe_federate(activity) do
450 Enum.each(User.all_superusers(), fn superuser ->
452 |> Pleroma.Emails.AdminEmail.report(actor, account, statuses, content)
453 |> Pleroma.Emails.Mailer.deliver_async()
460 def fetch_activities_for_context(context, opts \\ %{}) do
461 public = ["https://www.w3.org/ns/activitystreams#Public"]
464 if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
466 query = from(activity in Activity)
470 |> restrict_blocked(opts)
471 |> restrict_recipients(recipients, opts["user"])
478 "?->>'type' = ? and ?->>'context' = ?",
484 order_by: [desc: :id]
486 |> Activity.with_preloaded_object()
491 def fetch_public_activities(opts \\ %{}) do
492 q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts)
495 |> restrict_unlisted()
496 |> Pagination.fetch_paginated(opts)
500 @valid_visibilities ~w[direct unlisted public private]
502 defp restrict_visibility(query, %{visibility: visibility})
503 when is_list(visibility) do
504 if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
510 "activity_visibility(?, ?, ?) = ANY (?)",
518 Ecto.Adapters.SQL.to_sql(:all, Repo, query)
522 Logger.error("Could not restrict visibility to #{visibility}")
526 defp restrict_visibility(query, %{visibility: visibility})
527 when visibility in @valid_visibilities do
532 fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility)
535 Ecto.Adapters.SQL.to_sql(:all, Repo, query)
540 defp restrict_visibility(_query, %{visibility: visibility})
541 when visibility not in @valid_visibilities do
542 Logger.error("Could not restrict visibility to #{visibility}")
545 defp restrict_visibility(query, _visibility), do: query
547 def fetch_user_activities(user, reading_user, params \\ %{}) do
550 |> Map.put("type", ["Create", "Announce"])
551 |> Map.put("actor_id", user.ap_id)
552 |> Map.put("whole_db", true)
553 |> Map.put("pinned_activity_ids", user.info.pinned_activities)
557 ["https://www.w3.org/ns/activitystreams#Public"] ++
558 [reading_user.ap_id | reading_user.following]
560 ["https://www.w3.org/ns/activitystreams#Public"]
563 fetch_activities(recipients, params)
567 defp restrict_since(query, %{"since_id" => ""}), do: query
569 defp restrict_since(query, %{"since_id" => since_id}) do
570 from(activity in query, where: activity.id > ^since_id)
573 defp restrict_since(query, _), do: query
575 defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
576 when is_list(tag_reject) and tag_reject != [] do
579 where: fragment(~s(\(not \(? #> '{"object","tag"}'\) \\?| ?\)), activity.data, ^tag_reject)
583 defp restrict_tag_reject(query, _), do: query
585 defp restrict_tag_all(query, %{"tag_all" => tag_all})
586 when is_list(tag_all) and tag_all != [] do
589 where: fragment(~s(\(? #> '{"object","tag"}'\) \\?& ?), activity.data, ^tag_all)
593 defp restrict_tag_all(query, _), do: query
595 defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
598 where: fragment(~s(\(? #> '{"object","tag"}'\) \\?| ?), activity.data, ^tag)
602 defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
605 where: fragment(~s(? <@ (? #> '{"object","tag"}'\)), ^tag, activity.data)
609 defp restrict_tag(query, _), do: query
611 defp restrict_to_cc(query, recipients_to, recipients_cc) do
616 "(?->'to' \\?| ?) or (?->'cc' \\?| ?)",
625 defp restrict_recipients(query, [], _user), do: query
627 defp restrict_recipients(query, recipients, nil) do
628 from(activity in query, where: fragment("? && ?", ^recipients, activity.recipients))
631 defp restrict_recipients(query, recipients, user) do
634 where: fragment("? && ?", ^recipients, activity.recipients),
635 or_where: activity.actor == ^user.ap_id
639 defp restrict_local(query, %{"local_only" => true}) do
640 from(activity in query, where: activity.local == true)
643 defp restrict_local(query, _), do: query
645 defp restrict_actor(query, %{"actor_id" => actor_id}) do
646 from(activity in query, where: activity.actor == ^actor_id)
649 defp restrict_actor(query, _), do: query
651 defp restrict_type(query, %{"type" => type}) when is_binary(type) do
652 from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type))
655 defp restrict_type(query, %{"type" => type}) do
656 from(activity in query, where: fragment("?->>'type' = ANY(?)", activity.data, ^type))
659 defp restrict_type(query, _), do: query
661 defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
664 where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data)
668 defp restrict_favorited_by(query, _), do: query
670 defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
673 where: fragment(~s(not (? #> '{"object","attachment"}' = ?\)), activity.data, ^[])
677 defp restrict_media(query, _), do: query
679 defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
682 where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
686 defp restrict_replies(query, _), do: query
688 defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val == "true" or val == "1" do
689 from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data))
692 defp restrict_reblogs(query, _), do: query
694 defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
696 defp restrict_muted(query, %{"muting_user" => %User{info: info}}) do
701 where: fragment("not (? = ANY(?))", activity.actor, ^mutes),
702 where: fragment("not (?->'to' \\?| ?)", activity.data, ^mutes)
706 defp restrict_muted(query, _), do: query
708 defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
709 blocks = info.blocks || []
710 domain_blocks = info.domain_blocks || []
714 where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
715 where: fragment("not (? && ?)", activity.recipients, ^blocks),
716 where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks)
720 defp restrict_blocked(query, _), do: query
722 defp restrict_unlisted(query) do
727 "not (coalesce(?->'cc', '{}'::jsonb) \\?| ?)",
729 ^["https://www.w3.org/ns/activitystreams#Public"]
734 defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids}) do
735 from(activity in query, where: activity.id in ^ids)
738 defp restrict_pinned(query, _), do: query
740 defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
741 muted_reblogs = info.muted_reblogs || []
747 "not ( ?->>'type' = 'Announce' and ? = ANY(?))",
755 defp restrict_muted_reblogs(query, _), do: query
757 defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
759 defp maybe_preload_objects(query, _) do
761 |> Activity.with_preloaded_object()
764 def fetch_activities_query(recipients, opts \\ %{}) do
765 base_query = from(activity in Activity)
768 |> maybe_preload_objects(opts)
769 |> restrict_recipients(recipients, opts["user"])
770 |> restrict_tag(opts)
771 |> restrict_tag_reject(opts)
772 |> restrict_tag_all(opts)
773 |> restrict_since(opts)
774 |> restrict_local(opts)
775 |> restrict_actor(opts)
776 |> restrict_type(opts)
777 |> restrict_favorited_by(opts)
778 |> restrict_blocked(opts)
779 |> restrict_muted(opts)
780 |> restrict_media(opts)
781 |> restrict_visibility(opts)
782 |> restrict_replies(opts)
783 |> restrict_reblogs(opts)
784 |> restrict_pinned(opts)
785 |> restrict_muted_reblogs(opts)
788 def fetch_activities(recipients, opts \\ %{}) do
789 fetch_activities_query(recipients, opts)
790 |> Pagination.fetch_paginated(opts)
794 def fetch_activities_bounded(recipients_to, recipients_cc, opts \\ %{}) do
795 fetch_activities_query([], opts)
796 |> restrict_to_cc(recipients_to, recipients_cc)
797 |> Pagination.fetch_paginated(opts)
801 def upload(file, opts \\ []) do
802 with {:ok, data} <- Upload.store(file, opts) do
805 Map.put(data, "actor", opts[:actor])
810 Repo.insert(%Object{data: obj_data})
814 def user_data_from_user_object(data) do
816 data["icon"]["url"] &&
819 "url" => [%{"href" => data["icon"]["url"]}]
823 data["image"]["url"] &&
826 "url" => [%{"href" => data["image"]["url"]}]
829 locked = data["manuallyApprovesFollowers"] || false
830 data = Transmogrifier.maybe_fix_user_object(data)
835 "ap_enabled" => true,
836 "source_data" => data,
842 follower_address: data["followers"],
846 # nickname can be nil because of virtual actors
848 if data["preferredUsername"] do
852 "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}"
855 Map.put(user_data, :nickname, nil)
861 def fetch_and_prepare_user_from_ap_id(ap_id) do
862 with {:ok, data} <- fetch_and_contain_remote_object_from_id(ap_id) do
863 user_data_from_user_object(data)
865 e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
869 def make_user_from_ap_id(ap_id) do
870 if _user = User.get_by_ap_id(ap_id) do
871 Transmogrifier.upgrade_user_from_ap_id(ap_id)
873 with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do
874 User.insert_or_update_user(data)
881 def make_user_from_nickname(nickname) do
882 with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
883 make_user_from_ap_id(ap_id)
885 _e -> {:error, "No AP id in WebFinger"}
889 def should_federate?(inbox, public) do
893 inbox_info = URI.parse(inbox)
894 !Enum.member?(Pleroma.Config.get([:instance, :quarantined_instances], []), inbox_info.host)
898 def publish(actor, activity) do
900 if actor.follower_address in activity.recipients do
901 {:ok, followers} = User.get_followers(actor)
902 followers |> Enum.filter(&(!&1.local))
907 public = is_public?(activity)
909 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
910 json = Jason.encode!(data)
912 (Pleroma.Web.Salmon.remote_users(activity) ++ remote_followers)
913 |> Enum.filter(fn user -> User.ap_enabled?(user) end)
914 |> Enum.map(fn %{info: %{source_data: data}} ->
915 (is_map(data["endpoints"]) && Map.get(data["endpoints"], "sharedInbox")) || data["inbox"]
918 |> Enum.filter(fn inbox -> should_federate?(inbox, public) end)
919 |> Instances.filter_reachable()
920 |> Enum.each(fn {inbox, unreachable_since} ->
921 Federator.publish_single_ap(%{
925 id: activity.data["id"],
926 unreachable_since: unreachable_since
931 def publish_one(%{inbox: inbox, json: json, actor: actor, id: id} = params) do
932 Logger.info("Federating #{id} to #{inbox}")
933 host = URI.parse(inbox).host
935 digest = "SHA-256=" <> (:crypto.hash(:sha256, json) |> Base.encode64())
938 NaiveDateTime.utc_now()
939 |> Timex.format!("{WDshort}, {0D} {Mshort} {YYYY} {h24}:{m}:{s} GMT")
942 Pleroma.Web.HTTPSignatures.sign(actor, %{
944 "content-length": byte_size(json),
949 with {:ok, %{status: code}} when code in 200..299 <-
955 {"Content-Type", "application/activity+json"},
957 {"signature", signature},
961 if !Map.has_key?(params, :unreachable_since) || params[:unreachable_since],
962 do: Instances.set_reachable(inbox)
966 {_post_result, response} ->
967 unless params[:unreachable_since], do: Instances.set_unreachable(inbox)
973 # This will create a Create activity, which we need internally at the moment.
974 def fetch_object_from_id(id) do
975 if object = Object.get_cached_by_ap_id(id) do
978 with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
979 nil <- Object.normalize(data),
984 "actor" => data["actor"] || data["attributedTo"],
987 :ok <- Transmogrifier.contain_origin(id, params),
988 {:ok, activity} <- Transmogrifier.handle_incoming(params) do
989 {:ok, Object.normalize(activity)}
991 {:error, {:reject, nil}} ->
994 object = %Object{} ->
998 Logger.info("Couldn't get object via AP, trying out OStatus fetching...")
1000 case OStatus.fetch_activity_from_url(id) do
1001 {:ok, [activity | _]} -> {:ok, Object.normalize(activity)}
1008 def fetch_and_contain_remote_object_from_id(id) do
1009 Logger.info("Fetching object #{id} via AP")
1011 with true <- String.starts_with?(id, "http"),
1012 {:ok, %{body: body, status: code}} when code in 200..299 <-
1015 [{:Accept, "application/activity+json"}]
1017 {:ok, data} <- Jason.decode(body),
1018 :ok <- Transmogrifier.contain_origin_from_id(id, data) do
1026 # filter out broken threads
1027 def contain_broken_threads(%Activity{} = activity, %User{} = user) do
1028 entire_thread_visible_for_user?(activity, user)
1031 # do post-processing on a specific activity
1032 def contain_activity(%Activity{} = activity, %User{} = user) do
1033 contain_broken_threads(activity, user)
1036 # do post-processing on a timeline
1037 def contain_timeline(timeline, user) do
1039 |> Enum.filter(fn activity ->
1040 contain_activity(activity, user)