Merge pull request #9334 from annando/endless-scroll
authorPhilipp <admin+Github@philipp.info>
Thu, 1 Oct 2020 21:04:56 +0000 (23:04 +0200)
committerGitHub <noreply@github.com>
Thu, 1 Oct 2020 21:04:56 +0000 (23:04 +0200)
Endless scrolling for searches and contact comments

1  2 
include/conversation.php
src/Model/Contact.php

diff --combined include/conversation.php
@@@ -585,6 -585,10 +585,10 @@@ function conversation(App $a, array $it
                                        'template' => $tpl,
                                        'id' => ($preview ? 'P0' : $item['id']),
                                        'guid' => ($preview ? 'Q0' : $item['guid']),
+                                       'commented' => $item['commented'],
+                                       'received' => $item['received'],
+                                       'created_date' => $item['created'],
+                                       'uriid' => $item['uri-id'],
                                        'network' => $item['network'],
                                        'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
                                        'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),
@@@ -734,7 -738,7 +738,7 @@@ function conversation_fetch_comments($t
                                $row['direction'] = ['direction' => 4, 'title' => DI::l10n()->t('Tagged')];
                                break;
                        case Item::PT_ANNOUNCEMENT:
 -                              if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')  ) {
 +                              if (!empty($row['causer-id']) && DI::pConfig()->get(local_user(), 'system', 'display_resharer')) {
                                        $row['owner-link'] = $row['causer-link'];
                                        $row['owner-avatar'] = $row['causer-avatar'];
                                        $row['owner-name'] = $row['causer-name'];
diff --combined src/Model/Contact.php
@@@ -1286,16 -1286,16 +1286,16 @@@ class Contac
                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'));
                $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)) {
  
                        $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));
        {
                $destination = $url ?: $contact['url']; // Equivalent to ($url != '') ? $url : $contact['url'];
  
 -              if (!Session::isAuthenticated() || ($contact['network'] != Protocol::DFRN)) {
 +              if (!Session::isAuthenticated()) {
                        return $destination;
                }
  
                        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);
                }