Спустя три месяца

- Новые методы апи, newsfeed addBan и deleteBan. В newsfeed.getGlobal добавлен параметр return_banned хотя в ориг вк он был в newsfeed.get
- Все методы, связанные с игнором, перемещены в трейт
- Я уже забыл чё я там ещё добавил. А, ну да. В окне игноров теперь вместо описания группычеловека показывается кнопка "не игнорировать". И Кнопка Показать Игноры Не Показывается Если Игноров Нет
This commit is contained in:
lalka2018 2023-12-13 18:02:40 +03:00
parent 484b19dd8c
commit 874a654bd4
10 changed files with 168 additions and 80 deletions

View file

@ -164,7 +164,7 @@ class Wall implements Handler
} }
if(rand(0, 200) == 50) { if(rand(0, 200) == 50) {
$arr["fact"] = $this->user->getUsersIgnoredCount(); $arr["fact"] = $this->user->getIgnoresCount();
} }
$resolve($arr); $resolve($arr);

View file

@ -47,7 +47,7 @@ final class Newsfeed extends VKAPIRequestHandler
return $response; return $response;
} }
function getGlobal(string $fields = "", int $start_from = 0, int $start_time = 0, int $end_time = 0, int $offset = 0, int $count = 30, int $extended = 0) function getGlobal(string $fields = "", int $start_from = 0, int $start_time = 0, int $end_time = 0, int $offset = 0, int $count = 30, int $extended = 0, int $return_banned = 0)
{ {
$this->requireUser(); $this->requireUser();
@ -57,7 +57,7 @@ final class Newsfeed extends VKAPIRequestHandler
if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT) if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT)
$queryBase .= " AND `nsfw` = 0"; $queryBase .= " AND `nsfw` = 0";
if(($ignoredCount = $this->getUser()->getIgnoredSourcesCount()) > 0) { if(($ignoredCount = $this->getUser()->getIgnoredSourcesCount()) > 0 && $return_banned == 0) {
$sources = implode("', '", $this->getUser()->getIgnoredSources(1, $ignoredCount, true)); $sources = implode("', '", $this->getUser()->getIgnoredSources(1, $ignoredCount, true));
$queryBase .= " AND `posts`.`wall` NOT IN ('$sources')"; $queryBase .= " AND `posts`.`wall` NOT IN ('$sources')";
@ -128,4 +128,82 @@ final class Newsfeed extends VKAPIRequestHandler
return $retArr; return $retArr;
} }
} }
function addBan(string $user_ids = "", string $group_ids = "")
{
$this->requireUser();
$this->willExecuteWriteAction();
if(empty($user_ids) && empty($group_ids))
$this->fail(52, "Provide 'user_ids' or 'groups_ids'");
$arr = [];
if(!empty($user_ids)) {
$arr = array_merge($arr, array_map(function($el) {
return (int)$el;
}, explode(",", $user_ids)));
}
if(!empty($group_ids)) {
$arr = array_merge($arr, array_map(function($el) {
return abs((int)$el) * -1;
}, explode(",", $group_ids)));
}
$arr = array_unique($arr);
if(sizeof($arr) > 10 || sizeof($arr) < 1)
$this->fail(20, "You can ignore only 10 users/groups at once");
$successes = 0;
foreach($arr as $ar) {
$entity = getEntity($ar);
if(!$entity || $entity->isHideFromGlobalFeedEnabled() || $entity->isIgnoredBy($this->getUser())) continue;
$entity->toggleIgnore($this->getUser());
$successes += 1;
}
return (int)($successes > 0);
}
function deleteBan(string $user_ids = "", string $group_ids = "")
{
$this->requireUser();
$this->willExecuteWriteAction();
if(empty($user_ids) && empty($group_ids))
$this->fail(52, "Provide 'user_ids' or 'groups_ids'");
$arr = [];
if(!empty($user_ids)) {
$arr = array_merge($arr, array_map(function($el) {
return (int)$el;
}, explode(",", $user_ids)));
}
if(!empty($group_ids)) {
$arr = array_merge($arr, array_map(function($el) {
return abs((int)$el) * -1;
}, explode(",", $group_ids)));
}
$arr = array_unique($arr);
if(sizeof($arr) > 10 || sizeof($arr) < 1)
$this->fail(20, "You can unignore only 10 users/groups at once");
$successes = 0;
foreach($arr as $ar) {
$entity = getEntity($ar);
if(!$entity || $entity->isHideFromGlobalFeedEnabled() || !$entity->isIgnoredBy($this->getUser())) continue;
$entity->toggleIgnore($this->getUser());
$successes += 1;
}
return (int)($successes > 0);
}
} }

