1
1
Fork 0

Use "received" instead of "created" when displaying posts in creation order

This commit is contained in:
Michael 2019-07-07 21:30:33 +00:00
parent 9b8b2b36cd
commit 6bb418c5a7
12 changed files with 51 additions and 59 deletions

View file

@ -34,7 +34,7 @@
use Friendica\Database\DBA;
if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1316);
define('DB_UPDATE_VERSION', 1317);
}
return [
@ -672,15 +672,15 @@ return [
"extid" => ["extid(191)"],
"uid_id" => ["uid", "id"],
"uid_contactid_id" => ["uid", "contact-id", "id"],
"uid_created" => ["uid", "created"],
"uid_received" => ["uid", "received"],
"uid_commented" => ["uid", "commented"],
"uid_unseen_contactid" => ["uid", "unseen", "contact-id"],
"uid_network_received" => ["uid", "network", "received"],
"uid_network_commented" => ["uid", "network", "commented"],
"uid_thrparent" => ["uid", "thr-parent(190)"],
"uid_parenturi" => ["uid", "parent-uri(190)"],
"uid_contactid_created" => ["uid", "contact-id", "created"],
"authorid_created" => ["author-id", "created"],
"uid_contactid_received" => ["uid", "contact-id", "received"],
"authorid_received" => ["author-id", "received"],
"ownerid" => ["owner-id"],
"contact-id" => ["contact-id"],
"uid_uri" => ["uid", "uri(190)"],
@ -1256,15 +1256,15 @@ return [
"indexes" => [
"PRIMARY" => ["iid"],
"uid_network_commented" => ["uid", "network", "commented"],
"uid_network_created" => ["uid", "network", "created"],
"uid_network_received" => ["uid", "network", "received"],
"uid_contactid_commented" => ["uid", "contact-id", "commented"],
"uid_contactid_created" => ["uid", "contact-id", "created"],
"uid_contactid_received" => ["uid", "contact-id", "received"],
"contactid" => ["contact-id"],
"ownerid" => ["owner-id"],
"authorid" => ["author-id"],
"uid_created" => ["uid", "created"],
"uid_received" => ["uid", "received"],
"uid_commented" => ["uid", "commented"],
"uid_wall_created" => ["uid", "wall", "created"],
"uid_wall_received" => ["uid", "wall", "received"],
"private_wall_origin_commented" => ["private", "wall", "origin", "commented"],
]
],

View file

@ -1107,7 +1107,7 @@ function api_statuses_update($type)
if ($throttle_day > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60);
$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
$condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
$posts_day = DBA::count('thread', $condition);
if ($posts_day > $throttle_day) {
@ -1121,7 +1121,7 @@ function api_statuses_update($type)
if ($throttle_week > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*7);
$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
$condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
$posts_week = DBA::count('thread', $condition);
if ($posts_week > $throttle_week) {
@ -1135,7 +1135,7 @@ function api_statuses_update($type)
if ($throttle_month > 0) {
$datefrom = date(DateTimeFormat::MYSQL, time() - 24*60*60*30);
$condition = ["`uid` = ? AND `wall` AND `created` > ?", api_user(), $datefrom];
$condition = ["`uid` = ? AND `wall` AND `received` > ?", api_user(), $datefrom];
$posts_month = DBA::count('thread', $condition);
if ($posts_month > $throttle_month) {
@ -5057,7 +5057,7 @@ function api_get_announce($item)
$fields = ['author-id', 'author-name', 'author-link', 'author-avatar'];
$activity = Item::activityToIndex(ACTIVITY2_ANNOUNCE);
$condition = ['parent-uri' => $item['uri'], 'gravity' => GRAVITY_ACTIVITY, 'uid' => [0, $item['uid']], 'activity' => $activity];
$announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['created' => true]]);
$announce = Item::selectFirstForUser($item['uid'], $fields, $condition, ['order' => ['received' => true]]);
if (!DBA::isResult($announce)) {
return [];
}

View file

@ -800,12 +800,12 @@ function conversation_fetch_comments($thread_items) {
$parentlines = [];
$lineno = 0;
$actor = [];
$created = '';
$received = '';
while ($row = Item::fetch($thread_items)) {
if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['created'] > $created) && ($row['thr-parent'] == $row['parent-uri'])) {
if (($row['verb'] == ACTIVITY2_ANNOUNCE) && !empty($row['contact-uid']) && ($row['received'] > $received) && ($row['thr-parent'] == $row['parent-uri'])) {
$actor = ['link' => $row['author-link'], 'avatar' => $row['author-avatar'], 'name' => $row['author-name']];
$created = $row['created'];
$received = $row['received'];
}
if ((($row['gravity'] == GRAVITY_PARENT) && !$row['origin'] && !in_array($row['network'], [Protocol::DIASPORA])) &&
@ -1316,7 +1316,7 @@ function get_item_children(array &$item_list, array $parent, $recursive = true)
function sort_item_children(array $items)
{
$result = $items;
usort($result, 'sort_thr_created_rev');
usort($result, 'sort_thr_received_rev');
foreach ($result as $k => $i) {
if (isset($result[$k]['children'])) {
$result[$k]['children'] = sort_item_children($result[$k]['children']);
@ -1401,13 +1401,13 @@ function smart_flatten_conversation(array $parent)
/**
* Expands a flat list of items into corresponding tree-like conversation structures,
* sort the top-level posts either on "created" or "commented", and finally
* sort the top-level posts either on "received" or "commented", and finally
* append all the items at the top level (???)
*
* @brief Expands a flat item list into a conversation array for display
*
* @param array $item_list A list of items belonging to one or more conversations
* @param string $order Either on "created" or "commented"
* @param string $order Either on "received" or "commented"
* @return array
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
@ -1439,8 +1439,8 @@ function conv_sort(array $item_list, $order)
}
}
if (stristr($order, 'created')) {
usort($parents, 'sort_thr_created');
if (stristr($order, 'received')) {
usort($parents, 'sort_thr_received');
} elseif (stristr($order, 'commented')) {
usort($parents, 'sort_thr_commented');
}
@ -1477,27 +1477,27 @@ function conv_sort(array $item_list, $order)
}
/**
* @brief usort() callback to sort item arrays by the created key
* @brief usort() callback to sort item arrays by the received key
*
* @param array $a
* @param array $b
* @return int
*/
function sort_thr_created(array $a, array $b)
function sort_thr_received(array $a, array $b)
{
return strcmp($b['created'], $a['created']);
return strcmp($b['received'], $a['received']);
}
/**
* @brief usort() callback to reverse sort item arrays by the created key
* @brief usort() callback to reverse sort item arrays by the received key
*
* @param array $a
* @param array $b
* @return int
*/
function sort_thr_created_rev(array $a, array $b)
function sort_thr_received_rev(array $a, array $b)
{
return strcmp($a['created'], $b['created']);
return strcmp($a['received'], $b['received']);
}
/**

View file

@ -704,11 +704,11 @@ function networkThreadedView(App $a, $update, $parent)
}
if ($datequery) {
$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created <= '%s' ",
$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received <= '%s' ",
DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
}
if ($datequery2) {
$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.created >= '%s' ",
$sql_extra3 .= Strings::protectSprintf(sprintf(" AND $sql_table.received >= '%s' ",
DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
}
@ -718,8 +718,8 @@ function networkThreadedView(App $a, $update, $parent)
// Normal conversation view
if ($order === 'post') {
$ordering = '`created`';
$order_mode = 'created';
$ordering = '`received`';
$order_mode = 'received';
} else {
$ordering = '`commented`';
$order_mode = 'commented';

View file

@ -123,7 +123,7 @@ function ping_init(App $a)
$condition = ["`unseen` AND `uid` = ? AND `contact-id` != ?", local_user(), local_user()];
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid', 'wall'];
$params = ['order' => ['created' => true]];
$params = ['order' => ['received' => true]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBA::isResult($items)) {

View file

@ -186,7 +186,7 @@ function search_content(App $a) {
$condition = ["(`uid` = 0 OR (`uid` = ? AND NOT `global`))
AND `otype` = ? AND `type` = ? AND `term` = ?",
local_user(), TERM_OBJ_POST, TERM_HASHTAG, $search];
$params = ['order' => ['created' => true],
$params = ['order' => ['received' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
$terms = DBA::select('term', ['oid'], $condition, $params);

View file

@ -394,7 +394,7 @@ class NotificationsManager extends BaseObject
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
@ -485,7 +485,7 @@ class NotificationsManager extends BaseObject
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
@ -527,7 +527,7 @@ class NotificationsManager extends BaseObject
$fields = ['id', 'parent', 'verb', 'author-name', 'unseen', 'author-link', 'author-avatar', 'contact-avatar',
'network', 'created', 'object', 'parent-author-name', 'parent-author-link', 'parent-guid'];
$params = ['order' => ['created' => true], 'limit' => [$start, $limit]];
$params = ['order' => ['received' => true], 'limit' => [$start, $limit]];
$items = Item::selectForUser(local_user(), $fields, $condition, $params);
if (DBA::isResult($items)) {

View file

@ -1616,7 +1616,7 @@ class Contact extends BaseObject
$pager = new Pager($a->query_string);
$params = ['order' => ['created' => true],
$params = ['order' => ['received' => true],
'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
if ($thread_mode) {

View file

@ -1650,7 +1650,7 @@ class Item extends BaseObject
Logger::log('duplicated item with the same guid found. '.print_r($item,true));
return 0;
}
} else {
} elseif ($item['network'] == Protocol::OSTATUS) {
// Check for an existing post with the same content. There seems to be a problem with OStatus.
$condition = ["`body` = ? AND `network` = ? AND `created` = ? AND `contact-id` = ? AND `uid` = ?",
$item['body'], $item['network'], $item['created'], $item['contact-id'], $item['uid']];
@ -2905,18 +2905,10 @@ class Item extends BaseObject
if ($network != "") {
$condition[0] .= " AND `network` = ?";
$condition[] = $network;
}
/*
* There is an index "uid_network_received" but not "uid_network_created"
* This avoids the creation of another index just for one purpose.
* And it doesn't really matter wether to look at "received" or "created"
*/
$condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
$condition[] = $days;
} else {
$condition[0] .= " AND `created` < UTC_TIMESTAMP() - INTERVAL ? DAY";
$condition[] = $days;
}
$items = self::select(['file', 'resource-id', 'starred', 'type', 'id', 'post-type'], $condition);
@ -2967,10 +2959,10 @@ class Item extends BaseObject
public static function firstPostDate($uid, $wall = false)
{
$condition = ['uid' => $uid, 'wall' => $wall, 'deleted' => false, 'visible' => true, 'moderated' => false];
$params = ['order' => ['created' => false]];
$thread = DBA::selectFirst('thread', ['created'], $condition, $params);
$params = ['order' => ['received' => false]];
$thread = DBA::selectFirst('thread', ['received'], $condition, $params);
if (DBA::isResult($thread)) {
return substr(DateTimeFormat::local($thread['created']), 0, 10);
return substr(DateTimeFormat::local($thread['received']), 0, 10);
}
return false;
}

View file

@ -252,7 +252,7 @@ class Profile extends BaseModule
AND `item`.`wall`
$sql_extra4
$sql_extra
ORDER BY `item`.`created` DESC",
ORDER BY `item`.`received` DESC",
$a->profile['profile_uid'],
GRAVITY_ACTIVITY
);
@ -276,10 +276,10 @@ class Profile extends BaseModule
}
if (!empty($datequery)) {
$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` <= '%s' ", DBA::escape(DateTimeFormat::convert($datequery, 'UTC', date_default_timezone_get()))));
}
if (!empty($datequery2)) {
$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`created` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
$sql_extra2 .= Strings::protectSprintf(sprintf(" AND `thread`.`received` >= '%s' ", DBA::escape(DateTimeFormat::convert($datequery2, 'UTC', date_default_timezone_get()))));
}
// Does the profile page belong to a forum?
@ -326,7 +326,7 @@ class Profile extends BaseModule
$sql_extra3
$sql_extra
$sql_extra2
ORDER BY `thread`.`created` DESC
ORDER BY `thread`.`received` DESC
$pager_sql",
$a->profile['profile_uid']
);
@ -351,7 +351,7 @@ class Profile extends BaseModule
$items = DBA::toArray($items_stmt);
$o .= conversation($a, $items, $pager, 'profile', $update, false, 'created', $a->profile['profile_uid']);
$o .= conversation($a, $items, $pager, 'profile', $update, false, 'received', $a->profile['profile_uid']);
if (!$update) {
$o .= $pager->renderMinimal(count($items));

View file

@ -257,7 +257,7 @@ class DFRN
STRAIGHT_JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `item`.`uid` = %d AND `item`.`wall` AND `item`.`changed` > '%s'
AND `item`.`visible` $sql_extra
ORDER BY `item`.`parent` ".$sort.", `item`.`created` ASC LIMIT 0, 300",
ORDER BY `item`.`parent` ".$sort.", `item`.`received` ASC LIMIT 0, 300",
intval($owner_id),
DBA::escape($check_date),
DBA::escape($sort)

View file

@ -2219,7 +2219,7 @@ class OStatus
$check_date = DateTimeFormat::utc($last_update);
$authorid = Contact::getIdForURL($owner["url"], 0, true);
$condition = ["`uid` = ? AND `created` > ? AND NOT `deleted`
$condition = ["`uid` = ? AND `received` > ? AND NOT `deleted`
AND NOT `private` AND `visible` AND `wall` AND `parent-network` IN (?, ?)",
$owner["uid"], $check_date, Protocol::OSTATUS, Protocol::DFRN];
@ -2234,7 +2234,7 @@ class OStatus
$condition[] = $authorid;
}
$params = ['order' => ['created' => true], 'limit' => $max_items];
$params = ['order' => ['received' => true], 'limit' => $max_items];
if ($filter === 'posts') {
$ret = Item::selectThread([], $condition, $params);