|
|
@ -9,7 +9,6 @@ defmodule Pleroma.Web.CommonAPI do
|
|
|
|
alias Pleroma.FollowingRelationship
|
|
|
|
alias Pleroma.FollowingRelationship
|
|
|
|
alias Pleroma.Formatter
|
|
|
|
alias Pleroma.Formatter
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Repo
|
|
|
|
|
|
|
|
alias Pleroma.ThreadMute
|
|
|
|
alias Pleroma.ThreadMute
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.UserRelationship
|
|
|
|
alias Pleroma.UserRelationship
|
|
|
@ -26,36 +25,27 @@ defmodule Pleroma.Web.CommonAPI do
|
|
|
|
require Logger
|
|
|
|
require Logger
|
|
|
|
|
|
|
|
|
|
|
|
def post_chat_message(%User{} = user, %User{} = recipient, content) do
|
|
|
|
def post_chat_message(%User{} = user, %User{} = recipient, content) do
|
|
|
|
transaction =
|
|
|
|
with {_, true} <-
|
|
|
|
Repo.transaction(fn ->
|
|
|
|
{:content_length,
|
|
|
|
with {_, true} <-
|
|
|
|
String.length(content) <= Pleroma.Config.get([:instance, :chat_limit])},
|
|
|
|
{:content_length,
|
|
|
|
{_, {:ok, chat_message_data, _meta}} <-
|
|
|
|
String.length(content) <= Pleroma.Config.get([:instance, :chat_limit])},
|
|
|
|
{:build_object,
|
|
|
|
{_, {:ok, chat_message_data, _meta}} <-
|
|
|
|
Builder.chat_message(
|
|
|
|
{:build_object,
|
|
|
|
user,
|
|
|
|
Builder.chat_message(
|
|
|
|
recipient.ap_id,
|
|
|
|
user,
|
|
|
|
content |> Formatter.html_escape("text/plain")
|
|
|
|
recipient.ap_id,
|
|
|
|
)},
|
|
|
|
content |> Formatter.html_escape("text/plain")
|
|
|
|
{_, {:ok, create_activity_data, _meta}} <-
|
|
|
|
)},
|
|
|
|
{:build_create_activity, Builder.create(user, chat_message_data, [recipient.ap_id])},
|
|
|
|
{_, {:ok, create_activity_data, _meta}} <-
|
|
|
|
{_, {:ok, %Activity{} = activity, _meta}} <-
|
|
|
|
{:build_create_activity,
|
|
|
|
{:common_pipeline,
|
|
|
|
Builder.create(user, chat_message_data, [recipient.ap_id])},
|
|
|
|
Pipeline.common_pipeline(create_activity_data,
|
|
|
|
{_, {:ok, %Activity{} = activity, _meta}} <-
|
|
|
|
local: true
|
|
|
|
{:common_pipeline,
|
|
|
|
)} do
|
|
|
|
Pipeline.common_pipeline(create_activity_data,
|
|
|
|
{:ok, activity}
|
|
|
|
local: true
|
|
|
|
else
|
|
|
|
)} do
|
|
|
|
{:content_length, false} -> {:error, :content_too_long}
|
|
|
|
{:ok, activity}
|
|
|
|
e -> e
|
|
|
|
else
|
|
|
|
|
|
|
|
{:content_length, false} -> {:error, :content_too_long}
|
|
|
|
|
|
|
|
e -> e
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case transaction do
|
|
|
|
|
|
|
|
{:ok, value} -> value
|
|
|
|
|
|
|
|
error -> error
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|