diff options
author | rinpatch <rinpatch@sdf.org> | 2019-06-18 05:05:05 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-06-18 05:05:05 +0300 |
commit | c4e4f7d0e48ca09003984fb75166ec3cca0b8634 (patch) | |
tree | d551cdc5964ba2c4d80a11b8995444a744c91fd5 /lib/pleroma/web/common_api/utils.ex | |
parent | dce27de7337214618559d96093e0aa3068874f4a (diff) | |
download | pleroma-c4e4f7d0e48ca09003984fb75166ec3cca0b8634.tar.gz |
Add proper error handling for when the post exceeds character limits
Diffstat (limited to 'lib/pleroma/web/common_api/utils.ex')
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex index 6d82c0bd2..8b9477927 100644 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@ -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 |