don't expire pinned posts
This commit is contained in:
parent
9bf1065a06
commit
de4c935071
@ -301,14 +301,14 @@ def all_by_actor_and_id(actor, status_ids) do
|
|||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def follow_requests_for_actor(%Pleroma.User{ap_id: ap_id}) do
|
def follow_requests_for_actor(%User{ap_id: ap_id}) do
|
||||||
ap_id
|
ap_id
|
||||||
|> Queries.by_object_id()
|
|> Queries.by_object_id()
|
||||||
|> Queries.by_type("Follow")
|
|> Queries.by_type("Follow")
|
||||||
|> where([a], fragment("? ->> 'state' = 'pending'", a.data))
|
|> where([a], fragment("? ->> 'state' = 'pending'", a.data))
|
||||||
end
|
end
|
||||||
|
|
||||||
def following_requests_for_actor(%Pleroma.User{ap_id: ap_id}) do
|
def following_requests_for_actor(%User{ap_id: ap_id}) do
|
||||||
Queries.by_type("Follow")
|
Queries.by_type("Follow")
|
||||||
|> where([a], fragment("?->>'state' = 'pending'", a.data))
|
|> where([a], fragment("?->>'state' = 'pending'", a.data))
|
||||||
|> where([a], a.actor == ^ap_id)
|
|> where([a], a.actor == ^ap_id)
|
||||||
@ -343,4 +343,9 @@ def pinned_by_actor?(%Activity{} = activity) do
|
|||||||
actor = user_actor(activity)
|
actor = user_actor(activity)
|
||||||
activity.id in actor.pinned_activities
|
activity.id in actor.pinned_activities
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@spec pinned_by_actor?(Activity.t(), User.t()) :: boolean()
|
||||||
|
def pinned_by_actor?(%Activity{id: id}, %User{} = user) do
|
||||||
|
id in user.pinned_activities
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -21,8 +21,18 @@ def enqueue(args) do
|
|||||||
@impl true
|
@impl true
|
||||||
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
|
def perform(%Oban.Job{args: %{"activity_id" => id}}) do
|
||||||
with %Pleroma.Activity{} = activity <- find_activity(id),
|
with %Pleroma.Activity{} = activity <- find_activity(id),
|
||||||
%Pleroma.User{} = user <- find_user(activity.object.data["actor"]) do
|
%Pleroma.User{} = user <- find_user(activity.object.data["actor"]),
|
||||||
|
false <- pinned_by_actor?(activity, user) do
|
||||||
Pleroma.Web.CommonAPI.delete(activity.id, user)
|
Pleroma.Web.CommonAPI.delete(activity.id, user)
|
||||||
|
else
|
||||||
|
:pinned_by_actor ->
|
||||||
|
# if activity is pinned, schedule deletion on next day
|
||||||
|
enqueue(%{activity_id: id, expires_at: DateTime.add(DateTime.utc_now(), 24 * 3600)})
|
||||||
|
|
||||||
|
:ok
|
||||||
|
|
||||||
|
error ->
|
||||||
|
error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -54,6 +64,12 @@ defp find_user(ap_id) do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp pinned_by_actor?(activity, user) do
|
||||||
|
with true <- Pleroma.Activity.pinned_by_actor?(activity, user) do
|
||||||
|
:pinned_by_actor
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_expiration(id) do
|
def get_expiration(id) do
|
||||||
from(j in Oban.Job,
|
from(j in Oban.Job,
|
||||||
where: j.state == "scheduled",
|
where: j.state == "scheduled",
|
||||||
|
@ -44,4 +44,25 @@ test "enqueue job" do
|
|||||||
|
|
||||||
assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
assert %Oban.Job{} = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "don't delete pinned posts, schedule deletion on next day" do
|
||||||
|
activity = insert(:note_activity)
|
||||||
|
|
||||||
|
assert {:ok, _} =
|
||||||
|
PurgeExpiredActivity.enqueue(%{
|
||||||
|
activity_id: activity.id,
|
||||||
|
expires_at: DateTime.utc_now(),
|
||||||
|
validate: false
|
||||||
|
})
|
||||||
|
|
||||||
|
user = Pleroma.User.get_by_ap_id(activity.actor)
|
||||||
|
{:ok, activity} = Pleroma.Web.CommonAPI.pin(activity.id, user)
|
||||||
|
|
||||||
|
assert %{success: 1, failure: 0} ==
|
||||||
|
Oban.drain_queue(queue: :activity_expiration, with_scheduled: true)
|
||||||
|
|
||||||
|
job = Pleroma.Workers.PurgeExpiredActivity.get_expiration(activity.id)
|
||||||
|
|
||||||
|
assert DateTime.diff(job.scheduled_at, DateTime.add(DateTime.utc_now(), 24 * 3600)) in [0, 1]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user