Merge branch 'develop' into feature/digest-email
[akkoma] / lib / pleroma / web / common_api / utils.ex
index 6d82c0bd266cdf79abfce54f9c1c4b6a72384e33..8b9477927c84c3b5ae7f094a764810863358b88b 100644 (file)
@@ -504,4 +504,18 @@ defmodule Pleroma.Web.CommonAPI.Utils do
       "inReplyTo" => object.data["id"]
     }
   end
+
+  def validate_character_limit(full_payload, attachments, limit) do
+    length = String.length(full_payload)
+
+    if length < limit do
+      if length > 0 or Enum.count(attachments) > 0 do
+        :ok
+      else
+        {:error, "Cannot post an empty status without attachments"}
+      end
+    else
+      {:error, "The status is over the character limit"}
+    end
+  end
 end