Fix code style Receiver.php

This commit is contained in:
Michael 2025-01-05 08:48:02 +00:00
parent 8d1971e0b2
commit 9bcd00bfa8

View file

@ -47,6 +47,7 @@ use Friendica\Util\Strings;
class Receiver
{
const PUBLIC_COLLECTION = 'as:Public';
const ACCOUNT_TYPES = ['as:Person', 'as:Organization', 'as:Service', 'as:Group', 'as:Application'];
const CONTENT_TYPES = ['as:Note', 'as:Article', 'as:Video', 'as:Image', 'as:Event', 'as:Audio', 'as:Page', 'as:Question'];
const ACTIVITY_TYPES = ['as:Like', 'as:Dislike', 'as:Accept', 'as:Reject', 'as:TentativeAccept', 'as:View', 'as:Read', 'litepub:EmojiReact'];
@ -373,6 +374,7 @@ class Receiver
$receivers = array_replace($receivers, $additional);
if (empty($activity['thread-completion']) && (empty($reception_types[$uid]) || in_array($reception_types[$uid], [self::TARGET_UNKNOWN, self::TARGET_FOLLOWER, self::TARGET_ANSWER, self::TARGET_GLOBAL]))) {
$reception_types[$uid] = self::TARGET_BCC;
$owner = User::getOwnerDataById($uid);
if (!empty($owner['url'])) {
$urls['as:bcc'][] = $owner['url'];
@ -400,12 +402,14 @@ class Receiver
// Any activities on account types must not be altered
if (in_array($type, ['as:Flag'])) {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
$object_data['object_ids'] = JsonLD::fetchElementArray($activity, 'as:object', '@id');
$object_data['content'] = JsonLD::fetchElement($activity, 'as:content', '@type');
} elseif (in_array($object_type, self::ACCOUNT_TYPES)) {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
$object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor', '@id');
@ -436,12 +440,14 @@ class Receiver
// Create a mostly empty array out of the activity data (instead of the object).
// This way we later don't have to check for the existence of each individual array element.
$object_data = self::processObject($activity, $original_actor);
$object_data['name'] = $type;
$object_data['author'] = JsonLD::fetchElement($activity, 'as:actor', '@id');
$object_data['object_id'] = $object_id;
$object_data['object_type'] = ''; // Since we don't fetch the object, we don't know the type
} elseif (in_array($type, ['as:Add', 'as:Remove', 'as:Move'])) {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['target_id'] = JsonLD::fetchElement($activity, 'as:target', '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
@ -449,6 +455,7 @@ class Receiver
$object_data['object_content'] = JsonLD::fetchElement($activity['as:object'], 'as:content', '@type');
} else {
$object_data = [];
$object_data['id'] = JsonLD::fetchElement($activity, '@id');
$object_data['object_id'] = JsonLD::fetchElement($activity, 'as:object', '@id');
$object_data['object_actor'] = JsonLD::fetchElement($activity['as:object'], 'as:actor', '@id');
@ -555,6 +562,7 @@ class Receiver
$user = User::getById(array_key_first($receivers), ['language']);
$l10n = DI::l10n()->withLang($user['language']);
$object_data['name'] = $l10n->t('Chat');
$mail = DBA::selectFirst('mail', ['uri'], ['uid' => array_key_first($receivers), 'title' => $object_data['name']], ['order' => ['id' => true]]);
@ -1237,8 +1245,10 @@ class Receiver
// Exception: The receiver is targetted via "to" or this is a comment
if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::TYPE_COMMUNITY)) {
$networks = Protocol::FEDERATED;
$condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
$condition = [
'nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND],
'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']
];
// Group posts are only accepted from group contacts
if ($contact['contact-type'] == Contact::TYPE_COMMUNITY) {
@ -1277,6 +1287,7 @@ class Receiver
if (empty($receivers) && !empty($parent['parent-author-link'])) {
$uid = User::getIdForURL($parent['parent-author-link']);
$receivers[$uid] = ['uid' => $uid, 'type' => self::TARGET_BTO];
}
@ -1319,8 +1330,10 @@ class Receiver
*/
private static function getReceiverForActor(array $tags, array $receivers, int $target_type, array $profile): array
{
$basecondition = ['rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false];
$basecondition = [
'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER],
'network' => Protocol::FEDERATED, 'archive' => false, 'pending' => false
];
$condition = DBA::mergeConditions($basecondition, ["`uri-id` = ? AND `uid` != ?", $profile['uri-id'], 0]);
$contacts = DBA::select('contact', ['uid', 'rel'], $condition);
@ -1545,10 +1558,9 @@ class Receiver
continue;
}
$url = JsonLD::fetchElement($emoji['as:icon'], 'as:url', '@id');
$element = [
'name' => JsonLD::fetchElement($emoji, 'as:name', '@value'),
'href' => $url
'href' => JsonLD::fetchElement($emoji['as:icon'], 'as:url', '@id')
];
$emojilist[] = $element;
@ -1847,6 +1859,7 @@ class Receiver
}
$size = (int)JsonLD::fetchElement($url, 'pt:size', '@value');
$attachments[] = ['type' => $filetype, 'mediaType' => $mediatype, 'url' => $href, 'height' => $height, 'size' => $size, 'name' => ''];
} elseif (in_array($mediatype, ['application/x-bittorrent', 'application/x-bittorrent;x-scheme-handler/magnet'])) {
$height = (int)JsonLD::fetchElement($url, 'as:height', '@value');
@ -1909,7 +1922,8 @@ class Receiver
return $object_data;
}
private static function getCapabilities($object) {
private static function getCapabilities($object)
{
$capabilities = [];
foreach (['pixelfed:canAnnounce', 'pixelfed:canLike', 'pixelfed:canReply'] as $element) {
$capabilities_list = JsonLD::fetchElementArray($object['pixelfed:capabilities'], $element, '@id');
@ -1931,6 +1945,7 @@ class Receiver
public static function getObjectDataFromActivity(array $object): array
{
$object_data = [];
$object_data['object_type'] = JsonLD::fetchElement($object, '@type');
$object_data['id'] = JsonLD::fetchElement($object, '@id');
$object_data['reply-to-id'] = JsonLD::fetchElement($object, 'as:inReplyTo', '@id');