Merge pull request #4186 from annando/follow-tags

We can now follow hash tags
This commit is contained in:
Tobias Diekershoff 2018-01-08 09:51:12 +01:00 committed by GitHub
commit 746876ab44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -735,36 +735,43 @@ function networkThreadedView(App $a, $update = 0) {
} }
if (x($_GET, 'offset')) { if (x($_GET, 'offset')) {
$sql_extra3 .= sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"])); $sql_range = sprintf(" AND $sql_order <= '%s'", dbesc($_GET["offset"]));
} else {
$sql_range = '';
} }
$pager_sql = networkPager($a, $update); $pager_sql = networkPager($a, $update);
$last_date = '';
switch ($order_mode) { switch ($order_mode) {
case 'received': case 'received':
if ($last_received != '') { if ($last_received != '') {
$sql_extra3 .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received)); $last_date = $last_received;
$sql_range .= sprintf(" AND $sql_table.`received` < '%s'", dbesc($last_received));
$a->set_pager_page(1); $a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
} }
break; break;
case 'commented': case 'commented':
if ($last_commented != '') { if ($last_commented != '') {
$sql_extra3 .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented)); $last_date = $last_commented;
$sql_range .= sprintf(" AND $sql_table.`commented` < '%s'", dbesc($last_commented));
$a->set_pager_page(1); $a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
} }
break; break;
case 'created': case 'created':
if ($last_created != '') { if ($last_created != '') {
$sql_extra3 .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created)); $last_date = $last_created;
$sql_range .= sprintf(" AND $sql_table.`created` < '%s'", dbesc($last_created));
$a->set_pager_page(1); $a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
} }
break; break;
case 'id': case 'id':
if (($last_id > 0) && ($sql_table == "`thread`")) { if (($last_id > 0) && ($sql_table == "`thread`")) {
$sql_extra3 .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id)); $sql_range .= sprintf(" AND $sql_table.`iid` < '%s'", dbesc($last_id));
$a->set_pager_page(1); $a->set_pager_page(1);
$pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage'])); $pager_sql = sprintf(" LIMIT %d, %d ",intval($a->pager['start']), intval($a->pager['itemspage']));
} }
@ -778,28 +785,57 @@ function networkThreadedView(App $a, $update = 0) {
} else { } else {
$sql_extra4 = ""; $sql_extra4 = "";
} }
$r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`, $sql_order AS `order_date`
$r = q("SELECT `item`.`parent` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`
FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM $sql_table $sql_post_table INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`) AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4 WHERE `item`.`uid` = %d AND `item`.`visible` AND NOT `item`.`deleted` $sql_extra4
AND NOT `item`.`moderated` AND `item`.`unseen` AND NOT `item`.`moderated` AND `item`.`unseen`
$sql_extra3 $sql_extra $sql_nets $sql_extra3 $sql_extra $sql_range $sql_nets
ORDER BY `item_id` DESC LIMIT 100", ORDER BY `order_date` DESC LIMIT 100",
intval(local_user()) intval(local_user())
); );
} else { } else {
$r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` $r = q("SELECT `thread`.`iid` AS `item_id`, `thread`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid`, $sql_order AS `order_date`
FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` FROM $sql_table $sql_post_table STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
AND (NOT `contact`.`blocked` OR `contact`.`pending`) AND (NOT `contact`.`blocked` OR `contact`.`pending`)
WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted` WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
AND NOT `thread`.`moderated` AND NOT `thread`.`moderated`
$sql_extra2 $sql_extra3 $sql_extra $sql_nets $sql_extra2 $sql_extra3 $sql_range $sql_extra $sql_nets
ORDER BY $sql_order DESC $pager_sql", ORDER BY $sql_order DESC $pager_sql",
intval(local_user()) intval(local_user())
); );
} }
// Only show it when unfiltered (no groups, no networks, ...)
if (Config::get('system', 'comment_public') && (count($r) > 0) && (strlen($sql_extra . $sql_extra2 . $sql_extra3 . $sql_extra4 . $sql_nets) == 0)) {
$top_limit = current($r)['order_date'];
$bottom_limit = end($r)['order_date'];
// When checking for updates we need to fetch from the newest date to the newest date before
if ($update && !empty($_SESSION['network_last_date']) && ($bottom_limit > $_SESSION['network_last_date'])) {
$bottom_limit = $_SESSION['network_last_date'];
}
$_SESSION['network_last_date'] = $top_limit;
if ($last_date > $top_limit) {
$top_limit = $last_date;
}
$items = dba::p("SELECT `item`.`id` AS `item_id`, `item`.`network` AS `item_network`, `contact`.`uid` AS `contact_uid` FROM `item`
INNER JOIN (SELECT `oid` FROM `term` WHERE `term` IN
(SELECT SUBSTR(`term`, 2) FROM `search` WHERE `uid` = ? AND `term` LIKE '#%') AND `otype` = ? AND `type` = ? AND `uid` = 0) AS `term`
ON `item`.`id` = `term`.`oid`
INNER JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = 0 AND `item`.$ordering < ? AND `item`.$ordering > ?",
local_user(), TERM_OBJ_POST, TERM_HASHTAG, $top_limit, $bottom_limit);
$data = dba::inArray($items);
if (count($data) > 0) {
logger('Tagged items: '.count($data).' - '.$bottom_limit." - ".$top_limit.' - '.local_user()); //$last_date);
$r = array_merge($r, $data);
}
}
// Then fetch all the children of the parents that are on this page // Then fetch all the children of the parents that are on this page
$parents_arr = array(); $parents_arr = array();
@ -825,10 +861,8 @@ function networkThreadedView(App $a, $update = 0) {
} }
foreach ($parents_arr AS $parents) { foreach ($parents_arr AS $parents) {
$thread_items = dba::p(item_query() . " AND `item`.`uid` = ? $thread_items = dba::p(item_query() . " AND `item`.`parent` = ?
AND `item`.`parent` = ?
ORDER BY `item`.`commented` DESC LIMIT " . intval($max_comments + 1), ORDER BY `item`.`commented` DESC LIMIT " . intval($max_comments + 1),
local_user(),
$parents $parents
); );