forked from mirrors/akkoma
object: fetcher: add support for reinjecting pruned objects
This commit is contained in:
parent
c2b0b82e6a
commit
73df9d690d
2 changed files with 39 additions and 2 deletions
|
@ -8,6 +8,19 @@ defmodule Pleroma.Object.Fetcher do
|
|||
|
||||
@httpoison Application.get_env(:pleroma, :httpoison)
|
||||
|
||||
defp reinject_object(data) do
|
||||
Logger.debug("Reinjecting object #{data["id"]}")
|
||||
|
||||
with data <- Transmogrifier.fix_object(data),
|
||||
{:ok, object} <- Object.create(data) do
|
||||
{:ok, object}
|
||||
else
|
||||
e ->
|
||||
Logger.error("Error while processing object: #{inspect(e)}")
|
||||
{:error, e}
|
||||
end
|
||||
end
|
||||
|
||||
# TODO:
|
||||
# This will create a Create activity, which we need internally at the moment.
|
||||
def fetch_object_from_id(id) do
|
||||
|
@ -26,12 +39,17 @@ defmodule Pleroma.Object.Fetcher do
|
|||
"object" => data
|
||||
},
|
||||
:ok <- Containment.contain_origin(id, params),
|
||||
{:ok, activity} <- Transmogrifier.handle_incoming(params) do
|
||||
{:ok, Object.normalize(activity, false)}
|
||||
{:ok, activity} <- Transmogrifier.handle_incoming(params),
|
||||
{:object, _data, %Object{} = object} <-
|
||||
{:object, data, Object.normalize(activity, false)} do
|
||||
{:ok, object}
|
||||
else
|
||||
{:error, {:reject, nil}} ->
|
||||
{:reject, nil}
|
||||
|
||||
{:object, data, nil} ->
|
||||
reinject_object(data)
|
||||
|
||||
object = %Object{} ->
|
||||
{:ok, object}
|
||||
|
||||
|
|
|
@ -87,4 +87,23 @@ defmodule Pleroma.Object.FetcherTest do
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe "pruning" do
|
||||
test "it can refetch pruned objects" do
|
||||
object_id = "http://mastodon.example.org/@admin/99541947525187367"
|
||||
|
||||
{:ok, object} = Fetcher.fetch_object_from_id(object_id)
|
||||
|
||||
assert object
|
||||
|
||||
{:ok, _object} = Object.prune(object)
|
||||
|
||||
refute Object.get_by_ap_id(object_id)
|
||||
|
||||
{:ok, %Object{} = object_two} = Fetcher.fetch_object_from_id(object_id)
|
||||
|
||||
assert object.data["id"] == object_two.data["id"]
|
||||
assert object.id != object_two.id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue