mirror of
https://github.com/friendica/friendica
synced 2025-05-01 23:04:24 +02:00
Add fields to Report entity
- Add clock dependency to Moderation\Factory\Report - Change DateTime field to DateTimeImmutable to satisfy Clock return type - Add category, status and resolution constants
This commit is contained in:
parent
d29a84ae46
commit
76de49a25c
13 changed files with 543 additions and 222 deletions
|
@ -22,28 +22,51 @@
|
|||
namespace Friendica\Moderation\Factory;
|
||||
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Moderation\Collection;
|
||||
use Friendica\Moderation\Entity;
|
||||
use Psr\Clock\ClockInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
||||
{
|
||||
/** @var ClockInterface */
|
||||
private $clock;
|
||||
|
||||
public function __construct(LoggerInterface $logger, ClockInterface $clock)
|
||||
{
|
||||
parent::__construct($logger);
|
||||
|
||||
$this->clock = $clock;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $row `report` table row
|
||||
* @param array $postUriIds List of post URI ids from the `report-post` table
|
||||
* @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()
|
||||
* @return Entity\Report
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function createFromTableRow(array $row, array $postUriIds = []): Entity\Report
|
||||
public function createFromTableRow(array $row, Collection\Report\Posts $posts = null, Collection\Report\Rules $rules = null): Entity\Report
|
||||
{
|
||||
return new Entity\Report(
|
||||
$row['reporter-id'],
|
||||
$row['cid'],
|
||||
new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
|
||||
$row['comment'],
|
||||
$row['category'],
|
||||
$row['rules'],
|
||||
$row['forward'],
|
||||
$postUriIds,
|
||||
$row['gsid'],
|
||||
new \DateTimeImmutable($row['created'], new \DateTimeZone('UTC')),
|
||||
$row['category-id'],
|
||||
$row['uid'],
|
||||
$row['comment'],
|
||||
$row['forward'],
|
||||
$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'],
|
||||
$row['id'],
|
||||
);
|
||||
}
|
||||
|
@ -51,29 +74,44 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
|||
/**
|
||||
* Creates a Report entity from a Mastodon API /reports request
|
||||
*
|
||||
* @see \Friendica\Module\Api\Mastodon\Reports::post()
|
||||
*
|
||||
* @param int $uid
|
||||
* @param array $rules Line-number indexed node rules array, see System::getRules(true)
|
||||
* @param int $reporterId
|
||||
* @param int $cid
|
||||
* @param int $gsid
|
||||
* @param string $comment
|
||||
* @param string $category
|
||||
* @param bool $forward
|
||||
* @param array $postUriIds
|
||||
* @param array $ruleIds
|
||||
* @param ?int $uid
|
||||
* @return Entity\Report
|
||||
* @throws \Exception
|
||||
* @see \Friendica\Module\Api\Mastodon\Reports::post()
|
||||
*/
|
||||
public function createFromReportsRequest(int $reporterId, int $cid, string $comment = '', string $category = null, string $rules = '', bool $forward = false, array $postUriIds = [], int $uid = null): Entity\Report
|
||||
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
|
||||
{
|
||||
if (count($ruleIds)) {
|
||||
$categoryId = Entity\Report::CATEGORY_VIOLATION;
|
||||
} elseif ($category == 'spam') {
|
||||
$categoryId = Entity\Report::CATEGORY_SPAM;
|
||||
} else {
|
||||
$categoryId = Entity\Report::CATEGORY_OTHER;
|
||||
}
|
||||
|
||||
return new Entity\Report(
|
||||
$reporterId,
|
||||
$cid,
|
||||
new \DateTime('now', new \DateTimeZone('UTC')),
|
||||
$comment,
|
||||
$category,
|
||||
$rules,
|
||||
$forward,
|
||||
$postUriIds,
|
||||
$gsid,
|
||||
$this->clock->now(),
|
||||
$categoryId,
|
||||
$uid,
|
||||
$comment,
|
||||
$forward,
|
||||
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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue