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 Pleroma.Web.Streamer.stream("user", activity)
196 Pleroma.Web.Streamer.stream("list", activity)
198 if Enum.member?(activity.data["to"], public) do
199 Pleroma.Web.Streamer.stream("public", activity)
202 Pleroma.Web.Streamer.stream("public:local", activity)
205 if activity.data["type"] in ["Create"] do
206 object = Object.normalize(activity)
209 |> Map.get("tag", [])
210 |> Enum.filter(fn tag -> is_bitstring(tag) end)
211 |> Enum.each(fn tag -> Pleroma.Web.Streamer.stream("hashtag:" <> tag, activity) end)
213 if object.data["attachment"] != [] do
214 Pleroma.Web.Streamer.stream("public:media", activity)
217 Pleroma.Web.Streamer.stream("public:local:media", activity)
222 # TODO: Write test, replace with visibility test
223 if !Enum.member?(activity.data["cc"] || [], public) &&
226 User.get_cached_by_ap_id(activity.data["actor"]).follower_address
228 do: Pleroma.Web.Streamer.stream("direct", activity)
233 def create(%{to: to, actor: actor, context: context, object: object} = params, fake \\ false) do
234 additional = params[:additional] || %{}
235 # only accept false as false value
236 local = !(params[:local] == false)
237 published = params[:published]
241 %{to: to, actor: actor, published: published, context: context, object: object},
244 {:ok, activity} <- insert(create_data, local, fake),
245 {:fake, false, activity} <- {:fake, fake, activity},
246 _ <- increase_replies_count_if_reply(create_data),
247 _ <- increase_poll_votes_if_vote(create_data),
248 # Changing note count prior to enqueuing federation task in order to avoid
249 # race conditions on updating user.info
250 {:ok, _actor} <- increase_note_count_if_public(actor, activity),
251 :ok <- maybe_federate(activity) do
254 {:fake, true, activity} ->
259 def accept(%{to: to, actor: actor, object: object} = params) do
260 # only accept false as false value
261 local = !(params[:local] == false)
263 with data <- %{"to" => to, "type" => "Accept", "actor" => actor.ap_id, "object" => object},
264 {:ok, activity} <- insert(data, local),
265 :ok <- maybe_federate(activity) do
270 def reject(%{to: to, actor: actor, object: object} = params) do
271 # only accept false as false value
272 local = !(params[:local] == false)
274 with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object},
275 {:ok, activity} <- insert(data, local),
276 :ok <- maybe_federate(activity) do
281 def update(%{to: to, cc: cc, actor: actor, object: object} = params) do
282 # only accept false as false value
283 local = !(params[:local] == false)
292 {:ok, activity} <- insert(data, local),
293 :ok <- maybe_federate(activity) do
298 # TODO: This is weird, maybe we shouldn't check here if we can make the activity.
300 %User{ap_id: ap_id} = user,
301 %Object{data: %{"id" => _}} = object,
305 with nil <- get_existing_like(ap_id, object),
306 like_data <- make_like_data(user, object, activity_id),
307 {:ok, activity} <- insert(like_data, local),
308 {:ok, object} <- add_like_to_object(activity, object),
309 :ok <- maybe_federate(activity) do
310 {:ok, activity, object}
312 %Activity{} = activity -> {:ok, activity, object}
313 error -> {:error, error}
323 with %Activity{} = like_activity <- get_existing_like(actor.ap_id, object),
324 unlike_data <- make_unlike_data(actor, like_activity, activity_id),
325 {:ok, unlike_activity} <- insert(unlike_data, local),
326 {:ok, _activity} <- Repo.delete(like_activity),
327 {:ok, object} <- remove_like_from_object(like_activity, object),
328 :ok <- maybe_federate(unlike_activity) do
329 {:ok, unlike_activity, like_activity, object}
336 %User{ap_id: _} = user,
337 %Object{data: %{"id" => _}} = object,
342 with true <- is_public?(object),
343 announce_data <- make_announce_data(user, object, activity_id, public),
344 {:ok, activity} <- insert(announce_data, local),
345 {:ok, object} <- add_announce_to_object(activity, object),
346 :ok <- maybe_federate(activity) do
347 {:ok, activity, object}
349 error -> {:error, error}
359 with %Activity{} = announce_activity <- get_existing_announce(actor.ap_id, object),
360 unannounce_data <- make_unannounce_data(actor, announce_activity, activity_id),
361 {:ok, unannounce_activity} <- insert(unannounce_data, local),
362 :ok <- maybe_federate(unannounce_activity),
363 {:ok, _activity} <- Repo.delete(announce_activity),
364 {:ok, object} <- remove_announce_from_object(announce_activity, object) do
365 {:ok, unannounce_activity, object}
371 def follow(follower, followed, activity_id \\ nil, local \\ true) do
372 with data <- make_follow_data(follower, followed, activity_id),
373 {:ok, activity} <- insert(data, local),
374 :ok <- maybe_federate(activity) do
379 def unfollow(follower, followed, activity_id \\ nil, local \\ true) do
380 with %Activity{} = follow_activity <- fetch_latest_follow(follower, followed),
381 {:ok, follow_activity} <- update_follow_state(follow_activity, "cancelled"),
382 unfollow_data <- make_unfollow_data(follower, followed, follow_activity, activity_id),
383 {:ok, activity} <- insert(unfollow_data, local),
384 :ok <- maybe_federate(activity) do
389 def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
390 user = User.get_cached_by_ap_id(actor)
391 to = (object.data["to"] || []) ++ (object.data["cc"] || [])
393 with {:ok, object, activity} <- Object.delete(object),
399 "deleted_activity_id" => activity && activity.id
401 {:ok, activity} <- insert(data, local),
402 _ <- decrease_replies_count_if_reply(object),
403 # Changing note count prior to enqueuing federation task in order to avoid
404 # race conditions on updating user.info
405 {:ok, _actor} <- decrease_note_count_if_public(user, object),
406 :ok <- maybe_federate(activity) do
411 def block(blocker, blocked, activity_id \\ nil, local \\ true) do
412 ap_config = Application.get_env(:pleroma, :activitypub)
413 unfollow_blocked = Keyword.get(ap_config, :unfollow_blocked)
414 outgoing_blocks = Keyword.get(ap_config, :outgoing_blocks)
416 with true <- unfollow_blocked do
417 follow_activity = fetch_latest_follow(blocker, blocked)
419 if follow_activity do
420 unfollow(blocker, blocked, nil, local)
424 with true <- outgoing_blocks,
425 block_data <- make_block_data(blocker, blocked, activity_id),
426 {:ok, activity} <- insert(block_data, local),
427 :ok <- maybe_federate(activity) do
434 def unblock(blocker, blocked, activity_id \\ nil, local \\ true) do
435 with %Activity{} = block_activity <- fetch_latest_block(blocker, blocked),
436 unblock_data <- make_unblock_data(blocker, blocked, block_activity, activity_id),
437 {:ok, activity} <- insert(unblock_data, local),
438 :ok <- maybe_federate(activity) do
452 # only accept false as false value
453 local = !(params[:local] == false)
454 forward = !(params[:forward] == false)
456 additional = params[:additional] || %{}
468 Map.merge(additional, %{"to" => [], "cc" => [account.ap_id]})
470 Map.merge(additional, %{"to" => [], "cc" => []})
473 with flag_data <- make_flag_data(params, additional),
474 {:ok, activity} <- insert(flag_data, local),
475 :ok <- maybe_federate(activity) do
476 Enum.each(User.all_superusers(), fn superuser ->
478 |> Pleroma.Emails.AdminEmail.report(actor, account, statuses, content)
479 |> Pleroma.Emails.Mailer.deliver_async()
486 defp fetch_activities_for_context_query(context, opts) do
487 public = ["https://www.w3.org/ns/activitystreams#Public"]
490 if opts["user"], do: [opts["user"].ap_id | opts["user"].following] ++ public, else: public
492 from(activity in Activity)
493 |> restrict_blocked(opts)
494 |> restrict_poll_replies(opts)
495 |> restrict_recipients(recipients, opts["user"])
499 "?->>'type' = ? and ?->>'context' = ?",
506 |> order_by([activity], desc: activity.id)
509 @spec fetch_activities_for_context(String.t(), keyword() | map()) :: [Activity.t()]
510 def fetch_activities_for_context(context, opts \\ %{}) do
512 |> fetch_activities_for_context_query(opts)
513 |> Activity.with_preloaded_object()
517 @spec fetch_latest_activity_id_for_context(String.t(), keyword() | map()) ::
518 Pleroma.FlakeId.t() | nil
519 def fetch_latest_activity_id_for_context(context, opts \\ %{}) do
521 |> fetch_activities_for_context_query(opts)
527 def fetch_public_activities(opts \\ %{}) do
528 q = fetch_activities_query(["https://www.w3.org/ns/activitystreams#Public"], opts)
531 |> restrict_unlisted()
532 |> Pagination.fetch_paginated(opts)
536 @valid_visibilities ~w[direct unlisted public private]
538 defp restrict_visibility(query, %{visibility: visibility})
539 when is_list(visibility) do
540 if Enum.all?(visibility, &(&1 in @valid_visibilities)) do
546 "activity_visibility(?, ?, ?) = ANY (?)",
556 Logger.error("Could not restrict visibility to #{visibility}")
560 defp restrict_visibility(query, %{visibility: visibility})
561 when visibility in @valid_visibilities do
566 fragment("activity_visibility(?, ?, ?) = ?", a.actor, a.recipients, a.data, ^visibility)
572 defp restrict_visibility(_query, %{visibility: visibility})
573 when visibility not in @valid_visibilities do
574 Logger.error("Could not restrict visibility to #{visibility}")
577 defp restrict_visibility(query, _visibility), do: query
579 defp restrict_thread_visibility(query, %{"user" => %User{ap_id: ap_id}}) do
583 where: fragment("thread_visibility(?, (?)->>'id') = true", ^ap_id, a.data)
589 defp restrict_thread_visibility(query, _), do: query
591 def fetch_user_activities(user, reading_user, params \\ %{}) do
594 |> Map.put("type", ["Create", "Announce"])
595 |> Map.put("actor_id", user.ap_id)
596 |> Map.put("whole_db", true)
597 |> Map.put("pinned_activity_ids", user.info.pinned_activities)
601 ["https://www.w3.org/ns/activitystreams#Public"] ++
602 [reading_user.ap_id | reading_user.following]
604 ["https://www.w3.org/ns/activitystreams#Public"]
607 fetch_activities(recipients, params)
611 defp restrict_since(query, %{"since_id" => ""}), do: query
613 defp restrict_since(query, %{"since_id" => since_id}) do
614 from(activity in query, where: activity.id > ^since_id)
617 defp restrict_since(query, _), do: query
619 defp restrict_tag_reject(_query, %{"tag_reject" => _tag_reject, "skip_preload" => true}) do
620 raise "Can't use the child object without preloading!"
623 defp restrict_tag_reject(query, %{"tag_reject" => tag_reject})
624 when is_list(tag_reject) and tag_reject != [] do
626 [_activity, object] in query,
627 where: fragment("not (?)->'tag' \\?| (?)", object.data, ^tag_reject)
631 defp restrict_tag_reject(query, _), do: query
633 defp restrict_tag_all(_query, %{"tag_all" => _tag_all, "skip_preload" => true}) do
634 raise "Can't use the child object without preloading!"
637 defp restrict_tag_all(query, %{"tag_all" => tag_all})
638 when is_list(tag_all) and tag_all != [] do
640 [_activity, object] in query,
641 where: fragment("(?)->'tag' \\?& (?)", object.data, ^tag_all)
645 defp restrict_tag_all(query, _), do: query
647 defp restrict_tag(_query, %{"tag" => _tag, "skip_preload" => true}) do
648 raise "Can't use the child object without preloading!"
651 defp restrict_tag(query, %{"tag" => tag}) when is_list(tag) do
653 [_activity, object] in query,
654 where: fragment("(?)->'tag' \\?| (?)", object.data, ^tag)
658 defp restrict_tag(query, %{"tag" => tag}) when is_binary(tag) do
660 [_activity, object] in query,
661 where: fragment("(?)->'tag' \\? (?)", object.data, ^tag)
665 defp restrict_tag(query, _), do: query
667 defp restrict_to_cc(query, recipients_to, recipients_cc) do
672 "(?->'to' \\?| ?) or (?->'cc' \\?| ?)",
681 defp restrict_recipients(query, [], _user), do: query
683 defp restrict_recipients(query, recipients, nil) do
684 from(activity in query, where: fragment("? && ?", ^recipients, activity.recipients))
687 defp restrict_recipients(query, recipients, user) do
690 where: fragment("? && ?", ^recipients, activity.recipients),
691 or_where: activity.actor == ^user.ap_id
695 defp restrict_local(query, %{"local_only" => true}) do
696 from(activity in query, where: activity.local == true)
699 defp restrict_local(query, _), do: query
701 defp restrict_actor(query, %{"actor_id" => actor_id}) do
702 from(activity in query, where: activity.actor == ^actor_id)
705 defp restrict_actor(query, _), do: query
707 defp restrict_type(query, %{"type" => type}) when is_binary(type) do
708 from(activity in query, where: fragment("?->>'type' = ?", activity.data, ^type))
711 defp restrict_type(query, %{"type" => type}) do
712 from(activity in query, where: fragment("?->>'type' = ANY(?)", activity.data, ^type))
715 defp restrict_type(query, _), do: query
717 defp restrict_state(query, %{"state" => state}) do
718 from(activity in query, where: fragment("?->>'state' = ?", activity.data, ^state))
721 defp restrict_state(query, _), do: query
723 defp restrict_favorited_by(query, %{"favorited_by" => ap_id}) do
726 where: fragment(~s(? <@ (? #> '{"object","likes"}'\)), ^ap_id, activity.data)
730 defp restrict_favorited_by(query, _), do: query
732 defp restrict_media(_query, %{"only_media" => _val, "skip_preload" => true}) do
733 raise "Can't use the child object without preloading!"
736 defp restrict_media(query, %{"only_media" => val}) when val == "true" or val == "1" do
738 [_activity, object] in query,
739 where: fragment("not (?)->'attachment' = (?)", object.data, ^[])
743 defp restrict_media(query, _), do: query
745 defp restrict_replies(query, %{"exclude_replies" => val}) when val == "true" or val == "1" do
748 where: fragment("?->'object'->>'inReplyTo' is null", activity.data)
752 defp restrict_replies(query, _), do: query
754 defp restrict_reblogs(query, %{"exclude_reblogs" => val}) when val == "true" or val == "1" do
755 from(activity in query, where: fragment("?->>'type' != 'Announce'", activity.data))
758 defp restrict_reblogs(query, _), do: query
760 defp restrict_muted(query, %{"with_muted" => val}) when val in [true, "true", "1"], do: query
762 defp restrict_muted(query, %{"muting_user" => %User{info: info}}) do
767 where: fragment("not (? = ANY(?))", activity.actor, ^mutes),
768 where: fragment("not (?->'to' \\?| ?)", activity.data, ^mutes)
772 defp restrict_muted(query, _), do: query
774 defp restrict_blocked(query, %{"blocking_user" => %User{info: info}}) do
775 blocks = info.blocks || []
776 domain_blocks = info.domain_blocks || []
779 if has_named_binding?(query, :object), do: query, else: Activity.with_joined_object(query)
782 [activity, object: o] in query,
783 where: fragment("not (? = ANY(?))", activity.actor, ^blocks),
784 where: fragment("not (? && ?)", activity.recipients, ^blocks),
787 "not (?->>'type' = 'Announce' and ?->'to' \\?| ?)",
792 where: fragment("not (split_part(?, '/', 3) = ANY(?))", activity.actor, ^domain_blocks),
793 where: fragment("not (split_part(?->>'actor', '/', 3) = ANY(?))", o.data, ^domain_blocks)
797 defp restrict_blocked(query, _), do: query
799 defp restrict_unlisted(query) do
804 "not (coalesce(?->'cc', '{}'::jsonb) \\?| ?)",
806 ^["https://www.w3.org/ns/activitystreams#Public"]
811 defp restrict_pinned(query, %{"pinned" => "true", "pinned_activity_ids" => ids}) do
812 from(activity in query, where: activity.id in ^ids)
815 defp restrict_pinned(query, _), do: query
817 defp restrict_muted_reblogs(query, %{"muting_user" => %User{info: info}}) do
818 muted_reblogs = info.muted_reblogs || []
824 "not ( ?->>'type' = 'Announce' and ? = ANY(?))",
832 defp restrict_muted_reblogs(query, _), do: query
834 defp restrict_poll_replies(query, %{"include_poll_replies" => "true"}), do: query
836 defp restrict_poll_replies(query, _) do
837 if has_named_binding?(query, :object) do
838 from([activity, object: o] in query, where: fragment("?->'name' is null", o.data))
844 defp maybe_preload_objects(query, %{"skip_preload" => true}), do: query
846 defp maybe_preload_objects(query, _) do
848 |> Activity.with_preloaded_object()
851 defp maybe_preload_bookmarks(query, %{"skip_preload" => true}), do: query
853 defp maybe_preload_bookmarks(query, opts) do
855 |> Activity.with_preloaded_bookmark(opts["user"])
858 defp maybe_order(query, %{order: :desc}) do
860 |> order_by(desc: :id)
863 defp maybe_order(query, %{order: :asc}) do
865 |> order_by(asc: :id)
868 defp maybe_order(query, _), do: query
870 def fetch_activities_query(recipients, opts \\ %{}) do
871 base_query = from(activity in Activity)
874 |> maybe_preload_objects(opts)
875 |> maybe_preload_bookmarks(opts)
877 |> restrict_recipients(recipients, opts["user"])
878 |> restrict_tag(opts)
879 |> restrict_tag_reject(opts)
880 |> restrict_tag_all(opts)
881 |> restrict_since(opts)
882 |> restrict_local(opts)
883 |> restrict_actor(opts)
884 |> restrict_type(opts)
885 |> restrict_state(opts)
886 |> restrict_favorited_by(opts)
887 |> restrict_blocked(opts)
888 |> restrict_muted(opts)
889 |> restrict_media(opts)
890 |> restrict_visibility(opts)
891 |> restrict_thread_visibility(opts)
892 |> restrict_replies(opts)
893 |> restrict_reblogs(opts)
894 |> restrict_pinned(opts)
895 |> restrict_muted_reblogs(opts)
896 |> Activity.restrict_deactivated_users()
897 |> restrict_poll_replies(opts)
900 def fetch_activities(recipients, opts \\ %{}) do
901 fetch_activities_query(recipients, opts)
902 |> Pagination.fetch_paginated(opts)
906 def fetch_activities_bounded(recipients_to, recipients_cc, opts \\ %{}) do
907 fetch_activities_query([], opts)
908 |> restrict_to_cc(recipients_to, recipients_cc)
909 |> Pagination.fetch_paginated(opts)
913 def upload(file, opts \\ []) do
914 with {:ok, data} <- Upload.store(file, opts) do
917 Map.put(data, "actor", opts[:actor])
922 Repo.insert(%Object{data: obj_data})
926 def user_data_from_user_object(data) do
928 data["icon"]["url"] &&
931 "url" => [%{"href" => data["icon"]["url"]}]
935 data["image"]["url"] &&
938 "url" => [%{"href" => data["image"]["url"]}]
941 locked = data["manuallyApprovesFollowers"] || false
942 data = Transmogrifier.maybe_fix_user_object(data)
947 "ap_enabled" => true,
948 "source_data" => data,
954 follower_address: data["followers"],
958 # nickname can be nil because of virtual actors
960 if data["preferredUsername"] do
964 "#{data["preferredUsername"]}@#{URI.parse(data["id"]).host}"
967 Map.put(user_data, :nickname, nil)
973 def fetch_and_prepare_user_from_ap_id(ap_id) do
974 with {:ok, data} <- Fetcher.fetch_and_contain_remote_object_from_id(ap_id) do
975 user_data_from_user_object(data)
977 e -> Logger.error("Could not decode user at fetch #{ap_id}, #{inspect(e)}")
981 def make_user_from_ap_id(ap_id) do
982 if _user = User.get_cached_by_ap_id(ap_id) do
983 Transmogrifier.upgrade_user_from_ap_id(ap_id)
985 with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do
986 User.insert_or_update_user(data)
993 def make_user_from_nickname(nickname) do
994 with {:ok, %{"ap_id" => ap_id}} when not is_nil(ap_id) <- WebFinger.finger(nickname) do
995 make_user_from_ap_id(ap_id)
997 _e -> {:error, "No AP id in WebFinger"}
1001 # filter out broken threads
1002 def contain_broken_threads(%Activity{} = activity, %User{} = user) do
1003 entire_thread_visible_for_user?(activity, user)
1006 # do post-processing on a specific activity
1007 def contain_activity(%Activity{} = activity, %User{} = user) do
1008 contain_broken_threads(activity, user)
1011 def fetch_direct_messages_query do
1013 |> restrict_type(%{"type" => "Create"})
1014 |> restrict_visibility(%{visibility: "direct"})
1015 |> order_by([activity], asc: activity.id)