From 88a0e976daf92319138f3189c739b72ee0aa9b7c Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 30 Sep 2020 19:14:13 +0000 Subject: [PATCH] Endless scrolling for searches and contact comments --- include/conversation.php | 4 +++ src/Model/Contact.php | 30 +++++++++---------- src/Model/ItemContent.php | 17 ++++++++++- src/Model/Tag.php | 8 ++++- src/Module/Search/Index.php | 18 +++++++++-- view/templates/search_item.tpl | 4 +++ view/theme/frio/templates/search_item.tpl | 4 +++ view/theme/quattro/templates/search_item.tpl | 4 +++ view/theme/smoothly/templates/search_item.tpl | 5 +++- view/theme/vier/templates/search_item.tpl | 6 ++-- 10 files changed, 77 insertions(+), 23 deletions(-) diff --git a/include/conversation.php b/include/conversation.php index b984c3da2e..f618f801f5 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -585,6 +585,10 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o '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']), diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1ec1424dd8..a6bdb042a3 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1286,16 +1286,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 +1309,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 +1336,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)); diff --git a/src/Model/ItemContent.php b/src/Model/ItemContent.php index daa2766e2f..5268c49e95 100644 --- a/src/Model/ItemContent.php +++ b/src/Model/ItemContent.php @@ -29,10 +29,25 @@ use Friendica\DI; class ItemContent { - public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100) + /** + * Search posts for given content + * + * @param string $search + * @param integer $uid + * @param integer $start + * @param integer $limit + * @param integer $last_uriid + * @return array + */ + public static function getURIIdListBySearch(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0) { $condition = ["`uri-id` IN (SELECT `uri-id` FROM `item-content` WHERE MATCH (`title`, `content-warning`, `body`) AGAINST (? IN BOOLEAN MODE)) AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid]; + + if (!empty($last_uriid)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]); + } + $params = [ 'order' => ['uri-id' => true], 'group_by' => ['uri-id'], diff --git a/src/Model/Tag.php b/src/Model/Tag.php index c661892edf..7e99ae1a3a 100644 --- a/src/Model/Tag.php +++ b/src/Model/Tag.php @@ -462,11 +462,17 @@ class Tag * @param integer $uid * @param integer $start * @param integer $limit + * @param integer $last_uriid * @return array with URI-ID */ - public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100) + public static function getURIIdListByTag(string $search, int $uid = 0, int $start = 0, int $limit = 100, int $last_uriid = 0) { $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid]; + + if (!empty($last_uriid)) { + $condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]); + } + $params = [ 'order' => ['uri-id' => true], 'group_by' => ['uri-id'], diff --git a/src/Module/Search/Index.php b/src/Module/Search/Index.php index 7f5c7ab87b..82fe5543a8 100644 --- a/src/Module/Search/Index.php +++ b/src/Module/Search/Index.php @@ -155,15 +155,17 @@ class Index extends BaseSearch DI::config()->get('system', 'itemspage_network')); } + $last_uriid = isset($_GET['last_uriid']) ? intval($_GET['last_uriid']) : 0; +Logger::info('Blubb', ['uri' => $last_uriid]); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage); if ($tag) { Logger::info('Start tag search.', ['q' => $search]); - $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); + $uriids = Tag::getURIIdListByTag($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid); $count = Tag::countByTag($search, local_user()); } else { Logger::info('Start fulltext search.', ['q' => $search]); - $uriids = ItemContent::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage()); + $uriids = ItemContent::getURIIdListBySearch($search, local_user(), $pager->getStart(), $pager->getItemsPerPage(), $last_uriid); $count = ItemContent::countBySearch($search, local_user()); } @@ -177,6 +179,11 @@ class Index extends BaseSearch return $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()]); + } + if ($tag) { $title = DI::l10n()->t('Items tagged with: %s', $search); } else { @@ -191,7 +198,12 @@ class Index extends BaseSearch $o .= conversation(DI::app(), $items, 'search', false, false, 'commented', local_user()); - $o .= $pager->renderMinimal($count); + if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { + $o .= HTML::scrollLoader(); + } else { + $o .= $pager->renderMinimal($count); + } + return $o; } diff --git a/view/templates/search_item.tpl b/view/templates/search_item.tpl index 4c6dcb7226..ebf1c7cafa 100644 --- a/view/templates/search_item.tpl +++ b/view/templates/search_item.tpl @@ -1,5 +1,9 @@ + + + +
diff --git a/view/theme/frio/templates/search_item.tpl b/view/theme/frio/templates/search_item.tpl index d7a22927cc..b516d486fb 100644 --- a/view/theme/frio/templates/search_item.tpl +++ b/view/theme/frio/templates/search_item.tpl @@ -7,6 +7,10 @@
+ + + +
{{* Put additional actions in a top-right dropdown menu *}} diff --git a/view/theme/quattro/templates/search_item.tpl b/view/theme/quattro/templates/search_item.tpl index a7e755747e..dca5d31a1e 100644 --- a/view/theme/quattro/templates/search_item.tpl +++ b/view/theme/quattro/templates/search_item.tpl @@ -1,3 +1,7 @@ + + + +
{{if $item.star}}{{$item.star.starred}}{{/if}} {{if $item.lock}}{{$item.lock}}{{/if}} diff --git a/view/theme/smoothly/templates/search_item.tpl b/view/theme/smoothly/templates/search_item.tpl index 5d0764de4a..d2fdb1cc31 100644 --- a/view/theme/smoothly/templates/search_item.tpl +++ b/view/theme/smoothly/templates/search_item.tpl @@ -1,5 +1,8 @@ -
+ + + +