Fix all errors in Protocol namespace

This commit is contained in:
Art4 2024-11-17 18:39:17 +00:00
parent 5469637f2b
commit 9638113244
10 changed files with 46 additions and 36 deletions

View file

@ -323,7 +323,7 @@ class ClientToServer
$requester_id = Contact::getIdForURL($requester, $owner['uid']); $requester_id = Contact::getIdForURL($requester, $owner['uid']);
if (!empty($requester_id)) { if (!empty($requester_id)) {
$permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']); $permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']);
if (!empty($permissionSets)) { if ($permissionSets->getTotalCount() > 0) {
$condition = ['psid' => array_merge($permissionSets->column('id'), $condition = ['psid' => array_merge($permissionSets->column('id'),
[DI::permissionSet()->selectPublicForUser($owner['uid'])])]; [DI::permissionSet()->selectPublicForUser($owner['uid'])])];
} }

View file

@ -42,6 +42,8 @@ class Delivery
continue; continue;
} }
$result = [];
if (!$serverfail) { if (!$serverfail) {
$result = self::deliverToInbox($post['command'], 0, $inbox, $owner, $post['receivers'], $post['uri-id']); $result = self::deliverToInbox($post['command'], 0, $inbox, $owner, $post['receivers'], $post['uri-id']);
@ -121,11 +123,12 @@ class Delivery
$serverfail = $response->isTimeout(); $serverfail = $response->isTimeout();
} catch (\Throwable $th) { } catch (\Throwable $th) {
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]); Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
$response = null;
$success = false; $success = false;
$serverfail = true; $serverfail = true;
} }
$runtime = microtime(true) - $timestamp; $runtime = microtime(true) - $timestamp;
if (!$success) { if ($success === false) {
// 5xx errors are problems on the server. We don't need to continue delivery then. // 5xx errors are problems on the server. We don't need to continue delivery then.
if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) { if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
$serverfail = true; $serverfail = true;

View file

@ -520,7 +520,7 @@ class Processor
if (!DI::config()->get('system', 'decoupled_receiver')) { if (!DI::config()->get('system', 'decoupled_receiver')) {
return; return;
} }
$replies = [$item['thr-parent']]; $replies = [$item['thr-parent']];
if (!empty($item['parent-uri'])) { if (!empty($item['parent-uri'])) {
$replies[] = $item['parent-uri']; $replies[] = $item['parent-uri'];
@ -561,7 +561,7 @@ class Processor
if (in_array($activity['reply-to-id'], $activity['children'] ?? [])) { if (in_array($activity['reply-to-id'], $activity['children'] ?? [])) {
Logger::notice('reply-to-id is already in the list of children', ['id' => $activity['reply-to-id'], 'children' => $activity['children'], 'depth' => count($activity['children'])]); Logger::notice('reply-to-id is already in the list of children', ['id' => $activity['reply-to-id'], 'children' => $activity['children'], 'depth' => count($activity['children'])]);
return ''; return '';
} }
self::addActivityId($activity['reply-to-id']); self::addActivityId($activity['reply-to-id']);
@ -1361,6 +1361,7 @@ class Processor
} }
$hash = substr($tag['name'], 0, 1); $hash = substr($tag['name'], 0, 1);
$type = 0;
if ($tag['type'] == 'Mention') { if ($tag['type'] == 'Mention') {
if (in_array($hash, [Tag::TAG_CHARACTER[Tag::MENTION], if (in_array($hash, [Tag::TAG_CHARACTER[Tag::MENTION],
@ -1616,7 +1617,7 @@ class Processor
return []; return [];
} }
if (!self::isValidObject($object, $url)) { if (!self::isValidObject($object)) {
return []; return [];
} }
@ -1657,10 +1658,6 @@ class Processor
return ''; return '';
} }
if (empty($curlResult)) {
return '';
}
$body = $curlResult->getBodyString(); $body = $curlResult->getBodyString();
if (!$curlResult->isSuccess() || empty($body)) { if (!$curlResult->isSuccess() || empty($body)) {
if (in_array($curlResult->getReturnCode(), [403, 404, 406, 410])) { if (in_array($curlResult->getReturnCode(), [403, 404, 406, 410])) {
@ -1680,7 +1677,7 @@ class Processor
return null; return null;
} }
if (!self::isValidObject($object, $url)) { if (!self::isValidObject($object)) {
return null; return null;
} }
@ -1747,7 +1744,7 @@ class Processor
$ldactivity['children'] = $child['children'] ?? []; $ldactivity['children'] = $child['children'] ?? [];
$ldactivity['callstack'] = $child['callstack'] ?? []; $ldactivity['callstack'] = $child['callstack'] ?? [];
// This check is mostly superfluous, since there are similar checks before. This covers the case, when the fetched id doesn't match the url // This check is mostly superfluous, since there are similar checks before. This covers the case, when the fetched id doesn't match the url
if (in_array($activity['id'], $ldactivity['children'])) { if (in_array($activity['id'], $ldactivity['children'])) {
Logger::notice('Fetched id is already in the list of children. It will not be processed.', ['id' => $activity['id'], 'children' => $ldactivity['children'], 'depth' => count($ldactivity['children'])]); Logger::notice('Fetched id is already in the list of children. It will not be processed.', ['id' => $activity['id'], 'children' => $ldactivity['children'], 'depth' => count($ldactivity['children'])]);
return null; return null;
} }
@ -1829,6 +1826,8 @@ class Processor
Logger::notice('Fetch replies - start', ['replies' => $url, 'callstack' => $child['callstack'], 'system' => $callstack]); Logger::notice('Fetch replies - start', ['replies' => $url, 'callstack' => $child['callstack'], 'system' => $callstack]);
$fetched = 0; $fetched = 0;
foreach ($replies as $reply) { foreach ($replies as $reply) {
$id = '';
if (is_array($reply)) { if (is_array($reply)) {
$ldobject = JsonLD::compact($reply); $ldobject = JsonLD::compact($reply);
$id = JsonLD::fetchElement($ldobject, '@id'); $id = JsonLD::fetchElement($ldobject, '@id');
@ -2120,9 +2119,8 @@ class Processor
self::transmitPendingEvents($cid, $owner['uid']); self::transmitPendingEvents($cid, $owner['uid']);
} }
if (empty($contact)) { Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
Contact::update(['hub-verify' => $activity['id'], 'protocol' => Protocol::ACTIVITYPUB], ['id' => $cid]);
}
Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']); Logger::notice('Follow user ' . $uid . ' from contact ' . $cid . ' with id ' . $activity['id']);
Queue::remove($activity); Queue::remove($activity);
} }
@ -2334,6 +2332,8 @@ class Processor
*/ */
public static function acceptFollowUser(array $activity) public static function acceptFollowUser(array $activity)
{ {
$check_id = false;
if (!empty($activity['object_actor'])) { if (!empty($activity['object_actor'])) {
$uid = User::getIdForURL($activity['object_actor']); $uid = User::getIdForURL($activity['object_actor']);
$check_id = false; $check_id = false;

View file

@ -414,7 +414,7 @@ class Queue
{ {
$entries = DBA::select('inbox-entry', ['id'], ["NOT `trust` AND `wid` IS NULL"], ['order' => ['id' => true]]); $entries = DBA::select('inbox-entry', ['id'], ["NOT `trust` AND `wid` IS NULL"], ['order' => ['id' => true]]);
while ($entry = DBA::fetch($entries)) { while ($entry = DBA::fetch($entries)) {
$data = self::reprepareActivityById($entry['id'], false); $data = self::reprepareActivityById($entry['id']);
if ($data['trust']) { if ($data['trust']) {
DBA::update('inbox-entry', ['trust' => true], ['id' => $entry['id']]); DBA::update('inbox-entry', ['trust' => true], ['id' => $entry['id']]);
} }

View file

@ -304,9 +304,10 @@ class Receiver
*/ */
public static function prepareObjectData(array $activity, int $uid, bool $push, bool &$trust_source, string $original_actor = ''): array public static function prepareObjectData(array $activity, int $uid, bool $push, bool &$trust_source, string $original_actor = ''): array
{ {
$id = JsonLD::fetchElement($activity, '@id'); $id = JsonLD::fetchElement($activity, '@id');
$type = JsonLD::fetchElement($activity, '@type'); $type = JsonLD::fetchElement($activity, '@type');
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id'); $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
$object_type = '';
if (!empty($object_id) && in_array($type, ['as:Create', 'as:Update'])) { if (!empty($object_id) && in_array($type, ['as:Create', 'as:Update'])) {
$fetch_id = $object_id; $fetch_id = $object_id;
@ -630,7 +631,7 @@ class Receiver
$id = JsonLD::fetchElement($activity, '@id'); $id = JsonLD::fetchElement($activity, '@id');
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id'); $object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
if (!empty($published) && !empty($object_id) && in_array($type, ['as:Create', 'as:Update']) && in_array($object_type, self::CONTENT_TYPES) if (!empty($published) && $object_id !== null && in_array($type, ['as:Create', 'as:Update']) && in_array($object_type, self::CONTENT_TYPES)
&& ($push || ($completion != self::COMPLETION_MANUAL)) && DI::contentItem()->isTooOld($published) && !Post::exists(['uri' => $object_id])) { && ($push || ($completion != self::COMPLETION_MANUAL)) && DI::contentItem()->isTooOld($published) && !Post::exists(['uri' => $object_id])) {
Logger::debug('Activity is too old. It will not be processed', ['push' => $push, 'completion' => $completion, 'type' => $type, 'object-type' => $object_type, 'published' => $published, 'id' => $id, 'object-id' => $object_id]); Logger::debug('Activity is too old. It will not be processed', ['push' => $push, 'completion' => $completion, 'type' => $type, 'object-type' => $object_type, 'published' => $published, 'id' => $id, 'object-id' => $object_id]);
return true; return true;
@ -641,7 +642,7 @@ class Receiver
// Test the provided signatures against the actor and "attributedTo" // Test the provided signatures against the actor and "attributedTo"
if ($trust_source) { if ($trust_source) {
if (!empty($attributed_to) && !empty($actor)) { if (!empty($attributed_to) && $actor !== null) {
$trust_source = (in_array($actor, $signer) && in_array($attributed_to, $signer)); $trust_source = (in_array($actor, $signer) && in_array($attributed_to, $signer));
} else { } else {
$trust_source = in_array($actor, $signer); $trust_source = in_array($actor, $signer);
@ -1185,6 +1186,8 @@ class Receiver
} }
$parent_followers = ''; $parent_followers = '';
$parent_profile = [];
$parent = Post::selectFirstPost(['parent-author-link'], ['uri' => $reply]); $parent = Post::selectFirstPost(['parent-author-link'], ['uri' => $reply]);
if (!empty($parent['parent-author-link'])) { if (!empty($parent['parent-author-link'])) {
$parent_profile = APContact::getByURL($parent['parent-author-link']); $parent_profile = APContact::getByURL($parent['parent-author-link']);

View file

@ -573,11 +573,12 @@ class Transmitter
$exclusive = false; $exclusive = false;
$mention = false; $mention = false;
$audience = []; $audience = [];
$owner = false;
// Check if we should always deliver our stuff via BCC // Check if we should always deliver our stuff via BCC
if (!empty($item['uid'])) { if (!empty($item['uid'])) {
$owner = User::getOwnerDataById($item['uid']); $owner = User::getOwnerDataById($item['uid']);
if (!empty($owner)) { if (is_array($owner)) {
$always_bcc = $owner['hide-friends']; $always_bcc = $owner['hide-friends'];
$is_group = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY); $is_group = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
@ -1399,7 +1400,7 @@ class Transmitter
$type = self::getTypeOfItem($item); $type = self::getTypeOfItem($item);
if (!$object_mode) { if (!$object_mode) {
$data = ['@context' => $context ?? ActivityPub::CONTEXT]; $data = ['@context' => ActivityPub::CONTEXT];
if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) { if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
$type = 'Undo'; $type = 'Undo';
@ -1750,6 +1751,7 @@ class Transmitter
$title = $item['title']; $title = $item['title'];
$summary = $item['content-warning'] ?: BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB)); $summary = $item['content-warning'] ?: BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
$type = '';
if ($item['event-type'] == 'event') { if ($item['event-type'] == 'event') {
$type = 'Event'; $type = 'Event';

View file

@ -12,7 +12,6 @@ use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Core\Worker; use Friendica\Core\Worker;
use Friendica\Database\Database;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\DI; use Friendica\DI;
use Friendica\Model\Contact; use Friendica\Model\Contact;
@ -48,6 +47,8 @@ class Delivery
$top_level = false; $top_level = false;
$followup = false; $followup = false;
$public_message = false; $public_message = false;
$parent = false;
$thr_parent = false;
$items = []; $items = [];
if ($cmd == self::MAIL) { if ($cmd == self::MAIL) {

View file

@ -623,22 +623,21 @@ class Diaspora
*/ */
private static function validPosting(array $msg) private static function validPosting(array $msg)
{ {
$data = XML::parseString($msg['message']); $element = XML::parseString($msg['message']);
if (!is_object($data)) { if (!is_object($element)) {
Logger::info('No valid XML', ['message' => $msg['message']]); Logger::info('No valid XML', ['message' => $msg['message']]);
return false; return false;
} }
$oldXML = false;
// Is this the new or the old version? // Is this the new or the old version?
if ($data->getName() == 'XML') { if ($element->getName() === 'XML') {
$oldXML = true; $oldXML = true;
foreach ($data->post->children() as $child) { foreach ($element->post->children() as $child) {
$element = $child; $element = $child;
} }
} else {
$oldXML = false;
$element = $data;
} }
$type = $element->getName(); $type = $element->getName();
@ -1460,7 +1459,7 @@ class Diaspora
*/ */
foreach ($matches as $match) { foreach ($matches as $match) {
if (empty($match)) { if ($match === '') {
continue; continue;
} }
@ -3030,7 +3029,7 @@ class Diaspora
// The "addr" field should always be filled. // The "addr" field should always be filled.
// If this isn't the case, it will raise a notice some lines later. // If this isn't the case, it will raise a notice some lines later.
// And in the log we will see where it came from, and we can handle it there. // And in the log we will see where it came from, and we can handle it there.
Logger::notice('Empty addr', ['contact' => $contact ?? []]); Logger::notice('Empty addr', ['contact' => $contact]);
} }
$envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $pubkey ?? '', $public_batch); $envelope = self::buildMessage($msg, $owner, $contact, $owner['uprvkey'], $pubkey ?? '', $public_batch);
@ -3655,6 +3654,8 @@ class Diaspora
*/ */
public static function sendFollowup(array $item, array $owner, array $contact, bool $public_batch = false): int public static function sendFollowup(array $item, array $owner, array $contact, bool $public_batch = false): int
{ {
$type = '';
if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) { if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
$message = self::constructAttend($item, $owner); $message = self::constructAttend($item, $owner);
$type = 'event_participation'; $type = 'event_participation';

View file

@ -556,7 +556,7 @@ class Feed
Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]); Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
continue; continue;
} }
if (!empty($item['plink'])) { if (!empty($item['plink'])) {
$fetch_further_information = $contact['fetch_further_information'] ?? LocalRelationship::FFI_NONE; $fetch_further_information = $contact['fetch_further_information'] ?? LocalRelationship::FFI_NONE;
} else { } else {
@ -736,7 +736,7 @@ class Feed
$publish_at = date(DateTimeFormat::MYSQL, $publish_time); $publish_at = date(DateTimeFormat::MYSQL, $publish_time);
if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) { if (Post\Delayed::add($posting['item']['uri'], $posting['item'], $posting['notify'], Post\Delayed::PREPARED, $publish_at, $posting['taglist'], $posting['attachments'])) {
DI::pConfig()->set($item['uid'], 'system', 'last_publish', $publish_time); DI::pConfig()->set($posting['item']['uid'], 'system', 'last_publish', $publish_time);
} }
} }
} }
@ -1407,7 +1407,7 @@ class Feed
$contact = Contact::getByURL($item['author-link']) ?: $owner; $contact = Contact::getByURL($item['author-link']) ?: $owner;
$contact['nickname'] = $contact['nickname'] ?? $contact['nick']; $contact['nickname'] = $contact['nickname'] ?? $contact['nick'];
$author = self::addAuthor($doc, $contact, false); $author = self::addAuthor($doc, $contact);
$entry->appendChild($author); $entry->appendChild($author);
} }
} else { } else {

View file

@ -286,7 +286,7 @@ class JsonLD
* @param $type * @param $type
* @param $type_value * @param $type_value
* *
* @return string fetched element * @return string|null fetched element
*/ */
public static function fetchElement($array, $element, $key = '@id', $type = null, $type_value = null) public static function fetchElement($array, $element, $key = '@id', $type = null, $type_value = null)
{ {