Comments: Add reply button

Resolves #148
This commit is contained in:
Celestora 2021-10-12 14:18:07 +03:00
parent 4ab9d67718
commit 129d415877
4 changed files with 37 additions and 20 deletions

View file

@ -38,27 +38,29 @@ final class CommentPresenter extends OpenVKPresenter
$entity = $repo->get($eId);
if(!$entity) $this->notFound();
try {
$comment = new Comment;
$comment->setOwner($this->user->id);
$comment->setModel(get_class($entity));
$comment->setTarget($entity->getId());
$comment->setContent($this->postParam("text"));
$comment->setCreated(time());
$comment->save();
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
try {
$photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"]);
$comment->attach($photo);
} catch(ISE $ex) {
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
}
$photo = NULL;
if($_FILES["_pic_attachment"]["error"] === UPLOAD_ERR_OK) {
try {
$photo = Photo::fastMake($this->user->id, $this->postParam("text"), $_FILES["_pic_attachment"]);
} catch(ISE $ex) {
$this->flashFail("err", "Не удалось опубликовать пост", "Файл изображения повреждён, слишком велик или одна сторона изображения в разы больше другой.");
}
} catch(\LogicException $ex) {
$this->flashFail("err", "Не удалось опубликовать комментарий", "Нельзя опубликовать пустой комментарий.");
}
if(empty($this->postParam("text")) && is_null($photo))
$this->flashFail("err", "Не удалось опубликовать комментарий", "Нельзя опубликовать пустой комментарий.");
$comment = new Comment;
$comment->setOwner($this->user->id);
$comment->setModel(get_class($entity));
$comment->setTarget($entity->getId());
$comment->setContent($this->postParam("text"));
$comment->setCreated(time());
$comment->save();
if(!is_null($photo))
$comment->attach($photo);
if($entity->getOwner()->getId() !== $this->user->identity->getId())
if(($owner = $entity->getOwner()) instanceof User)
(new CommentNotification($owner, $comment, $entity, $this->user->identity))->emit();

View file

@ -34,3 +34,7 @@
<a class="profile_link" style="display:block;width:96%;" href="/report.pl/{$post->getId()}?type=post">{_report}</a>
</div>
{/block}
{block bodyScripts}
{script "js/al_comments.js"}
{/block}

View file

@ -1,7 +1,7 @@
{var author = $comment->getOwner()}
<a name="cid={$comment->getId()}"></a>
<table border="0" style="font-size: 11px;" class="post">
<table border="0" style="font-size: 11px;" class="post" data-comment-id="{$comment->getId()}" data-owner-id="{$author->getId()}">
<tbody>
<tr>
<td width="54" valign="top">
@ -30,9 +30,11 @@
{var canDelete = $comment->getOwner()->getId() == $thisUser->getId()}
{var canDelete = $canDelete || $comment->getTarget()->getOwner()->getId() == $thisUser->getId()}
{if $canDelete}
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a>
<a href="/comment{$comment->getId()}/delete">{_"delete"}</a>&nbsp;|&nbsp;
{/if}
<a class="comment-reply">Ответить</a>
<div style="float: right; font-size: .7rem;">
<a href="/comment{$comment->getId()}/like?hash={rawurlencode($csrfToken)}">
<div class="heart" style="{if $comment->hasLikeFrom($thisUser)}opacity: 1;{else}opacity: 0.4;{/if}"></div>

View file

@ -0,0 +1,9 @@
u(".comment-reply").on("click", function(e) {
let inputbox = u("#write textarea");
let comment = u(e.target).closest(".post");
let authorId = comment.data("owner-id");
let authorNm = u(".post-author > a > b", comment.first()).text().trim();
inputbox.text("[id" + authorId + "|" + authorNm + "], ");
inputbox.trigger("focusin");
});