aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/common_api/utils.ex
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2019-06-19 10:22:23 +0000
committerrinpatch <rinpatch@sdf.org>2019-06-19 10:22:23 +0000
commitdf2dab69a7756153ef015bb705b256b35f07fc0c (patch)
tree66b22e53de1b856d5c003a9b9001f4c3b5aeae91 /lib/pleroma/web/common_api/utils.ex
parent5c6c4ce634d6fe17f62b71871ecb28edc34a40dd (diff)
parentc4e4f7d0e48ca09003984fb75166ec3cca0b8634 (diff)
downloadpleroma-df2dab69a7756153ef015bb705b256b35f07fc0c.tar.gz
Merge branch 'begone-the-dot-hack' into 'develop'
Remove the dot hack when posting from Mastodon API and add proper errors when the post exceeds character limits See merge request pleroma/pleroma!1298
Diffstat (limited to 'lib/pleroma/web/common_api/utils.ex')
-rw-r--r--lib/pleroma/web/common_api/utils.ex14
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