mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-04-24 13:57:23 -04:00
Do not persist remote transient activities
Imported from Akkoma
This commit is contained in:
parent
57d9ecedd8
commit
91993a8401
2 changed files with 42 additions and 0 deletions
|
@ -115,6 +115,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||
end
|
||||
end
|
||||
|
||||
@unpersisted_activity_types ~w[Undo Delete Remove]
|
||||
@impl true
|
||||
def persist(%{"type" => type} = object, [local: false] = meta)
|
||||
when type in @unpersisted_activity_types do
|
||||
{:ok, object, meta}
|
||||
{recipients, _, _} = get_recipients(object)
|
||||
|
||||
unpersisted = %Activity{
|
||||
data: object,
|
||||
local: false,
|
||||
recipients: recipients,
|
||||
actor: object["actor"]
|
||||
}
|
||||
|
||||
{:ok, unpersisted, meta}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def persist(object, meta) do
|
||||
with local <- Keyword.fetch!(meta, :local),
|
||||
|
|
|
@ -14,6 +14,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.ActivityPub.Builder
|
||||
alias Pleroma.Web.ActivityPub.Utils
|
||||
alias Pleroma.Web.AdminAPI.AccountView
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
@ -2695,4 +2696,28 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
"first" => "https://social.example/users/alice/collections/featured?page=true"
|
||||
})
|
||||
end
|
||||
|
||||
describe "persist/1" do
|
||||
test "should not persist remote delete activities" do
|
||||
poster = insert(:user, local: false)
|
||||
{:ok, post} = CommonAPI.post(poster, %{status: "hhhhhh"})
|
||||
|
||||
{:ok, delete_data, meta} = Builder.delete(poster, post)
|
||||
local_opts = Keyword.put(meta, :local, false)
|
||||
{:ok, act, _meta} = ActivityPub.persist(delete_data, local_opts)
|
||||
refute act.inserted_at
|
||||
end
|
||||
|
||||
test "should not persist remote undo activities" do
|
||||
poster = insert(:user, local: false)
|
||||
liker = insert(:user, local: false)
|
||||
{:ok, post} = CommonAPI.post(poster, %{status: "hhhhhh"})
|
||||
{:ok, like} = CommonAPI.favorite(liker, post.id)
|
||||
|
||||
{:ok, undo_data, meta} = Builder.undo(liker, like)
|
||||
local_opts = Keyword.put(meta, :local, false)
|
||||
{:ok, act, _meta} = ActivityPub.persist(undo_data, local_opts)
|
||||
refute act.inserted_at
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue