From 752953e472dec0548cdf5291843e6b64e9d9f083 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Mon, 20 Jun 2022 20:59:08 +0200 Subject: [PATCH] Changes: - as @MrPetovan pointed out, $actor can be NULL earlier and used later as NULL - added some missing type-hints - added missing documentation - the added @TODO points out to avoid true|false|null for a boolean --- src/Model/APContact.php | 1 + src/Protocol/ActivityPub/Receiver.php | 4 ++-- src/Protocol/ActivityPub/Transmitter.php | 28 ++++++++++++++++++------ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 5c1d962a84..9269ee7903 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -116,6 +116,7 @@ class APContact * @return array profile array * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException + * @todo Rewrite parameter $update to avoid true|false|null (boolean is binary, null adds a third case) */ public static function getByURL(string $url, $update = null): array { diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 29f6b5bec7..e4f938c01d 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -95,9 +95,9 @@ class Receiver $ldactivity = JsonLD::compact($activity); - $actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id'); + $actor = JsonLD::fetchElement($ldactivity, 'as:actor', '@id') ?? ''; + $apcontact = APContact::getByURL($actor); - $apcontact = APContact::getByURL($actor ?? ''); if (empty($apcontact)) { Logger::notice('Unable to retrieve AP contact for actor - message is discarded', ['actor' => $actor]); return; diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 8483d5d1dd..52c140fe13 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -2201,13 +2201,14 @@ class Transmitter * Transmits a message that we don't want to follow this contact anymore * * @param string $target Target profile + * @param integer $cid Contact id * @param integer $uid User ID + * @return bool success * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException * @throws \Exception - * @return bool success */ - public static function sendContactUndo($target, $cid, $uid) + public static function sendContactUndo(string $target, int $cid, int $uid) { $profile = APContact::getByURL($target); if (empty($profile['inbox'])) { @@ -2223,15 +2224,20 @@ class Transmitter $id = DI::baseUrl() . '/activity/' . System::createGUID(); $owner = User::getOwnerDataById($uid); - $data = ['@context' => ActivityPub::CONTEXT, + $data = [ + '@context' => ActivityPub::CONTEXT, 'id' => $id, 'type' => 'Undo', 'actor' => $owner['url'], - 'object' => ['id' => $object_id, 'type' => 'Follow', + 'object' => [ + 'id' => $object_id, + 'type' => 'Follow', 'actor' => $owner['url'], - 'object' => $profile['url']], + 'object' => $profile['url'] + ], 'instrument' => self::getService(), - 'to' => [$profile['url']]]; + 'to' => [$profile['url']] + ]; Logger::info('Sending undo to ' . $target . ' for user ' . $uid . ' with id ' . $id); @@ -2239,7 +2245,15 @@ class Transmitter return HTTPSignature::transmit($signed, $profile['inbox'], $uid); } - private static function prependMentions($body, int $uriid, string $authorLink) + /** + * Prepends mentions (@) to $body variable + * + * @param string $body HTML code + * @param int $uriid URI id + * @param string $authorLink Author link + * @return string HTML code with prepended mentions + */ + private static function prependMentions(string $body, int $uriid, string $authorLink): string { $mentions = []; -- 2.39.5