From f2ff05637fc651e54d65cea083b5d960ee94afaf Mon Sep 17 00:00:00 2001 From: FloatingGhost Date: Sat, 25 Jun 2022 18:41:26 +0100 Subject: [PATCH] Allow for embedding object data in publish --- lib/pleroma/web/federator.ex | 12 ++++++++++-- lib/pleroma/web/federator/publisher.ex | 3 +++ lib/pleroma/workers/publisher_worker.ex | 11 ++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/lib/pleroma/web/federator.ex b/lib/pleroma/web/federator.ex index 69cfc2d52..82fb9e4e0 100644 --- a/lib/pleroma/web/federator.ex +++ b/lib/pleroma/web/federator.ex @@ -47,8 +47,16 @@ def publish(%{id: "pleroma:fakeid"} = activity) do end @impl true - def publish(activity) do - PublisherWorker.enqueue("publish", %{"activity_id" => activity.id}) + def publish(%{data: %{"object" => object}} = activity) when is_binary(object) do + 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 # Job Worker Callbacks diff --git a/lib/pleroma/web/federator/publisher.ex b/lib/pleroma/web/federator/publisher.ex index b7ee56803..74084558d 100644 --- a/lib/pleroma/web/federator/publisher.ex +++ b/lib/pleroma/web/federator/publisher.ex @@ -31,6 +31,9 @@ defmodule Pleroma.Web.Federator.Publisher do """ @spec enqueue_one(module(), Map.t()) :: :ok def enqueue_one(module, %{} = params) do + IO.puts("ENQUEUE") + IO.inspect(params) + PublisherWorker.enqueue( "publish_one", %{"module" => to_string(module), "params" => params} diff --git a/lib/pleroma/workers/publisher_worker.ex b/lib/pleroma/workers/publisher_worker.ex index 6209715b3..545887071 100644 --- a/lib/pleroma/workers/publisher_worker.ex +++ b/lib/pleroma/workers/publisher_worker.ex @@ -13,11 +13,20 @@ def backoff(%Job{attempt: attempt}) when is_integer(attempt) do end @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) Federator.perform(:publish, activity) 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 params = Map.new(params, fn {k, v} -> {String.to_atom(k), v} end) Federator.perform(:publish_one, String.to_atom(module_name), params)