Fixed comments showing disliked posts
This commit is contained in:
parent
db19005622
commit
1415f5c521
3 changed files with 45 additions and 45 deletions
|
@ -63,6 +63,8 @@ final class CommentController extends AbstractController
|
|||
PostFilter::ORDER_LAST_COMMENT_TIME =>
|
||||
PostFilter::ORDER_DESC]);
|
||||
|
||||
$this->postService->decorateFilterFromBrowsingSettings($filter);
|
||||
|
||||
$requirement = new Requirement();
|
||||
$requirement->setValue(new RequirementRangedValue());
|
||||
$requirement->getValue()->setMinValue(1);
|
||||
|
|
|
@ -7,13 +7,9 @@ use Szurubooru\Entities\Post;
|
|||
use Szurubooru\FormData\PostEditFormData;
|
||||
use Szurubooru\FormData\UploadFormData;
|
||||
use Szurubooru\Helpers\InputReader;
|
||||
use Szurubooru\Helpers\TypeHelper;
|
||||
use Szurubooru\Privilege;
|
||||
use Szurubooru\Router;
|
||||
use Szurubooru\SearchServices\Filters\PostFilter;
|
||||
use Szurubooru\SearchServices\Parsers\PostSearchParser;
|
||||
use Szurubooru\SearchServices\Requirements\Requirement;
|
||||
use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
|
||||
use Szurubooru\Services\AuthService;
|
||||
use Szurubooru\Services\PostService;
|
||||
use Szurubooru\Services\PrivilegeService;
|
||||
|
@ -83,7 +79,7 @@ final class PostController extends AbstractController
|
|||
|
||||
$filter = $this->postSearchParser->createFilterFromInputReader($this->inputReader);
|
||||
$filter->setPageSize($this->config->posts->postsPerPage);
|
||||
$this->decorateFilterFromBrowsingSettings($filter);
|
||||
$this->postService->decorateFilterFromBrowsingSettings($filter);
|
||||
|
||||
$result = $this->postService->getFiltered($filter);
|
||||
$entities = $this->postViewProxy->fromArray($result->getEntities(), $this->getLightFetchConfig());
|
||||
|
@ -172,44 +168,4 @@ final class PostController extends AbstractController
|
|||
PostViewProxy::FETCH_TAGS => true,
|
||||
];
|
||||
}
|
||||
|
||||
private function decorateFilterFromBrowsingSettings($filter)
|
||||
{
|
||||
$currentUser = $this->authService->getLoggedInUser();
|
||||
$userSettings = $currentUser->getBrowsingSettings();
|
||||
if (!$userSettings)
|
||||
return;
|
||||
|
||||
if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_SAFETY)))
|
||||
{
|
||||
$values = [];
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->safe))
|
||||
$values[] = Post::POST_SAFETY_SAFE;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->sketchy))
|
||||
$values[] = Post::POST_SAFETY_SKETCHY;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->unsafe))
|
||||
$values[] = Post::POST_SAFETY_UNSAFE;
|
||||
if (count($values))
|
||||
{
|
||||
$requirementValue = new RequirementCompositeValue();
|
||||
$requirementValue->setValues($values);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_SAFETY);
|
||||
$requirement->setValue($requirementValue);
|
||||
$requirement->setNegated(true);
|
||||
$filter->addRequirement($requirement);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_USER_SCORE)))
|
||||
{
|
||||
$requirementValue = new RequirementCompositeValue();
|
||||
$requirementValue->setValues([$currentUser->getName(), -1]);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_USER_SCORE);
|
||||
$requirement->setValue($requirementValue);
|
||||
$requirement->setNegated(true);
|
||||
$filter->addRequirement($requirement);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,9 +10,11 @@ use Szurubooru\Entities\Tag;
|
|||
use Szurubooru\FormData\PostEditFormData;
|
||||
use Szurubooru\FormData\UploadFormData;
|
||||
use Szurubooru\Helpers\MimeHelper;
|
||||
use Szurubooru\Helpers\TypeHelper;
|
||||
use Szurubooru\SearchServices\Filters\PostFilter;
|
||||
use Szurubooru\SearchServices\Filters\SnapshotFilter;
|
||||
use Szurubooru\SearchServices\Requirements\Requirement;
|
||||
use Szurubooru\SearchServices\Requirements\RequirementCompositeValue;
|
||||
use Szurubooru\SearchServices\Requirements\RequirementSingleValue;
|
||||
use Szurubooru\Services\AuthService;
|
||||
use Szurubooru\Services\HistoryService;
|
||||
|
@ -372,6 +374,46 @@ class PostService
|
|||
$this->transactionManager->commit($transactionFunc);
|
||||
}
|
||||
|
||||
public function decorateFilterFromBrowsingSettings(PostFilter $filter)
|
||||
{
|
||||
$currentUser = $this->authService->getLoggedInUser();
|
||||
$userSettings = $currentUser->getBrowsingSettings();
|
||||
if (!$userSettings)
|
||||
return;
|
||||
|
||||
if (!empty($userSettings->listPosts) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_SAFETY)))
|
||||
{
|
||||
$values = [];
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->safe))
|
||||
$values[] = Post::POST_SAFETY_SAFE;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->sketchy))
|
||||
$values[] = Post::POST_SAFETY_SKETCHY;
|
||||
if (!TypeHelper::toBool($userSettings->listPosts->unsafe))
|
||||
$values[] = Post::POST_SAFETY_UNSAFE;
|
||||
if (count($values))
|
||||
{
|
||||
$requirementValue = new RequirementCompositeValue();
|
||||
$requirementValue->setValues($values);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_SAFETY);
|
||||
$requirement->setValue($requirementValue);
|
||||
$requirement->setNegated(true);
|
||||
$filter->addRequirement($requirement);
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($userSettings->hideDownvoted) and !count($filter->getRequirementsByType(PostFilter::REQUIREMENT_USER_SCORE)))
|
||||
{
|
||||
$requirementValue = new RequirementCompositeValue();
|
||||
$requirementValue->setValues([$currentUser->getName(), -1]);
|
||||
$requirement = new Requirement();
|
||||
$requirement->setType(PostFilter::REQUIREMENT_USER_SCORE);
|
||||
$requirement->setValue($requirementValue);
|
||||
$requirement->setNegated(true);
|
||||
$filter->addRequirement($requirement);
|
||||
}
|
||||
}
|
||||
|
||||
private function assertNoPostWithThisContentChecksum(Post $parent)
|
||||
{
|
||||
$checksumToCheck = $parent->getContentChecksum();
|
||||
|
|
Loading…
Reference in a new issue