From 8e67d289977cfe87edfa7854c383eb6e362a13d9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 23 Nov 2022 10:35:49 -0500 Subject: [PATCH 1/6] Return early if user contact doesn't exist in Mastodon\Notification::getType - Address https://github.com/friendica/friendica/issues/11993#issuecomment-1321804594 --- src/Factory/Api/Mastodon/Notification.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Factory/Api/Mastodon/Notification.php b/src/Factory/Api/Mastodon/Notification.php index adaf2d868..32ea681da 100644 --- a/src/Factory/Api/Mastodon/Notification.php +++ b/src/Factory/Api/Mastodon/Notification.php @@ -87,6 +87,11 @@ class Notification extends BaseFactory if (($contact['uid'] == 0) && !empty($contact['uri-id'])) { $contact = Contact::selectFirst(['pending'], ['uri-id' => $contact['uri-id'], 'uid' => $Notification->uid]); } + + if (!isset($contact['pending'])) { + return ''; + } + $type = $contact['pending'] ? MstdnNotification::TYPE_INTRODUCTION : MstdnNotification::TYPE_FOLLOW; } elseif (($Notification->verb == Activity::ANNOUNCE) && in_array($Notification->type, [Post\UserNotification::TYPE_DIRECT_COMMENT, Post\UserNotification::TYPE_DIRECT_THREAD_COMMENT])) { From a8eabae12fd8e54c6b16fd6f306640701b8dae23 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 23 Nov 2022 10:40:41 -0500 Subject: [PATCH 2/6] Ensure $owner is set in ActivityPub\Transmitter::sendActivity - Address https://github.com/friendica/friendica/issues/11993#issuecomment-1322704863 --- src/Protocol/ActivityPub/Transmitter.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index 1d71e9333..e540cc2a9 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -2031,6 +2031,10 @@ class Transmitter } $owner = User::getOwnerDataById($uid); + if (empty($owner)) { + Logger::warning('No user found for actor, aborting', ['uid' => $uid]); + return false; + } if (empty($id)) { $id = DI::baseUrl() . '/activity/' . System::createGUID(); From a5af1408d6f772a52382bdad9e79e93d54bb81f3 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 23 Nov 2022 10:47:51 -0500 Subject: [PATCH 3/6] Ward against the possible case that $actor is empty in ActivityPub\Processor::createItem - Address https://github.com/friendica/friendica/issues/11993#issuecomment-1323273452 --- src/Protocol/ActivityPub/Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 98fed12a3..3f61fe8f1 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -431,7 +431,7 @@ class Processor $item['owner-id'] = $item['author-id']; } else { $actor = APContact::getByURL($item['owner-link'], false); - $item['isForum'] = ($actor['type'] == 'Group'); + $item['isForum'] = ($actor['type'] ?? 'Person') == 'Group'; } $item['uri'] = $activity['id']; From 7c6d54c98903a2a8a77fd32411041e61036f1d1d Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 23 Nov 2022 11:00:15 -0500 Subject: [PATCH 4/6] Ensure $attachment has a width and a height when it's an image in Mastodon\Attachment - Address https://github.com/friendica/friendica/issues/11993#issuecomment-1323274513 --- src/Factory/Api/Mastodon/Attachment.php | 10 +++++++--- src/Object/Api/Mastodon/Attachment.php | 12 +++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Factory/Api/Mastodon/Attachment.php b/src/Factory/Api/Mastodon/Attachment.php index 5a87aeed9..accebe343 100644 --- a/src/Factory/Api/Mastodon/Attachment.php +++ b/src/Factory/Api/Mastodon/Attachment.php @@ -94,12 +94,17 @@ class Attachment extends BaseFactory */ public function createFromPhoto(int $id): array { - $photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type'], ['id' => $id]); + $photo = Photo::selectFirst(['resource-id', 'uid', 'id', 'title', 'type', 'width', 'height'], ['id' => $id]); if (empty($photo)) { return []; } - $attachment = ['id' => $photo['id'], 'description' => $photo['title']]; + $attachment = [ + 'id' => $photo['id'], + 'description' => $photo['title'], + 'width' => $photo['width'], + 'height' => $photo['height'], + ]; $photoTypes = Images::supportedTypes(); $ext = $photoTypes[$photo['type']]; @@ -113,7 +118,6 @@ class Attachment extends BaseFactory $preview_url = ''; } - $object = new \Friendica\Object\Api\Mastodon\Attachment($attachment, 'image', $url, $preview_url, ''); return $object->toArray(); } diff --git a/src/Object/Api/Mastodon/Attachment.php b/src/Object/Api/Mastodon/Attachment.php index 90b1bffb9..3f890bf74 100644 --- a/src/Object/Api/Mastodon/Attachment.php +++ b/src/Object/Api/Mastodon/Attachment.php @@ -22,6 +22,8 @@ namespace Friendica\Object\Api\Mastodon; use Friendica\BaseDataTransferObject; +use Friendica\Core\Logger; +use Friendica\Core\System; /** * Class Attachment @@ -50,8 +52,12 @@ class Attachment extends BaseDataTransferObject /** * Creates an attachment * - * @param array $attachment - * @throws \Friendica\Network\HTTPException\InternalServerErrorException + * @param array $attachment Expected keys: id, description + * If $type == 'image': width, height[, preview-width, preview-height] + * @param string $type One of: audio, video, gifv, image, unknown + * @param string $url + * @param string $preview + * @param string $remote */ public function __construct(array $attachment, string $type, string $url, string $preview, string $remote) { @@ -70,7 +76,7 @@ class Attachment extends BaseDataTransferObject $this->meta['original']['aspect'] = (float) ((int) $attachment['width'] / (int) $attachment['height']); } - if ((int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) { + if (isset($attachment['preview-width']) && (int) $attachment['preview-width'] > 0 && (int) $attachment['preview-height'] > 0) { $this->meta['small']['width'] = (int) $attachment['preview-width']; $this->meta['small']['height'] = (int) $attachment['preview-height']; $this->meta['small']['size'] = (int) $attachment['preview-width'] . 'x' . (int) $attachment['preview-height']; From 14ebc4a8210df588eb5509f81b50d083433433e5 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 23 Nov 2022 11:05:36 -0500 Subject: [PATCH 5/6] Ensure $owner is set in ActivityPub\Transmitter::sendContactReject - Address https://github.com/friendica/friendica/issues/11993#issuecomment-1289535020 --- src/Protocol/ActivityPub/Transmitter.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index e540cc2a9..65abb5d5d 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -2171,6 +2171,11 @@ class Transmitter } $owner = User::getOwnerDataById($uid); + if (empty($owner)) { + Logger::notice('No user found for actor', ['uid' => $uid]); + return false; + } + $data = [ '@context' => ActivityPub::CONTEXT, 'id' => DI::baseUrl() . '/activity/' . System::createGUID(), From 32aa8bd19856203f7ee3bc5a5e4785c8a44fee04 Mon Sep 17 00:00:00 2001 From: Marek Bachmann Date: Wed, 23 Nov 2022 18:17:33 +0100 Subject: [PATCH 6/6] Added information that max image upload size on admin page does not affect server-side upload limits --- src/Module/Admin/Site.php | 2 +- view/lang/C/messages.po | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Module/Admin/Site.php b/src/Module/Admin/Site.php index e27719460..f7fc9d793 100644 --- a/src/Module/Admin/Site.php +++ b/src/Module/Admin/Site.php @@ -467,7 +467,7 @@ class Site extends BaseAdmin '$show_help' => ['show_help', DI::l10n()->t('Show help entry from navigation menu'), !DI::config()->get('system', 'hide_help'), DI::l10n()->t('Displays the menu entry for the Help pages from the navigation menu. It is always accessible by calling /help directly.')], '$singleuser' => ['singleuser', DI::l10n()->t('Single user instance'), DI::config()->get('system', 'singleuser', '---'), DI::l10n()->t('Make this instance multi-user or single-user for the named user'), $user_names], - '$maximagesize' => ['maximagesize', DI::l10n()->t('Maximum image size'), DI::config()->get('system', 'maximagesize'), DI::l10n()->t('Maximum size in bytes of uploaded images. Default is 0, which means no limits.')], + '$maximagesize' => ['maximagesize', DI::l10n()->t('Maximum image size'), DI::config()->get('system', 'maximagesize'), DI::l10n()->t('Maximum size in bytes of uploaded images. Default is 0, which means no limits. Be aware that this setting does not affect server-side upload limits.')], '$maximagelength' => ['maximagelength', DI::l10n()->t('Maximum image length'), DI::config()->get('system', 'max_image_length'), DI::l10n()->t('Maximum length in pixels of the longest side of uploaded images. Default is -1, which means no limits.')], '$jpegimagequality' => ['jpegimagequality', DI::l10n()->t('JPEG image quality'), DI::config()->get('system', 'jpeg_quality'), DI::l10n()->t('Uploaded JPEGS will be saved at this quality setting [0-100]. Default is 100, which is full quality.')], diff --git a/view/lang/C/messages.po b/view/lang/C/messages.po index 8494c627f..14ac264f1 100644 --- a/view/lang/C/messages.po +++ b/view/lang/C/messages.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: 2022.12-dev\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2022-11-23 14:15+0000\n" +"POT-Creation-Date: 2022-11-23 18:16+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -4285,7 +4285,7 @@ msgstr "" #: src/Module/Admin/Site.php:470 msgid "" "Maximum size in bytes of uploaded images. Default is 0, which means no " -"limits." +"limits. Be aware that this setting does not affect server-side upload limits." msgstr "" #: src/Module/Admin/Site.php:471