Initial poll refresh support

Implement refreshing the object with an interval and call the function
when getting the poll.
This commit is contained in:
rinpatch 2019-09-18 18:13:21 +03:00
commit 7ef575d11e
8 changed files with 126 additions and 4 deletions

View file

@ -7,17 +7,19 @@ defmodule Pleroma.Object.Fetcher do
alias Pleroma.Object
alias Pleroma.Object.Containment
alias Pleroma.Signature
alias Pleroma.Repo
alias Pleroma.Web.ActivityPub.InternalFetchActor
alias Pleroma.Web.ActivityPub.Transmogrifier
alias Pleroma.Web.OStatus
require Logger
defp reinject_object(data) do
defp reinject_object(struct, data) do
Logger.debug("Reinjecting object #{data["id"]}")
with data <- Transmogrifier.fix_object(data),
{:ok, object} <- Object.create(data) do
changeset <- Object.change(struct, %{data: data}),
{:ok, object} <- Repo.insert_or_update(changeset) do
{:ok, object}
else
e ->
@ -26,6 +28,15 @@ defmodule Pleroma.Object.Fetcher do
end
end
def refetch_object(%Object{data: %{"id" => id}} = object) do
with {:ok, data} <- fetch_and_contain_remote_object_from_id(id),
{:ok, object} <- reinject_object(object, data) do
{:ok, object}
else
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, options \\ []) do
@ -57,7 +68,7 @@ defmodule Pleroma.Object.Fetcher do
{:reject, nil}
{:object, data, nil} ->
reinject_object(data)
reinject_object(%Object{}, data)
{:normalize, object = %Object{}} ->
{:ok, object}