forked from YokaiRick/akkoma
Merge pull request 'Allow for embedding object data in publish' (#16) from undo-emoji-remote into develop
Reviewed-on: AkkomaGang/akkoma#16
This commit is contained in:
commit
0543954d14
2 changed files with 20 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue