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.Conversation
8 alias Pleroma.Notification
10 alias Pleroma.Object.Fetcher
11 alias Pleroma.Pagination
15 alias Pleroma.Web.ActivityPub.MRF
16 alias Pleroma.Web.ActivityPub.Transmogrifier
17 alias Pleroma.Web.WebFinger
20 import Pleroma.Web.ActivityPub.Utils
21 import Pleroma.Web.ActivityPub.Visibility
25 # For Announce activities, we filter the recipients based on following status for any actors
26 # that match actual users. See issue #164 for more information about why this is necessary.
27 defp get_recipients(%{"type" => "Announce"} = data) do
28 to = Map.get(data, "to", [])
29 cc = Map.get(data, "cc", [])
30 bcc = Map.get(data, "bcc", [])
31 actor = User.get_cached_by_ap_id(data["actor"])
34 Enum.filter(Enum.concat([to, cc, bcc]), fn recipient ->
35 case User.get_cached_by_ap_id(recipient) do
37 user -> User.following?(user, actor)
44 defp get_recipients(%{"type" => "Create"} = data) do
45 to = Map.get(data, "to", [])
46 cc = Map.get(data, "cc", [])
47 bcc = Map.get(data, "bcc", [])
48 actor = Map.get(data, "actor", [])
49 recipients = [to, cc, bcc, [actor]] |> Enum.concat() |> Enum.uniq()
53 defp get_recipients(data) do
54 to = Map.get(data, "to", [])
55 cc = Map.get(data, "cc", [])
56 bcc = Map.get(data, "bcc", [])
57 recipients = Enum.concat([to, cc, bcc])
61 defp check_actor_is_active(actor) do
62 if not is_nil(actor) do
63 with user <- User.get_cached_by_ap_id(actor),
64 false <- user.info.deactivated do
74 defp check_remote_limit(%{"object" => %{"content" => content}}) when not is_nil(content) do
75 limit = Pleroma.Config.get([:instance, :remote_limit])
76 String.length(content) <= limit
79 defp check_remote_limit(_), do: true
81 def increase_note_count_if_public(actor, object) do
82 if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
85 def decrease_note_count_if_public(actor, object) do
86 if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
89 def increase_replies_count_if_reply(%{
90 "object" => %{"inReplyTo" => reply_ap_id} = object,
93 if is_public?(object) do
94 Object.increase_replies_count(reply_ap_id)
98 def increase_replies_count_if_reply(_create_data), do: :noop
100 def decrease_replies_count_if_reply(%Object{
101 data: %{"inReplyTo" => reply_ap_id} = object
103 if is_public?(object) do
104 Object.decrease_replies_count(reply_ap_id)
108 def decrease_replies_count_if_reply(_object), do: :noop
110 def insert(map, local \\ true, fake \\ false) when is_map(map) do
111 with nil <- Activity.normalize(map),
112 map <- lazy_put_activity_defaults(map, fake),
113 :ok <- check_actor_is_active(map["actor"]),
114 {_, true} <- {:remote_limit_error, check_remote_limit(map)},
115 {:ok, map} <- MRF.filter(map),
116 {recipients, _, _} = get_recipients(map),
117 {:fake, false, map, recipients} <- {:fake, fake, map, recipients},
118 {:ok, map, object} <- insert_full_object(map) do
120 Repo.insert(%Activity{
124 recipients: recipients
127 # Splice in the child object if we have one.
129 if !is_nil(object) do
130 Map.put(activity, :object, object)
136 Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
139 Notification.create_notifications(activity)
143 |> Conversation.create_or_bump_for()
144 |> get_participations()
147 stream_out_participations(participations)
150 %Activity{} = activity ->
153 {:fake, true, map, recipients} ->
154 activity = %Activity{
158 recipients: recipients,
162 Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
170 defp get_participations({:ok, %{participations: participations}}), do: participations
171 defp get_participations(_), do: []
173 def stream_out_participations(participations) do
176 |> Repo.preload(:user)
178 Enum.each(participations, fn participation ->
179 Pleroma.Web.Streamer.stream("participation", participation)
183 def stream_out(activity) do
184 public = "https://www.w3.org/ns/activitystreams#Public"
186 if activity.data["type"] in ["Create", "Announce", "Delete"] do
187 Pleroma.Web.Streamer.stream("user", activity)
188 Pleroma.Web.Streamer.stream("list", activity)
190 if Enum.member?(activity.data["to"], public) do
191 Pleroma.Web.Streamer.stream("public", activity)
194 Pleroma.Web.Streamer.stream("public:local", activity)
197 if activity.data["type"] in ["Create"] do
198 object = Object.normalize(activity)
201 |> Map.get("tag", [])
202 |> Enum.filter(fn tag -> is_bitstring(tag) end)
203 |> Enum.each(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end)
205 if object.data["attachment"] != [] do
206 Pleroma.Web.Streamer.stream("public:media", activity)
209 Pleroma.Web.Streamer.stream("public:local:media", activity)
214 # TODO: Write test, replace with visibility test
215 if !Enum.member?(activity.data["cc"] || [], public) &&
218 User.get_cached_by_ap_id(activity.data["actor"]).follower_address
220 do: Pleroma.Web.Streamer.stream("direct", activity)
225 def create(%{to: to, actor: actor, context: context, object: object} = params, fake \\ false) do
226 additional = params[:additional] || %{}
227 # only accept false as false value
228 local = !(params[:local] == false)
229 published = params[:published]
233 %{to: to, actor: actor, published: published, context: context, object: object},
236 {:ok, activity} <- insert(create_data, local, fake),
237 {:fake, false, activity} <- {:fake, fake, activity},
238 _ <- increase_replies_count_if_reply(create_data),
239 # Changing note count prior to enqueuing federation task in order to avoid
240 # race conditions on updating user.info
241 {:ok, _actor} <- increase_note_count_if_public(actor, activity),
242 :ok <- maybe_federate(activity) do
245 {:fake, true, activity} ->
250 def accept(%{to: to, actor: actor, object: object} = params) do
251 # only accept false as false value
252 local = !(params[:local] == false)
254 with data <- %{"to" => to, "type" => "Accept", "actor" => actor.ap_id, "object" => object},
255 {:ok, activity} <- insert(data, local),
256 :ok <- maybe_federate(activity) do
261 def reject(%{to: to, actor: actor, object: object} = params) do
262 # only accept false as false value
263 local = !(params[:local] == false)
265 with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object},
266 {:ok, activity} <- insert(data, local),
267 :ok <- maybe_federate(activity) do
272 def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
273 # only accept false as false value
274 local = !(params[:local] == false)
283 {:ok, activity} <- insert(data, local),
284 :ok <- maybe_federate(activity) do
289 # TODO: This is weird, maybe we shouldn't check here if we can make the activity.
291 %User{ap_id: ap_id} = user,
292 %Object{data: %{"id" => _}} = object,
296 with nil <- get_existing_like(ap_id, object),
297 like_data <- make_like_data(user, object, activity_id),
298 {:ok, activity} <- insert(like_data, local),
299 {:ok, object} <- add_like_to_object(activity, object),
300 :ok <- maybe_federate(activity) do
301 {:ok, activity, object}
303 %Activity{} = activity -> {:ok, activity, object}
304 error -> {:error, error}
314 with %Activity{} = like_activity <- get_existing_like(actor.ap_id, object),
315 unlike_data <- make_unlike_data(actor, like_activity, activity_id),
316 {:ok, unlike_activity} <- insert(unlike_data, local),
317 {:ok, _activity} <- Repo.delete(like_activity),
318 {:ok, object} <- remove_like_from_object(like_activity, object),
319 :ok <- maybe_federate(unlike_activity) do
320 {:ok, unlike_activity, like_activity, object}
327 %User{ap_id: _} = user,
328 %Object{data: %{"id" => _}} = object,
333 with true <- is_public?(object),
334 announce_data <- make_announce_data(user, object, activity_id, public),
335 {:ok, activity} <- insert(announce_data, local),
336 {:ok, object} <- add_announce_to_object(activity, object),
337 :ok <- maybe_federate(activity) do
338 {:ok, activity, object}
340 error -> {:error, error}
350 with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object),
351 unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id),
352 {:ok, unannounce_activity} <- insert(unannounce_data, local),
353 :ok <- maybe_federate(unannounce_activity),
354 {:ok, _activity} <- Repo.delete(announce_activity),
355 {:ok, object} <- remove_announce_from_object(announce_activity, object) do
356 {:ok, unannounce_activity, object}
362 def follow(follower, followed, activity_id \\ nil, local \\ true) do
363 with data <- make_follow_data(follower, followed, activity_id),
364 {:ok, activity} <- insert(data, local),
365 :ok <- maybe_federate(activity) do
370 def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
371 with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
372 {:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
373 unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
374 {:ok, activity} <- insert(unfollow_data, local),
375 :ok <- maybe_federate(activity) do
380 def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
381 user = User.get_cached_by_ap_id(actor)
382 to = (object.data["to"] || []) ++ (object.data["cc"] || [])
384 with {:ok, object, activity} <- Object.delete(object),
390 "deleted_activity_id" => activity && activity.id
392 {:ok, activity} <- insert(data, local),
393 _ <- decrease_replies_count_if_reply(object),
394 # Changing note count prior to enqueuing federation task in order to avoid
395 # race conditions on updating user.info
396 {:ok, _actor} <- decrease_note_count_if_public(user, object),
397 :ok <- maybe_federate(activity) do
402 def block(blocker, blocked, activity_id \\ nil, local \\ true) do
403 ap_config = Application.get_env(:pleroma, :activitypub)
404 unfollow_blocked = Keyword.get(ap_config, :unfollow_blocked)
405 outgoing_blocks = Keyword.get(ap_config, :outgoing_blocks)
407 with true <- unfollow_blocked do
408 follow_activity = fetch_latest_follow(blocker, blocked)
410 if follow_activity do
411 unfollow(blocker, blocked, nil, local)
415 with true <- outgoing_blocks,
416 block_data <- make_block_data(blocker, blocked, activity_id),
417 {:ok, activity} <- insert(block_data, local),
418 :ok <- maybe_federate(activity) do
425 def unblock(blocker, blocked, activity_id \\ nil, local \\ true) do
426 with %Activity{} = block_activity <- fetch_latest_block(blocker, blocked),
427 unblock_data <- make_unblock_data(blocker, blocked, block_activity, activity_id),
428 {:ok, activity} <- insert(unblock_data, local),
429 :ok <- maybe_federate(activity) do
443 # only accept false as false value
444 local = !(params[:local] == false)
445 forward = !(params[:forward] == false)
447 additional = params[:additional] || %{}
459 Map.merge(additional, %{"to" => [], "cc" => [account.ap_id]})
461 Map.merge(additional, %{"to" => [], "cc" => []})
464 with flag_data <- make_flag_data(params, additional),
465 {:ok, activity} <- insert(flag_data, local),
466 :ok <- maybe_federate(activity) do
467 Enum.each(User.all_superusers(), fn superuser ->
469 |> Pleroma.Emails.AdminEmail.report(actor, account, statuses, content)
470 |> Pleroma.Emails.Mailer.deliver_async()
477 defp fetch_activities_for_context_query(context, opts) do
478 public = ["https://www.w3.org/ns/activitystreams#Public"]
481 if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
483 from(activity in Activity)
484 |> restrict_blocked(opts)
485 |> restrict_recipients(recipients, opts["user"])
489 "?->>'type' = ? and ?->>'context' = ?",
496 |> order_by([activity], desc: activity.id)
499 @spec fetch_activities_for_context(String.t(), keyword() | map()) :: [Activity.t()]
500 def fetch_activities_for_context(context, opts \\ %{}) do
502 |> fetch_activities_for_context_query(opts)
503 |> Activity.with_preloaded_object()
507 @spec fetch_latest_activity_id_for_context(String.t(), keyword() | map()) ::
508 Pleroma.FlakeId.t() | nil
509 def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
511 |> fetch_activities_for_context_query(opts)
517 def fetch_public_activities(opts \\ %{}) do
518 q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts)
521 |> restrict_unlisted()
522 |> Pagination.fetch_paginated(opts)
526 @valid_visibilities ~w[direct unlisted public private]
528 defp restrict_visibility(query, %{visibility: visibility})
529 when is_list(visibility) do
530 if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
536 "activity_visibility(?, ?, ?) = ANY (?)",
544 Ecto.Adapters.SQL.to_sql(:all, Repo, query)
548 Logger.error("Could not restrict visibility to #{visibility}")
552 defp restrict_visibility(query, %{visibility: visibility})
553 when visibility in @valid_visibilities do
558 fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility)
561 Ecto.Adapters.SQL.to_sql(:all, Repo, query)
566 defp restrict_visibility(_query, %{visibility: visibility})
567 when visibility not in @valid_visibilities do
568 Logger.error("Could not restrict visibility to #{visibility}")
571 defp restrict_visibility(query, _visibility), do: query
573 def fetch_user_activities(user, reading_user, params \\ %{}) do
576 |> Map.put("type", ["Create", "Announce"])
577 |> Map.put("actor_id", user.ap_id)
578 |> Map.put("whole_db", true)
579 |> Map.put("pinned_activity_ids", user.info.pinned_activities)
583 ["https://www.w3.org/ns/activitystreams#Public"] ++
584 [reading_user.ap_id | reading_user.following]
586 ["https://www.w3.org/ns/activitystreams#Public"]
589 fetch_activities(recipients, params)
593 defp restrict_since(query, %{"since_id" => ""}), do: query
595 defp restrict_since(query, %{"since_id" => since_id}) do
596 from(activity in query, where: activity.id > ^since_id)
599 defp restrict_since(query, _), do: query
601 defp restrict_tag_reject(_query, %{"tag_reject" => _tag_reject, "skip_preload" => true}) do
602 raise "Can't use the child object without preloading!"
605 defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
606 when is_list(tag_reject) and tag_reject != [] do
608 [_activity, object] in query,
609 where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
613 defp restrict_tag_reject(query, _), do: query
615 defp restrict_tag_all(_query, %{"tag_all" => _tag_all, "skip_preload" => true}) do
616 raise "Can't use the child object without preloading!"
619 defp restrict_tag_all(query, %{"tag_all" => tag_all})
620 when is_list(tag_all) and tag_all != [] do
622 [_activity, object] in query,
623 where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
627 defp restrict_tag_all(query, _), do: query
629 defp restrict_tag(_query, %{"tag" => _tag, "skip_preload" => true}) do
630 raise "Can't use the child object without preloading!"
633 defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
635 [_activity, object] in query,
636 where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
640 defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
642 [_activity, object] in query,
643 where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
647 defp restrict_tag(query, _), do: query
649 defp restrict_to_cc(query, recipients_to, recipients_cc) do
654 "(?->'to' \\?| ?) or (?->'cc' \\?| ?)",
663 defp restrict_recipients(query, [], _user), do: query
665 defp restrict_recipients(query, recipients, nil) do
666 from(activity in query, where: fragment("? && ?", ^recipients, activity.recipients))
669 defp restrict_recipients(query, recipients, user) do
672 where: fragment("? && ?", ^recipients, activity.recipients),
673 or_where: activity.actor == ^user.ap_id
677 defp restrict_local(query, %{"local_only" => true}) do
678 from(activity in query, where: activity.local == true)
681 defp restrict_local(query, _), do: query
683 defp restrict_actor(query, %{"actor_id" => actor_id}) do
684 from(activity in query, where: activity.actor == ^actor_id)
687 defp restrict_actor(query, _), do: query
689 defp restrict_type(query, %{"type" => type}) when is_binary(type) do
690 from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type))
693 defp restrict_type(query, %{"type" => type}) do
694 from(activity in query, where: fragment("?->>'type' = ANY(?)", activity.data, ^type))
697 defp restrict_type(query, _), do: query
699 defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
702 where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data)
706 defp restrict_favorited_by(query, _), do: query
708 defp restrict_media(_query, %{"only_media" => _val, "skip_preload" => true}) do
709 raise "Can't use the child object without preloading!"
712 defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
714 [_activity, object] in query,
715 where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
719 defp restrict_media(query, _), do: query
721 defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
724 where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
728 defp restrict_replies(query, _), do: query
730 defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val == "true" or val == "1" do
731 from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data))
734 defp restrict_reblogs(query, _), do: query
736 defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
738 defp restrict_muted(query, %{"muting_user" => %User{info: info}}) do
743 where: fragment("not (? = ANY(?))", activity.actor, ^mutes),
744 where: fragment("not (?->'to' \\?| ?)", activity.data, ^mutes)
748 defp restrict_muted(query, _), do: query
750 defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
751 blocks = info.blocks || []
752 domain_blocks = info.domain_blocks || []
756 where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
757 where: fragment("not (? && ?)", activity.recipients, ^blocks),
760 "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
765 where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks)
769 defp restrict_blocked(query, _), do: query
771 defp restrict_unlisted(query) do
776 "not (coalesce(?->'cc', '{}'::jsonb) \\?| ?)",
778 ^["https://www.w3.org/ns/activitystreams#Public"]
783 defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids}) do
784 from(activity in query, where: activity.id in ^ids)
787 defp restrict_pinned(query, _), do: query
789 defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
790 muted_reblogs = info.muted_reblogs || []
796 "not ( ?->>'type' = 'Announce' and ? = ANY(?))",
804 defp restrict_muted_reblogs(query, _), do: query
806 defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
808 defp maybe_preload_objects(query, _) do
810 |> Activity.with_preloaded_object()
813 defp maybe_preload_bookmarks(query, %{"skip_preload" => true}), do: query
815 defp maybe_preload_bookmarks(query, opts) do
817 |> Activity.with_preloaded_bookmark(opts["user"])
820 defp maybe_order(query, %{order: :desc}) do
822 |> order_by(desc: :id)
825 defp maybe_order(query, %{order: :asc}) do
827 |> order_by(asc: :id)
830 defp maybe_order(query, _), do: query
832 def fetch_activities_query(recipients, opts \\ %{}) do
834 |> maybe_preload_objects(opts)
835 |> maybe_preload_bookmarks(opts)
837 |> restrict_recipients(recipients, opts["user"])
838 |> restrict_tag(opts)
839 |> restrict_tag_reject(opts)
840 |> restrict_tag_all(opts)
841 |> restrict_since(opts)
842 |> restrict_local(opts)
843 |> restrict_actor(opts)
844 |> restrict_type(opts)
845 |> restrict_favorited_by(opts)
846 |> restrict_blocked(opts)
847 |> restrict_muted(opts)
848 |> restrict_media(opts)
849 |> restrict_visibility(opts)
850 |> restrict_replies(opts)
851 |> restrict_reblogs(opts)
852 |> restrict_pinned(opts)
853 |> restrict_muted_reblogs(opts)
856 def fetch_activities(recipients, opts \\ %{}) do
857 list_memberships = Pleroma.List.memberships(opts["user"])
859 fetch_activities_query(recipients ++ list_memberships, opts)
860 |> Pagination.fetch_paginated(opts)
862 |> maybe_update_cc(list_memberships, opts["user"])
865 defp maybe_update_cc(activities, [], _), do: activities
866 defp maybe_update_cc(activities, _, nil), do: activities
868 defp maybe_update_cc(activities, list_memberships, user) do
869 Enum.map(activities, fn
870 %{data: %{"bcc" => bcc}} = activity when is_list(bcc) ->
871 if Enum.any?(bcc, &(&1 in list_memberships)) do
872 update_in(activity.data["cc"], &[user.ap_id | &1])
882 def fetch_activities_bounded(recipients_to, recipients_cc, opts \\ %{}) do
883 fetch_activities_query([], opts)
884 |> restrict_to_cc(recipients_to, recipients_cc)
885 |> Pagination.fetch_paginated(opts)
889 def upload(file, opts \\ []) do
890 with {:ok, data} <- Upload.store(file, opts) do
893 Map.put(data, "actor", opts[:actor])
898 Repo.insert(%Object{data: obj_data})
902 def user_data_from_user_object(data) do
904 data["icon"]["url"] &&
907 "url" => [%{"href" => data["icon"]["url"]}]
911 data["image"]["url"] &&
914 "url" => [%{"href" => data["image"]["url"]}]
917 locked = data["manuallyApprovesFollowers"] || false
918 data = Transmogrifier.maybe_fix_user_object(data)
923 "ap_enabled" => true,
924 "source_data" => data,
930 follower_address: data["followers"],
934 # nickname can be nil because of virtual actors
936 if data["preferredUsername"] do
940 "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}"
943 Map.put(user_data, :nickname, nil)
949 def fetch_and_prepare_user_from_ap_id(ap_id) do
950 with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
951 user_data_from_user_object(data)
953 e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
957 def make_user_from_ap_id(ap_id) do
958 if _user = User.get_cached_by_ap_id(ap_id) do
959 Transmogrifier.upgrade_user_from_ap_id(ap_id)
961 with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do
962 User.insert_or_update_user(data)
969 def make_user_from_nickname(nickname) do
970 with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
971 make_user_from_ap_id(ap_id)
973 _e -> {:error, "No AP id in WebFinger"}
977 # filter out broken threads
978 def contain_broken_threads(%Activity{} = activity, %User{} = user) do
979 entire_thread_visible_for_user?(activity, user)
982 # do post-processing on a specific activity
983 def contain_activity(%Activity{} = activity, %User{} = user) do
984 contain_broken_threads(activity, user)
987 # do post-processing on a timeline
988 def contain_timeline(timeline, user) do
990 |> Enum.filter(fn activity ->
991 contain_activity(activity, user)