From 0735a22cdd403f3f51128f9ca67000e708f69ddd Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 14:52:22 +0000 Subject: [PATCH 1/6] Fix notice "undefined index: uri" --- src/Model/APContact.php | 4 ++-- src/Model/Contact.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 5c60ebae59..aa5dbe2f71 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -124,7 +124,7 @@ class APContact $apcontact = DBA::selectFirst('apcontact', [], ['addr' => $url]); } - if (DBA::isResult($apcontact) && ($apcontact['updated'] > $ref_update) && !empty($apcontact['pubkey'])) { + if (DBA::isResult($apcontact) && ($apcontact['updated'] > $ref_update) && !empty($apcontact['pubkey']) && !empty($apcontact['uri-id'])) { return $apcontact; } @@ -352,7 +352,7 @@ class APContact if (empty($apcontact['uuid'])) { $apcontact['uri-id'] = ItemURI::getIdByURI($apcontact['url']); } else { - $apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['uri'], 'guid' => $apcontact['uuid']]); + $apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['url'], 'guid' => $apcontact['uuid']]); } $apcontact['updated'] = DateTimeFormat::utcNow(); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 30158c5b4f..0184861c3c 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1072,12 +1072,12 @@ class Contact return 0; } - $contact = self::getByURL($url, false, ['id', 'network'], $uid); + $contact = self::getByURL($url, false, ['id', 'network', 'uri-id'], $uid); if (!empty($contact)) { $contact_id = $contact["id"]; - if (empty($update)) { + if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) { Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]); return $contact_id; } @@ -2157,7 +2157,7 @@ class Contact if (empty($guid)) { $ret['uri-id'] = ItemURI::getIdByURI($ret['url']); } else { - $ret['uri-id'] = ItemURI::insert(['uri' => $ret['uri'], 'guid' => $guid]); + $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]); } $ret['nurl'] = Strings::normaliseLink($ret['url']); From 04580ad4fb568d89d76570ff5e97591a037fe841 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 16:20:22 +0000 Subject: [PATCH 2/6] Don't update automatically to make tests happy --- src/Model/Contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 0184861c3c..3fa8e74b48 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1077,7 +1077,7 @@ class Contact if (!empty($contact)) { $contact_id = $contact["id"]; - if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) { + if (empty($update)) { Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]); return $contact_id; } From e0fdde32878216e1c291386e7d3931ac0de5c807 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 17:13:54 +0000 Subject: [PATCH 3/6] Fix the tests, hopefully --- src/Model/Contact.php | 2 +- tests/datasets/api.fixture.php | 205 +++++++++++--------- tests/datasets/storage/database.fixture.php | 8 + 3 files changed, 125 insertions(+), 90 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 3fa8e74b48..0184861c3c 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1077,7 +1077,7 @@ class Contact if (!empty($contact)) { $contact_id = $contact["id"]; - if (empty($update)) { + if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) { Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]); return $contact_id; } diff --git a/tests/datasets/api.fixture.php b/tests/datasets/api.fixture.php index fbf2aad47c..2c6512f8c6 100644 --- a/tests/datasets/api.fixture.php +++ b/tests/datasets/api.fixture.php @@ -71,95 +71,6 @@ return [ 'theme' => 'frio', ], ], - 'contact' => [ - [ - 'id' => 42, - 'uid' => 42, - 'name' => 'Self contact', - 'nick' => 'selfcontact', - 'self' => 1, - 'nurl' => 'http://localhost/profile/selfcontact', - 'url' => 'http://localhost/profile/selfcontact', - 'about' => 'User used in tests', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FOLLOWER, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - // Having the same name and nick allows us to test - // the fallback to api_get_nick() in api_get_user() - [ - 'id' => 43, - 'uid' => 0, - 'name' => 'othercontact', - 'nick' => 'othercontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/othercontact', - 'url' => 'http://localhost/profile/othercontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::NOTHING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 44, - 'uid' => 42, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 45, - 'uid' => 0, - 'name' => 'Friend contact', - 'nick' => 'friendcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/friendcontact', - 'url' => 'http://localhost/profile/friendcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 46, - 'uid' => 42, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::FRIEND, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - [ - 'id' => 47, - 'uid' => 0, - 'name' => 'Mutual contact', - 'nick' => 'mutualcontact', - 'self' => 0, - 'nurl' => 'http://localhost/profile/mutualcontact', - 'url' => 'http://localhost/profile/mutualcontact', - 'pending' => 0, - 'blocked' => 0, - 'rel' => Contact::SHARING, - 'network' => Protocol::DFRN, - 'location' => 'DFRN', - ], - ], 'item-uri' => [ [ 'id' => 1, @@ -191,6 +102,122 @@ return [ 'uri' => '6', 'guid' => '6', ], + + [ + 'id' => 42, + 'uri' => 'http://localhost/profile/selfcontact', + 'guid' => '42', + ], + [ + 'id' => 43, + 'uri' => 'http://localhost/profile/othercontact', + 'guid' => '43', + ], + [ + 'id' => 44, + 'uri' => 'http://localhost/profile/friendcontact', + 'guid' => '44', + ], + [ + 'id' => 46, + 'uri' => 'http://localhost/profile/mutualcontact', + 'guid' => '46', + ], + ], + 'contact' => [ + [ + 'id' => 42, + 'uid' => 42, + 'uri-id' => 42, + 'name' => 'Self contact', + 'nick' => 'selfcontact', + 'self' => 1, + 'nurl' => 'http://localhost/profile/selfcontact', + 'url' => 'http://localhost/profile/selfcontact', + 'about' => 'User used in tests', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FOLLOWER, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + // Having the same name and nick allows us to test + // the fallback to api_get_nick() in api_get_user() + [ + 'id' => 43, + 'uid' => 0, + 'uri-id' => 43, + 'name' => 'othercontact', + 'nick' => 'othercontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/othercontact', + 'url' => 'http://localhost/profile/othercontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::NOTHING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 44, + 'uid' => 42, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 45, + 'uid' => 0, + 'uri-id' => 44, + 'name' => 'Friend contact', + 'nick' => 'friendcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/friendcontact', + 'url' => 'http://localhost/profile/friendcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 46, + 'uid' => 42, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::FRIEND, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], + [ + 'id' => 47, + 'uid' => 0, + 'uri-id' => 46, + 'name' => 'Mutual contact', + 'nick' => 'mutualcontact', + 'self' => 0, + 'nurl' => 'http://localhost/profile/mutualcontact', + 'url' => 'http://localhost/profile/mutualcontact', + 'pending' => 0, + 'blocked' => 0, + 'rel' => Contact::SHARING, + 'network' => Protocol::DFRN, + 'location' => 'DFRN', + ], ], 'verb' => [ [ diff --git a/tests/datasets/storage/database.fixture.php b/tests/datasets/storage/database.fixture.php index 6a73d4ed2a..9a8c675319 100644 --- a/tests/datasets/storage/database.fixture.php +++ b/tests/datasets/storage/database.fixture.php @@ -33,10 +33,18 @@ return [ 'theme' => 'frio', ], ], + 'item-uri' => [ + [ + 'id' => 42, + 'uri' => 'http://localhost/profile/selfcontact', + 'guid' => '42', + ], + ], 'contact' => [ [ 'id' => 42, 'uid' => 42, + 'uri-id' => 42, 'name' => 'Self contact', 'nick' => 'selfcontact', 'self' => 1, From d6c1e1fd1c8897c6a26a60486448c699e65843a8 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 18:10:48 +0000 Subject: [PATCH 4/6] Fix "Undefined index: reply-to-id" --- src/Protocol/ActivityPub/Processor.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index f4892b6c0f..ef4e109764 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -26,6 +26,7 @@ use Friendica\Content\Text\HTML; use Friendica\Content\Text\Markdown; use Friendica\Core\Logger; use Friendica\Core\Protocol; +use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\APContact; @@ -191,6 +192,10 @@ class Processor */ public static function createItem($activity) { + if (empty($activity['reply-to-id'])) { + $activity['reply-to-id'] = $activity['id']; + } + $item = []; $item['verb'] = Activity::POST; $item['thr-parent'] = $activity['reply-to-id']; From 90897f36cab3540e76d0e290006a9dec3b2621d6 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 19:30:41 +0000 Subject: [PATCH 5/6] Fix notices because of unknown Hubzilla activity type --- src/Protocol/ActivityPub/Processor.php | 4 ---- src/Protocol/ActivityPub/Receiver.php | 15 ++++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index ef4e109764..fa04dc7347 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -192,10 +192,6 @@ class Processor */ public static function createItem($activity) { - if (empty($activity['reply-to-id'])) { - $activity['reply-to-id'] = $activity['id']; - } - $item = []; $item['verb'] = Activity::POST; $item['thr-parent'] = $activity['reply-to-id']; diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 7c753f1886..277c93cd76 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -333,7 +333,8 @@ class Receiver $object_type = self::fetchObjectType($activity, $object_id, $uid); // Fetch the content only on activities where this matters - if (in_array($type, ['as:Create', 'as:Update', 'as:Announce'])) { + // We can receive "#emojiReaction" when fetching content from Hubzilla systems + if (in_array($type, ['as:Create', 'as:Update', 'as:Announce']) || strpos($type, '#emojiReaction')) { // Always fetch on "Announce" $object_data = self::fetchObject($object_id, $activity['as:object'], $trust_source && ($type != 'as:Announce'), $uid); if (empty($object_data)) { @@ -501,7 +502,7 @@ class Receiver if (!empty($activity['from-relay'])) { $object_data['from-relay'] = $activity['from-relay']; } - + switch ($type) { case 'as:Create': if (in_array($object_data['object_type'], self::CONTENT_TYPES)) { @@ -627,7 +628,7 @@ class Receiver * @param array $activity * @param string $actor * @param array $tags - * @param boolean $fetch_unlisted + * @param boolean $fetch_unlisted * * @return array with receivers (user id) * @throws \Exception @@ -687,7 +688,7 @@ class Receiver $receivers[0] = ['uid' => 0, 'type' => self::TARGET_GLOBAL]; } - // Add receiver "-1" for unlisted posts + // Add receiver "-1" for unlisted posts if ($fetch_unlisted && ($receiver == self::PUBLIC_COLLECTION) && ($element == 'as:cc')) { $receivers[-1] = ['uid' => -1, 'type' => self::TARGET_GLOBAL]; } @@ -950,7 +951,7 @@ class Receiver Logger::info('Empty id'); return false; } - + if ($id != $object_id) { Logger::info('Fetched id differs from provided id', ['provided' => $object_id, 'fetched' => $id]); return false; @@ -1232,7 +1233,7 @@ class Receiver if (empty($object['as:url'])) { return $object_data; } - + $urls = $object['as:url']; $keys = array_keys($urls); if (!is_numeric(array_pop($keys))) { @@ -1299,7 +1300,7 @@ class Receiver * @return array * @throws \Exception */ - private static function processObject($object) + public static function processObject($object) { if (!JsonLD::fetchElement($object, '@id')) { return false; From de39091a793e027ceeba497d44463481a038c243 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 9 Jul 2021 19:32:06 +0000 Subject: [PATCH 6/6] Revert some test changes --- src/Protocol/ActivityPub/Processor.php | 1 - src/Protocol/ActivityPub/Receiver.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index fa04dc7347..f4892b6c0f 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -26,7 +26,6 @@ use Friendica\Content\Text\HTML; use Friendica\Content\Text\Markdown; use Friendica\Core\Logger; use Friendica\Core\Protocol; -use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\APContact; diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index 277c93cd76..d59d9c4af6 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -1300,7 +1300,7 @@ class Receiver * @return array * @throws \Exception */ - public static function processObject($object) + private static function processObject($object) { if (!JsonLD::fetchElement($object, '@id')) { return false;