]> git.mxchange.org Git - friendica.git/commitdiff
Sorting changed to "created"
authorMichael <heluecht@pirati.ca>
Thu, 14 Dec 2023 06:18:17 +0000 (06:18 +0000)
committerMichael <heluecht@pirati.ca>
Thu, 14 Dec 2023 06:18:17 +0000 (06:18 +0000)
database.sql
doc/database/db_post-thread-user.md
doc/database/db_post-user.md
src/Content/Conversation.php
src/Model/Contact.php
src/Module/Contact/Conversations.php
src/Module/Contact/Posts.php
static/dbstructure.config.php

index 013f182285c80cebdd57f416d2821dc767496183..134d1f82619bb729f2abada5414666a6e025cfa0 100644 (file)
@@ -1534,8 +1534,8 @@ CREATE TABLE IF NOT EXISTS `post-user` (
         INDEX `event-id` (`event-id`),
         INDEX `psid` (`psid`),
         INDEX `author-id_uid` (`author-id`,`uid`),
-        INDEX `author-id_received` (`author-id`,`received`),
-        INDEX `owner-id_received` (`owner-id`,`received`),
+        INDEX `author-id_created` (`author-id`,`created`),
+        INDEX `owner-id_created` (`owner-id`,`created`),
         INDEX `parent-uri-id_uid` (`parent-uri-id`,`uid`),
         INDEX `uid_wall_received` (`uid`,`wall`,`received`),
         INDEX `uid_contactid` (`uid`,`contact-id`),
@@ -1596,6 +1596,8 @@ CREATE TABLE IF NOT EXISTS `post-thread-user` (
         INDEX `post-user-id` (`post-user-id`),
         INDEX `commented` (`commented`),
         INDEX `received` (`received`),
+        INDEX `author-id_created` (`author-id`,`created`),
+        INDEX `owner-id_created` (`owner-id`,`created`),
         INDEX `uid_received` (`uid`,`received`),
         INDEX `uid_wall_received` (`uid`,`wall`,`received`),
         INDEX `uid_commented` (`uid`,`commented`),
index e4f5e39bdae85b91733a3698f68a53c094bf4ef4..b4114d13c9d83fee986b5731cbe57638a1339422 100644 (file)
@@ -50,6 +50,8 @@ Indexes
 | post-user-id      | post-user-id        |
 | commented         | commented           |
 | received          | received            |
+| author-id_created | author-id, created  |
+| owner-id_created  | owner-id, created   |
 | uid_received      | uid, received       |
 | uid_wall_received | uid, wall, received |
 | uid_commented     | uid, commented      |
index d56fa620b810b8b6bd99bba8bb4c4322baac29e6..2823391d47e4350abb4566528a55a85ac96c9f11 100644 (file)
@@ -58,8 +58,8 @@ Indexes
 | event-id             | event-id                |
 | psid                 | psid                    |
 | author-id_uid        | author-id, uid          |
-| author-id_received   | author-id, received     |
-| owner-id_received    | owner-id, received      |
+| author-id_created    | author-id, created      |
+| owner-id_created     | owner-id, created       |
 | parent-uri-id_uid    | parent-uri-id, uid      |
 | uid_wall_received    | uid, wall, received     |
 | uid_contactid        | uid, contact-id         |
index 517a364b6e71840b8de299ab004df5275f406e17..1f321b75e8ab61c487bd8cf5b17b92c2661acedc 100644 (file)
@@ -1298,6 +1298,8 @@ class Conversation
                        usort($parents, [$this, 'sortThrFeaturedReceived']);
                } elseif (stristr($order, 'pinned_commented')) {
                        usort($parents, [$this, 'sortThrFeaturedCommented']);
+               } elseif (stristr($order, 'pinned_created')) {
+                       usort($parents, [$this, 'sortThrFeaturedCreated']);
                } elseif (stristr($order, 'received')) {
                        usort($parents, [$this, 'sortThrReceived']);
                } elseif (stristr($order, 'commented')) {
@@ -1375,6 +1377,24 @@ class Conversation
                return strcmp($b['commented'], $a['commented']);
        }
 
+       /**
+        * usort() callback to sort item arrays by featured and the created key
+        *
+        * @param array $a
+        * @param array $b
+        * @return int
+        */
+       private function sortThrFeaturedCreated(array $a, array $b): int
+       {
+               if ($b['featured'] && !$a['featured']) {
+                       return 1;
+               } elseif (!$b['featured'] && $a['featured']) {
+                       return -1;
+               }
+
+               return strcmp($b['created'], $a['created']);
+       }
+
        /**
         * usort() callback to sort item arrays by the received key
         *
index af9c631af9fe3f14d4c63dd28ad2dc58a057d4c2..9fdcef29f3ac2b71965d6ef4963bb860dd56afb1 100644 (file)
@@ -1579,7 +1579,7 @@ class Contact
         * @return string posts in HTML
         * @throws \Exception
         */
-       public static function getPostsFromId(int $cid, int $uid, bool $only_media = false, string $last_received = null): string
+       public static function getPostsFromId(int $cid, int $uid, bool $only_media = false, string $last_created = null): string
        {
                $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
                if (!DBA::isResult($contact)) {
@@ -1596,8 +1596,8 @@ class Contact
 
                $condition = DBA::mergeConditions($condition, ["`$contact_field` = ? AND `gravity` IN (?, ?)", $cid, Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]);
 
-               if (!empty($last_received)) {
-                       $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+               if (!empty($last_created)) {
+                       $condition = DBA::mergeConditions($condition, ["`created` < ?", $last_created]);
                }
 
                if ($only_media) {
@@ -1615,7 +1615,7 @@ class Contact
 
                $pager = new Pager(DI::l10n(), DI::args()->getQueryString(), $itemsPerPage);
 
-               $params = ['order' => ['received' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
+               $params = ['order' => ['created' => true], 'limit' => [$pager->getStart(), $pager->getItemsPerPage()]];
 
                if (DI::pConfig()->get($uid, 'system', 'infinite_scroll')) {
                        $tpl = Renderer::getMarkupTemplate('infinite_scroll_head.tpl');
@@ -1647,7 +1647,7 @@ class Contact
         * @return string posts in HTML
         * @throws \Exception
         */
-       public static function getThreadsFromId(int $cid, int $uid, int $update = 0, int $parent = 0, string $last_received = ''): string
+       public static function getThreadsFromId(int $cid, int $uid, int $update = 0, int $parent = 0, string $last_created = ''): string
        {
                $contact = DBA::selectFirst('contact', ['contact-type', 'network'], ['id' => $cid]);
                if (!DBA::isResult($contact)) {
@@ -1662,8 +1662,8 @@ class Contact
 
                if (!empty($parent)) {
                        $condition = DBA::mergeConditions($condition, ['parent' => $parent]);
-               } elseif (!empty($last_received)) {
-                       $condition = DBA::mergeConditions($condition, ["`received` < ?", $last_received]);
+               } elseif (!empty($last_created)) {
+                       $condition = DBA::mergeConditions($condition, ["`created` < ?", $last_created]);
                }
 
                $contact_field = ((($contact["contact-type"] == self::TYPE_COMMUNITY) || ($contact['network'] == Protocol::MAIL)) ? 'owner-id' : 'author-id');
@@ -1683,30 +1683,30 @@ class Contact
                        $o = '';
                }
 
-               $condition1 = DBA::mergeConditions($condition, ["`$contact_field` = ?", $cid]);
+               $condition1 = DBA::mergeConditions($condition, ["`$contact_field` = ? AND `gravity` = ?", $cid, Item::GRAVITY_PARENT]);
 
                $condition2 = DBA::mergeConditions($condition, [
                        "`author-id` = ? AND `gravity` = ? AND `vid` = ? AND `protocol` != ? AND `thr-parent-id` = `parent-uri-id`",
                        $cid, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Conversation::PARCEL_DIASPORA
                ]);
 
-               $sql1 = "SELECT `uri-id`, `received` FROM `post-thread-user-view` WHERE " . array_shift($condition1);
-               $sql2 = "SELECT `thr-parent-id` AS `uri-id`, `received` FROM `post-user-view` WHERE " . array_shift($condition2);
+               $sql1 = "SELECT `uri-id`, `created` FROM `post-thread-user-view` WHERE " . array_shift($condition1);
+               $sql2 = "SELECT `thr-parent-id` AS `uri-id`, `created` FROM `post-user-view` WHERE " . array_shift($condition2);
 
                $union = array_merge($condition1, $condition2);
                $sql = $sql1 . " UNION " . $sql2;
 
-               $sql .= " ORDER BY `received` DESC LIMIT ?, ?";
+               $sql .= " ORDER BY `created` DESC LIMIT ?, ?";
                $union = array_merge($union, [$pager->getStart(), $pager->getItemsPerPage()]);
                $items = Post::toArray(DBA::p($sql, $union));
 
-               if ($pager->getStart() == 0) {
-                       $fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'received'];
+               if (empty($last_created) && ($pager->getStart() == 0)) {
+                       $fields = ['uri-id', 'thr-parent-id', 'gravity', 'author-id', 'created'];
                        $pinned = Post\Collection::selectToArrayForContact($cid, Post\Collection::FEATURED, $fields);
                        $items = array_merge($items, $pinned);
                }
 
-               $o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_received', $uid);
+               $o .= DI::conversation()->render($items, ConversationContent::MODE_CONTACTS, $update, false, 'pinned_created', $uid);
 
                if (!$update) {
                        if (DI::pConfig()->get($uid, 'system', 'infinite_scroll')) {
index 853c4d8eac692cbebd40a7102d4a30b4818ccaba..660bbc8218231e636918471ff3008759c9b61ab0 100644 (file)
@@ -113,7 +113,7 @@ class Conversations extends BaseModule
                $o = $this->conversation->statusEditor([], 0, true);
 
                $o .= Contact::getTabsHTML($contact, Contact::TAB_CONVERSATIONS);
-               $o .= Model\Contact::getThreadsFromId($contact['id'], $this->userSession->getLocalUserId(), 0, 0, $request['last_received'] ?? '');
+               $o .= Model\Contact::getThreadsFromId($contact['id'], $this->userSession->getLocalUserId(), 0, 0, $request['last_created'] ?? '');
 
                return $o;
        }
index 61785653be352f13ee933530fa6a03f24f6b25a9..9285683333a1515364989fa784ef74ce53a85485 100644 (file)
@@ -99,7 +99,7 @@ class Posts extends BaseModule
 
                $o = Contact::getTabsHTML($contact, Contact::TAB_POSTS);
 
-               $o .= Model\Contact::getPostsFromId($contact['id'], $this->userSession->getLocalUserId(), false, $request['last_received'] ?? '');
+               $o .= Model\Contact::getPostsFromId($contact['id'], $this->userSession->getLocalUserId(), false, $request['last_created'] ?? '');
 
                return $o;
        }
index cd5b0563ab08d397a4ff12c4a20e3d23907082a2..53221d9e444cdfd92c60ba8f8b24fae610b027f2 100644 (file)
@@ -1551,8 +1551,8 @@ return [
                        "event-id" => ["event-id"],
                        "psid" => ["psid"],
                        "author-id_uid" => ["author-id", "uid"],
-                       "author-id_received" => ["author-id", "received"],
-                       "owner-id_received" => ["owner-id", "received"],
+                       "author-id_created" => ["author-id", "created"],
+                       "owner-id_created" => ["owner-id", "created"],
                        "parent-uri-id_uid" => ["parent-uri-id", "uid"],
                        "uid_wall_received" => ["uid", "wall", "received"],
                        "uid_contactid" => ["uid", "contact-id"],
@@ -1602,6 +1602,8 @@ return [
                        "post-user-id" => ["post-user-id"],
                        "commented" => ["commented"],
                        "received" => ["received"],
+                       "author-id_created" => ["author-id", "created"],
+                       "owner-id_created" => ["owner-id", "created"],
                        "uid_received" => ["uid", "received"],
                        "uid_wall_received" => ["uid", "wall", "received"],
                        "uid_commented" => ["uid", "commented"],