Allow for embedding object data in publish
This commit is contained in:
parent
c977a27043
commit
f2ff05637f
3 changed files with 23 additions and 3 deletions
|
@ -47,8 +47,16 @@ defmodule Pleroma.Web.Federator do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def publish(activity) do
|
def publish(%{data: %{"object" => object}} = activity) when is_binary(object) do
|
||||||
PublisherWorker.enqueue("publish", %{"activity_id" => activity.id})
|
PublisherWorker.enqueue("publish", %{"activity_id" => activity.id, "object_data" => nil})
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def publish(%{data: %{"object" => object}} = activity) when is_map(object) or is_list(object) do
|
||||||
|
PublisherWorker.enqueue("publish", %{
|
||||||
|
"activity_id" => activity.id,
|
||||||
|
"object_data" => Jason.encode!(object)
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
# Job Worker Callbacks
|
# Job Worker Callbacks
|
||||||
|
|
|
@ -31,6 +31,9 @@ defmodule Pleroma.Web.Federator.Publisher do
|
||||||
"""
|
"""
|
||||||
@spec enqueue_one(module(), Map.t()) :: :ok
|
@spec enqueue_one(module(), Map.t()) :: :ok
|
||||||
def enqueue_one(module, %{} = params) do
|
def enqueue_one(module, %{} = params) do
|
||||||
|
IO.puts("ENQUEUE")
|
||||||
|
IO.inspect(params)
|
||||||
|
|
||||||
PublisherWorker.enqueue(
|
PublisherWorker.enqueue(
|
||||||
"publish_one",
|
"publish_one",
|
||||||
%{"module" => to_string(module), "params" => params}
|
%{"module" => to_string(module), "params" => params}
|
||||||
|
|
|
@ -13,11 +13,20 @@ defmodule Pleroma.Workers.PublisherWorker do
|
||||||
end
|
end
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def perform(%Job{args: %{"op" => "publish", "activity_id" => activity_id}}) do
|
def perform(%Job{args: %{"op" => "publish", "activity_id" => activity_id, "object_data" => nil}}) do
|
||||||
activity = Activity.get_by_id(activity_id)
|
activity = Activity.get_by_id(activity_id)
|
||||||
Federator.perform(:publish, activity)
|
Federator.perform(:publish, activity)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@impl Oban.Worker
|
||||||
|
def perform(%Job{
|
||||||
|
args: %{"op" => "publish", "activity_id" => activity_id, "object_data" => object_data}
|
||||||
|
}) do
|
||||||
|
activity = Activity.get_by_id(activity_id)
|
||||||
|
activity = %{activity | data: Map.put(activity.data, "object", Jason.decode!(object_data))}
|
||||||
|
Federator.perform(:publish, activity)
|
||||||
|
end
|
||||||
|
|
||||||
def perform(%Job{args: %{"op" => "publish_one", "module" => module_name, "params" => params}}) do
|
def perform(%Job{args: %{"op" => "publish_one", "module" => module_name, "params" => params}}) do
|
||||||
params = Map.new(params, fn {k, v} -> {String.to_atom(k), v} end)
|
params = Map.new(params, fn {k, v} -> {String.to_atom(k), v} end)
|
||||||
Federator.perform(:publish_one, String.to_atom(module_name), params)
|
Federator.perform(:publish_one, String.to_atom(module_name), params)
|
||||||
|
|
Loading…
Reference in a new issue