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
30 actor = User.get_cached_by_ap_id(data["actor"])
34 |> Enum.filter(fn recipient ->
35 case User.get_cached_by_ap_id(recipient) do
40 User.following?(user, actor)
47 defp get_recipients(%{"type" => "Create"} = data) do
50 actor = data["actor"] || []
51 recipients = (to ++ cc ++ [actor]) |> Enum.uniq()
55 defp get_recipients(data) do
62 defp check_actor_is_active(actor) do
63 if not is_nil(actor) do
64 with user <- User.get_cached_by_ap_id(actor),
65 false <- user.info.deactivated do
75 defp check_remote_limit(%{"object" => %{"content" => content}}) when not is_nil(content) do
76 limit = Pleroma.Config.get([:instance, :remote_limit])
77 String.length(content) <= limit
80 defp check_remote_limit(_), do: true
82 def increase_note_count_if_public(actor, object) do
83 if is_public?(object), do: User.increase_note_count(actor), else: {:ok, actor}
86 def decrease_note_count_if_public(actor, object) do
87 if is_public?(object), do: User.decrease_note_count(actor), else: {:ok, actor}
90 def increase_replies_count_if_reply(%{
91 "object" => %{"inReplyTo" => reply_ap_id} = object,
94 if is_public?(object) do
95 Object.increase_replies_count(reply_ap_id)
99 def increase_replies_count_if_reply(_create_data), do: :noop
101 def decrease_replies_count_if_reply(%Object{
102 data: %{"inReplyTo" => reply_ap_id} = object
104 if is_public?(object) do
105 Object.decrease_replies_count(reply_ap_id)
109 def decrease_replies_count_if_reply(_object), do: :noop
111 def increase_poll_votes_if_vote(%{
112 "object" => %{"inReplyTo" => reply_ap_id, "name" => name},
115 Object.increase_vote_count(reply_ap_id, name)
118 def increase_poll_votes_if_vote(_create_data), do: :noop
120 def insert(map, local \\ true, fake \\ false) when is_map(map) do
121 with nil <- Activity.normalize(map),
122 map <- lazy_put_activity_defaults(map, fake),
123 :ok <- check_actor_is_active(map["actor"]),
124 {_, true} <- {:remote_limit_error, check_remote_limit(map)},
125 {:ok, map} <- MRF.filter(map),
126 {recipients, _, _} = get_recipients(map),
127 {:fake, false, map, recipients} <- {:fake, fake, map, recipients},
128 {:ok, map, object} <- insert_full_object(map) do
130 Repo.insert(%Activity{
134 recipients: recipients
137 # Splice in the child object if we have one.
139 if !is_nil(object) do
140 Map.put(activity, :object, object)
145 PleromaJobQueue.enqueue(:background, Pleroma.Web.RichMedia.Helpers, [:fetch, activity])
147 Notification.create_notifications(activity)
151 |> Conversation.create_or_bump_for()
152 |> get_participations()
155 stream_out_participations(participations)
158 %Activity{} = activity ->
161 {:fake, true, map, recipients} ->
162 activity = %Activity{
166 recipients: recipients,
170 Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
178 defp get_participations({:ok, %{participations: participations}}), do: participations
179 defp get_participations(_), do: []
181 def stream_out_participations(participations) do
184 |> Repo.preload(:user)
186 Enum.each(participations, fn participation ->
187 Pleroma.Web.Streamer.stream("participation", participation)
191 def stream_out(activity) do
192 public = "https://www.w3.org/ns/activitystreams#Public"
194 if activity.data["type"] in ["Create", "Announce", "Delete"] do
195 object = Object.normalize(activity)
196 # Do not stream out poll replies
197 unless object.data["type"] == "Answer" do
198 Pleroma.Web.Streamer.stream("user", activity)
199 Pleroma.Web.Streamer.stream("list", activity)
201 if Enum.member?(activity.data["to"], public) do
202 Pleroma.Web.Streamer.stream("public", activity)
205 Pleroma.Web.Streamer.stream("public:local", activity)
208 if activity.data["type"] in ["Create"] do
210 |> Map.get("tag", [])
211 |> Enum.filter(fn tag -> is_bitstring(tag) end)
212 |> Enum.each(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end)
214 if object.data["attachment"] != [] do
215 Pleroma.Web.Streamer.stream("public:media", activity)
218 Pleroma.Web.Streamer.stream("public:local:media", activity)
223 # TODO: Write test, replace with visibility test
224 if !Enum.member?(activity.data["cc"] || [], public) &&
227 User.get_cached_by_ap_id(activity.data["actor"]).follower_address
229 do: Pleroma.Web.Streamer.stream("direct", activity)
235 def create(%{to: to, actor: actor, context: context, object: object} = params, fake \\ false) do
236 additional = params[:additional] || %{}
237 # only accept false as false value
238 local = !(params[:local] == false)
239 published = params[:published]
243 %{to: to, actor: actor, published: published, context: context, object: object},
246 {:ok, activity} <- insert(create_data, local, fake),
247 {:fake, false, activity} <- {:fake, fake, activity},
248 _ <- increase_replies_count_if_reply(create_data),
249 _ <- increase_poll_votes_if_vote(create_data),
250 # Changing note count prior to enqueuing federation task in order to avoid
251 # race conditions on updating user.info
252 {:ok, _actor} <- increase_note_count_if_public(actor, activity),
253 :ok <- maybe_federate(activity) do
256 {:fake, true, activity} ->
261 def accept(%{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" => "Accept", "actor" => actor.ap_id, "object" => object},
266 {:ok, activity} <- insert(data, local),
267 :ok <- maybe_federate(activity) do
272 def reject(%{to: to, actor: actor, object: object} = params) do
273 # only accept false as false value
274 local = !(params[:local] == false)
276 with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object},
277 {:ok, activity} <- insert(data, local),
278 :ok <- maybe_federate(activity) do
283 def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
284 # only accept false as false value
285 local = !(params[:local] == false)
294 {:ok, activity} <- insert(data, local),
295 :ok <- maybe_federate(activity) do
300 # TODO: This is weird, maybe we shouldn't check here if we can make the activity.
302 %User{ap_id: ap_id} = user,
303 %Object{data: %{"id" => _}} = object,
307 with nil <- get_existing_like(ap_id, object),
308 like_data <- make_like_data(user, object, activity_id),
309 {:ok, activity} <- insert(like_data, local),
310 {:ok, object} <- add_like_to_object(activity, object),
311 :ok <- maybe_federate(activity) do
312 {:ok, activity, object}
314 %Activity{} = activity -> {:ok, activity, object}
315 error -> {:error, error}
325 with %Activity{} = like_activity <- get_existing_like(actor.ap_id, object),
326 unlike_data <- make_unlike_data(actor, like_activity, activity_id),
327 {:ok, unlike_activity} <- insert(unlike_data, local),
328 {:ok, _activity} <- Repo.delete(like_activity),
329 {:ok, object} <- remove_like_from_object(like_activity, object),
330 :ok <- maybe_federate(unlike_activity) do
331 {:ok, unlike_activity, like_activity, object}
338 %User{ap_id: _} = user,
339 %Object{data: %{"id" => _}} = object,
344 with true <- is_public?(object),
345 announce_data <- make_announce_data(user, object, activity_id, public),
346 {:ok, activity} <- insert(announce_data, local),
347 {:ok, object} <- add_announce_to_object(activity, object),
348 :ok <- maybe_federate(activity) do
349 {:ok, activity, object}
351 error -> {:error, error}
361 with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object),
362 unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id),
363 {:ok, unannounce_activity} <- insert(unannounce_data, local),
364 :ok <- maybe_federate(unannounce_activity),
365 {:ok, _activity} <- Repo.delete(announce_activity),
366 {:ok, object} <- remove_announce_from_object(announce_activity, object) do
367 {:ok, unannounce_activity, object}
373 def follow(follower, followed, activity_id \\ nil, local \\ true) do
374 with data <- make_follow_data(follower, followed, activity_id),
375 {:ok, activity} <- insert(data, local),
376 :ok <- maybe_federate(activity) do
381 def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
382 with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
383 {:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
384 unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
385 {:ok, activity} <- insert(unfollow_data, local),
386 :ok <- maybe_federate(activity) do
391 def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
392 user = User.get_cached_by_ap_id(actor)
393 to = (object.data["to"] || []) ++ (object.data["cc"] || [])
395 with {:ok, object, activity} <- Object.delete(object),
401 "deleted_activity_id" => activity && activity.id
403 {:ok, activity} <- insert(data, local),
404 _ <- decrease_replies_count_if_reply(object),
405 # Changing note count prior to enqueuing federation task in order to avoid
406 # race conditions on updating user.info
407 {:ok, _actor} <- decrease_note_count_if_public(user, object),
408 :ok <- maybe_federate(activity) do
413 def block(blocker, blocked, activity_id \\ nil, local \\ true) do
414 ap_config = Application.get_env(:pleroma, :activitypub)
415 unfollow_blocked = Keyword.get(ap_config, :unfollow_blocked)
416 outgoing_blocks = Keyword.get(ap_config, :outgoing_blocks)
418 with true <- unfollow_blocked do
419 follow_activity = fetch_latest_follow(blocker, blocked)
421 if follow_activity do
422 unfollow(blocker, blocked, nil, local)
426 with true <- outgoing_blocks,
427 block_data <- make_block_data(blocker, blocked, activity_id),
428 {:ok, activity} <- insert(block_data, local),
429 :ok <- maybe_federate(activity) do
436 def unblock(blocker, blocked, activity_id \\ nil, local \\ true) do
437 with %Activity{} = block_activity <- fetch_latest_block(blocker, blocked),
438 unblock_data <- make_unblock_data(blocker, blocked, block_activity, activity_id),
439 {:ok, activity} <- insert(unblock_data, local),
440 :ok <- maybe_federate(activity) do
454 # only accept false as false value
455 local = !(params[:local] == false)
456 forward = !(params[:forward] == false)
458 additional = params[:additional] || %{}
470 Map.merge(additional, %{"to" => [], "cc" => [account.ap_id]})
472 Map.merge(additional, %{"to" => [], "cc" => []})
475 with flag_data <- make_flag_data(params, additional),
476 {:ok, activity} <- insert(flag_data, local),
477 :ok <- maybe_federate(activity) do
478 Enum.each(User.all_superusers(), fn superuser ->
480 |> Pleroma.Emails.AdminEmail.report(actor, account, statuses, content)
481 |> Pleroma.Emails.Mailer.deliver_async()
488 defp fetch_activities_for_context_query(context, opts) do
489 public = ["https://www.w3.org/ns/activitystreams#Public"]
492 if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
494 from(activity in Activity)
495 |> maybe_preload_objects(opts)
496 |> exclude_poll_votes(opts)
497 |> restrict_blocked(opts)
498 |> restrict_recipients(recipients, opts["user"])
502 "?->>'type' = ? and ?->>'context' = ?",
509 |> order_by([activity], desc: activity.id)
512 @spec fetch_activities_for_context(String.t(), keyword() | map()) :: [Activity.t()]
513 def fetch_activities_for_context(context, opts \\ %{}) do
515 |> fetch_activities_for_context_query(opts)
519 @spec fetch_latest_activity_id_for_context(String.t(), keyword() | map()) ::
520 Pleroma.FlakeId.t() | nil
521 def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
523 |> fetch_activities_for_context_query(Map.merge(%{"skip_preload" => true}, opts))
529 def fetch_public_activities(opts \\ %{}) do
530 q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts)
533 |> restrict_unlisted()
534 |> Pagination.fetch_paginated(opts)
538 @valid_visibilities ~w[direct unlisted public private]
540 defp restrict_visibility(query, %{visibility: visibility})
541 when is_list(visibility) do
542 if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
548 "activity_visibility(?, ?, ?) = ANY (?)",
558 Logger.error("Could not restrict visibility to #{visibility}")
562 defp restrict_visibility(query, %{visibility: visibility})
563 when visibility in @valid_visibilities do
568 fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility)
574 defp restrict_visibility(_query, %{visibility: visibility})
575 when visibility not in @valid_visibilities do
576 Logger.error("Could not restrict visibility to #{visibility}")
579 defp restrict_visibility(query, _visibility), do: query
581 defp restrict_thread_visibility(query, %{"user" => %User{ap_id: ap_id}}) do
585 where: fragment("thread_visibility(?, (?)->>'id') = true", ^ap_id, a.data)
591 defp restrict_thread_visibility(query, _), do: query
593 def fetch_user_activities(user, reading_user, params \\ %{}) do
596 |> Map.put("type", ["Create", "Announce"])
597 |> Map.put("actor_id", user.ap_id)
598 |> Map.put("whole_db", true)
599 |> Map.put("pinned_activity_ids", user.info.pinned_activities)
603 ["https://www.w3.org/ns/activitystreams#Public"] ++
604 [reading_user.ap_id | reading_user.following]
606 ["https://www.w3.org/ns/activitystreams#Public"]
609 fetch_activities(recipients, params)
613 defp restrict_since(query, %{"since_id" => ""}), do: query
615 defp restrict_since(query, %{"since_id" => since_id}) do
616 from(activity in query, where: activity.id > ^since_id)
619 defp restrict_since(query, _), do: query
621 defp restrict_tag_reject(_query, %{"tag_reject" => _tag_reject, "skip_preload" => true}) do
622 raise "Can't use the child object without preloading!"
625 defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
626 when is_list(tag_reject) and tag_reject != [] do
628 [_activity, object] in query,
629 where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
633 defp restrict_tag_reject(query, _), do: query
635 defp restrict_tag_all(_query, %{"tag_all" => _tag_all, "skip_preload" => true}) do
636 raise "Can't use the child object without preloading!"
639 defp restrict_tag_all(query, %{"tag_all" => tag_all})
640 when is_list(tag_all) and tag_all != [] do
642 [_activity, object] in query,
643 where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
647 defp restrict_tag_all(query, _), do: query
649 defp restrict_tag(_query, %{"tag" => _tag, "skip_preload" => true}) do
650 raise "Can't use the child object without preloading!"
653 defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
655 [_activity, object] in query,
656 where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
660 defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
662 [_activity, object] in query,
663 where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
667 defp restrict_tag(query, _), do: query
669 defp restrict_to_cc(query, recipients_to, recipients_cc) do
674 "(?->'to' \\?| ?) or (?->'cc' \\?| ?)",
683 defp restrict_recipients(query, [], _user), do: query
685 defp restrict_recipients(query, recipients, nil) do
686 from(activity in query, where: fragment("? && ?", ^recipients, activity.recipients))
689 defp restrict_recipients(query, recipients, user) do
692 where: fragment("? && ?", ^recipients, activity.recipients),
693 or_where: activity.actor == ^user.ap_id
697 defp restrict_local(query, %{"local_only" => true}) do
698 from(activity in query, where: activity.local == true)
701 defp restrict_local(query, _), do: query
703 defp restrict_actor(query, %{"actor_id" => actor_id}) do
704 from(activity in query, where: activity.actor == ^actor_id)
707 defp restrict_actor(query, _), do: query
709 defp restrict_type(query, %{"type" => type}) when is_binary(type) do
710 from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type))
713 defp restrict_type(query, %{"type" => type}) do
714 from(activity in query, where: fragment("?->>'type' = ANY(?)", activity.data, ^type))
717 defp restrict_type(query, _), do: query
719 defp restrict_state(query, %{"state" => state}) do
720 from(activity in query, where: fragment("?->>'state' = ?", activity.data, ^state))
723 defp restrict_state(query, _), do: query
725 defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
728 where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data)
732 defp restrict_favorited_by(query, _), do: query
734 defp restrict_media(_query, %{"only_media" => _val, "skip_preload" => true}) do
735 raise "Can't use the child object without preloading!"
738 defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
740 [_activity, object] in query,
741 where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
745 defp restrict_media(query, _), do: query
747 defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
750 where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
754 defp restrict_replies(query, _), do: query
756 defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val == "true" or val == "1" do
757 from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data))
760 defp restrict_reblogs(query, _), do: query
762 defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
764 defp restrict_muted(query, %{"muting_user" => %User{info: info}}) do
769 where: fragment("not (? = ANY(?))", activity.actor, ^mutes),
770 where: fragment("not (?->'to' \\?| ?)", activity.data, ^mutes)
774 defp restrict_muted(query, _), do: query
776 defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
777 blocks = info.blocks || []
778 domain_blocks = info.domain_blocks || []
781 if has_named_binding?(query, :object), do: query, else: Activity.with_joined_object(query)
784 [activity, object: o] in query,
785 where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
786 where: fragment("not (? && ?)", activity.recipients, ^blocks),
789 "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
794 where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks),
795 where: fragment("not (split_part(?->>'actor', '/', 3) = ANY(?))", o.data, ^domain_blocks)
799 defp restrict_blocked(query, _), do: query
801 defp restrict_unlisted(query) do
806 "not (coalesce(?->'cc', '{}'::jsonb) \\?| ?)",
808 ^["https://www.w3.org/ns/activitystreams#Public"]
813 defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids}) do
814 from(activity in query, where: activity.id in ^ids)
817 defp restrict_pinned(query, _), do: query
819 defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
820 muted_reblogs = info.muted_reblogs || []
826 "not ( ?->>'type' = 'Announce' and ? = ANY(?))",
834 defp restrict_muted_reblogs(query, _), do: query
836 defp exclude_poll_votes(query, %{"include_poll_votes" => "true"}), do: query
838 defp exclude_poll_votes(query, _) do
839 if has_named_binding?(query, :object) do
840 from([activity, object: o] in query,
841 where: fragment("not(?->>'type' = ?)", o.data, "Answer")
848 defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
850 defp maybe_preload_objects(query, _) do
852 |> Activity.with_preloaded_object()
855 defp maybe_preload_bookmarks(query, %{"skip_preload" => true}), do: query
857 defp maybe_preload_bookmarks(query, opts) do
859 |> Activity.with_preloaded_bookmark(opts["user"])
862 defp maybe_order(query, %{order: :desc}) do
864 |> order_by(desc: :id)
867 defp maybe_order(query, %{order: :asc}) do
869 |> order_by(asc: :id)
872 defp maybe_order(query, _), do: query
874 def fetch_activities_query(recipients, opts \\ %{}) do
875 base_query = from(activity in Activity)
878 |> maybe_preload_objects(opts)
879 |> maybe_preload_bookmarks(opts)
881 |> exclude_poll_votes(opts)
882 |> restrict_recipients(recipients, opts["user"])
883 |> restrict_tag(opts)
884 |> restrict_tag_reject(opts)
885 |> restrict_tag_all(opts)
886 |> restrict_since(opts)
887 |> restrict_local(opts)
888 |> restrict_actor(opts)
889 |> restrict_type(opts)
890 |> restrict_state(opts)
891 |> restrict_favorited_by(opts)
892 |> restrict_blocked(opts)
893 |> restrict_muted(opts)
894 |> restrict_media(opts)
895 |> restrict_visibility(opts)
896 |> restrict_thread_visibility(opts)
897 |> restrict_replies(opts)
898 |> restrict_reblogs(opts)
899 |> restrict_pinned(opts)
900 |> restrict_muted_reblogs(opts)
901 |> Activity.restrict_deactivated_users()
904 def fetch_activities(recipients, opts \\ %{}) do
905 fetch_activities_query(recipients, opts)
906 |> Pagination.fetch_paginated(opts)
910 def fetch_activities_bounded(recipients_to, recipients_cc, opts \\ %{}) do
911 fetch_activities_query([], opts)
912 |> restrict_to_cc(recipients_to, recipients_cc)
913 |> Pagination.fetch_paginated(opts)
917 def upload(file, opts \\ []) do
918 with {:ok, data} <- Upload.store(file, opts) do
921 Map.put(data, "actor", opts[:actor])
926 Repo.insert(%Object{data: obj_data})
930 def user_data_from_user_object(data) do
932 data["icon"]["url"] &&
935 "url" => [%{"href" => data["icon"]["url"]}]
939 data["image"]["url"] &&
942 "url" => [%{"href" => data["image"]["url"]}]
945 locked = data["manuallyApprovesFollowers"] || false
946 data = Transmogrifier.maybe_fix_user_object(data)
951 "ap_enabled" => true,
952 "source_data" => data,
958 follower_address: data["followers"],
962 # nickname can be nil because of virtual actors
964 if data["preferredUsername"] do
968 "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}"
971 Map.put(user_data, :nickname, nil)
977 def fetch_and_prepare_user_from_ap_id(ap_id) do
978 with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
979 user_data_from_user_object(data)
981 e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
985 def make_user_from_ap_id(ap_id) do
986 if _user = User.get_cached_by_ap_id(ap_id) do
987 Transmogrifier.upgrade_user_from_ap_id(ap_id)
989 with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do
990 User.insert_or_update_user(data)
997 def make_user_from_nickname(nickname) do
998 with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
999 make_user_from_ap_id(ap_id)
1001 _e -> {:error, "No AP id in WebFinger"}
1005 # filter out broken threads
1006 def contain_broken_threads(%Activity{} = activity, %User{} = user) do
1007 entire_thread_visible_for_user?(activity, user)
1010 # do post-processing on a specific activity
1011 def contain_activity(%Activity{} = activity, %User{} = user) do
1012 contain_broken_threads(activity, user)
1015 def fetch_direct_messages_query do
1017 |> restrict_type(%{"type" => "Create"})
1018 |> restrict_visibility(%{visibility: "direct"})
1019 |> order_by([activity], asc: activity.id)