Skip to content

Commit

Permalink
feat(privacy): add ability to hide your like
Browse files Browse the repository at this point in the history
  • Loading branch information
mrilyew committed Nov 25, 2024
1 parent 6007a81 commit e4a79a8
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Web/Models/Entities/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ function toggleLike(User $user): bool
{
$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)
Expand Down
10 changes: 8 additions & 2 deletions Web/Models/Entities/Postable.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,14 @@ function getLikers(int $page = 1, ?int $perPage = NULL): \Traversable
"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
Expand Down
7 changes: 7 additions & 0 deletions Web/Models/Entities/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ function getPrivacySetting(string $id): int
"wall.write",
"messages.write",
"audios.read",
"likes.read",
],
])->get($id);
}
Expand Down Expand Up @@ -1062,6 +1063,7 @@ function setPrivacySetting(string $id, int $status): void
"wall.write",
"messages.write",
"audios.read",
"likes.read",
],
])->set($id, $status)->toInteger());
}
Expand Down Expand Up @@ -1338,6 +1340,11 @@ function getRealId()
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) [];
Expand Down
1 change: 1 addition & 0 deletions Web/Presenters/UserPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ function renderSettings(): void
"wall.write",
"messages.write",
"audios.read",
"likes.read",
];
foreach($settings as $setting) {
$input = $this->postParam(str_replace(".", "_", $setting));
Expand Down
11 changes: 11 additions & 0 deletions Web/Presenters/templates/User/Settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,17 @@
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_privacy_setting_see_likes}</span>
</td>
<td>
<select name="likes.read", style="width: 164px;">
<option value="2" {if $user->getPrivacySetting('likes.read') == 2}selected{/if}>{_privacy_value_anybody}</option>
<option value="0" {if $user->getPrivacySetting('likes.read') == 0}selected{/if}>{_privacy_value_only_me_dative}</option>
</select>
</td>
</tr>
<tr>
<td width="120" valign="top">
<span class="nobold">{_profile_type}</span>
Expand Down
2 changes: 1 addition & 1 deletion Web/static/js/al_wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ async function __uploadToTextarea(file, textareaNode) {
if(filetype == 'photo') {
const temp_url = URL.createObjectURL(file)
const rand = random_int(0, 1000)
textareaNode.find('.post-horizontal').append(`<a id='temp_filler${rand}' class="upload-item"><img src='${temp_url}'></a>`)
textareaNode.find('.post-horizontal').append(`<a id='temp_filler${rand}' class="upload-item lagged"><img src='${temp_url}'></a>`)

const res = await fetch(`/photos/upload`, {
method: 'POST',
Expand Down
1 change: 1 addition & 0 deletions locales/en.strings
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,7 @@
"privacy_setting_write_wall" = "Who can publish posts on my wall";
"privacy_setting_write_messages" = "Who can write messages to me";
"privacy_setting_view_audio" = "Who can see my audios";
"privacy_setting_see_likes" = "Who can see my likes";
"privacy_value_anybody" = "Anybody";
"privacy_value_anybody_dative" = "Anybody";
"privacy_value_users" = "OpenVK users";
Expand Down
1 change: 1 addition & 0 deletions locales/ru.strings
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@
"privacy_setting_write_wall" = "Кто может писать у меня на стене";
"privacy_setting_write_messages" = "Кто может писать мне сообщения";
"privacy_setting_view_audio" = "Кому видно мои аудиозаписи";
"privacy_setting_see_likes" = "Кому видны мои лайки";
"privacy_value_anybody" = "Все желающие";
"privacy_value_anybody_dative" = "Всем желающим";
"privacy_value_users" = "Пользователям OpenVK";
Expand Down

0 comments on commit e4a79a8

Please sign in to comment.