mirror of
https://github.com/openvk/openvk
synced 2024-12-25 01:51:03 +03:00
888
This commit is contained in:
parent
5710d131fd
commit
51775a9ccf
14 changed files with 324 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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']}
|
||||
|
|
|
@ -144,6 +144,9 @@
|
|||
{var $canReport = $thisUser->getId() != $club->getOwner()->getId()}
|
||||
{if $canReport}
|
||||
<a class="profile_link" style="display:block;" href="javascript:reportVideo()">{_report}</a>
|
||||
<a class="profile_link" style="display:block;" id="ignoreSomeone" data-id="-{$club->getId()}">
|
||||
{if !$club->isIgnoredBy($thisUser)}{_ignore_club}{else}{_unignore_club}{/if}
|
||||
</a>
|
||||
|
||||
<script>
|
||||
function reportVideo() {
|
||||
|
|
|
@ -171,6 +171,9 @@
|
|||
{/if}
|
||||
|
||||
<a class="profile_link" style="display:block;width:96%;" href="javascript:reportUser()">{_report}</a>
|
||||
<a class="profile_link" style="display:block;width:96%;" id="ignoreSomeone" data-id="{$user->getId()}">
|
||||
{if !$user->isIgnoredBy($thisUser)}{_ignore_user}{else}{_unignore_user}{/if}
|
||||
</a>
|
||||
<script>
|
||||
function reportUser() {
|
||||
uReportMsgTxt = tr("going_to_report_user");
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
<div n:attr="id => (isset($globalFeed) ? 'activetabs' : 'ki')" class="tab">
|
||||
<a n:attr="id => (isset($globalFeed) ? 'act_tab_a' : 'ki')" href="/feed/all">{_all_news}</a>
|
||||
</div>
|
||||
|
||||
<span n:if="isset($globalFeed)" class="ignoredSourcesLink">{_ignored_sources}</span>
|
||||
</div>
|
||||
|
||||
<div n:class="postFeedWrapper, $thisUser->hasMicroblogEnabled() ? postFeedWrapperMicroblog">
|
||||
|
|
|
@ -141,6 +141,8 @@ routes:
|
|||
handler: "Wall->delete"
|
||||
- url: "/wall{num}_{num}/pin"
|
||||
handler: "Wall->pin"
|
||||
- url: "/wall/ignoreSource"
|
||||
handler: "Wall->ignoreSource"
|
||||
- url: "/blob_{text}/{?path}.{text}"
|
||||
handler: "Blob->file"
|
||||
placeholders:
|
||||
|
|
|
@ -2761,7 +2761,7 @@ body.article .floating_sidebar, body.article .page_content {
|
|||
pointer-events: none;
|
||||
}
|
||||
|
||||
.lagged * {
|
||||
.lagged *, .lagged {
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
|
@ -2846,3 +2846,30 @@ body.article .floating_sidebar, body.article .page_content {
|
|||
background: #E9F0F1 !important;
|
||||
}
|
||||
|
||||
.ignoredSourcesLink {
|
||||
float: right;
|
||||
margin-right: 3px;
|
||||
margin-top: 2px;
|
||||
color: #2B587A;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.ignoredSourcesLink:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.ignorredList {
|
||||
height: 87%;
|
||||
border: 1px solid gray;
|
||||
overflow-y: scroll;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.smolContent img {
|
||||
width: 38px;
|
||||
}
|
||||
|
||||
.smolContent {
|
||||
height: 42px;
|
||||
padding-bottom: 9px;
|
||||
}
|
||||
|
|
81
Web/static/js/al_feed.js
Normal file
81
Web/static/js/al_feed.js
Normal file
|
@ -0,0 +1,81 @@
|
|||
$(document).on("click", ".ignoredSourcesLink", (e) => {
|
||||
let body = `
|
||||
<span id="ignoredClubersList">${tr("ignored_clubsers_list")}</span>
|
||||
<div class="ignorredList">
|
||||
<div class="list" style="padding-top: 7px;padding-left: 7px;"></div>
|
||||
</div>
|
||||
`
|
||||
MessageBox(tr("ignored_sources"), body, [tr("cancel")], [Function.noop]);
|
||||
|
||||
document.querySelector(".ovk-diag-body").style.padding = "10px"
|
||||
document.querySelector(".ovk-diag-body").style.height = "330px"
|
||||
|
||||
async function insertMoreSources(page) {
|
||||
document.querySelector(".ignorredList .list").insertAdjacentHTML("beforeend", `<img id="loader" src="/assets/packages/static/openvk/img/loading_mini.gif">`)
|
||||
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", `
|
||||
<div class="smolContent">
|
||||
<a href="${a.url}" target="_blank"><img style="float: left;" src="${a.avatar}"></a>
|
||||
<div style="float: left;margin-left: 6px;">
|
||||
<a href="${a.url}" target="_blank">${ovk_proc_strtr(escapeHtml(a.name), 12)}</a><br>
|
||||
<span>${ovk_proc_strtr(escapeHtml(a.additional), 40)}</span>
|
||||
</div>
|
||||
</div>
|
||||
`)
|
||||
}
|
||||
|
||||
if(ar.fact && document.querySelector("#ignoredClubersList").dataset.fact != 1) {
|
||||
document.querySelector("#ignoredClubersList").innerHTML += " "+tr("interesting_fact", Number(ar.fact))
|
||||
document.querySelector("#ignoredClubersList").setAttribute("data-fact", "1")
|
||||
}
|
||||
|
||||
if(page < pagesCount) {
|
||||
document.querySelector(".ignorredList .list").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;">
|
||||
<span>more...</span>
|
||||
</div>`)
|
||||
}
|
||||
}
|
||||
|
||||
insertMoreSources(1)
|
||||
|
||||
$(".ignorredList .list").on("click", "#showMoreIgnors", (e) => {
|
||||
u(e.currentTarget).remove()
|
||||
insertMoreSources(Number(e.currentTarget.dataset.page))
|
||||
})
|
||||
})
|
||||
|
||||
$(document).on("click", "#ignoreSomeone", (e) => {
|
||||
let xhr = new XMLHttpRequest()
|
||||
xhr.open("POST", "/wall/ignoreSource")
|
||||
|
||||
xhr.onloadstart = () => {
|
||||
e.currentTarget.classList.add("lagged")
|
||||
}
|
||||
|
||||
xhr.onerror = xhr.ontimeout = () => {
|
||||
MessageBox(tr("error"), "Unknown error occured", [tr("ok")], [Function.noop]);
|
||||
}
|
||||
|
||||
xhr.onload = () => {
|
||||
let result = JSON.parse(xhr.responseText)
|
||||
e.currentTarget.classList.remove("lagged")
|
||||
if(result.success) {
|
||||
e.currentTarget.innerHTML = result.text
|
||||
} else {
|
||||
MessageBox(tr("error"), result.flash.message, [tr("ok")], [Function.noop]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
let formdata = new FormData
|
||||
formdata.append("hash", u("meta[name=csrf]").attr("value"))
|
||||
formdata.append("source", e.currentTarget.dataset.id)
|
||||
|
||||
xhr.send(formdata)
|
||||
})
|
6
install/sqls/00041-ignored-sources.sql
Normal file
6
install/sqls/00041-ignored-sources.sql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE `ignored_sources` (
|
||||
`id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`owner` bigint(20) UNSIGNED NOT NULL,
|
||||
`ignored_source` bigint(20) NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_520_ci;
|
|
@ -222,6 +222,21 @@
|
|||
|
||||
"edited_short" = "edited";
|
||||
|
||||
"ignored_sources" = "Ignored sources";
|
||||
"ignore_user" = "Ignore user";
|
||||
"unignore_user" = "Stop ignoring user";
|
||||
|
||||
"ignore_club" = "Ignore club";
|
||||
"unignore_club" = "Stop ignoring club";
|
||||
|
||||
"ignored_clubsers_list" = "This users and clubs doesn't appears in your global feed.";
|
||||
"interesting_fact_zero" = "Fun fact: you doesn't have been ignored!";
|
||||
"interesting_fact_one" = "Fun fact: you have been ignored by one user";
|
||||
"interesting_fact_few" = "Fun fact: you have been ignored by $1 users.";
|
||||
"interesting_fact_many" = "Fun fact: you have been ignored by $1 users.";
|
||||
"interesting_fact_other" = "Fun fact: you have been ignored by $1 users.";
|
||||
"add_new_ignores" = "Add new";
|
||||
|
||||
/* Friends */
|
||||
|
||||
"friends" = "Friends";
|
||||
|
|
|
@ -199,6 +199,20 @@
|
|||
"post_is_ad" = "Этот пост был размещён за взятку.";
|
||||
"edited_short" = "ред.";
|
||||
|
||||
"ignored_sources" = "Игнорируемые источники";
|
||||
"ignore_user" = "Игнорировать пользователя";
|
||||
"unignore_user" = "Не игнорировать пользователя";
|
||||
|
||||
"ignore_club" = "Игнорировать группу";
|
||||
"unignore_club" = "Не игнорировать группу";
|
||||
"ignored_clubsers_list" = "Эти пользователи и группы не показываются в глобальной ленте.";
|
||||
"interesting_fact_zero" = "Интересный факт: вас никто не игнорирует!";
|
||||
"interesting_fact_one" = "Интересный факт: вас игнорирует один пользователь.";
|
||||
"interesting_fact_few" = "Интересный факт: вас игнорирует $1 пользователя.";
|
||||
"interesting_fact_many" = "Интересный факт: вас игнорирует $1 пользователей.";
|
||||
"interesting_fact_other" = "Интересный факт: вас игнорирует $1 пользователей.";
|
||||
"add_new_ignores" = "Добавить новое";
|
||||
|
||||
/* Friends */
|
||||
|
||||
"friends" = "Друзья";
|
||||
|
|
Loading…
Reference in a new issue