X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Factivity.ex;h=c94667fb9f177be171898c9b6b4d42766a9bb1a0;hb=8c86a06ed12d93b88894282be1b4c665ccf72bc2;hp=7e36c1b5343d40abb1f52377f962d0fc8774e6c8;hpb=99cc26bb02f2ac7ab26aa761ee5427406830a778;p=akkoma diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex index 7e36c1b53..c94667fb9 100644 --- a/lib/pleroma/activity.ex +++ b/lib/pleroma/activity.ex @@ -277,6 +277,13 @@ defmodule Pleroma.Activity do def get_create_by_object_ap_id_with_object(_), do: nil + def get_local_create_by_object_ap_id(ap_id) when is_binary(ap_id) do + ap_id + |> create_by_object_ap_id() + |> where(local: true) + |> Repo.one() + end + @spec create_by_id_with_object(String.t()) :: t() | nil def create_by_id_with_object(id) do get_by_id_with_opts(id, preload: [:object], filter: [type: "Create"]) @@ -292,7 +299,14 @@ defmodule Pleroma.Activity do get_in_reply_to_activity_from_object(Object.normalize(activity, fetch: false)) end - def normalize(obj) when is_map(obj), do: get_by_ap_id_with_object(obj["id"]) + def get_quoted_activity_from_object(%Object{data: %{"quoteUri" => ap_id}}) do + get_create_by_object_ap_id_with_object(ap_id) + end + + def get_quoted_activity_from_object(_), do: nil + + def normalize(%Activity{data: %{"id" => ap_id}}), do: get_by_ap_id_with_object(ap_id) + def normalize(%{"id" => ap_id}), do: get_by_ap_id_with_object(ap_id) def normalize(ap_id) when is_binary(ap_id), do: get_by_ap_id_with_object(ap_id) def normalize(_), do: nil @@ -301,7 +315,7 @@ defmodule Pleroma.Activity do |> Queries.by_object_id() |> Queries.exclude_type("Delete") |> select([u], u) - |> Repo.delete_all() + |> Repo.delete_all(timeout: :infinity) |> elem(1) |> Enum.find(fn %{data: %{"type" => "Create", "object" => ap_id}} when is_binary(ap_id) -> ap_id == id @@ -360,15 +374,27 @@ defmodule Pleroma.Activity do |> Repo.all() end - def restrict_deactivated_users(query) do - deactivated_users = - from(u in User.Query.build(%{deactivated: true}), select: u.ap_id) - |> Repo.all() + def follow_activity(%User{ap_id: ap_id}, %User{ap_id: followed_ap_id}) do + Queries.by_type("Follow") + |> where([a], a.actor == ^ap_id) + |> where([a], fragment("?->>'object' = ?", a.data, ^followed_ap_id)) + |> where([a], fragment("?->>'state'", a.data) in ["pending", "accept"]) + |> Repo.one() + end - Activity.Queries.exclude_authors(query, deactivated_users) + def restrict_deactivated_users(query) do + query + |> join( + :inner_lateral, + [activity], + active in fragment( + "SELECT is_active from users WHERE ap_id = ? AND is_active = TRUE", + activity.actor + ) + ) end - defdelegate search(user, query, options \\ []), to: Pleroma.Activity.Search + defdelegate search(user, query, options \\ []), to: Pleroma.Search.DatabaseSearch def direct_conversation_id(activity, for_user) do alias Pleroma.Conversation.Participation