From 30590cf46b88d0008c9a7163b8339aa9376f2378 Mon Sep 17 00:00:00 2001 From: lain Date: Mon, 4 May 2020 12:53:40 +0200 Subject: [PATCH] CommonAPI: Refactor for readability --- lib/pleroma/web/common_api/common_api.ex | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index 1eda0b2f2..e428cc17d 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -26,9 +26,7 @@ defmodule Pleroma.Web.CommonAPI do require Logger def post_chat_message(%User{} = user, %User{} = recipient, content) do - with {_, true} <- - {:content_length, - String.length(content) <= Pleroma.Config.get([:instance, :chat_limit])}, + with :ok <- validate_chat_content_length(content), {_, {:ok, chat_message_data, _meta}} <- {:build_object, Builder.chat_message( @@ -44,9 +42,14 @@ defmodule Pleroma.Web.CommonAPI do local: true )} do {:ok, activity} + end + end + + defp validate_chat_content_length(content) do + if String.length(content) <= Pleroma.Config.get([:instance, :chat_limit]) do + :ok else - {:content_length, false} -> {:error, :content_too_long} - e -> e + {:error, :content_too_long} end end