diff --git a/Web/Models/Entities/Comment.php b/Web/Models/Entities/Comment.php
index d813d6be..d64a2763 100644
--- a/Web/Models/Entities/Comment.php
+++ b/Web/Models/Entities/Comment.php
@@ -90,4 +90,12 @@ class Comment extends Post
{
return "/wall" . $this->getTarget()->getPrettyId() . "#_comment" . $this->getId();
}
+
+ function canBeEditedBy(?User $user = NULL): bool
+ {
+ if(!$user)
+ return false;
+
+ return $user->getId() == $this->getOwner(false)->getId();
+ }
}
diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php
index 42941901..2d323a8e 100644
--- a/Web/Models/Entities/Post.php
+++ b/Web/Models/Entities/Post.php
@@ -245,6 +245,17 @@ class Post extends Postable
$this->unwire();
$this->save();
}
+
+ function canBeEditedBy(?User $user = NULL): bool
+ {
+ if(!$user)
+ return false;
+
+ if($this->isDeactivationMessage() || $this->isUpdateAvatarMessage())
+ return false;
+
+ return $user->getId() == $this->getOwner(false)->getId();
+ }
use Traits\TRichText;
}
diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php
index 3e115ec7..c368c40f 100644
--- a/Web/Presenters/WallPresenter.php
+++ b/Web/Presenters/WallPresenter.php
@@ -3,7 +3,7 @@ namespace openvk\Web\Presenters;
use openvk\Web\Models\Exceptions\TooMuchOptionsException;
use openvk\Web\Models\Entities\{Poll, Post, Photo, Video, Club, User};
use openvk\Web\Models\Entities\Notifications\{MentionNotification, RepostNotification, WallPostNotification};
-use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes};
+use openvk\Web\Models\Repositories\{Posts, Users, Clubs, Albums, Notes, Comments};
use Chandler\Database\DatabaseConnection;
use Nette\InvalidStateException as ISE;
use Bhaktaraz\RSSGenerator\Item;
@@ -498,4 +498,31 @@ final class WallPresenter extends OpenVKPresenter
# TODO localize message based on language and ?act=(un)pin
$this->flashFail("succ", tr("information_-1"), tr("changes_saved_comment"));
}
+
+ function renderEdit()
+ {
+ $this->assertUserLoggedIn();
+ $this->willExecuteWriteAction();
+
+ if($_SERVER["REQUEST_METHOD"] !== "POST")
+ $this->redirect("/id0");
+
+ if($this->postParam("type") == "post") {
+ $post = $this->posts->get((int)$this->postParam("postid"));
+ } else {
+ $post = (new Comments)->get((int)$this->postParam("postid"));
+ }
+
+ if(!$post || $post->isDeleted())
+ $this->returnJson(["error" => "Invalid post"]);
+
+ if(!$post->canBeEditedBy($this->user->identity))
+ $this->returnJson(["error" => "Access denied"]);
+
+ $post->setEdited(time());
+ $post->setContent($this->postParam("newContent"));
+ $post->save(true);
+
+ $this->returnJson(["error" => "no", "new_content" => $post->getText(), "new_edited" => (string)$post->getEditTime()]);
+ }
}
diff --git a/Web/Presenters/templates/Wall/Post.xml b/Web/Presenters/templates/Wall/Post.xml
index 575c7bba..8ac11bb7 100644
--- a/Web/Presenters/templates/Wall/Post.xml
+++ b/Web/Presenters/templates/Wall/Post.xml
@@ -34,6 +34,14 @@
{/if}
{_delete}
+
+ {_changes_history}
+
{_report}