aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/web/common_api/utils.ex
diff options
context:
space:
mode:
authorEgor Kislitsyn <egor@kislitsyn.com>2019-07-11 13:26:59 +0700
committerEgor Kislitsyn <egor@kislitsyn.com>2019-07-11 13:26:59 +0700
commit182f7bbb1170c44eac4ab4a9efa4ff0bff991c98 (patch)
treef4c6fe46e82f667be49c8e6aad0ed3b418e4332f /lib/pleroma/web/common_api/utils.ex
parentddd4a09b72ede65345ddf45a68eb239b54eda86c (diff)
parent4016341a77337e3b71295d27808eebc05152b086 (diff)
downloadpleroma-182f7bbb1170c44eac4ab4a9efa4ff0bff991c98.tar.gz
Merge branch 'develop' into feature/addressable-lists
Diffstat (limited to 'lib/pleroma/web/common_api/utils.ex')
-rw-r--r--lib/pleroma/web/common_api/utils.ex23
1 files changed, 20 insertions, 3 deletions
diff --git a/lib/pleroma/web/common_api/utils.ex b/lib/pleroma/web/common_api/utils.ex
index 6c9e117ae..d4bfdd7e4 100644
--- a/lib/pleroma/web/common_api/utils.ex
+++ b/lib/pleroma/web/common_api/utils.ex
@@ -3,6 +3,8 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.Utils do
+ import Pleroma.Web.Gettext
+
alias Calendar.Strftime
alias Comeonin.Pbkdf2
alias Pleroma.Activity
@@ -381,7 +383,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
true <- Pbkdf2.checkpw(password, db_user.password_hash) do
{:ok, db_user}
else
- _ -> {:error, "Invalid password."}
+ _ -> {:error, dgettext("errors", "Invalid password.")}
end
end
@@ -464,7 +466,8 @@ defmodule Pleroma.Web.CommonAPI.Utils do
if String.length(comment) <= max_size do
{:ok, format_input(comment, "text/plain")}
else
- {:error, "Comment must be up to #{max_size} characters"}
+ {:error,
+ dgettext("errors", "Comment must be up to %{max_size} characters", max_size: max_size)}
end
end
@@ -499,7 +502,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
context
else
_e ->
- {:error, "No such conversation"}
+ {:error, dgettext("errors", "No such conversation")}
end
end
@@ -513,4 +516,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, dgettext("errors", "Cannot post an empty status without attachments")}
+ end
+ else
+ {:error, dgettext("errors", "The status is over the character limit")}
+ end
+ end
end