2020-04-08 13:55:43 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.ChatMessageHandling do
|
2020-04-28 14:26:19 +00:00
|
|
|
alias Pleroma.Repo
|
2020-04-08 13:55:43 +00:00
|
|
|
alias Pleroma.Web.ActivityPub.Pipeline
|
|
|
|
|
|
|
|
def handle_incoming(
|
2020-04-28 14:26:19 +00:00
|
|
|
%{"type" => "Create", "object" => %{"type" => "ChatMessage"}} = data,
|
2020-04-08 13:55:43 +00:00
|
|
|
_options
|
|
|
|
) do
|
2020-04-28 14:26:19 +00:00
|
|
|
# Create has to be run inside a transaction because the object is created as a side effect.
|
|
|
|
# If this does not work, we need to roll back creating the activity.
|
2020-04-28 15:29:54 +00:00
|
|
|
case Repo.transaction(fn -> Pipeline.common_pipeline(data, local: false) end) do
|
|
|
|
{:ok, {:ok, activity, _}} ->
|
|
|
|
{:ok, activity}
|
2020-04-28 14:26:19 +00:00
|
|
|
|
2020-04-28 15:29:54 +00:00
|
|
|
{:ok, e} ->
|
|
|
|
e
|
2020-04-28 14:26:19 +00:00
|
|
|
|
2020-04-28 15:29:54 +00:00
|
|
|
{:error, e} ->
|
2020-04-16 13:21:47 +00:00
|
|
|
{:error, e}
|
2020-04-08 13:55:43 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|