]> git.mxchange.org Git - friendica.git/blob - src/Model/APContact.php
09a6cb9e78db781f1ccabac557cd5fbc0747b40c
[friendica.git] / src / Model / APContact.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Model;
23
24 use Friendica\Content\Text\HTML;
25 use Friendica\Core\Cache\Enum\Duration;
26 use Friendica\Core\Logger;
27 use Friendica\Core\Protocol;
28 use Friendica\Core\System;
29 use Friendica\Database\DBA;
30 use Friendica\DI;
31 use Friendica\Model\Item;
32 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
33 use Friendica\Network\HTTPException;
34 use Friendica\Network\Probe;
35 use Friendica\Protocol\ActivityNamespace;
36 use Friendica\Protocol\ActivityPub;
37 use Friendica\Protocol\ActivityPub\Transmitter;
38 use Friendica\Util\Crypto;
39 use Friendica\Util\DateTimeFormat;
40 use Friendica\Util\HTTPSignature;
41 use Friendica\Util\JsonLD;
42 use Friendica\Util\Network;
43 use GuzzleHttp\Psr7\Uri;
44
45 class APContact
46 {
47         /**
48          * Fetch webfinger data
49          *
50          * @param string $addr Address
51          * @return array webfinger data
52          */
53         private static function fetchWebfingerData(string $addr): array
54         {
55                 $addr_parts = explode('@', $addr);
56                 if (count($addr_parts) != 2) {
57                         return [];
58                 }
59
60                 if (Contact::isLocal($addr) && ($local_uid = User::getIdForURL($addr)) && ($local_owner = User::getOwnerDataById($local_uid))) {
61                         $data = [
62                                 'addr'      => $local_owner['addr'],
63                                 'baseurl'   => $local_owner['baseurl'],
64                                 'url'       => $local_owner['url'],
65                                 'subscribe' => $local_owner['baseurl'] . '/contact/follow?url={uri}'];
66
67                         if (!empty($local_owner['alias']) && ($local_owner['url'] != $local_owner['alias'])) {
68                                 $data['alias'] = $local_owner['alias'];
69                         }
70
71                         return $data;
72                 }
73
74                 $data = ['addr' => $addr];
75                 $template = 'https://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
76                 $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), HttpClientAccept::JRD_JSON);
77                 if (empty($webfinger['links'])) {
78                         $template = 'http://' . $addr_parts[1] . '/.well-known/webfinger?resource=acct:' . urlencode($addr);
79                         $webfinger = Probe::webfinger(str_replace('{uri}', urlencode($addr), $template), HttpClientAccept::JRD_JSON);
80                         if (empty($webfinger['links'])) {
81                                 return [];
82                         }
83                         $data['baseurl'] = 'http://' . $addr_parts[1];
84                 } else {
85                         $data['baseurl'] = 'https://' . $addr_parts[1];
86                 }
87
88                 foreach ($webfinger['links'] as $link) {
89                         if (empty($link['rel'])) {
90                                 continue;
91                         }
92
93                         if (!empty($link['template']) && ($link['rel'] == ActivityNamespace::OSTATUSSUB)) {
94                                 $data['subscribe'] = $link['template'];
95                         }
96
97                         if (!empty($link['href']) && !empty($link['type']) && ($link['rel'] == 'self') && ($link['type'] == 'application/activity+json')) {
98                                 $data['url'] = $link['href'];
99                         }
100
101                         if (!empty($link['href']) && !empty($link['type']) && ($link['rel'] == 'http://webfinger.net/rel/profile-page') && ($link['type'] == 'text/html')) {
102                                 $data['alias'] = $link['href'];
103                         }
104                 }
105
106                 if (!empty($data['url']) && !empty($data['alias']) && ($data['url'] == $data['alias'])) {
107                         unset($data['alias']);
108                 }
109
110                 return $data;
111         }
112
113         /**
114          * Fetches a profile from a given url
115          *
116          * @param string  $url    profile url
117          * @param boolean $update true = always update, false = never update, null = update when not found or outdated
118          * @return array profile array
119          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
120          * @throws \ImagickException
121          * @todo Rewrite parameter $update to avoid true|false|null (boolean is binary, null adds a third case)
122          */
123         public static function getByURL(string $url, $update = null): array
124         {
125                 if (empty($url) || Network::isUrlBlocked($url)) {
126                         Logger::info('Domain is blocked', ['url' => $url]);
127                         return [];
128                 }
129
130                 $fetched_contact = [];
131
132                 if (empty($update)) {
133                         if (is_null($update)) {
134                                 $ref_update = DateTimeFormat::utc('now - 1 month');
135                         } else {
136                                 $ref_update = DBA::NULL_DATETIME;
137                         }
138
139                         $apcontact = DBA::selectFirst('apcontact', [], ['url' => $url]);
140                         if (!DBA::isResult($apcontact)) {
141                                 $apcontact = DBA::selectFirst('apcontact', [], ['alias' => $url]);
142                         }
143
144                         if (!DBA::isResult($apcontact)) {
145                                 $apcontact = DBA::selectFirst('apcontact', [], ['addr' => $url]);
146                         }
147
148                         if (DBA::isResult($apcontact) && ($apcontact['updated'] > $ref_update) && !empty($apcontact['pubkey']) && !empty($apcontact['uri-id'])) {
149                                 return $apcontact;
150                         }
151
152                         if (!is_null($update)) {
153                                 return DBA::isResult($apcontact) ? $apcontact : [];
154                         }
155
156                         if (DBA::isResult($apcontact)) {
157                                 $fetched_contact = $apcontact;
158                         }
159                 }
160
161                 $apcontact = [];
162
163                 $webfinger = empty(parse_url($url, PHP_URL_SCHEME));
164                 if ($webfinger) {
165                         $apcontact = self::fetchWebfingerData($url);
166                         if (empty($apcontact['url'])) {
167                                 return $fetched_contact;
168                         }
169                         $url = $apcontact['url'];
170                 } elseif (empty(parse_url($url, PHP_URL_PATH))) {
171                         $apcontact['baseurl'] = $url;
172                 }
173
174                 // Detect multiple fast repeating request to the same address
175                 // See https://github.com/friendica/friendica/issues/9303
176                 $cachekey = 'apcontact:' . ItemURI::getIdByURI($url);
177                 $result = DI::cache()->get($cachekey);
178                 if (!is_null($result)) {
179                         Logger::notice('Multiple requests for the address', ['url' => $url, 'update' => $update, 'callstack' => System::callstack(20), 'result' => $result]);
180                         if (!empty($fetched_contact)) {
181                                 return $fetched_contact;
182                         }
183                 } else {
184                         DI::cache()->set($cachekey, System::callstack(20), Duration::FIVE_MINUTES);
185                 }
186
187                 if (Network::isLocalLink($url) && ($local_uid = User::getIdForURL($url))) {
188                         try {
189                                 $data = Transmitter::getProfile($local_uid);
190                                 $local_owner = User::getOwnerDataById($local_uid);
191                         } catch(HTTPException\NotFoundException $e) {
192                                 $data = null;
193                         }
194                 }
195
196                 if (empty($data)) {
197                         $local_owner = [];
198
199                         $curlResult = HTTPSignature::fetchRaw($url);
200                         $failed = empty($curlResult) || empty($curlResult->getBody()) ||
201                                 (!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
202
203                         if (!$failed) {
204                                 $data = json_decode($curlResult->getBody(), true);
205                                 $failed = empty($data) || !is_array($data);
206                         }
207
208                         if (!$failed && ($curlResult->getReturnCode() == 410)) {
209                                 $data = ['@context' => ActivityPub::CONTEXT, 'id' => $url, 'type' => 'Tombstone'];
210                         }
211
212                         if ($failed) {
213                                 self::markForArchival($fetched_contact ?: []);
214                                 return $fetched_contact;
215                         }
216                 }
217
218                 $compacted = JsonLD::compact($data);
219                 if (empty($compacted['@id'])) {
220                         return $fetched_contact;
221                 }
222
223                 $apcontact['url'] = $compacted['@id'];
224                 $apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value');
225                 $apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
226                 $apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
227                 $apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
228                 $apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
229                 $apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
230
231                 $apcontact['sharedinbox'] = '';
232                 if (!empty($compacted['as:endpoints'])) {
233                         $apcontact['sharedinbox'] = (JsonLD::fetchElement($compacted['as:endpoints'], 'as:sharedInbox', '@id') ?? '');
234                 }
235
236                 $apcontact['featured']      = JsonLD::fetchElement($compacted, 'toot:featured', '@id');
237                 $apcontact['featured-tags'] = JsonLD::fetchElement($compacted, 'toot:featuredTags', '@id');
238
239                 $apcontact['nick'] = JsonLD::fetchElement($compacted, 'as:preferredUsername', '@value') ?? '';
240                 $apcontact['name'] = JsonLD::fetchElement($compacted, 'as:name', '@value');
241
242                 if (empty($apcontact['name'])) {
243                         $apcontact['name'] = $apcontact['nick'];
244                 }
245
246                 $apcontact['about'] = HTML::toBBCode(JsonLD::fetchElement($compacted, 'as:summary', '@value') ?? '');
247
248                 $ims = JsonLD::fetchElementArray($compacted, 'vcard:hasInstantMessage');
249
250                 if (!empty($ims)) {
251                         foreach ($ims as $link) {
252                                 if (substr($link, 0, 5) == 'xmpp:') {
253                                         $apcontact['xmpp'] = substr($link, 5);
254                                 }
255                                 if (substr($link, 0, 7) == 'matrix:') {
256                                         $apcontact['matrix'] = substr($link, 7);
257                                 }
258                         }
259                 }
260
261                 $apcontact['photo'] = JsonLD::fetchElement($compacted, 'as:icon', '@id');
262                 if (is_array($apcontact['photo']) || !empty($compacted['as:icon']['as:url']['@id'])) {
263                         $apcontact['photo'] = JsonLD::fetchElement($compacted['as:icon'], 'as:url', '@id');
264                 }
265
266                 $apcontact['header'] = JsonLD::fetchElement($compacted, 'as:image', '@id');
267                 if (is_array($apcontact['header']) || !empty($compacted['as:image']['as:url']['@id'])) {
268                         $apcontact['header'] = JsonLD::fetchElement($compacted['as:image'], 'as:url', '@id');
269                 }
270
271                 if (empty($apcontact['alias'])) {
272                         $apcontact['alias'] = JsonLD::fetchElement($compacted, 'as:url', '@id');
273                         if (is_array($apcontact['alias'])) {
274                                 $apcontact['alias'] = JsonLD::fetchElement($compacted['as:url'], 'as:href', '@id');
275                         }
276                 }
277
278                 // Quit if none of the basic values are set
279                 if (empty($apcontact['url']) || empty($apcontact['type']) || (($apcontact['type'] != 'Tombstone') && empty($apcontact['inbox']))) {
280                         return $fetched_contact;
281                 } elseif ($apcontact['type'] == 'Tombstone') {
282                         // The "inbox" field must have a content
283                         $apcontact['inbox'] = '';
284                 }
285
286                 // Quit if this doesn't seem to be an account at all
287                 if (!in_array($apcontact['type'], ActivityPub::ACCOUNT_TYPES)) {
288                         return $fetched_contact;
289                 }
290
291                 if (empty($apcontact['addr'])) {
292                         try {
293                                 $apcontact['addr'] = $apcontact['nick'] . '@' . (new Uri($apcontact['url']))->getAuthority();
294                         } catch (\Throwable $e) {
295                                 Logger::warning('Unable to coerce APContact URL into a UriInterface object', ['url' => $apcontact['url'], 'error' => $e->getMessage()]);
296                                 $apcontact['addr'] = '';
297                         }
298                 }
299
300                 $apcontact['pubkey'] = null;
301                 if (!empty($compacted['w3id:publicKey'])) {
302                         $apcontact['pubkey'] = trim(JsonLD::fetchElement($compacted['w3id:publicKey'], 'w3id:publicKeyPem', '@value') ?? '');
303                         if (strpos($apcontact['pubkey'], 'RSA ') !== false) {
304                                 $apcontact['pubkey'] = Crypto::rsaToPem($apcontact['pubkey']);
305                         }
306                 }
307
308                 $apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
309
310                 $apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
311
312                 if (!empty($compacted['as:generator'])) {
313                         $apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
314                         $apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
315                 }
316
317                 if (!empty($apcontact['following'])) {
318                         if (!empty($local_owner)) {
319                                 $following = ActivityPub\Transmitter::getContacts($local_owner, [Contact::SHARING, Contact::FRIEND], 'following');
320                         } else {
321                                 $following = ActivityPub::fetchContent($apcontact['following']);
322                         }
323                         if (!empty($following['totalItems'])) {
324                                 // Mastodon seriously allows for this condition?
325                                 // Jul 14 2021 - See https://mastodon.social/@BLUW for a negative following count
326                                 if ($following['totalItems'] < 0) {
327                                         $following['totalItems'] = 0;
328                                 }
329                                 $apcontact['following_count'] = $following['totalItems'];
330                         }
331                 }
332
333                 if (!empty($apcontact['followers'])) {
334                         if (!empty($local_owner)) {
335                                 $followers = ActivityPub\Transmitter::getContacts($local_owner, [Contact::FOLLOWER, Contact::FRIEND], 'followers');
336                         } else {
337                                 $followers = ActivityPub::fetchContent($apcontact['followers']);
338                         }
339                         if (!empty($followers['totalItems'])) {
340                                 // Mastodon seriously allows for this condition?
341                                 // Jul 14 2021 - See https://mastodon.online/@goes11 for a negative followers count
342                                 if ($followers['totalItems'] < 0) {
343                                         $followers['totalItems'] = 0;
344                                 }
345                                 $apcontact['followers_count'] = $followers['totalItems'];
346                         }
347                 }
348
349                 if (!empty($apcontact['outbox'])) {
350                         if (!empty($local_owner)) {
351                                 $statuses_count = self::getStatusesCount($local_owner);
352                         } else {
353                                 $outbox = ActivityPub::fetchContent($apcontact['outbox']);
354                                 $statuses_count = $outbox['totalItems'] ?? 0;
355                         }
356                         if (!empty($statuses_count)) {
357                                 // Mastodon seriously allows for this condition?
358                                 // Jul 20 2021 - See https://chaos.social/@m11 for a negative posts count
359                                 if ($statuses_count < 0) {
360                                         $statuses_count = 0;
361                                 }
362                                 $apcontact['statuses_count'] = $statuses_count;
363                         }
364                 }
365
366                 $apcontact['discoverable'] = JsonLD::fetchElement($compacted, 'toot:discoverable', '@value');
367
368                 // To-Do
369
370                 // Unhandled
371                 // tag, attachment, image, nomadicLocations, signature, movedTo, liked
372
373                 // Unhandled from Misskey
374                 // sharedInbox, isCat
375
376                 // Unhandled from Kroeg
377                 // kroeg:blocks, updated
378
379                 // When the photo is too large, try to shorten it by removing parts
380                 if (strlen($apcontact['photo'] ?? '') > 255) {
381                         $parts = parse_url($apcontact['photo']);
382                         unset($parts['fragment']);
383                         $apcontact['photo'] = (string)Uri::fromParts($parts);
384
385                         if (strlen($apcontact['photo']) > 255) {
386                                 unset($parts['query']);
387                                 $apcontact['photo'] = (string)Uri::fromParts($parts);
388                         }
389
390                         if (strlen($apcontact['photo']) > 255) {
391                                 $apcontact['photo'] = substr($apcontact['photo'], 0, 255);
392                         }
393                 }
394
395                 if (!$webfinger && !empty($apcontact['addr'])) {
396                         $data = self::fetchWebfingerData($apcontact['addr']);
397                         if (!empty($data)) {
398                                 $apcontact['baseurl'] = $data['baseurl'];
399
400                                 if (empty($apcontact['alias']) && !empty($data['alias'])) {
401                                         $apcontact['alias'] = $data['alias'];
402                                 }
403                                 if (!empty($data['subscribe'])) {
404                                         $apcontact['subscribe'] = $data['subscribe'];
405                                 }
406                         } else {
407                                 $apcontact['addr'] = null;
408                         }
409                 }
410
411                 if (empty($apcontact['baseurl'])) {
412                         $apcontact['baseurl'] = null;
413                 }
414
415                 if (empty($apcontact['subscribe'])) {
416                         $apcontact['subscribe'] = null;
417                 }
418
419                 if (!empty($apcontact['baseurl']) && empty($fetched_contact['gsid'])) {
420                         $apcontact['gsid'] = GServer::getID($apcontact['baseurl']);
421                 } elseif (!empty($fetched_contact['gsid'])) {
422                         $apcontact['gsid'] = $fetched_contact['gsid'];
423                 } else {
424                         $apcontact['gsid'] = null;
425                 }
426
427                 self::unarchiveInbox($apcontact['inbox'], false, $apcontact['gsid']);
428
429                 if (!empty($apcontact['sharedinbox'])) {
430                         self::unarchiveInbox($apcontact['sharedinbox'], true, $apcontact['gsid']);
431                 }
432
433                 if ($apcontact['url'] == $apcontact['alias']) {
434                         $apcontact['alias'] = null;
435                 }
436
437                 if (empty($apcontact['uuid'])) {
438                         $apcontact['uri-id'] = ItemURI::getIdByURI($apcontact['url']);
439                 } else {
440                         $apcontact['uri-id'] = ItemURI::insert(['uri' => $apcontact['url'], 'guid' => $apcontact['uuid']]);
441                 }
442
443                 foreach (APContact\Endpoint::ENDPOINT_NAMES as $type => $name) {
444                         $value = JsonLD::fetchElement($compacted, $name, '@id');
445                         if (empty($value)) {
446                                 continue;
447                         }
448                         APContact\Endpoint::update($apcontact['uri-id'], $type, $value);
449                 }
450
451                 if (!empty($compacted['as:endpoints'])) {
452                         foreach ($compacted['as:endpoints'] as $name => $endpoint) {
453                                 if (empty($endpoint['@id']) || !is_string($endpoint['@id'])) {
454                                         continue;
455                                 }
456
457                                 if (in_array($name, APContact\Endpoint::ENDPOINT_NAMES)) {
458                                         $key = array_search($name, APContact\Endpoint::ENDPOINT_NAMES);
459                                         APContact\Endpoint::update($apcontact['uri-id'], $key, $endpoint['@id']);
460                                         Logger::debug('Store endpoint', ['key' => $key, 'name' => $name, 'endpoint' => $endpoint['@id']]);
461                                 } elseif (!in_array($name, ['as:sharedInbox', 'as:uploadMedia', 'as:oauthTokenEndpoint', 'as:oauthAuthorizationEndpoint', 'litepub:oauthRegistrationEndpoint'])) {
462                                         Logger::debug('Unknown endpoint', ['name' => $name, 'endpoint' => $endpoint['@id']]);
463                                 }
464                         }
465                 }
466
467                 $apcontact['updated'] = DateTimeFormat::utcNow();
468
469                 // We delete the old entry when the URL is changed
470                 if ($url != $apcontact['url']) {
471                         Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]);
472                         DBA::delete('apcontact', ['url' => $url]);
473                 }
474
475                 // Limit the length on incoming fields
476                 $apcontact = DI::dbaDefinition()->truncateFieldsForTable('apcontact', $apcontact);
477
478                 if (DBA::exists('apcontact', ['url' => $apcontact['url']])) {
479                         DBA::update('apcontact', $apcontact, ['url' => $apcontact['url']]);
480                 } else {
481                         DBA::replace('apcontact', $apcontact);
482                 }
483
484                 Logger::info('Updated profile', ['url' => $url]);
485
486                 return DBA::selectFirst('apcontact', [], ['url' => $apcontact['url']]) ?: [];
487         }
488
489         /**
490          * Fetch the number of statuses for the given owner
491          *
492          * @param array $owner
493          *
494          * @return integer
495          */
496         private static function getStatusesCount(array $owner): int
497         {
498                 $condition = [
499                         'private'        => [Item::PUBLIC, Item::UNLISTED],
500                         'author-id'      => Contact::getIdForURL($owner['url'], 0, false),
501                         'gravity'        => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT],
502                         'network'        => Protocol::DFRN,
503                         'parent-network' => Protocol::FEDERATED,
504                         'deleted'        => false,
505                         'visible'        => true,
506                 ];
507
508                 $count = Post::countPosts($condition);
509
510                 return $count;
511         }
512
513         /**
514          * Mark the given AP Contact as "to archive"
515          *
516          * @param array $apcontact
517          * @return void
518          */
519         public static function markForArchival(array $apcontact)
520         {
521                 if (!empty($apcontact['inbox'])) {
522                         Logger::info('Set inbox status to failure', ['inbox' => $apcontact['inbox']]);
523                         HTTPSignature::setInboxStatus($apcontact['inbox'], false, false, $apcontact['gsid']);
524                 }
525
526                 if (!empty($apcontact['sharedinbox'])) {
527                         // Check if there are any available inboxes
528                         $available = DBA::exists('apcontact', ["`sharedinbox` = ? AnD `inbox` IN (SELECT `url` FROM `inbox-status` WHERE `success` > `failure`)",
529                                 $apcontact['sharedinbox']]);
530                         if (!$available) {
531                                 // If all known personal inboxes are failing then set their shared inbox to failure as well
532                                 Logger::info('Set shared inbox status to failure', ['sharedinbox' => $apcontact['sharedinbox']]);
533                                 HTTPSignature::setInboxStatus($apcontact['sharedinbox'], false, true, $apcontact['gsid']);
534                         }
535                 }
536         }
537
538         /**
539          * Unmark the given AP Contact as "to archive"
540          *
541          * @param array $apcontact
542          * @return void
543          */
544         public static function unmarkForArchival(array $apcontact)
545         {
546                 if (!empty($apcontact['inbox'])) {
547                         Logger::info('Set inbox status to success', ['inbox' => $apcontact['inbox']]);
548                         HTTPSignature::setInboxStatus($apcontact['inbox'], true, false, $apcontact['gsid']);
549                 }
550                 if (!empty($apcontact['sharedinbox'])) {
551                         Logger::info('Set shared inbox status to success', ['sharedinbox' => $apcontact['sharedinbox']]);
552                         HTTPSignature::setInboxStatus($apcontact['sharedinbox'], true, true, $apcontact['gsid']);
553                 }
554         }
555
556         /**
557          * Unarchive inboxes
558          *
559          * @param string  $url    inbox url
560          * @param boolean $shared Shared Inbox
561          * @param int     $gsid   Global server id
562          * @return void
563          */
564         private static function unarchiveInbox(string $url, bool $shared, int $gsid = null)
565         {
566                 if (empty($url)) {
567                         return;
568                 }
569
570                 HTTPSignature::setInboxStatus($url, true, $shared, $gsid);
571         }
572
573         /**
574          * Check if the apcontact is a relay account
575          *
576          * @param array $apcontact
577          *
578          * @return bool
579          */
580         public static function isRelay(array $apcontact): bool
581         {
582                 if (empty($apcontact['nick']) || $apcontact['nick'] != 'relay') {
583                         return false;
584                 }
585
586                 if (!empty($apcontact['type']) && $apcontact['type'] == 'Application') {
587                         return true;
588                 }
589
590                 if (!empty($apcontact['type']) && in_array($apcontact['type'], ['Group', 'Service']) && is_null($apcontact['outbox'])) {
591                         return true;
592                 }
593
594                 return false;
595         }
596 }