Endless scrolling for searches and contact comments

This commit is contained in:
Michael 2020-09-30 19:14:13 +00:00
parent 0b37f1d56c
commit 88a0e976da
10 changed files with 77 additions and 23 deletions

View file

@ -585,6 +585,10 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
'template' => $tpl, 'template' => $tpl,
'id' => ($preview ? 'P0' : $item['id']), 'id' => ($preview ? 'P0' : $item['id']),
'guid' => ($preview ? 'Q0' : $item['guid']), 'guid' => ($preview ? 'Q0' : $item['guid']),
'commented' => $item['commented'],
'received' => $item['received'],
'created_date' => $item['created'],
'uriid' => $item['uri-id'],
'network' => $item['network'], 'network' => $item['network'],
'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']), 'network_name' => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']), 'network_icon' => ContactSelector::networkToIcon($item['network'], $item['author-link']),

View file

@ -1286,15 +1286,15 @@ class Contact
if ($thread_mode) { if ($thread_mode) {
$condition = ["(`$contact_field` = ? OR (`causer-id` = ? AND `post-type` = ?)) AND `gravity` = ? AND " . $sql, $condition = ["(`$contact_field` = ? OR (`causer-id` = ? AND `post-type` = ?)) AND `gravity` = ? AND " . $sql,
$cid, $cid, Item::PT_ANNOUNCEMENT, GRAVITY_PARENT, local_user()]; $cid, $cid, Item::PT_ANNOUNCEMENT, GRAVITY_PARENT, local_user()];
} 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']) : ''; $last_received = isset($_GET['last_received']) ? DateTimeFormat::utc($_GET['last_received']) : '';
if (!empty($last_received)) { if (!empty($last_received)) {
$condition = DBA::mergeConditions($condition, ["`received` < ?", $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()];
}
if (DI::mode()->isMobile()) { if (DI::mode()->isMobile()) {
$itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network', $itemsPerPage = DI::pConfig()->get(local_user(), 'system', 'itemspage_mobile_network',
@ -1309,7 +1309,6 @@ class Contact
$params = ['order' => ['received' => true], 'group_by' => ['uri-id'], $params = ['order' => ['received' => true], 'group_by' => ['uri-id'],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]]; 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
if ($thread_mode) {
if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) { if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
$tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl'); $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
$o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]); $o = Renderer::replaceMacros($tpl, ['$reload_uri' => DI::args()->getQueryString()]);
@ -1317,6 +1316,7 @@ class Contact
$o = ''; $o = '';
} }
if ($thread_mode) {
$r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri'], $condition, $params); $r = Item::selectForUser(local_user(), ['uri', 'gravity', 'parent-uri'], $condition, $params);
$items = []; $items = [];
while ($item = DBA::fetch($r)) { while ($item = DBA::fetch($r)) {
@ -1336,11 +1336,11 @@ class Contact
$items = Item::inArray($r); $items = Item::inArray($r);
$o = conversation($a, $items, 'contact-posts', false); $o .= conversation($a, $items, 'contact-posts', false);
} }
if (!$update) { 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(); $o .= HTML::scrollLoader();
} else { } else {
$o .= $pager->renderMinimal(count($items)); $o .= $pager->renderMinimal(count($items));

View file

@ -29,10 +29,25 @@ use Friendica\DI;
class ItemContent 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)) $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]; AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
if (!empty($last_uriid)) {
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
}
$params = [ $params = [
'order' => ['uri-id' => true], 'order' => ['uri-id' => true],
'group_by' => ['uri-id'], 'group_by' => ['uri-id'],

View file

@ -462,11 +462,17 @@ class Tag
* @param integer $uid * @param integer $uid
* @param integer $start * @param integer $start
* @param integer $limit * @param integer $limit
* @param integer $last_uriid
* @return array with URI-ID * @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]; $condition = ["`name` = ? AND (NOT `private` OR (`private` AND `uid` = ?))", $search, $uid];
if (!empty($last_uriid)) {
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $last_uriid]);
}
$params = [ $params = [
'order' => ['uri-id' => true], 'order' => ['uri-id' => true],
'group_by' => ['uri-id'], 'group_by' => ['uri-id'],

View file

@ -155,15 +155,17 @@ class Index extends BaseSearch
DI::config()->get('system', 'itemspage_network')); 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); $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
if ($tag) { if ($tag) {
Logger::info('Start tag search.', ['q' => $search]); 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()); $count = Tag::countByTag($search, local_user());
} else { } else {
Logger::info('Start fulltext search.', ['q' => $search]); 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()); $count = ItemContent::countBySearch($search, local_user());
} }
@ -177,6 +179,11 @@ class Index extends BaseSearch
return $o; 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) { if ($tag) {
$title = DI::l10n()->t('Items tagged with: %s', $search); $title = DI::l10n()->t('Items tagged with: %s', $search);
} else { } else {
@ -191,7 +198,12 @@ class Index extends BaseSearch
$o .= conversation(DI::app(), $items, 'search', false, false, 'commented', local_user()); $o .= conversation(DI::app(), $items, 'search', false, false, 'commented', local_user());
if (DI::pConfig()->get(local_user(), 'system', 'infinite_scroll')) {
$o .= HTML::scrollLoader();
} else {
$o .= $pager->renderMinimal($count); $o .= $pager->renderMinimal($count);
}
return $o; return $o;
} }

