X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FProtocol%2FActivityPub%2FProcessor.php;h=d57842c2b226362eae4c16cccc9fa3e4eaf842c2;hb=24c32cff0dcd38d5aa509208f5f17abb05a8b140;hp=d098ddb691343f957f9ea1f525807158995099cf;hpb=2722ef82cf6fe35e5cf0c583a1232a58fce5e824;p=friendica.git diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index d098ddb691..d57842c2b2 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -1,6 +1,6 @@ $activity]); + Queue::remove($activity); + return; + } + + $from = Contact::getByURL($activity['object_id'], false, ['uri-id']); + if (empty($from['uri-id'])) { + Logger::info('Object not found', ['activity' => $activity]); + Queue::remove($activity); + return; + } + + $contacts = DBA::select('contact', ['uid', 'url'], ["`uri-id` = ? AND `uid` != ? AND `rel` IN (?, ?)", $from['uri-id'], 0, Contact::FRIEND, Contact::SHARING]); + while ($from_contact = DBA::fetch($contacts)) { + $result = Contact::createFromProbeForUser($from_contact['uid'], $activity['target_id']); + Logger::debug('Follower added', ['from' => $from_contact, 'result' => $result]); + } + DBA::close($contacts); + Queue::remove($activity); + } + /** * Blocks the user by the contact * @@ -1783,6 +1827,43 @@ class Processor 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; + } + + $reporter_id = Contact::getIdForURL($activity['actor']); + if (empty($reporter_id)) { + Logger::info('Unknown actor', ['activity' => $activity]); + Queue::remove($activity); + return; + } + + $uri_ids = []; + foreach ($activity['object_ids'] as $status_id) { + $post = Post::selectFirst(['uri-id'], ['uri' => $status_id]); + if (!empty($post['uri-id'])) { + $uri_ids[] = $post['uri-id']; + } + } + + $report = DI::reportFactory()->createFromReportsRequest($reporter_id, $account_id, $activity['content'], null, '', false, $uri_ids); + DI::report()->save($report); + + Logger::info('Stored report', ['reporter' => $reporter_id, 'account_id' => $account_id, 'comment' => $activity['content'], 'object_ids' => $activity['object_ids']]); + } + /** * Accept a follow request * @@ -1792,17 +1873,38 @@ class Processor */ public static function acceptFollowUser(array $activity) { - $uid = User::getIdForURL($activity['object_actor']); + if (!empty($activity['object_actor'])) { + $uid = User::getIdForURL($activity['object_actor']); + $check_id = false; + } elseif (!empty($activity['receiver']) && (count($activity['receiver']) == 1)) { + $uid = array_shift($activity['receiver']); + $check_id = true; + } + if (empty($uid)) { + Logger::notice('User could not be detected', ['activity' => $activity]); + Queue::remove($activity); return; } $cid = Contact::getIdForURL($activity['actor'], $uid); if (empty($cid)) { - Logger::info('No contact found', ['actor' => $activity['actor']]); + Logger::notice('No contact found', ['actor' => $activity['actor']]); + Queue::remove($activity); return; } + $id = Transmitter::activityIDFromContact($cid); + if ($id == $activity['object_id']) { + Logger::info('Successful id check', ['uid' => $uid, 'cid' => $cid]); + } else { + Logger::info('Unsuccessful id check', ['uid' => $uid, 'cid' => $cid, 'id' => $id, 'object_id' => $activity['object_id']]); + if ($check_id) { + Queue::remove($activity); + return; + } + } + self::switchContact($cid); $fields = ['pending' => false];