Merge pull request #12516 from annando/api-report

AP: We can now store received reports
This commit is contained in:
Hypolite Petovan 2022-12-23 22:00:45 -05:00 committed by GitHub
commit e9c6611965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 3 deletions

View File

@ -532,6 +532,16 @@ abstract class DI
return self::$dice->create(Contact\Introduction\Factory\Introduction::class); return self::$dice->create(Contact\Introduction\Factory\Introduction::class);
} }
public static function report(): Moderation\Repository\Report
{
return self::$dice->create(Moderation\Repository\Report::class);
}
public static function reportFactory(): Moderation\Factory\Report
{
return self::$dice->create(Moderation\Factory\Report::class);
}
public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship public static function localRelationship(): Contact\LocalRelationship\Repository\LocalRelationship
{ {
return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class); return self::$dice->create(Contact\LocalRelationship\Repository\LocalRelationship::class);

View File

@ -45,7 +45,7 @@ class Report extends \Friendica\BaseRepository
$this->factory = $factory; $this->factory = $factory;
} }
public function selectOneById(int $lastInsertId): \Friendica\Moderation\Factory\Report public function selectOneById(int $lastInsertId): \Friendica\Moderation\Entity\Report
{ {
return $this->_selectOne(['id' => $lastInsertId]); return $this->_selectOne(['id' => $lastInsertId]);
} }
@ -59,6 +59,8 @@ class Report extends \Friendica\BaseRepository
'forward' => $Report->forward, 'forward' => $Report->forward,
]; ];
$postUriIds = $Report->postUriIds;
if ($Report->id) { if ($Report->id) {
$this->db->update(self::$table_name, $fields, ['id' => $Report->id]); $this->db->update(self::$table_name, $fields, ['id' => $Report->id]);
} else { } else {
@ -70,7 +72,7 @@ class Report extends \Friendica\BaseRepository
$this->db->delete('report-post', ['rid' => $Report->id]); $this->db->delete('report-post', ['rid' => $Report->id]);
foreach ($Report->postUriIds as $uriId) { foreach ($postUriIds as $uriId) {
if (Post::exists(['uri-id' => $uriId])) { if (Post::exists(['uri-id' => $uriId])) {
$this->db->insert('report-post', ['rid' => $Report->id, 'uri-id' => $uriId]); $this->db->insert('report-post', ['rid' => $Report->id, 'uri-id' => $uriId]);
} else { } else {

View File

@ -1821,6 +1821,40 @@ class Processor
Queue::remove($activity); Queue::remove($activity);
} }
/**
* Report a user
*
* @param array $activity
* @return void
* @throws \Exception
*/
public static function ReportAccount(array $activity)
{
$account_id = Contact::getIdForURL($activity['object_id']);
if (empty($account_id)) {
Logger::info('Unknown account', ['activity' => $activity]);
Queue::remove($activity);
return;
}
$status_ids = $activity['object_ids'];
array_shift($status_ids);
$uri_ids = [];
foreach ($status_ids as $status_id) {
$post = Post::selectFirst(['uri-id'], ['uri' => $status_id]);
if (!empty($post['uri-id'])) {
$uri_ids[] = $post['uri-id'];
}
}
// @todo We should store the actor
$report = DI::reportFactory()->createFromReportsRequest(0, $account_id, $activity['content'], false, $uri_ids);
DI::report()->save($report);
Logger::info('Stored report', ['account_id' => $account_id, 'comment' => $activity['content'], 'status_ids' => $status_ids]);
}
/** /**
* Accept a follow request * Accept a follow request
* *

View File

@ -406,7 +406,14 @@ class Receiver
} }
// Any activities on account types must not be altered // Any activities on account types must not be altered
if (in_array($object_type, self::ACCOUNT_TYPES)) { if (in_array($type, ['as:Flag'])) {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
$object_data['object_ids'] = JsonLD::fetchElementArray($activity, 'as:object', '@id');
$object_data['content'] = JsonLD::fetchElement($activity, 'as:content', '@type');
$object_data['push'] = $push;
} elseif (in_array($object_type, self::ACCOUNT_TYPES)) {
$object_data = []; $object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id'); $object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id'); $object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
@ -843,6 +850,14 @@ class Receiver
} }
break; break;
case 'as:Flag':
if (in_array($object_data['object_type'], self::ACCOUNT_TYPES)) {
ActivityPub\Processor::ReportAccount($object_data);
} else {
return false;
}
break;
case 'as:Remove': case 'as:Remove':
if (in_array($object_data['object_type'], self::CONTENT_TYPES)) { if (in_array($object_data['object_type'], self::CONTENT_TYPES)) {
ActivityPub\Processor::removeFromFeaturedCollection($object_data); ActivityPub\Processor::removeFromFeaturedCollection($object_data);