]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Fix tests
[friendica.git] / src / Model / Contact.php
index 1ec1424dd8db7948fabd307d58326cc0d7a807bc..e997bffdef95a5dee31c178b12cf57ab09a9ae28 100644 (file)
@@ -225,7 +225,7 @@ class Contact
                // Add internal fields
                $removal = [];
                if (!empty($fields)) {
-                       foreach (['id', 'avatar', 'updated', 'last-update', 'success_update', 'failure_update', 'network'] as $internal) {
+                       foreach (['id', 'avatar', 'created', 'updated', 'last-update', 'success_update', 'failure_update', 'network'] as $internal) {
                                if (!in_array($internal, $fields)) {
                                        $fields[] = $internal;
                                        $removal[] = $internal;
@@ -255,9 +255,8 @@ class Contact
                }
 
                // Update the contact in the background if needed
-               $updated = max($contact['success_update'], $contact['updated'], $contact['last-update'], $contact['failure_update']);
-               if ((($updated < DateTimeFormat::utc('now -7 days')) || empty($contact['avatar'])) &&
-                       in_array($contact['network'], Protocol::FEDERATED)) {
+               $updated = max($contact['success_update'], $contact['created'], $contact['updated'], $contact['last-update'], $contact['failure_update']);
+               if (($updated < DateTimeFormat::utc('now -7 days')) && in_array($contact['network'], Protocol::FEDERATED)) {
                        Worker::add(PRIORITY_LOW, "UpdateContact", $contact['id']);
                }
 
@@ -1286,16 +1285,16 @@ class Contact
                if ($thread_mode) {
                        $condition = ["(`$contact_field` = ? OR (`causer-id` = ? AND `post-type` = ?)) AND `gravity` = ? AND " . $sql,
                                $cid, $cid, Item::PT_ANNOUNCEMENT, GRAVITY_PARENT, local_user()];
-
-                       $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
-                       if (!empty($last_received)) {
-                               $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
-                       }
                } else {
                        $condition = ["`$contact_field` = ? AND `gravity` IN (?, ?) AND " . $sql,
                                $cid, GRAVITY_PARENT, GRAVITY_COMMENT, local_user()];
                }
 
+               $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
+               if (!empty($last_received)) {
+                       $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+               }
+
                if (DI::mode()->isMobile()) {
                        $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
                                DI::config()->get('system', 'itemspage_network_mobile'));
@@ -1309,14 +1308,14 @@ class Contact
                $params = ['order' => ['received' => true], 'group_by' => ['uri-id'],
                        'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
 
-               if ($thread_mode) {
-                       if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
-                               $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
-                               $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
-                       } else {
-                               $o = '';
-                       }
-               
+               if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+                       $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
+                       $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
+               } else {
+                       $o = '';
+               }
+
+               if ($thread_mode) {             
                        $r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri'], $condition, $params);
                        $items = [];
                        while ($item = DBA::fetch($r)) {
@@ -1336,11 +1335,11 @@ class Contact
 
                        $items = Item::inArray($r);
 
-                       $o = conversation($a, $items, 'contact-posts', false);
+                       $o .= conversation($a, $items, 'contact-posts', false);
                }
 
                if (!$update) {
-                       if ($thread_mode && DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+                       if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
                                $o .= HTML::scrollLoader();
                        } else {
                                $o .= $pager->renderMinimal(count($items));
@@ -1859,10 +1858,6 @@ class Contact
                        return false;
                }
 
-               if (Contact\Relation::isDiscoverable($ret['url'])) {
-                       Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
-               }
-
                if (isset($ret['hide']) && is_bool($ret['hide'])) {
                        $ret['unsearchable'] = $ret['hide'];
                }
@@ -1911,6 +1906,10 @@ class Contact
                if (!$update) {
                        self::updateContact($id, $uid, $ret['url'], ['failed' => false, 'last-update' => $updated, 'success_update' => $updated]);
 
+                       if (Contact\Relation::isDiscoverable($ret['url'])) {
+                               Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
+                       }
+       
                        // Update the public contact
                        if ($uid != 0) {
                                $contact = self::getByURL($ret['url'], false, ['id']);
@@ -1948,6 +1947,10 @@ class Contact
 
                self::updateContact($id, $uid, $ret['url'], $ret);
 
+               if (Contact\Relation::isDiscoverable($ret['url'])) {
+                       Worker::add(PRIORITY_LOW, 'ContactDiscovery', $ret['url']);
+               }
+
                return true;
        }
 
@@ -2578,7 +2581,7 @@ class Contact
        {
                $destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
 
-               if (!Session::isAuthenticated() || ($contact['network'] != Protocol::DFRN)) {
+               if (!Session::isAuthenticated()) {
                        return $destination;
                }
 
@@ -2587,6 +2590,14 @@ class Contact
                        return $url;
                }
 
+               if (DI::pConfig()->get(local_user(), 'system', 'stay_local') && ($url == '')) {
+                       return 'contact/' . $contact['id'] . '/conversations';
+               }
+
+               if ($contact['network'] != Protocol::DFRN) {
+                       return $destination;
+               }
+
                if (!empty($contact['uid'])) {
                        return self::magicLink($contact['url'], $url);
                }
@@ -2697,21 +2708,24 @@ class Contact
        {
                $added = 0;
                $updated = 0;
+               $unchanged = 0;
                $count = 0;
 
                foreach ($urls as $url) {
-                       $contact = Contact::getByURL($url, false, ['id']); 
+                       $contact = Contact::getByURL($url, false, ['id', 'updated']);
                        if (empty($contact['id'])) {
                                Worker::add(PRIORITY_LOW, 'AddContact', 0, $url);
                                ++$added;
-                       } else {
+                       } elseif ($contact['updated'] < DateTimeFormat::utc('now -7 days')) {
                                Worker::add(PRIORITY_LOW, 'UpdateContact', $contact['id']);
                                ++$updated;
+                       } else {
+                               ++$unchanged;
                        }
                        ++$count;
                }
 
-               return ['count' => $count, 'added' => $added, 'updated' => $updated];
+               return ['count' => $count, 'added' => $added, 'updated' => $updated, 'unchanged' => $unchanged];
        }
 
        /**