2022-11-13 01:58:56 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2023-01-01 15:36:24 +01:00
|
|
|
* @copyright Copyright (C) 2010-2023, the Friendica project
|
2022-11-13 01:58:56 +01:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Moderation\Factory;
|
|
|
|
|
|
|
|
use Friendica\Capabilities\ICanCreateFromTableRow;
|
2022-12-10 15:08:12 +01:00
|
|
|
use Friendica\Core\System;
|
|
|
|
use Friendica\Moderation\Collection;
|
2022-11-13 01:58:56 +01:00
|
|
|
use Friendica\Moderation\Entity;
|
2022-12-10 15:08:12 +01:00
|
|
|
use Psr\Clock\ClockInterface;
|
|
|
|
use Psr\Log\LoggerInterface;
|
2022-11-13 01:58:56 +01:00
|
|
|
|
|
|
|
class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
|
|
|
{
|
2022-12-10 15:08:12 +01:00
|
|
|
/** @var ClockInterface */
|
|
|
|
private $clock;
|
|
|
|
|
|
|
|
public function __construct(LoggerInterface $logger, ClockInterface $clock)
|
|
|
|
{
|
|
|
|
parent::__construct($logger);
|
|
|
|
|
|
|
|
$this->clock = $clock;
|
|
|
|
}
|
|
|
|
|
2022-11-13 01:58:56 +01:00
|
|
|
/**
|
2022-12-10 15:08:12 +01:00
|
|
|
* @param array $row `report` table row
|
|
|
|
* @param Collection\Report\Posts|null $posts List of posts attached to the report
|
|
|
|
* @param Collection\Report\Rules|null $rules List of rules from the terms of service, see System::getRules()
|
2022-11-13 01:58:56 +01:00
|
|
|
* @return Entity\Report
|
|
|
|
* @throws \Exception
|
|
|
|
*/
|
2022-12-10 15:08:12 +01:00
|
|
|
public function createFromTableRow(array $row, Collection\Report\Posts $posts = null, Collection\Report\Rules $rules = null): Entity\Report
|
2022-11-13 01:58:56 +01:00
|
|
|
{
|
|
|
|
return new Entity\Report(
|
2022-12-24 09:03:37 +01:00
|
|
|
$row['reporter-id'],
|
2022-11-13 01:58:56 +01:00
|
|
|
$row['cid'],
|
2022-12-10 15:08:12 +01:00
|
|
|
$row['gsid'],
|
|
|
|
new \DateTimeImmutable($row['created'], new \DateTimeZone('UTC')),
|
|
|
|
$row['category-id'],
|
|
|
|
$row['uid'],
|
2022-11-13 01:58:56 +01:00
|
|
|
$row['comment'],
|
|
|
|
$row['forward'],
|
2022-12-10 15:08:12 +01:00
|
|
|
$posts ?? new Collection\Report\Posts(),
|
|
|
|
$rules ?? new Collection\Report\Rules(),
|
|
|
|
$row['public-remarks'],
|
|
|
|
$row['private-remarks'],
|
|
|
|
$row['edited'] ? new \DateTimeImmutable($row['edited'], new \DateTimeZone('UTC')) : null,
|
|
|
|
$row['status'],
|
|
|
|
$row['resolution'],
|
|
|
|
$row['assigned-uid'],
|
|
|
|
$row['last-editor-uid'],
|
2022-11-13 01:58:56 +01:00
|
|
|
$row['id'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a Report entity from a Mastodon API /reports request
|
|
|
|
*
|
2022-12-10 15:08:12 +01:00
|
|
|
* @param array $rules Line-number indexed node rules array, see System::getRules(true)
|
2022-12-24 09:03:37 +01:00
|
|
|
* @param int $reporterId
|
2022-11-13 01:58:56 +01:00
|
|
|
* @param int $cid
|
2022-12-10 15:08:12 +01:00
|
|
|
* @param int $gsid
|
2022-11-13 01:58:56 +01:00
|
|
|
* @param string $comment
|
2022-12-10 15:08:12 +01:00
|
|
|
* @param string $category
|
2022-11-13 01:58:56 +01:00
|
|
|
* @param bool $forward
|
|
|
|
* @param array $postUriIds
|
2022-12-10 15:08:12 +01:00
|
|
|
* @param array $ruleIds
|
|
|
|
* @param ?int $uid
|
2022-11-13 01:58:56 +01:00
|
|
|
* @return Entity\Report
|
2022-12-10 15:08:12 +01:00
|
|
|
* @see \Friendica\Module\Api\Mastodon\Reports::post()
|
2022-11-13 01:58:56 +01:00
|
|
|
*/
|
2022-12-10 15:08:12 +01:00
|
|
|
public function createFromReportsRequest(array $rules, int $reporterId, int $cid, int $gsid, string $comment = '', string $category = '', bool $forward = false, array $postUriIds = [], array $ruleIds = [], int $uid = null): Entity\Report
|
2022-11-13 01:58:56 +01:00
|
|
|
{
|
2022-12-10 15:08:12 +01:00
|
|
|
if (count($ruleIds)) {
|
|
|
|
$categoryId = Entity\Report::CATEGORY_VIOLATION;
|
|
|
|
} elseif ($category == 'spam') {
|
|
|
|
$categoryId = Entity\Report::CATEGORY_SPAM;
|
|
|
|
} else {
|
|
|
|
$categoryId = Entity\Report::CATEGORY_OTHER;
|
|
|
|
}
|
|
|
|
|
2022-11-13 01:58:56 +01:00
|
|
|
return new Entity\Report(
|
2022-12-24 09:03:37 +01:00
|
|
|
$reporterId,
|
2022-11-13 01:58:56 +01:00
|
|
|
$cid,
|
2022-12-10 15:08:12 +01:00
|
|
|
$gsid,
|
|
|
|
$this->clock->now(),
|
|
|
|
$categoryId,
|
|
|
|
$uid,
|
2022-11-13 01:58:56 +01:00
|
|
|
$comment,
|
|
|
|
$forward,
|
2022-12-10 15:08:12 +01:00
|
|
|
new Collection\Report\Posts(array_map(function ($uriId) {
|
|
|
|
return new Entity\Report\Post($uriId);
|
|
|
|
}, $postUriIds)),
|
|
|
|
new Collection\Report\Rules(array_map(function ($lineId) use ($rules) {
|
|
|
|
return new Entity\Report\Rule($lineId, $rules[$lineId] ?? '');
|
|
|
|
}, $ruleIds)),
|
2022-11-13 01:58:56 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|