mirror of
https://github.com/openvk/openvk
synced 2025-07-07 00:09:48 +03:00
Add configurable limit on the depth of likes
This commit is contained in:
parent
e44cfa5bc4
commit
edc93fd13e
2 changed files with 34 additions and 20 deletions
|
@ -9,6 +9,27 @@ class Post extends Postable
|
|||
{
|
||||
protected $tableName = "posts";
|
||||
protected $upperNodeReferenceColumnName = "wall";
|
||||
|
||||
private function setLikeRecursively(bool $liked, User $user, int $depth): void
|
||||
{
|
||||
$searchData = [
|
||||
"origin" => $user->getId(),
|
||||
"model" => static::class,
|
||||
"target" => $this->getRecord()->id,
|
||||
];
|
||||
|
||||
if((sizeof(DB::i()->getContext()->table("likes")->where($searchData)) > 0) !== $liked) {
|
||||
if($this->getOwner(false)->getId() !== $user->getId() && !($this->getOwner() instanceof Club))
|
||||
(new LikeNotification($this->getOwner(false), $this, $user))->emit();
|
||||
|
||||
parent::setLike($liked, $user);
|
||||
}
|
||||
|
||||
if($depth < ovkGetQuirk("wall.repost-liking-recursion-limit"))
|
||||
foreach($this->getChildren() as $attachment)
|
||||
if($attachment instanceof Post)
|
||||
$attachment->setLikeRecursively($liked, $user, $depth + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* May return fake owner (group), if flags are [1, (*)]
|
||||
|
@ -130,33 +151,16 @@ class Post extends Postable
|
|||
if($this->getOwner(false)->getId() !== $user->getId() && !($this->getOwner() instanceof Club))
|
||||
(new LikeNotification($this->getOwner(false), $this, $user))->emit();
|
||||
|
||||
foreach($this->getChildren() as $attachment) {
|
||||
foreach($this->getChildren() as $attachment)
|
||||
if($attachment instanceof Post)
|
||||
$attachment->setLike($liked, $user);
|
||||
}
|
||||
$attachment->setLikeRecursively($liked, $user, 2);
|
||||
|
||||
return $liked;
|
||||
}
|
||||
|
||||
function setLike(bool $liked, User $user): void
|
||||
{
|
||||
$searchData = [
|
||||
"origin" => $user->getId(),
|
||||
"model" => static::class,
|
||||
"target" => $this->getRecord()->id,
|
||||
];
|
||||
|
||||
if((sizeof(DB::i()->getContext()->table("likes")->where($searchData)) > 0) !== $liked) {
|
||||
if($this->getOwner(false)->getId() !== $user->getId() && !($this->getOwner() instanceof Club))
|
||||
(new LikeNotification($this->getOwner(false), $this, $user))->emit();
|
||||
|
||||
parent::setLike($liked, $user);
|
||||
}
|
||||
|
||||
foreach($this->getChildren() as $attachment) {
|
||||
if($attachment instanceof Post)
|
||||
$attachment->setLike($liked, $user);
|
||||
}
|
||||
$this->setLikeRecursively($liked, $user, 1);
|
||||
}
|
||||
|
||||
function deletePost(): void
|
||||
|
|
10
quirks.yml
10
quirks.yml
|
@ -34,3 +34,13 @@ blobs.erase-upon-deletion: 0
|
|||
# + Set this option to 1 if you want to use quirky VK Mobile behaviour (yes graffiti in comments)
|
||||
# + Set this option to 0 if you want to use VK Desktop behaviour (no graffiti in comments)
|
||||
comments.allow-graffiti: 0
|
||||
|
||||
# Maximum recursion depth of likes on reposts
|
||||
# Restriction on the recursion depth of repost likes.
|
||||
# For example, if the value is 5, likes will be set for a maximum of 5 posts, even if there are more posts in the repost hierarchy.
|
||||
# Needed to protect against attacks
|
||||
#
|
||||
# Possible values:
|
||||
# + Set this option to -1 if you want to disable the limit
|
||||
# + Set this option to any non-negative number to be this limit
|
||||
wall.repost-liking-recursion-limit: 10
|
||||
|
|
Loading…
Reference in a new issue