]> git.mxchange.org Git - friendica.git/blobdiff - src/Model/Contact.php
Endless scrolling on contact pages
[friendica.git] / src / Model / Contact.php
index 81b05559f7a5b1273e345f54ae85c0bb457db532..221211358ea784eb5d8e9bd13d6ad84a38c7a5dc 100644 (file)
@@ -23,9 +23,11 @@ namespace Friendica\Model;
 
 use Friendica\App\BaseURL;
 use Friendica\Content\Pager;
+use Friendica\Content\Text\HTML;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
 use Friendica\Core\Protocol;
+use Friendica\Core\Renderer;
 use Friendica\Core\Session;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
@@ -1273,7 +1275,7 @@ class Contact
                }
 
                if (empty($contact["network"]) || in_array($contact["network"], Protocol::FEDERATED)) {
-                       $sql = "(`item`.`uid` = 0 OR (`item`.`uid` = ? AND NOT `item`.`global`))";
+                       $sql = "`item`.`uid` IN (0, ?)";
                } else {
                        $sql = "`item`.`uid` = ?";
                }
@@ -1281,8 +1283,13 @@ class Contact
                $contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
 
                if ($thread_mode) {
-                       $condition = ["`$contact_field` = ? AND (`gravity` = ? OR (`gravity` = ? AND `vid` = ?)) AND " . $sql,
-                               $cid, GRAVITY_PARENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), local_user()];
+                       $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()];
@@ -1298,10 +1305,17 @@ class Contact
 
                $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
 
-               $params = ['order' => ['received' => true],
+               $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 = '';
+                       }
+               
                        $r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri'], $condition, $params);
                        $items = [];
                        while ($item = DBA::fetch($r)) {
@@ -1315,7 +1329,7 @@ class Contact
                        }
                        DBA::close($r);
 
-                       $o = conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
+                       $o .= conversation($a, $items, 'contacts', $update, false, 'commented', local_user());
                } else {
                        $r = Item::selectForUser(local_user(), [], $condition, $params);
 
@@ -1325,7 +1339,11 @@ class Contact
                }
 
                if (!$update) {
-                       $o .= $pager->renderMinimal(count($items));
+                       if ($thread_mode && DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
+                               $o .= HTML::scrollLoader();
+                       } else {
+                               $o .= $pager->renderMinimal(count($items));
+                       }
                }
 
                return $o;