mirror of
https://github.com/friendica/friendica
synced 2024-12-22 19:20:17 +00:00
Fix all errors in Protocol namespace
This commit is contained in:
parent
5469637f2b
commit
9638113244
10 changed files with 46 additions and 36 deletions
|
@ -323,7 +323,7 @@ class ClientToServer
|
|||
$requester_id = Contact::getIdForURL($requester, $owner['uid']);
|
||||
if (!empty($requester_id)) {
|
||||
$permissionSets = DI::permissionSet()->selectByContactId($requester_id, $owner['uid']);
|
||||
if (!empty($permissionSets)) {
|
||||
if ($permissionSets->getTotalCount() > 0) {
|
||||
$condition = ['psid' => array_merge($permissionSets->column('id'),
|
||||
[DI::permissionSet()->selectPublicForUser($owner['uid'])])];
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ class Delivery
|
|||
continue;
|
||||
}
|
||||
|
||||
$result = [];
|
||||
|
||||
if (!$serverfail) {
|
||||
$result = self::deliverToInbox($post['command'], 0, $inbox, $owner, $post['receivers'], $post['uri-id']);
|
||||
|
||||
|
@ -121,11 +123,12 @@ class Delivery
|
|||
$serverfail = $response->isTimeout();
|
||||
} catch (\Throwable $th) {
|
||||
Logger::notice('Got exception', ['code' => $th->getCode(), 'message' => $th->getMessage()]);
|
||||
$response = null;
|
||||
$success = false;
|
||||
$serverfail = true;
|
||||
}
|
||||
$runtime = microtime(true) - $timestamp;
|
||||
if (!$success) {
|
||||
if ($success === false) {
|
||||
// 5xx errors are problems on the server. We don't need to continue delivery then.
|
||||
if (!$serverfail && ($response->getReturnCode() >= 500) && ($response->getReturnCode() <= 599)) {
|
||||
$serverfail = true;
|
||||
|
|
|
@ -520,7 +520,7 @@ class Processor
|
|||
if (!DI::config()->get('system', 'decoupled_receiver')) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
$replies = [$item['thr-parent']];
|
||||
if (!empty($item['parent-uri'])) {
|
||||
$replies[] = $item['parent-uri'];
|
||||
|
@ -561,7 +561,7 @@ class Processor
|
|||
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'])]);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
self::addActivityId($activity['reply-to-id']);
|
||||
|
||||
|
@ -1361,6 +1361,7 @@ class Processor
|
|||
}
|
||||
|
||||
$hash = substr($tag['name'], 0, 1);
|
||||
$type = 0;
|
||||
|
||||
if ($tag['type'] == 'Mention') {
|
||||
if (in_array($hash, [Tag::TAG_CHARACTER[Tag::MENTION],
|
||||
|
@ -1616,7 +1617,7 @@ class Processor
|
|||
return [];
|
||||
}
|
||||
|
||||
if (!self::isValidObject($object, $url)) {
|
||||
if (!self::isValidObject($object)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
|
@ -1657,10 +1658,6 @@ class Processor
|
|||
return '';
|
||||
}
|
||||
|
||||
if (empty($curlResult)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$body = $curlResult->getBodyString();
|
||||
if (!$curlResult->isSuccess() || empty($body)) {
|
||||
if (in_array($curlResult->getReturnCode(), [403, 404, 406, 410])) {
|
||||
|
@ -1680,7 +1677,7 @@ class Processor
|
|||
return null;
|
||||
}
|
||||
|
||||
if (!self::isValidObject($object, $url)) {
|
||||
if (!self::isValidObject($object)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -1747,7 +1744,7 @@ class Processor
|
|||
$ldactivity['children'] = $child['children'] ?? [];
|
||||
$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
|
||||
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'])]);
|
||||
return null;
|
||||
}
|
||||
|
@ -1829,6 +1826,8 @@ class Processor
|
|||
Logger::notice('Fetch replies - start', ['replies' => $url, 'callstack' => $child['callstack'], 'system' => $callstack]);
|
||||
$fetched = 0;
|
||||
foreach ($replies as $reply) {
|
||||
$id = '';
|
||||
|
||||
if (is_array($reply)) {
|
||||
$ldobject = JsonLD::compact($reply);
|
||||
$id = JsonLD::fetchElement($ldobject, '@id');
|
||||
|
@ -2120,9 +2119,8 @@ class Processor
|
|||
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']);
|
||||
Queue::remove($activity);
|
||||
}
|
||||
|
@ -2334,6 +2332,8 @@ class Processor
|
|||
*/
|
||||
public static function acceptFollowUser(array $activity)
|
||||
{
|
||||
$check_id = false;
|
||||
|
||||
if (!empty($activity['object_actor'])) {
|
||||
$uid = User::getIdForURL($activity['object_actor']);
|
||||
$check_id = false;
|
||||
|
|
|
@ -414,7 +414,7 @@ class Queue
|
|||
{
|
||||
$entries = DBA::select('inbox-entry', ['id'], ["NOT `trust` AND `wid` IS NULL"], ['order' => ['id' => true]]);
|
||||
while ($entry = DBA::fetch($entries)) {
|
||||
$data = self::reprepareActivityById($entry['id'], false);
|
||||
$data = self::reprepareActivityById($entry['id']);
|
||||
if ($data['trust']) {
|
||||
DBA::update('inbox-entry', ['trust' => true], ['id' => $entry['id']]);
|
||||
}
|
||||
|
|
|
@ -304,9 +304,10 @@ class Receiver
|
|||
*/
|
||||
public static function prepareObjectData(array $activity, int $uid, bool $push, bool &$trust_source, string $original_actor = ''): array
|
||||
{
|
||||
$id = JsonLD::fetchElement($activity, '@id');
|
||||
$type = JsonLD::fetchElement($activity, '@type');
|
||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||
$id = JsonLD::fetchElement($activity, '@id');
|
||||
$type = JsonLD::fetchElement($activity, '@type');
|
||||
$object_id = JsonLD::fetchElement($activity, 'as:object', '@id');
|
||||
$object_type = '';
|
||||
|
||||
if (!empty($object_id) && in_array($type, ['as:Create', 'as:Update'])) {
|
||||
$fetch_id = $object_id;
|
||||
|
@ -630,7 +631,7 @@ class Receiver
|
|||
$id = JsonLD::fetchElement($activity, '@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])) {
|
||||
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;
|
||||
|
@ -641,7 +642,7 @@ class Receiver
|
|||
|
||||
// Test the provided signatures against the actor and "attributedTo"
|
||||
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));
|
||||
} else {
|
||||
$trust_source = in_array($actor, $signer);
|
||||
|
@ -1185,6 +1186,8 @@ class Receiver
|
|||
}
|
||||
|
||||
$parent_followers = '';
|
||||
$parent_profile = [];
|
||||
|
||||
$parent = Post::selectFirstPost(['parent-author-link'], ['uri' => $reply]);
|
||||
if (!empty($parent['parent-author-link'])) {
|
||||
$parent_profile = APContact::getByURL($parent['parent-author-link']);
|
||||
|
|
|
@ -573,11 +573,12 @@ class Transmitter
|
|||
$exclusive = false;
|
||||
$mention = false;
|
||||
$audience = [];
|
||||
$owner = false;
|
||||
|
||||
// Check if we should always deliver our stuff via BCC
|
||||
if (!empty($item['uid'])) {
|
||||
$owner = User::getOwnerDataById($item['uid']);
|
||||
if (!empty($owner)) {
|
||||
if (is_array($owner)) {
|
||||
$always_bcc = $owner['hide-friends'];
|
||||
$is_group = ($owner['account-type'] == User::ACCOUNT_TYPE_COMMUNITY);
|
||||
|
||||
|
@ -1399,7 +1400,7 @@ class Transmitter
|
|||
$type = self::getTypeOfItem($item);
|
||||
|
||||
if (!$object_mode) {
|
||||
$data = ['@context' => $context ?? ActivityPub::CONTEXT];
|
||||
$data = ['@context' => ActivityPub::CONTEXT];
|
||||
|
||||
if ($item['deleted'] && ($item['gravity'] == Item::GRAVITY_ACTIVITY)) {
|
||||
$type = 'Undo';
|
||||
|
@ -1750,6 +1751,7 @@ class Transmitter
|
|||
|
||||
$title = $item['title'];
|
||||
$summary = $item['content-warning'] ?: BBCode::toPlaintext(BBCode::getAbstract($item['body'], Protocol::ACTIVITYPUB));
|
||||
$type = '';
|
||||
|
||||
if ($item['event-type'] == 'event') {
|
||||
$type = 'Event';
|
||||
|
|
|
@ -12,7 +12,6 @@ use Friendica\Contact\FriendSuggest\Exception\FriendSuggestNotFoundException;
|
|||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\Database;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Contact;
|
||||
|
@ -48,6 +47,8 @@ class Delivery
|
|||
$top_level = false;
|
||||
$followup = false;
|
||||
$public_message = false;
|
||||
$parent = false;
|
||||
$thr_parent = false;
|
||||
|
||||
$items = [];
|
||||
if ($cmd == self::MAIL) {
|
||||
|
|
|
@ -623,22 +623,21 @@ class Diaspora
|
|||
*/
|
||||
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']]);
|
||||
return false;
|
||||
}
|
||||
|
||||
$oldXML = false;
|
||||
|
||||
// Is this the new or the old version?
|
||||
if ($data->getName() == 'XML') {
|
||||
if ($element->getName() === 'XML') {
|
||||
$oldXML = true;
|
||||
foreach ($data->post->children() as $child) {
|
||||
foreach ($element->post->children() as $child) {
|
||||
$element = $child;
|
||||
}
|
||||
} else {
|
||||
$oldXML = false;
|
||||
$element = $data;
|
||||
}
|
||||
|
||||
$type = $element->getName();
|
||||
|
@ -1460,7 +1459,7 @@ class Diaspora
|
|||
*/
|
||||
|
||||
foreach ($matches as $match) {
|
||||
if (empty($match)) {
|
||||
if ($match === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -3030,7 +3029,7 @@ class Diaspora
|
|||
// The "addr" field should always be filled.
|
||||
// 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.
|
||||
Logger::notice('Empty addr', ['contact' => $contact ?? []]);
|
||||
Logger::notice('Empty addr', ['contact' => $contact]);
|
||||
}
|
||||
|
||||
$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
|
||||
{
|
||||
$type = '';
|
||||
|
||||
if (in_array($item['verb'], [Activity::ATTEND, Activity::ATTENDNO, Activity::ATTENDMAYBE])) {
|
||||
$message = self::constructAttend($item, $owner);
|
||||
$type = 'event_participation';
|
||||
|
|
|
@ -556,7 +556,7 @@ class Feed
|
|||
Logger::info('Feed is too old', ['created' => $item['created'], 'uid' => $item['uid'], 'uri' => $item['uri']]);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if (!empty($item['plink'])) {
|
||||
$fetch_further_information = $contact['fetch_further_information'] ?? LocalRelationship::FFI_NONE;
|
||||
} else {
|
||||
|
@ -736,7 +736,7 @@ class Feed
|
|||
$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'])) {
|
||||
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['nickname'] = $contact['nickname'] ?? $contact['nick'];
|
||||
$author = self::addAuthor($doc, $contact, false);
|
||||
$author = self::addAuthor($doc, $contact);
|
||||
$entry->appendChild($author);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -286,7 +286,7 @@ class JsonLD
|
|||
* @param $type
|
||||
* @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)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue