diff options
author | rinpatch <rinpatch@sdf.org> | 2019-06-19 10:22:23 +0000 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2019-06-19 10:22:23 +0000 |
commit | df2dab69a7756153ef015bb705b256b35f07fc0c (patch) | |
tree | 66b22e53de1b856d5c003a9b9001f4c3b5aeae91 | |
parent | 5c6c4ce634d6fe17f62b71871ecb28edc34a40dd (diff) | |
parent | c4e4f7d0e48ca09003984fb75166ec3cca0b8634 (diff) | |
download | pleroma-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
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 3 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/utils.ex | 14 | ||||
-rw-r--r-- | lib/pleroma/web/mastodon_api/mastodon_api_controller.ex | 9 |
3 files changed, 16 insertions, 10 deletions
diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index f5193512e..42b78494d 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -212,7 +212,7 @@ defmodule Pleroma.Web.CommonAPI do cw <- data["spoiler_text"] || "", sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}), full_payload <- String.trim(status <> cw), - length when length in 1..limit <- String.length(full_payload), + :ok <- validate_character_limit(full_payload, attachments, limit), object <- make_note_data( user.ap_id, @@ -247,6 +247,7 @@ defmodule Pleroma.Web.CommonAPI do res else + {:error, _} = e -> e e -> {:error, e} end end 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 diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex index 457709578..0c22790f2 100644 --- a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex +++ b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -544,15 +544,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end end - def post_status(conn, %{"status" => "", "media_ids" => media_ids} = params) - when length(media_ids) > 0 do - params = - params - |> Map.put("status", ".") - - post_status(conn, params) - end - def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do params = params |