X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Factivity.ex;h=b0f1a900d78cfa26390e5ad2972cfa169aa89851;hb=778010ef8e1f4509bd554e65556336e5e8457ef6;hp=17af042573f22ccad27cbf29d4d87e7d149f9541;hpb=c5830ac037c0c344bd22b674c41f4dc244a088aa;p=akkoma
diff --git a/lib/pleroma/activity.ex b/lib/pleroma/activity.ex
index 17af04257..b0f1a900d 100644
--- a/lib/pleroma/activity.ex
+++ b/lib/pleroma/activity.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Activity do
@@ -14,6 +14,7 @@ defmodule Pleroma.Activity do
alias Pleroma.ReportNote
alias Pleroma.ThreadMute
alias Pleroma.User
+ alias Pleroma.Web.ActivityPub.ActivityPub
import Ecto.Changeset
import Ecto.Query
@@ -23,6 +24,8 @@ defmodule Pleroma.Activity do
@primary_key {:id, FlakeId.Ecto.CompatType, autogenerate: true}
+ @cachex Pleroma.Config.get([:cachex, :provider], Cachex)
+
schema "activities" do
field(:data, :map)
field(:local, :boolean, default: true)
@@ -110,6 +113,7 @@ defmodule Pleroma.Activity do
from([a] in query,
left_join: b in Bookmark,
on: b.user_id == ^user.id and b.activity_id == a.id,
+ as: :bookmark,
preload: [bookmark: b]
)
end
@@ -120,6 +124,7 @@ defmodule Pleroma.Activity do
from([a] in query,
left_join: r in ReportNote,
on: a.id == r.activity_id,
+ as: :report_note,
preload: [report_notes: r]
)
end
@@ -153,6 +158,18 @@ defmodule Pleroma.Activity do
def get_bookmark(_, _), do: nil
+ def get_report(activity_id) do
+ opts = %{
+ type: "Flag",
+ skip_preload: true,
+ preload_report_notes: true
+ }
+
+ ActivityPub.fetch_activities_query([], opts)
+ |> where(id: ^activity_id)
+ |> Repo.one()
+ end
+
def change(struct, params \\ %{}) do
struct
|> cast(params, [:data, :recipients])
@@ -181,6 +198,19 @@ defmodule Pleroma.Activity do
end
end
+ def get_by_id_with_user_actor(id) do
+ case FlakeId.flake_id?(id) do
+ true ->
+ Activity
+ |> where([a], a.id == ^id)
+ |> with_preloaded_user_actor()
+ |> Repo.one()
+
+ _ ->
+ nil
+ end
+ end
+
def get_by_id_with_object(id) do
Activity
|> where(id: ^id)
@@ -246,7 +276,7 @@ defmodule Pleroma.Activity do
defp get_in_reply_to_activity_from_object(_), do: nil
def get_in_reply_to_activity(%Activity{} = activity) do
- get_in_reply_to_activity_from_object(Object.normalize(activity))
+ 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"])
@@ -272,7 +302,7 @@ defmodule Pleroma.Activity do
defp purge_web_resp_cache(%Activity{} = activity) do
%{path: path} = URI.parse(activity.data["id"])
- Cachex.del(:web_resp_cache, path)
+ @cachex.del(:web_resp_cache, path)
activity
end
@@ -315,6 +345,20 @@ defmodule Pleroma.Activity do
|> Repo.all()
end
+ def follow_requests_outstanding_since?(
+ %User{ap_id: follower_id},
+ %User{ap_id: followee_id},
+ since_datetime
+ ) do
+ followee_id
+ |> Queries.by_object_id()
+ |> Queries.by_type("Follow")
+ |> where([a], a.inserted_at > ^since_datetime)
+ |> where([a], fragment("? ->> 'state' != 'accept'", a.data))
+ |> where([a], a.actor == ^follower_id)
+ |> Repo.exists?()
+ end
+
def restrict_deactivated_users(query) do
deactivated_users =
from(u in User.Query.build(%{deactivated: true}), select: u.ap_id)
@@ -343,4 +387,15 @@ defmodule Pleroma.Activity do
actor = user_actor(activity)
activity.id in actor.pinned_activities
end
+
+ @spec get_by_object_ap_id_with_object(String.t()) :: t() | nil
+ def get_by_object_ap_id_with_object(ap_id) when is_binary(ap_id) do
+ ap_id
+ |> Queries.by_object_id()
+ |> with_preloaded_object()
+ |> first()
+ |> Repo.one()
+ end
+
+ def get_by_object_ap_id_with_object(_), do: nil
end