]> git.mxchange.org Git - friendica.git/commitdiff
Use "received" instead of "created" when displaying posts in creation order
authorMichael <heluecht@pirati.ca>
Sun, 7 Jul 2019 21:30:33 +0000 (21:30 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 7 Jul 2019 21:30:33 +0000 (21:30 +0000)
12 files changed:
config/dbstructure.config.php
include/api.php
include/conversation.php
mod/network.php
mod/ping.php
mod/search.php
src/Core/NotificationsManager.php
src/Model/Contact.php
src/Model/Item.php
src/Module/Profile.php
src/Protocol/DFRN.php
src/Protocol/OStatus.php

index 3c2b81352b4bb7c5f5e4a840e33a4a4f71368e28..40fc2ef0c396673502667d516738dcc4daa8c3e5 100755 (executable)
@@ -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"],
                ]
        ],
index 0fab1f47c164e02a64e944494827ae2c6d8467c5..6c6e6f7dcdcc5460c5be2591faffa16f5694df6a 100644 (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 [];
        }
index a2927f9bfaf68dfb766a330a2ffea9f1494bc837..798a224016c911bf72d8284ad5a053ce8a6ee9db 100644 (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']);
 }
 
 /**
index 87eb4308b41549d20a199463fbb2f39dbc7bed33..3e19cbce4dd8ae5b24922998f38bdd3d003d3e5e 100644 (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';
index 9b844cc48ddc02ad7ce52f3753e20f3d74cd08ce..f30d1a61b9da5175af37a86a91406f537fe641b6 100644 (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)) {
index 4144e2608f91f6b9bb7a44b4e5c4fd6a4e3bb1bd..dca7b153c2fe7a6a78bd366b6483616fad220323 100644 (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);
 
index 5b2e97005aec370ea502de52570334963a3fca81..8ac5d93c729d33779573990638b978af602dcf3e 100644 (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)) {
index 775cc3fdad269431a036e9dfd170209d46bf55d4..757508f261d86a50017419f38a781cec1fe822a6 100644 (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) {
index c3ff0520bb5f53560fabec5647b5b0d4f1fffbe8..d43bdb0a1b44e83ec4d7e7fcda4cd5aaff1c3d97 100644 (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,19 +2905,11 @@ 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;
                }
 
+               $condition[0] .= " AND `received` < UTC_TIMESTAMP() - INTERVAL ? DAY";
+               $condition[] = $days;
+
                $items = self::select(['file', 'resource-id', 'starred', 'type', 'id', 'post-type'], $condition);
 
                if (!DBA::isResult($items)) {
@@ -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;
        }
index 9bc52af7a98535ec3cef3c5bcddc4bfa4c79a546..8e5bedd847ae367252973e0375f449858048d572 100644 (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));
index 31d363a118eb2091862751833542ab3c2472b22d..3aa3ab957c90515d53a4d78147a8d6a0e2368676 100644 (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)
index 9fa0ff43af73e9120122178142dba54257ee03e4..127773f3c6ce1a15dd7ee61a76f191544c0dbf6d 100644 (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);