mirror of
https://github.com/friendica/friendica
synced 2024-11-19 08:23:40 +00:00
Merge pull request #9016 from annando/network-view
Using a view for the network page
This commit is contained in:
commit
6dff5fa562
4 changed files with 142 additions and 53 deletions
59
database.sql
59
database.sql
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 2020.09-dev (Red Hot Poker)
|
-- Friendica 2020.09-dev (Red Hot Poker)
|
||||||
-- DB_UPDATE_VERSION 1359
|
-- DB_UPDATE_VERSION 1360
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
@ -1388,6 +1388,63 @@ CREATE VIEW `tag-view` AS SELECT
|
||||||
LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
|
LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
|
||||||
LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
|
LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`;
|
||||||
|
|
||||||
|
--
|
||||||
|
-- VIEW network-item-view
|
||||||
|
--
|
||||||
|
DROP VIEW IF EXISTS `network-item-view`;
|
||||||
|
CREATE VIEW `network-item-view` AS SELECT
|
||||||
|
`item`.`parent-uri-id` AS `uri-id`,
|
||||||
|
`item`.`parent-uri` AS `uri`,
|
||||||
|
`item`.`parent` AS `parent`,
|
||||||
|
`item`.`received` AS `received`,
|
||||||
|
`item`.`commented` AS `commented`,
|
||||||
|
`item`.`created` AS `created`,
|
||||||
|
`item`.`uid` AS `uid`,
|
||||||
|
`item`.`starred` AS `starred`,
|
||||||
|
`item`.`mention` AS `mention`,
|
||||||
|
`item`.`network` AS `network`,
|
||||||
|
`item`.`unseen` AS `unseen`,
|
||||||
|
`item`.`gravity` AS `gravity`,
|
||||||
|
`item`.`contact-id` AS `contact-id`
|
||||||
|
FROM `item`
|
||||||
|
INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
|
||||||
|
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
||||||
|
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
|
||||||
|
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
|
||||||
|
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
|
||||||
|
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
|
||||||
|
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
|
||||||
|
AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
|
||||||
|
AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
|
||||||
|
|
||||||
|
--
|
||||||
|
-- VIEW network-thread-view
|
||||||
|
--
|
||||||
|
DROP VIEW IF EXISTS `network-thread-view`;
|
||||||
|
CREATE VIEW `network-thread-view` AS SELECT
|
||||||
|
`item`.`uri-id` AS `uri-id`,
|
||||||
|
`item`.`uri` AS `uri`,
|
||||||
|
`item`.`parent-uri-id` AS `parent-uri-id`,
|
||||||
|
`thread`.`iid` AS `parent`,
|
||||||
|
`thread`.`received` AS `received`,
|
||||||
|
`thread`.`commented` AS `commented`,
|
||||||
|
`thread`.`created` AS `created`,
|
||||||
|
`thread`.`uid` AS `uid`,
|
||||||
|
`thread`.`starred` AS `starred`,
|
||||||
|
`thread`.`mention` AS `mention`,
|
||||||
|
`thread`.`network` AS `network`,
|
||||||
|
`thread`.`contact-id` AS `contact-id`
|
||||||
|
FROM `thread`
|
||||||
|
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
||||||
|
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
|
||||||
|
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
|
||||||
|
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
|
||||||
|
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
|
||||||
|
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
|
||||||
|
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
|
||||||
|
AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
|
||||||
|
AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`);
|
||||||
|
|
||||||
--
|
--
|
||||||
-- VIEW owner-view
|
-- VIEW owner-view
|
||||||
--
|
--
|
||||||
|
|
|
@ -499,19 +499,24 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
$o .= status_editor($a, $x);
|
$o .= status_editor($a, $x);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql_table = $update ? '`item`' : '`thread`';
|
$conditionFields = ['uid' => local_user()];
|
||||||
|
$conditionStrings = [];
|
||||||
|
|
||||||
$sql_extra = ($star ? " AND `thread`.`starred` " : '') .
|
if ($star) {
|
||||||
($conv ? " AND $sql_table.`mention`" : '') .
|
$conditionFields['starred'] = true;
|
||||||
($nets ? sprintf(" AND $sql_table.`network` = '%s' ", DBA::escape($nets)) : '');
|
}
|
||||||
|
if ($conv) {
|
||||||
|
$conditionFields['mention'] = true;
|
||||||
|
}
|
||||||
|
if ($nets) {
|
||||||
|
$conditionFields['network'] = $nets;
|
||||||
|
}
|
||||||
|
|
||||||
if ($datequery) {
|
if ($datequery) {
|
||||||
$sql_extra .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ",
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` <= ? ", DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get())]);
|
||||||
DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
|
|
||||||
}
|
}
|
||||||
if ($datequery2) {
|
if ($datequery2) {
|
||||||
$sql_extra .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ",
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` >= ? ", DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get())]);
|
||||||
DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($gid) {
|
if ($gid) {
|
||||||
|
@ -525,7 +530,7 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
// NOTREACHED
|
// NOTREACHED
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql_extra .= sprintf(" AND `thread`.`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = %d) ", intval($gid));
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`contact-id` IN (SELECT `contact-id` FROM `group_member` WHERE `gid` = ?)", $gid]);
|
||||||
|
|
||||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
|
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('section_title.tpl'), [
|
||||||
'$title' => DI::l10n()->t('Group: %s', $group['name'])
|
'$title' => DI::l10n()->t('Group: %s', $group['name'])
|
||||||
|
@ -533,7 +538,7 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
} elseif ($cid) {
|
} elseif ($cid) {
|
||||||
$contact = Contact::getById($cid);
|
$contact = Contact::getById($cid);
|
||||||
if (DBA::isResult($contact)) {
|
if (DBA::isResult($contact)) {
|
||||||
$sql_extra .= " AND " . $sql_table . ".`contact-id` = " . intval($cid);
|
$conditionFields['contact-id'] = $cid;
|
||||||
|
|
||||||
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
|
$o = Renderer::replaceMacros(Renderer::getMarkupTemplate('viewcontact_template.tpl'), [
|
||||||
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
|
'contacts' => [ModuleContact::getContactTemplateVars($contact)],
|
||||||
|
@ -558,8 +563,6 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
$order_mode = 'commented';
|
$order_mode = 'commented';
|
||||||
}
|
}
|
||||||
|
|
||||||
$sql_order = "$sql_table.$ordering";
|
|
||||||
|
|
||||||
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
|
$pager = new Pager(DI::l10n(), DI::args()->getQueryString());
|
||||||
|
|
||||||
networkPager($a, $pager);
|
networkPager($a, $pager);
|
||||||
|
@ -572,22 +575,22 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
switch ($order_mode) {
|
switch ($order_mode) {
|
||||||
case 'received':
|
case 'received':
|
||||||
if ($last_received != '') {
|
if ($last_received != '') {
|
||||||
$sql_extra .= sprintf(" AND $sql_table.`received` < '%s'", DBA::escape($last_received));
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`received` < ?", $last_received]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'commented':
|
case 'commented':
|
||||||
if ($last_commented != '') {
|
if ($last_commented != '') {
|
||||||
$sql_extra .= sprintf(" AND $sql_table.`commented` < '%s'", DBA::escape($last_commented));
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`commented` < ?", $last_commented]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'created':
|
case 'created':
|
||||||
if ($last_created != '') {
|
if ($last_created != '') {
|
||||||
$sql_extra .= sprintf(" AND $sql_table.`created` < '%s'", DBA::escape($last_created));
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`created` < ?", $last_created]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'uriid':
|
case 'uriid':
|
||||||
if ($last_uriid > 0) {
|
if ($last_uriid > 0) {
|
||||||
$sql_extra .= sprintf(" AND $sql_table.`uri-id` < '%s'", DBA::escape($last_uriid));
|
$conditionStrings = DBA::mergeConditions($conditionStrings, ["`uri-id` < ?", $last_uriid]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -596,47 +599,23 @@ function networkThreadedView(App $a, $update, $parent)
|
||||||
if ($update) {
|
if ($update) {
|
||||||
if (!empty($parent)) {
|
if (!empty($parent)) {
|
||||||
// Load only a single thread
|
// Load only a single thread
|
||||||
$sql_extra2 = "`item`.`id` = ".intval($parent);
|
$conditionFields['id'] = $parent;
|
||||||
} elseif ($order === 'post') {
|
} elseif ($order === 'post') {
|
||||||
// Only load new toplevel posts
|
// Only load new toplevel posts
|
||||||
$sql_extra2 = "`item`.`unseen` AND `item`.`gravity` = " . GRAVITY_PARENT;
|
$conditionFields['unseen'] = true;
|
||||||
|
$conditionFields['gravity'] = GRAVITY_PARENT;
|
||||||
} else {
|
} else {
|
||||||
// Load all unseen items
|
// Load all unseen items
|
||||||
$sql_extra2 = "`item`.`unseen`";
|
$conditionFields['unseen'] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$r = q("SELECT `item`.`parent-uri` AS `uri`, `item`.`parent` AS `item_id`, $sql_order AS `order_date`
|
$params = ['order' => [$order_mode => true], 'limit' => 100];
|
||||||
FROM `item`
|
$table = 'network-item-view';
|
||||||
INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
|
|
||||||
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
|
|
||||||
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
|
||||||
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
|
|
||||||
WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
|
|
||||||
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
|
|
||||||
AND NOT `thread`.`moderated` AND $sql_extra2
|
|
||||||
$sql_extra
|
|
||||||
ORDER BY `order_date` DESC LIMIT 100",
|
|
||||||
intval(local_user()),
|
|
||||||
intval(local_user())
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
$r = q("SELECT `item`.`uri`, `thread`.`iid` AS `item_id`, $sql_order AS `order_date`
|
$params = ['order' => [$order_mode => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
|
||||||
FROM `thread`
|
$table = 'network-thread-view';
|
||||||
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id`
|
|
||||||
AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
|
||||||
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
|
|
||||||
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = %d
|
|
||||||
WHERE `thread`.`uid` = %d AND `thread`.`visible` AND NOT `thread`.`deleted`
|
|
||||||
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
|
|
||||||
AND NOT `thread`.`moderated`
|
|
||||||
$sql_extra
|
|
||||||
ORDER BY `order_date` DESC LIMIT %d, %d",
|
|
||||||
intval(local_user()),
|
|
||||||
intval(local_user()),
|
|
||||||
intval($pager->getStart()),
|
|
||||||
intval($pager->getItemsPerPage())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
$r = DBA::selectToArray($table, [], DBA::mergeConditions($conditionFields, $conditionStrings), $params);
|
||||||
|
|
||||||
return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r);
|
return $o . network_display_post($a, $pager, (!$gid && !$cid && !$star), $update, $ordering, $r);
|
||||||
}
|
}
|
||||||
|
@ -649,8 +628,8 @@ function network_display_post($a, $pager, $mark_all, $update, $ordering, $items)
|
||||||
$parents_arr = [];
|
$parents_arr = [];
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
if (!in_array($item['item_id'], $parents_arr) && ($item['item_id'] > 0)) {
|
if (!in_array($item['parent'], $parents_arr) && ($item['parent'] > 0)) {
|
||||||
$parents_arr[] = $item['item_id'];
|
$parents_arr[] = $item['parent'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$parents_str = implode(', ', $parents_arr);
|
$parents_str = implode(', ', $parents_arr);
|
||||||
|
|
|
@ -54,7 +54,7 @@
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
|
||||||
if (!defined('DB_UPDATE_VERSION')) {
|
if (!defined('DB_UPDATE_VERSION')) {
|
||||||
define('DB_UPDATE_VERSION', 1359);
|
define('DB_UPDATE_VERSION', 1360);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
|
|
@ -68,6 +68,59 @@ return [
|
||||||
LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
|
LEFT JOIN `tag` ON `post-tag`.`tid` = `tag`.`id`
|
||||||
LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`"
|
LEFT JOIN `contact` ON `post-tag`.`cid` = `contact`.`id`"
|
||||||
],
|
],
|
||||||
|
"network-item-view" => [
|
||||||
|
"fields" => [
|
||||||
|
"uri-id" => ["item", "parent-uri-id"],
|
||||||
|
"uri" => ["item", "parent-uri"],
|
||||||
|
"parent" => ["item", "parent"],
|
||||||
|
"received" => ["item", "received"],
|
||||||
|
"commented" => ["item", "commented"],
|
||||||
|
"created" => ["item", "created"],
|
||||||
|
"uid" => ["item", "uid"],
|
||||||
|
"starred" => ["item", "starred"],
|
||||||
|
"mention" => ["item", "mention"],
|
||||||
|
"network" => ["item", "network"],
|
||||||
|
"unseen" => ["item", "unseen"],
|
||||||
|
"gravity" => ["item", "gravity"],
|
||||||
|
"contact-id" => ["item", "contact-id"],
|
||||||
|
],
|
||||||
|
"query" => "FROM `item`
|
||||||
|
INNER JOIN `thread` ON `thread`.`iid` = `item`.`parent`
|
||||||
|
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
||||||
|
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
|
||||||
|
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
|
||||||
|
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
|
||||||
|
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
|
||||||
|
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
|
||||||
|
AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
|
||||||
|
AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)"
|
||||||
|
],
|
||||||
|
"network-thread-view" => [
|
||||||
|
"fields" => [
|
||||||
|
"uri-id" => ["item", "uri-id"],
|
||||||
|
"uri" => ["item", "uri"],
|
||||||
|
"parent-uri-id" => ["item", "parent-uri-id"],
|
||||||
|
"parent" => ["thread", "iid"],
|
||||||
|
"received" => ["thread", "received"],
|
||||||
|
"commented" => ["thread", "commented"],
|
||||||
|
"created" => ["thread", "created"],
|
||||||
|
"uid" => ["thread", "uid"],
|
||||||
|
"starred" => ["thread", "starred"],
|
||||||
|
"mention" => ["thread", "mention"],
|
||||||
|
"network" => ["thread", "network"],
|
||||||
|
"contact-id" => ["thread", "contact-id"],
|
||||||
|
],
|
||||||
|
"query" => "FROM `thread`
|
||||||
|
STRAIGHT_JOIN `contact` ON `contact`.`id` = `thread`.`contact-id` AND (NOT `contact`.`blocked` OR `contact`.`pending`)
|
||||||
|
STRAIGHT_JOIN `item` ON `item`.`id` = `thread`.`iid`
|
||||||
|
LEFT JOIN `user-item` ON `user-item`.`iid` = `item`.`id` AND `user-item`.`uid` = `thread`.`uid`
|
||||||
|
LEFT JOIN `user-contact` AS `author` ON `author`.`uid` = `thread`.`uid` AND `author`.`cid` = `thread`.`author-id`
|
||||||
|
LEFT JOIN `user-contact` AS `owner` ON `owner`.`uid` = `thread`.`uid` AND `owner`.`cid` = `thread`.`owner-id`
|
||||||
|
WHERE `thread`.`visible` AND NOT `thread`.`deleted` AND NOT `thread`.`moderated`
|
||||||
|
AND (`user-item`.`hidden` IS NULL OR NOT `user-item`.`hidden`)
|
||||||
|
AND (`author`.`blocked` IS NULL OR NOT `author`.`blocked`)
|
||||||
|
AND (`owner`.`blocked` IS NULL OR NOT `owner`.`blocked`)"
|
||||||
|
],
|
||||||
"owner-view" => [
|
"owner-view" => [
|
||||||
"fields" => [
|
"fields" => [
|
||||||
"id" => ["contact", "id"],
|
"id" => ["contact", "id"],
|
||||||
|
|
Loading…
Reference in a new issue