diff --git a/src/Controllers/CommentController.php b/src/Controllers/CommentController.php index 8ca7f0d0..0db4537d 100644 --- a/src/Controllers/CommentController.php +++ b/src/Controllers/CommentController.php @@ -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); diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index fd20ea9c..7275b3c8 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -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); - } - } } diff --git a/src/Services/PostService.php b/src/Services/PostService.php index acdc86d9..e88f6fed 100644 --- a/src/Services/PostService.php +++ b/src/Services/PostService.php @@ -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();