From e4a79a8ffb0b4bc14a375d2d2358595e01e2028b Mon Sep 17 00:00:00 2001 From: mrilyew <99399973+mrilyew@users.noreply.github.com> Date: Mon, 25 Nov 2024 22:29:33 +0300 Subject: [PATCH] feat(privacy): add ability to hide your like --- Web/Models/Entities/Post.php | 2 +- Web/Models/Entities/Postable.php | 10 ++++++++-- Web/Models/Entities/User.php | 7 +++++++ Web/Presenters/UserPresenter.php | 1 + Web/Presenters/templates/User/Settings.xml | 11 +++++++++++ Web/static/js/al_wall.js | 2 +- locales/en.strings | 1 + locales/ru.strings | 1 + 8 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Web/Models/Entities/Post.php b/Web/Models/Entities/Post.php index 0b210fb0..30c6eac3 100644 --- a/Web/Models/Entities/Post.php +++ b/Web/Models/Entities/Post.php @@ -301,7 +301,7 @@ class Post extends Postable { $liked = parent::toggleLike($user); - if($this->getOwner(false)->getId() !== $user->getId() && !($this->getOwner() instanceof Club) && !$this instanceof Comment) + if(!$user->isPrivateLikes() && $this->getOwner(false)->getId() !== $user->getId() && !($this->getOwner() instanceof Club) && !$this instanceof Comment) (new LikeNotification($this->getOwner(false), $this, $user))->emit(); foreach($this->getChildren() as $attachment) diff --git a/Web/Models/Entities/Postable.php b/Web/Models/Entities/Postable.php index 55e1adf7..fc6cb8ca 100644 --- a/Web/Models/Entities/Postable.php +++ b/Web/Models/Entities/Postable.php @@ -97,8 +97,14 @@ abstract class Postable extends Attachable "target" => $this->getRecord()->id, ])->page($page, $perPage); - foreach($sel as $like) - yield (new Users)->get($like->origin); + foreach($sel as $like) { + $user = (new Users)->get($like->origin); + if($user->isPrivateLikes() && OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["enable"]) { + $user = (new Users)->get((int) OPENVK_ROOT_CONF["openvk"]["preferences"]["wall"]["anonymousPosting"]["account"]); + } + + yield $user; + } } function isAnonymous(): bool diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index 1e17dd82..a0574f3d 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -498,6 +498,7 @@ class User extends RowModel "wall.write", "messages.write", "audios.read", + "likes.read", ], ])->get($id); } @@ -1062,6 +1063,7 @@ class User extends RowModel "wall.write", "messages.write", "audios.read", + "likes.read", ], ])->set($id, $status)->toInteger()); } @@ -1338,6 +1340,11 @@ class User extends RowModel return $this->getId(); } + function isPrivateLikes(): bool + { + return $this->getPrivacySetting("likes.read") == User::PRIVACY_NO_ONE; + } + function toVkApiStruct(?User $user = NULL, string $fields = ''): object { $res = (object) []; diff --git a/Web/Presenters/UserPresenter.php b/Web/Presenters/UserPresenter.php index b64823fb..4c6bb0dd 100644 --- a/Web/Presenters/UserPresenter.php +++ b/Web/Presenters/UserPresenter.php @@ -503,6 +503,7 @@ final class UserPresenter extends OpenVKPresenter "wall.write", "messages.write", "audios.read", + "likes.read", ]; foreach($settings as $setting) { $input = $this->postParam(str_replace(".", "_", $setting)); diff --git a/Web/Presenters/templates/User/Settings.xml b/Web/Presenters/templates/User/Settings.xml index d34993e8..244c52c4 100644 --- a/Web/Presenters/templates/User/Settings.xml +++ b/Web/Presenters/templates/User/Settings.xml @@ -395,6 +395,17 @@ +