View file

@ -1,5 +1,9 @@
<a name="{{$item.id}}" ></a> <a name="{{$item.id}}" ></a>
<span class="commented" style="display: none;">{{$item.commented}}</span>
<span class="received" style="display: none;">{{$item.received}}</span>
<span class="created" style="display: none;">{{$item.created_date}}</span>
<span class="uriid" style="display: none;">{{$item.uriid}}</span>
<div class="wall-item-outside-wrapper {{$item.indent}}{{$item.previewing}}" id="wall-item-outside-wrapper-{{$item.id}}" > <div class="wall-item-outside-wrapper {{$item.indent}}{{$item.previewing}}" id="wall-item-outside-wrapper-{{$item.id}}" >
<div class="wall-item-content-wrapper {{$item.indent}}" id="wall-item-content-wrapper-{{$item.id}}" > <div class="wall-item-content-wrapper {{$item.indent}}" id="wall-item-content-wrapper-{{$item.id}}" >
<div class="wall-item-info" id="wall-item-info-{{$item.id}}"> <div class="wall-item-info" id="wall-item-info-{{$item.id}}">

View file

@ -7,6 +7,10 @@
<div class="panel item-{{$item.id}}" id="item-{{$item.guid}}"> <div class="panel item-{{$item.id}}" id="item-{{$item.guid}}">
<span class="commented" style="display: none;">{{$item.commented}}</span>
<span class="received" style="display: none;">{{$item.received}}</span>
<span class="created" style="display: none;">{{$item.created_date}}</span>
<span class="uriid" style="display: none;">{{$item.uriid}}</span>
<div class="wall-item-container panel-body{{$item.indent}} {{$item.shiny}} {{$item.previewing}}" > <div class="wall-item-container panel-body{{$item.indent}} {{$item.shiny}} {{$item.previewing}}" >
<div class="media"> <div class="media">
{{* Put additional actions in a top-right dropdown menu *}} {{* Put additional actions in a top-right dropdown menu *}}

View file

@ -1,3 +1,7 @@
<span class="commented" style="display: none;">{{$item.commented}}</span>
<span class="received" style="display: none;">{{$item.received}}</span>
<span class="created" style="display: none;">{{$item.created_date}}</span>
<span class="uriid" style="display: none;">{{$item.uriid}}</span>
<div class="wall-item-decor"> <div class="wall-item-decor">
{{if $item.star}}<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}} {{if $item.star}}<span class="icon s22 star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}}
{{if $item.lock}}<span class="icon s22 lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}} {{if $item.lock}}<span class="icon s22 lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}

View file

@ -1,5 +1,8 @@
<div class="wall-item-outside-wrapper {{$item.indent}} {{$item.shiny}}{{$item.previewing}}" id="wall-item-outside-wrapper-{{$item.id}}" > <div class="wall-item-outside-wrapper {{$item.indent}} {{$item.shiny}}{{$item.previewing}}" id="wall-item-outside-wrapper-{{$item.id}}" >
<span class="commented" style="display: none;">{{$item.commented}}</span>
<span class="received" style="display: none;">{{$item.received}}</span>
<span class="created" style="display: none;">{{$item.created_date}}</span>
<span class="uriid" style="display: none;">{{$item.uriid}}</span>
<div class="wall-item-content-wrapper {{$item.indent}} {{$item.shiny}}" id="wall-item-content-wrapper-{{$item.id}}" > <div class="wall-item-content-wrapper {{$item.indent}} {{$item.shiny}}" id="wall-item-content-wrapper-{{$item.id}}" >
<div class="wall-item-info" id="wall-item-info-{{$item.id}}"> <div class="wall-item-info" id="wall-item-info-{{$item.id}}">
<div class="wall-item-photo-wrapper mframe" id="wall-item-photo-wrapper-{{$item.id}}" <div class="wall-item-photo-wrapper mframe" id="wall-item-photo-wrapper-{{$item.id}}"

View file

@ -1,5 +1,7 @@
<span class="commented" style="display: none;">{{$item.commented}}</span>
<span class="received" style="display: none;">{{$item.received}}</span>
<span class="created" style="display: none;">{{$item.created_date}}</span>
<span class="uriid" style="display: none;">{{$item.uriid}}</span>
<div class="wall-item-decor"> <div class="wall-item-decor">
{{if $item.star}}<span class="icon star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}} {{if $item.star}}<span class="icon star {{$item.isstarred}}" id="starred-{{$item.id}}" title="{{$item.star.starred}}">{{$item.star.starred}}</span>{{/if}}
{{if $item.lock}}<span class="icon lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}} {{if $item.lock}}<span class="icon lock fakelink" onclick="lockview(event, 'item', {{$item.id}});" title="{{$item.lock}}">{{$item.lock}}</span>{{/if}}