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
This commit is contained in:
commit
df2dab69a7
@ -212,7 +212,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||||||
cw <- data["spoiler_text"] || "",
|
cw <- data["spoiler_text"] || "",
|
||||||
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
|
sensitive <- data["sensitive"] || Enum.member?(tags, {"#nsfw", "nsfw"}),
|
||||||
full_payload <- String.trim(status <> cw),
|
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 <-
|
object <-
|
||||||
make_note_data(
|
make_note_data(
|
||||||
user.ap_id,
|
user.ap_id,
|
||||||
@ -247,6 +247,7 @@ defmodule Pleroma.Web.CommonAPI do
|
|||||||
|
|
||||||
res
|
res
|
||||||
else
|
else
|
||||||
|
{:error, _} = e -> e
|
||||||
e -> {:error, e}
|
e -> {:error, e}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -504,4 +504,18 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
|||||||
"inReplyTo" => object.data["id"]
|
"inReplyTo" => object.data["id"]
|
||||||
}
|
}
|
||||||
end
|
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
|
end
|
||||||
|
@ -544,15 +544,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
|||||||
end
|
end
|
||||||
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
|
def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
|
||||||
params =
|
params =
|
||||||
params
|
params
|
||||||
|
Loading…
Reference in New Issue
Block a user