From 8f10cf8e53a8f5583b9c5db0259a204a641d0864 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 13 Dec 2020 12:16:04 -0500 Subject: [PATCH 1/4] Simplify Contact::addRelationship call in ActivityPub\Processor::followUser - Address https://github.com/friendica/friendica/issues/9250#issuecomment-743382769 --- src/Protocol/ActivityPub/Processor.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 8f89b17f80..088a10e908 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -903,20 +903,15 @@ class Processor if (!empty($cid)) { self::switchContact($cid); DBA::update('contact', ['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]); - $contact = DBA::selectFirst('contact', [], ['id' => $cid, 'network' => Protocol::NATIVE_SUPPORT]); - } else { - $contact = []; } $item = ['author-id' => Contact::getIdForURL($activity['actor']), 'author-link' => $activity['actor']]; - $note = Strings::escapeTags(trim($activity['content'] ?? '')); - // Ensure that the contact has got the right network type self::switchContact($item['author-id']); - $result = Contact::addRelationship($owner, $contact, $item, false, $note); + $result = Contact::addRelationship($owner, [], $item, false, $activity['content'] ?? ''); if ($result === true) { ActivityPub\Transmitter::sendContactAccept($item['author-link'], $activity['id'], $owner['uid']); } From 61aa4efa8941659dee5c7dc4986ebc99922ae2b3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 13 Dec 2020 12:18:10 -0500 Subject: [PATCH 2/4] Account for missing contact in dfrn_request_post - Address https://github.com/friendica/friendica/issues/9250#issuecomment-743407998 --- mod/dfrn_request.php | 2 +- src/Network/Probe.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 3f784015dd..47478d3848 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -299,7 +299,7 @@ function dfrn_request_post(App $a) $network = $data["network"]; // Canonicalize email-style profile locator - $url = Probe::webfingerDfrn($data['url'], $hcard); + $url = Probe::webfingerDfrn($data['url'] ?? $url, $hcard); if (substr($url, 0, 5) === 'stat:') { // Every time we detect the remote subscription we define this as OStatus. diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 67db29a4f3..d5dcba5295 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -258,7 +258,7 @@ class Probe * @return string profile link * @throws HTTPException\InternalServerErrorException */ - public static function webfingerDfrn($webbie, &$hcard_url) + public static function webfingerDfrn(string $webbie, string &$hcard_url) { $profile_link = ''; From 0441b912acc6451a04e8e7ac79b07f2b1de1a957 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 13 Dec 2020 13:42:08 -0500 Subject: [PATCH 3/4] Return early if an URI id cannot be obtained in ActivityPub\Processor::createItem - Address https://github.com/friendica/friendica/issues/9250#issuecomment-743769813 --- src/Model/ItemURI.php | 4 ++-- src/Protocol/ActivityPub/Processor.php | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Model/ItemURI.php b/src/Model/ItemURI.php index 7f05786c8e..6421b2dbd9 100644 --- a/src/Model/ItemURI.php +++ b/src/Model/ItemURI.php @@ -31,10 +31,10 @@ class ItemURI * * @param array $fields Item-uri fields * - * @return integer item-uri id + * @return int|null item-uri id * @throws \Exception */ - public static function insert($fields) + public static function insert(array $fields) { // If the URI gets too long we only take the first parts and hope for best $uri = substr($fields['uri'], 0, 255); diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 088a10e908..f60eea7122 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -327,6 +327,10 @@ class Processor $item['guid'] = $activity['diaspora:guid'] ?: $guid; $item['uri-id'] = ItemURI::insert(['uri' => $item['uri'], 'guid' => $item['guid']]); + if (empty($item['uri-id'])) { + Logger::warning('Unable to get a uri-id for an item uri', ['uri' => $item['uri'], 'guid' => $item['guid']]); + return []; + } $item = self::processContent($activity, $item); if (empty($item)) { From 481c5c9e81f0eded399c5bdc3c25b27f7a628018 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 14 Dec 2020 09:10:43 -0500 Subject: [PATCH 4/4] Account for inbox array in Worker/APDelivery - Address https://github.com/friendica/friendica/issues/9250#issuecomment-744339671 --- src/Worker/APDelivery.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Worker/APDelivery.php b/src/Worker/APDelivery.php index 7173475bef..c98f1e3993 100644 --- a/src/Worker/APDelivery.php +++ b/src/Worker/APDelivery.php @@ -31,6 +31,28 @@ use Friendica\Util\HTTPSignature; class APDelivery { + /** + * Delivers ActivityPub messages + * + * @param string $cmd + * @param integer $target_id + * @param string|array $inboxes + * @param integer $uid + * @param array $receivers + * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @throws \ImagickException + */ + public static function execute(string $cmd, int $target_id, $inboxes, int $uid, array $receivers = []) + { + if (is_string($inboxes)) { + $inboxes = [$inboxes]; + } + + foreach ($inboxes as $inbox) { + self::perform($cmd, $target_id, $inbox, $uid, $receivers); + } + } + /** * Delivers ActivityPub messages * @@ -42,7 +64,7 @@ class APDelivery * @throws \Friendica\Network\HTTPException\InternalServerErrorException * @throws \ImagickException */ - public static function execute($cmd, $target_id, $inbox, $uid, $receivers = []) + private static function perform(string $cmd, int $target_id, string $inbox, int $uid, array $receivers = []) { if (ActivityPub\Transmitter::archivedInbox($inbox)) { Logger::info('Inbox is archived', ['cmd' => $cmd, 'inbox' => $inbox, 'id' => $target_id, 'uid' => $uid]);