From 51775a9ccf69914d186f8c76474c54767267dddb Mon Sep 17 00:00:00 2001
From: lalka2016 <99399973+lalka2016@users.noreply.github.com>
Date: Tue, 26 Sep 2023 14:17:59 +0300
Subject: [PATCH 1/4] 888
---
ServiceAPI/Wall.php | 26 ++++++++
Web/Models/Entities/Club.php | 22 +++++++
Web/Models/Entities/User.php | 57 +++++++++++++++++
Web/Presenters/WallPresenter.php | 64 +++++++++++++++++++
Web/Presenters/templates/@layout.xml | 1 +
Web/Presenters/templates/Group/View.xml | 3 +
Web/Presenters/templates/User/View.xml | 3 +
Web/Presenters/templates/Wall/Feed.xml | 2 +
Web/routes.yml | 2 +
Web/static/css/main.css | 29 ++++++++-
Web/static/js/al_feed.js | 81 +++++++++++++++++++++++++
install/sqls/00041-ignored-sources.sql | 6 ++
locales/en.strings | 15 +++++
locales/ru.strings | 14 +++++
14 files changed, 324 insertions(+), 1 deletion(-)
create mode 100644 Web/static/js/al_feed.js
create mode 100644 install/sqls/00041-ignored-sources.sql
diff --git a/ServiceAPI/Wall.php b/ServiceAPI/Wall.php
index 787a998e..86d4ac5a 100644
--- a/ServiceAPI/Wall.php
+++ b/ServiceAPI/Wall.php
@@ -137,4 +137,30 @@ class Wall implements Handler
$resolve($arr);
}
+
+ function getIgnoredSources(int $page = 1, callable $resolve, callable $reject)
+ {
+ $surses = $this->user->getIgnoredSources($page, 10);
+
+ $arr = [
+ "count" => $this->user->getIgnoredSourcesCount(),
+ "items" => []
+ ];
+
+ foreach($surses as $surs) {
+ $arr["items"][] = [
+ "id" => $surs->getRealId(),
+ "name" => $surs->getCanonicalName(),
+ "additional" => (($surs->getRealId() > 0 ? $surs->getStatus() : $surs->getDescription()) ?? "..."),
+ "avatar" => $surs->getAvatarURL(),
+ "url" => $surs->getURL(),
+ ];
+ }
+
+ if(rand(0, 200) == 50) {
+ $arr["fact"] = $this->user->getUsersIgnoredCount();
+ }
+
+ $resolve($arr);
+ }
}
diff --git a/Web/Models/Entities/Club.php b/Web/Models/Entities/Club.php
index fbdc503b..37cc62bb 100644
--- a/Web/Models/Entities/Club.php
+++ b/Web/Models/Entities/Club.php
@@ -401,6 +401,28 @@ class Club extends RowModel
return (object) $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;
}
diff --git a/Web/Models/Entities/User.php b/Web/Models/Entities/User.php
index aaf00ec9..ce13668d 100644
--- a/Web/Models/Entities/User.php
+++ b/Web/Models/Entities/User.php
@@ -1239,6 +1239,63 @@ class User extends RowModel
return $res;
}
+
+ function getRealId()
+ {
+ return $this->getId();
+ }
+
+ function getIgnoredSources(int $page = 1, int $perPage = 10, bool $onlyIds = false)
+ {
+ $sources = DatabaseConnection::i()->getContext()->table("ignored_sources")->where("owner", $this->getId())->page($page, $perPage);
+ $arr = [];
+
+ foreach($sources as $source) {
+ $ignoredSource = (int)$source->ignored_source;
+
+ if($ignoredSource > 0)
+ $ignoredSourceModel = (new Users)->get($ignoredSource);
+ else
+ $ignoredSourceModel = (new Clubs)->get(abs($ignoredSource));
+
+ if(!$ignoredSourceModel)
+ continue;
+
+ if(!$onlyIds)
+ $arr[] = $ignoredSourceModel;
+ else
+ $arr[] = $ignoredSourceModel->getRealId();
+ }
+
+ return $arr;
+ }
+
+ function getIgnoredSourcesCount()
+ {
+ 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()));
+ }
use Traits\TBackDrops;
use Traits\TSubscribable;
diff --git a/Web/Presenters/WallPresenter.php b/Web/Presenters/WallPresenter.php
index ef9e4689..cc6861be 100644
--- a/Web/Presenters/WallPresenter.php
+++ b/Web/Presenters/WallPresenter.php
@@ -174,6 +174,12 @@ final class WallPresenter extends OpenVKPresenter
if($this->user->identity->getNsfwTolerance() === User::NSFW_INTOLERANT)
$queryBase .= " AND `nsfw` = 0";
+ if(($ignoredCount = $this->user->identity->getIgnoredSourcesCount()) > 0) {
+ $sources = implode("', '", $this->user->identity->getIgnoredSources(1, $ignoredCount, true));
+
+ $queryBase .= " AND `posts`.`wall` NOT IN ('$sources')";
+ }
+
$posts = DatabaseConnection::i()->getConnection()->query("SELECT `posts`.`id` " . $queryBase . " ORDER BY `created` DESC LIMIT " . $pPage . " OFFSET " . ($page - 1) * $pPage);
$count = DatabaseConnection::i()->getConnection()->query("SELECT COUNT(*) " . $queryBase)->fetch()->{"COUNT(*)"};
@@ -575,4 +581,62 @@ final class WallPresenter extends OpenVKPresenter
"avatar" => $post->getOwner()->getAvatarUrl()
]]);
}
+
+ function renderIgnoreSource()
+ {
+ $this->assertUserLoggedIn();
+ $this->willExecuteWriteAction(true);
+
+ if($_SERVER["REQUEST_METHOD"] !== "POST")
+ exit("куда ты полез?");
+
+ $owner = $this->user->id;
+ $ignoredSource = (int)$this->postParam("source");
+
+ if($this->user->identity->getIgnoredSourcesCount() > 50)
+ $this->flashFail("err", "Error", "Max ignors count is 50", null, true);
+
+ if($ignoredSource > 0) {
+ $ignoredSourceModel = (new Users)->get($ignoredSource);
+
+ if(!$ignoredSourceModel)
+ $this->flashFail("err", "Error", "Invalid user", null, true);
+
+ if($ignoredSourceModel->getId() == $this->user->id)
+ $this->flashFail("err", "Error", "Can't ignore yourself", null, true);
+ } else {
+ $ignoredSourceModel = (new Clubs)->get(abs($ignoredSource));
+
+ if(!$ignoredSourceModel)
+ $this->flashFail("err", "Error", "Invalid club", null, true);
+ }
+
+ if($ignoredSourceModel->isIgnoredBy($this->user->identity)) {
+ DatabaseConnection::i()->getContext()->table("ignored_sources")->where([
+ "owner" => $this->user->id,
+ "ignored_source" => $ignoredSource
+ ])->delete();
+
+ $tr = "";
+
+ if($ignoredSource > 0)
+ $tr = tr("ignore_user");
+ else
+ $tr = tr("ignore_club");
+
+ $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
+ $tr = tr("unignore_club");
+
+ $this->returnJson(["success" => true, "act" => "ignored", "text" => $tr]);
+ }
+ }
}
diff --git a/Web/Presenters/templates/@layout.xml b/Web/Presenters/templates/@layout.xml
index f8a975e0..b0f3988a 100644
--- a/Web/Presenters/templates/@layout.xml
+++ b/Web/Presenters/templates/@layout.xml
@@ -382,6 +382,7 @@
{ifset $thisUser}
{script "js/al_notifs.js"}
+ {script "js/al_feed.js"}
{/ifset}
{if OPENVK_ROOT_CONF['openvk']['preferences']['bellsAndWhistles']['fartscroll']}
diff --git a/Web/Presenters/templates/Group/View.xml b/Web/Presenters/templates/Group/View.xml
index 0242bbb8..413019ef 100644
--- a/Web/Presenters/templates/Group/View.xml
+++ b/Web/Presenters/templates/Group/View.xml
@@ -144,6 +144,9 @@
{var $canReport = $thisUser->getId() != $club->getOwner()->getId()}
{if $canReport}
{_report}
+
+ {if !$club->isIgnoredBy($thisUser)}{_ignore_club}{else}{_unignore_club}{/if}
+