CommonAPI: Refactor for readability

This commit is contained in:
lain 2020-05-04 12:53:40 +02:00
parent 57e6f2757a
commit 30590cf46b
1 changed files with 8 additions and 5 deletions

View File

@ -26,9 +26,7 @@ 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
with {_, true} <- with :ok <- validate_chat_content_length(content),
{:content_length,
String.length(content) <= Pleroma.Config.get([:instance, :chat_limit])},
{_, {:ok, chat_message_data, _meta}} <- {_, {:ok, chat_message_data, _meta}} <-
{:build_object, {:build_object,
Builder.chat_message( Builder.chat_message(
@ -44,9 +42,14 @@ def post_chat_message(%User{} = user, %User{} = recipient, content) do
local: true local: true
)} do )} do
{:ok, activity} {:ok, activity}
end
end
defp validate_chat_content_length(content) do
if String.length(content) <= Pleroma.Config.get([:instance, :chat_limit]) do
:ok
else else
{:content_length, false} -> {:error, :content_too_long} {:error, :content_too_long}
e -> e
end end
end end