From 1a98961c3c571e33eb9544dcad824063751ac31c Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 18 Mar 2023 06:41:35 +0000
Subject: [PATCH] Issue 12858: Peertube avatars can now be fetched

---
 src/Model/APContact.php | 6 +++++-
 src/Util/Images.php     | 7 ++++++-
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/Model/APContact.php b/src/Model/APContact.php
index 20457b46e8..dc062fe5b5 100644
--- a/src/Model/APContact.php
+++ b/src/Model/APContact.php
@@ -29,7 +29,6 @@ use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
 use Friendica\Model\Item;
-use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPException;
 use Friendica\Network\Probe;
 use Friendica\Protocol\ActivityNamespace;
@@ -259,6 +258,11 @@ class APContact
 		$apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id');
 		if (is_array($apcontact['photo']) || !empty($compacted['as:icon']['as:url']['@id'])) {
 			$apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id');
+		} elseif (empty($apcontact['photo'])) {
+			$photo = JsonLD::fetchElementArray($compacted, 'as:icon', 'as:url');
+			if (!empty($photo[0]['@id'])) {
+				$apcontact['photo'] = $photo[0]['@id'];
+			}
 		}
 
 		$apcontact['header'] = JsonLD::fetchElement($compacted, 'as:image', '@id');
diff --git a/src/Util/Images.php b/src/Util/Images.php
index 6874d36e9b..90d120081b 100644
--- a/src/Util/Images.php
+++ b/src/Util/Images.php
@@ -229,7 +229,12 @@ class Images
 		}
 
 		if (empty($img_str)) {
-			$img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
+			try {
+				$img_str = DI::httpClient()->fetch($url, HttpClientAccept::IMAGE, 4);
+			} catch (\Exception $exception) {
+				Logger::notice('Image is invalid', ['url' => $url, 'exception' => $exception]);
+				return [];
+			}
 		}
 
 		if (!$img_str) {
-- 
2.39.5