View file

@ -461,29 +461,8 @@ class Club extends RowModel
return $res; return $res;
} }
function isIgnoredBy(User $user): bool
{
$ctx = DB::i()->getContext();
$data = [
"owner" => $user->getId(),
"ignored_source" => $this->getId() * -1,
];
$sub = $ctx->table("ignored_sources")->where($data);
if(!$sub->fetch()) {
return false;
}
return true;
}
function getRealId()
{
return $this->getId() * -1;
}
use Traits\TBackDrops; use Traits\TBackDrops;
use Traits\TSubscribable; use Traits\TSubscribable;
use Traits\TAudioStatuses; use Traits\TAudioStatuses;
use Traits\TIgnorable;
} }

View file

@ -0,0 +1,48 @@
<?php declare(strict_types=1);
namespace openvk\Web\Models\Entities\Traits;
use Chandler\Database\DatabaseConnection;
use openvk\Web\Models\Entities\User;
trait TIgnorable
{
function isIgnoredBy(User $user): bool
{
$ctx = DatabaseConnection::i()->getContext();
$data = [
"owner" => $user->getId(),
"ignored_source" => $this->getRealId(),
];
$sub = $ctx->table("ignored_sources")->where($data);
if(!$sub->fetch()) {
return false;
}
return true;
}
function getIgnoresCount()
{
return sizeof(DatabaseConnection::i()->getContext()->table("ignored_sources")->where("ignored_source", $this->getRealId()));
}
function toggleIgnore(User $user): bool
{
if($this->isIgnoredBy($user)) {
DatabaseConnection::i()->getContext()->table("ignored_sources")->where([
"owner" => $user->getId(),
"ignored_source" => $this->getRealId(),
])->delete();
return false;
} else {
DatabaseConnection::i()->getContext()->table("ignored_sources")->insert([
"owner" => $user->getId(),
"ignored_source" => $this->getRealId(),
]);
return true;
}
}
}

View file

@ -1368,28 +1368,6 @@ class User extends RowModel
{ {
return sizeof(DatabaseConnection::i()->getContext()->table("ignored_sources")->where("owner", $this->getId())); return sizeof(DatabaseConnection::i()->getContext()->table("ignored_sources")->where("owner", $this->getId()));
} }
function isIgnoredBy(User $user): bool
{
$ctx = DatabaseConnection::i()->getContext();
$data = [
"owner" => $user->getId(),
"ignored_source" => $this->getId(),
];
$sub = $ctx->table("ignored_sources")->where($data);
if(!$sub->fetch()) {
return false;
}
return true;
}
function getUsersIgnoredCount()
{
return sizeof(DatabaseConnection::i()->getContext()->table("ignored_sources")->where("ignored_source", $this->getId()));
}
function getAudiosCollectionSize() function getAudiosCollectionSize()
{ {
@ -1430,7 +1408,13 @@ class User extends RowModel
return $returnArr; return $returnArr;
} }
function isHideFromGlobalFeedEnabled(): bool
{
return $this->isClosed();
}
use Traits\TBackDrops; use Traits\TBackDrops;
use Traits\TSubscribable; use Traits\TSubscribable;
use Traits\TAudioStatuses; use Traits\TAudioStatuses;
use Traits\TIgnorable;
} }

View file

