Add ctrl+enter + fix empty posts

This commit is contained in:
lalka2016 2023-09-07 17:01:54 +03:00
parent 2f05d81c02
commit c3395f39bb
2 changed files with 18 additions and 4 deletions

View file

@ -507,11 +507,10 @@ final class WallPresenter extends OpenVKPresenter
if($_SERVER["REQUEST_METHOD"] !== "POST") if($_SERVER["REQUEST_METHOD"] !== "POST")
$this->redirect("/id0"); $this->redirect("/id0");
if($this->postParam("type") == "post") { if($this->postParam("type") == "post")
$post = $this->posts->get((int)$this->postParam("postid")); $post = $this->posts->get((int)$this->postParam("postid"));
} else { else
$post = (new Comments)->get((int)$this->postParam("postid")); $post = (new Comments)->get((int)$this->postParam("postid"));
}
if(!$post || $post->isDeleted()) if(!$post || $post->isDeleted())
$this->returnJson(["error" => "Invalid post"]); $this->returnJson(["error" => "Invalid post"]);
@ -519,8 +518,18 @@ final class WallPresenter extends OpenVKPresenter
if(!$post->canBeEditedBy($this->user->identity)) if(!$post->canBeEditedBy($this->user->identity))
$this->returnJson(["error" => "Access denied"]); $this->returnJson(["error" => "Access denied"]);
$attachmentsCount = sizeof(iterator_to_array($post->getChildren()));
if(empty($this->postParam("newContent")) && $attachmentsCount < 1)
$this->returnJson(["error" => "Empty post"]);
$post->setEdited(time()); $post->setEdited(time());
try {
$post->setContent($this->postParam("newContent")); $post->setContent($this->postParam("newContent"));
} catch(\LengthException $e) {
$this->returnJson(["error" => $e->getMessage()]);
}
if($this->postParam("type") === "post") { if($this->postParam("type") === "post") {
$post->setNsfw($this->postParam("nsfw") == "true"); $post->setNsfw($this->postParam("nsfw") == "true");

View file

@ -358,6 +358,11 @@ $(document).on("click", "#editPost", (e) => {
"&fromgroup="+(content.querySelector("#fromgroup") != null ? content.querySelector("#fromgroup").checked : 0)) "&fromgroup="+(content.querySelector("#fromgroup") != null ? content.querySelector("#fromgroup").checked : 0))
}) })
u(".editMenu").on("keydown", (e) => {
if(e.ctrlKey && e.keyCode === 13)
content.querySelector("#endEditing").click()
});
text.style.display = "none" text.style.display = "none"
setupWallPostInputHandlers(999) setupWallPostInputHandlers(999)
} else { } else {