diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php index f94479ba..102c50ce 100644 --- a/ServiceAPI/Wall.php +++ b/ServiceAPI/Wall.php @@ -164,7 +164,7 @@ class Wall implements Handler } if(rand(0, 200) == 50) { - $arr["fact"] = $this->user->getUsersIgnoredCount(); + $arr["fact"] = $this->user->getIgnoresCount(); } $resolve($arr); diff --git a/VKAPI/Handlers/Newsfeed.php b/VKAPI/Handlers/Newsfeed.php index 02dfb645..fc876b5f 100644 --- a/VKAPI/Handlers/Newsfeed.php +++ b/VKAPI/Handlers/Newsfeed.php @@ -47,7 +47,7 @@ final class Newsfeed extends VKAPIRequestHandler 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(); @@ -57,7 +57,7 @@ final class Newsfeed extends VKAPIRequestHandler if($this->getUser()->getNsfwTolerance() === User::NSFW_INTOLERANT) $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)); $queryBase .= " AND `posts`.`wall` NOT IN ('$sources')"; @@ -128,4 +128,82 @@ final class Newsfeed extends VKAPIRequestHandler 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); + } } diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php index 69a3583d..cbbe622b 100644 --- a/Web/Models/Entities/Club.php +++ b/Web/Models/Entities/Club.php @@ -461,29 +461,8 @@ class Club extends RowModel 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\TSubscribable; use Traits\TAudioStatuses; + use Traits\TIgnorable; } diff --git a/Web/Models/Entities/Traits/TIgnorable.php b/Web/Models/Entities/Traits/TIgnorable.php new file mode 100644 index 00000000..a3bbc1a1 --- /dev/null +++ b/Web/Models/Entities/Traits/TIgnorable.php @@ -0,0 +1,48 @@ +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; + } + } +} diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php index d3a11b9f..697abdde 100644 --- a/Web/Models/Entities/User.php +++ b/Web/Models/Entities/User.php @@ -1368,28 +1368,6 @@ class User extends RowModel { 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() { @@ -1430,7 +1408,13 @@ class User extends RowModel return $returnArr; } + function isHideFromGlobalFeedEnabled(): bool + { + return $this->isClosed(); + } + use Traits\TBackDrops; use Traits\TSubscribable; use Traits\TAudioStatuses; + use Traits\TIgnorable; } diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php index b56170b3..04cf44ed 100644 --- a/Web/Presenters/WallPresenter.php +++ b/Web/Presenters/WallPresenter.php @@ -679,23 +679,20 @@ final class WallPresenter extends OpenVKPresenter if($ignoredSourceModel->getId() == $this->user->id) $this->flashFail("err", "Error", tr("cant_ignore_self"), null, true); + + if($ignoredSourceModel->isClosed()) + $this->flashFail("err", "Error", tr("no_sense"), null, true); } else { $ignoredSourceModel = (new Clubs)->get(abs($ignoredSource)); if(!$ignoredSourceModel) $this->flashFail("err", "Error", tr("invalid_club"), null, true); - if($ignoredSourceModel->isHideFromGlobalFeedEnabled()) { + if($ignoredSourceModel->isHideFromGlobalFeedEnabled()) $this->flashFail("err", "Error", tr("no_sense"), null, true); - } } - - if($ignoredSourceModel->isIgnoredBy($this->user->identity)) { - DatabaseConnection::i()->getContext()->table("ignored_sources")->where([ - "owner" => $this->user->id, - "ignored_source" => $ignoredSource - ])->delete(); - + + if(!$ignoredSourceModel->toggleIgnore($this->user->identity)) { $tr = ""; if($ignoredSource > 0) @@ -705,11 +702,6 @@ final class WallPresenter extends OpenVKPresenter $this->returnJson(["success" => true, "act" => "unignored", "text" => $tr]); } else { - DatabaseConnection::i()->getContext()->table("ignored_sources")->insert([ - "owner" => $this->user->id, - "ignored_source" => $ignoredSource - ]); - if($ignoredSource > 0) $tr = tr("unignore_user"); else diff --git a/Web/Presenters/templates/Wall/Feed.xml b/Web/Presenters/templates/Wall/Feed.xml index e8f4e335..be15387a 100644 --- a/Web/Presenters/templates/Wall/Feed.xml +++ b/Web/Presenters/templates/Wall/Feed.xml @@ -16,7 +16,7 @@ {_all_news} - {_ignored_sources} + {_ignored_sources}
diff --git a/Web/static/css/main.css b/Web/static/css/main.css index 4b63cd2d..922b44a3 100644 --- a/Web/static/css/main.css +++ b/Web/static/css/main.css @@ -3023,7 +3023,7 @@ body.article .floating_sidebar, body.article .page_content { background: #E9F0F1 !important; } -.ignoredSourcesLink { +#_ignoredSourcesLink { float: right; margin-right: 3px; margin-top: 2px; @@ -3031,22 +3031,23 @@ body.article .floating_sidebar, body.article .page_content { cursor: pointer; } -.ignoredSourcesLink:hover { +#_ignoredSourcesLink:hover { text-decoration: underline; } -.ignorredList { +._ignorredList { height: 87%; border: 1px solid gray; - overflow-y: scroll; + overflow-y: auto; margin-top: 4px; + padding: 5px; } -.smolContent img { +._ignorredList ._ignoredListContent img { width: 38px; } -.smolContent { +._ignorredList ._ignoredListContent { height: 42px; padding-bottom: 9px; } diff --git a/Web/static/js/al_feed.js b/Web/static/js/al_feed.js index b72b0aae..ac8a1040 100644 --- a/Web/static/js/al_feed.js +++ b/Web/static/js/al_feed.js @@ -1,9 +1,7 @@ -$(document).on("click", ".ignoredSourcesLink", (e) => { +$(document).on("click", "#_ignoredSourcesLink", (e) => { let body = ` ${tr("ignored_clubsers_list")} -
-
-
+
` 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" async function insertMoreSources(page) { - document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", ``) + document.querySelector("._ignorredList").insertAdjacentHTML("beforeend", ``) let ar = await API.Wall.getIgnoredSources(page) u("#loader").remove() let pagesCount = Math.ceil(Number(ar.count) / 10) for(const a of ar.items) { - document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", ` -
- + document.querySelector("._ignorredList").insertAdjacentHTML("beforeend", ` + `) @@ -35,7 +35,7 @@ $(document).on("click", ".ignoredSourcesLink", (e) => { } if(page < pagesCount) { - document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", ` + document.querySelector("._ignorredList").insertAdjacentHTML("beforeend", `
more...
`) @@ -69,7 +69,6 @@ $(document).on("click", "#ignoreSomeone", (e) => { e.currentTarget.innerHTML = result.text } else { MessageBox(tr("error"), result.flash.message, [tr("ok")], [Function.noop]); - } } diff --git a/bootstrap.php b/bootstrap.php index 4df91af6..2fabdb66 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -275,6 +275,13 @@ function parseAttachments(string $attachments) 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 { $scheme = ovk_is_ssl() ? "https" : "http";