@ -679,23 +679,20 @@ final class WallPresenter extends OpenVKPresenter
if($ignoredSourceModel->getId() == $this->user->id) if($ignoredSourceModel->getId() == $this->user->id)
$this->flashFail("err", "Error", tr("cant_ignore_self"), null, true); $this->flashFail("err", "Error", tr("cant_ignore_self"), null, true);
if($ignoredSourceModel->isClosed())
$this->flashFail("err", "Error", tr("no_sense"), null, true);
} else { } else {
$ignoredSourceModel = (new Clubs)->get(abs($ignoredSource)); $ignoredSourceModel = (new Clubs)->get(abs($ignoredSource));
if(!$ignoredSourceModel) if(!$ignoredSourceModel)
$this->flashFail("err", "Error", tr("invalid_club"), null, true); $this->flashFail("err", "Error", tr("invalid_club"), null, true);
if($ignoredSourceModel->isHideFromGlobalFeedEnabled()) { if($ignoredSourceModel->isHideFromGlobalFeedEnabled())
$this->flashFail("err", "Error", tr("no_sense"), null, true); $this->flashFail("err", "Error", tr("no_sense"), null, true);
}
} }
if($ignoredSourceModel->isIgnoredBy($this->user->identity)) { if(!$ignoredSourceModel->toggleIgnore($this->user->identity)) {
DatabaseConnection::i()->getContext()->table("ignored_sources")->where([
"owner" => $this->user->id,
"ignored_source" => $ignoredSource
])->delete();
$tr = ""; $tr = "";
if($ignoredSource > 0) if($ignoredSource > 0)
@ -705,11 +702,6 @@ final class WallPresenter extends OpenVKPresenter
$this->returnJson(["success" => true, "act" => "unignored", "text" => $tr]); $this->returnJson(["success" => true, "act" => "unignored", "text" => $tr]);
} else { } else {
DatabaseConnection::i()->getContext()->table("ignored_sources")->insert([
"owner" => $this->user->id,
"ignored_source" => $ignoredSource
]);
if($ignoredSource > 0) if($ignoredSource > 0)
$tr = tr("unignore_user"); $tr = tr("unignore_user");
else else

View file

@ -16,7 +16,7 @@
<a n:attr="id => (isset($globalFeed) ? 'act_tab_a' : 'ki')" href="/feed/all">{_all_news}</a> <a n:attr="id => (isset($globalFeed) ? 'act_tab_a' : 'ki')" href="/feed/all">{_all_news}</a>
</div> </div>
<span n:if="isset($globalFeed)" class="ignoredSourcesLink">{_ignored_sources}</span> <span n:if="isset($globalFeed) && $thisUser->getIgnoredSourcesCount() > 0" id="_ignoredSourcesLink">{_ignored_sources}</span>
</div> </div>
<div n:class="postFeedWrapper, $thisUser->hasMicroblogEnabled() ? postFeedWrapperMicroblog"> <div n:class="postFeedWrapper, $thisUser->hasMicroblogEnabled() ? postFeedWrapperMicroblog">

View file

@ -3023,7 +3023,7 @@ body.article .floating_sidebar, body.article .page_content {
background: #E9F0F1 !important; background: #E9F0F1 !important;
} }
.ignoredSourcesLink { #_ignoredSourcesLink {
float: right; float: right;
margin-right: 3px; margin-right: 3px;
margin-top: 2px; margin-top: 2px;
@ -3031,22 +3031,23 @@ body.article .floating_sidebar, body.article .page_content {
cursor: pointer; cursor: pointer;
} }
.ignoredSourcesLink:hover { #_ignoredSourcesLink:hover {
text-decoration: underline; text-decoration: underline;
} }
.ignorredList { ._ignorredList {
height: 87%; height: 87%;
border: 1px solid gray; border: 1px solid gray;
overflow-y: scroll; overflow-y: auto;
margin-top: 4px; margin-top: 4px;
padding: 5px;
} }
.smolContent img { ._ignorredList ._ignoredListContent img {
width: 38px; width: 38px;
} }
.smolContent { ._ignorredList ._ignoredListContent {
height: 42px; height: 42px;
padding-bottom: 9px; padding-bottom: 9px;
} }

View file

