]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/GContact.php
Ensure APContact::getByUrl always returns an array
[friendica.git] / src / Model / GContact.php
index 19d27109ea856c779a83904c2af0667342d01b4a..95f1080f8d56570cdd87a2e522121c3024f98c79 100644 (file)
@@ -627,10 +627,11 @@ class GContact
                        $contact['about'] = $contact['about'] ?? '';
                        $contact['generation'] = $contact['generation'] ?? 0;
 
-                       $fields = ['name' => $contact['name'], 'nick' => $contact['nick'], 'addr' => $contact['addr'], 'network' => $contact['network'],
+                       $fields = ['name' => $contact['name'], 'nick' => $contact['nick'] ?? '', 'addr' => $contact['addr'] ?? '', 'network' => $contact['network'],
                                'url' => $contact['url'], 'nurl' => Strings::normaliseLink($contact['url']), 'photo' => $contact['photo'],
                                'created' => DateTimeFormat::utcNow(), 'updated' => DateTimeFormat::utcNow(), 'location' => $contact['location'],
                                'about' => $contact['about'], 'hide' => $contact['hide'], 'generation' => $contact['generation']];
+
                        DBA::insert('gcontact', $fields);
 
                        $condition = ['nurl' => Strings::normaliseLink($contact['url'])];
@@ -809,14 +810,11 @@ class GContact
                        return;
                }
 
-               // When the profile doesn't have got a feed, then we exit here
-               if (empty($data['poll'])) {
-                       return;
-               }
-
-               if ($data['network'] == Protocol::ACTIVITYPUB) {
+               if (!empty($data['outbox'])) {
+                       self::updateFromOutbox($data['outbox'], $data);
+               } elseif (!empty($data['poll']) && ($data['network'] == Protocol::ACTIVITYPUB)) {
                        self::updateFromOutbox($data['poll'], $data);
-               } else {
+               } elseif (!empty($data['poll'])) {
                        self::updateFromFeed($data);
                }
        }
@@ -885,10 +883,17 @@ class GContact
                }
 
                $last_updated = '';
-
                foreach ($items as $activity) {
-                       if ($last_updated < $activity['published']) {
-                               $last_updated = $activity['published'];
+                       if (!empty($activity['published'])) {
+                               $published =  DateTimeFormat::utc($activity['published']);
+                       } elseif (!empty($activity['object']['published'])) {
+                               $published =  DateTimeFormat::utc($activity['object']['published']);
+                       } else {
+                               continue;
+                       }
+
+                       if ($last_updated < $published) {
+                               $last_updated = $published;
                        }
                }