@ -1,9 +1,7 @@
$(document).on("click", ".ignoredSourcesLink", (e) => { $(document).on("click", "#_ignoredSourcesLink", (e) => {
let body = ` let body = `
<span id="ignoredClubersList">${tr("ignored_clubsers_list")}</span> <span id="ignoredClubersList">${tr("ignored_clubsers_list")}</span>
<div class="ignorredList"> <div class="_ignorredList"></div>
<div class="list" style="padding-top: 7px;padding-left: 7px;"></div>
</div>
` `
MessageBox(tr("ignored_sources"), body, [tr("cancel")], [Function.noop]); MessageBox(tr("ignored_sources"), body, [tr("cancel")], [Function.noop]);
@ -11,19 +9,21 @@ $(document).on("click", ".ignoredSourcesLink", (e) => {
document.querySelector(".ovk-diag-body").style.height = "330px" document.querySelector(".ovk-diag-body").style.height = "330px"
async function insertMoreSources(page) { async function insertMoreSources(page) {
document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", `<img id="loader" src="/assets/packages/static/openvk/img/loading_mini.gif">`) document.querySelector("._ignorredList").insertAdjacentHTML("beforeend", `<img id="loader" src="/assets/packages/static/openvk/img/loading_mini.gif">`)
let ar = await API.Wall.getIgnoredSources(page) let ar = await API.Wall.getIgnoredSources(page)
u("#loader").remove() u("#loader").remove()
let pagesCount = Math.ceil(Number(ar.count) / 10) let pagesCount = Math.ceil(Number(ar.count) / 10)
for(const a of ar.items) { for(const a of ar.items) {
document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", ` document.querySelector("._ignorredList").insertAdjacentHTML("beforeend", `
<div class="smolContent"> <div class="_ignoredListContent">
<a href="${a.url}" target="_blank"><img style="float: left;width: 38px;height: 38px;object-fit: cover;" src="${a.avatar}"></a> <a href="${a.url}" target="_blank">
<img style="float: left" class="ava" src="${a.avatar}">
</a>
<div style="float: left;margin-left: 6px;"> <div style="float: left;margin-left: 6px;">
<a href="${a.url}" target="_blank">${ovk_proc_strtr(escapeHtml(a.name), 12)}</a><br> <a href="${a.url}" target="_blank">${ovk_proc_strtr(escapeHtml(a.name), 30)}</a><br>
<span>${ovk_proc_strtr(escapeHtml(a.additional), 40)}</span> <a class="profile_link" id="ignoreSomeone" data-id="${a.id}">${a.id > 0 ? tr("unignore_user") : tr("unignore_club")}</a>
</div> </div>
</div> </div>
`) `)
@ -35,7 +35,7 @@ $(document).on("click", ".ignoredSourcesLink", (e) => {
} }
if(page < pagesCount) { if(page < pagesCount) {
document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", ` document.querySelector("._ignorredList").insertAdjacentHTML("beforeend", `
<div id="showMoreIgnors" data-pagesCount="${pagesCount}" data-page="${page + 1}" style="width: 99%;text-align: center;background: #d5d5d5;height: 22px;padding-top: 9px;cursor:pointer;"> <div id="showMoreIgnors" data-pagesCount="${pagesCount}" data-page="${page + 1}" style="width: 99%;text-align: center;background: #d5d5d5;height: 22px;padding-top: 9px;cursor:pointer;">
<span>more...</span> <span>more...</span>
</div>`) </div>`)
@ -69,7 +69,6 @@ $(document).on("click", "#ignoreSomeone", (e) => {
e.currentTarget.innerHTML = result.text e.currentTarget.innerHTML = result.text
} else { } else {
MessageBox(tr("error"), result.flash.message, [tr("ok")], [Function.noop]); MessageBox(tr("error"), result.flash.message, [tr("ok")], [Function.noop]);
} }
} }

View file

@ -275,6 +275,13 @@ function parseAttachments(string $attachments)
return $returnArr; return $returnArr;
} }
function getEntity(int $id) {
if($id > 0)
return (new openvk\Web\Models\Repositories\Users)->get($id);
return (new openvk\Web\Models\Repositories\Clubs)->get(abs($id));
}
function ovk_scheme(bool $with_slashes = false): string function ovk_scheme(bool $with_slashes = false): string
{ {
$scheme = ovk_is_ssl() ? "https" : "http"; $scheme = ovk_is_ssl() ? "https" : "http";