]> git.mxchange.org Git - friendica.git/commitdiff
Pinned posts now work for visitors in the intended way
authorMichael <heluecht@pirati.ca>
Fri, 8 Nov 2019 06:52:44 +0000 (06:52 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 8 Nov 2019 06:52:44 +0000 (06:52 +0000)
include/conversation.php
src/Model/Item.php
src/Module/Profile.php
src/Object/Post.php

index 724d18dfeab9a08265d772837e9e03fddfe220db..b7f8d91fc40cd37193851788f0cb0383e7949eaf 100644 (file)
@@ -801,10 +801,12 @@ function conversation(App $a, array $items, Pager $pager, $mode, $update, $previ
 /**
  * Fetch all comments from a query. Additionally set the newest resharer as thread owner.
  *
- * @param $thread_items Database statement with thread posts
+ * @param array   $thread_items Database statement with thread posts
+ * @param boolean $pinned       Is the item pinned?
+ *
  * @return array items with parents and comments
  */
-function conversation_fetch_comments($thread_items) {
+function conversation_fetch_comments($thread_items, $pinned) {
        $comments = [];
        $parentlines = [];
        $lineno = 0;
@@ -822,6 +824,10 @@ function conversation_fetch_comments($thread_items) {
                        $parentlines[] = $lineno;
                }
 
+               if ($row['gravity'] == GRAVITY_PARENT) {
+                       $row['pinned'] = $pinned;
+               }
+
                $comments[] = $row;
                $lineno++;
        }
@@ -872,7 +878,7 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
 
                $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
 
-               $comments = conversation_fetch_comments($thread_items);
+               $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
 
                if (count($comments) != 0) {
                        $items = array_merge($items, $comments);
index dde33437a506ab998ae3796f73abbf743c6f2fa9..159fac455b9dd96f33c75da491fab12bda68b351 100644 (file)
@@ -148,11 +148,13 @@ class Item extends BaseObject
         *
         * @param integer $uid       User ID
         * @param array   $selected  Array of selected fields, empty for all
+        * @param array   $condition Array of fields for condition
+        * @param array   $params    Array of several parameters
         *
         * @return boolean|object
         * @throws \Exception
         */
-       public static function selectPinned(int $uid, array $selected = [])
+       public static function selectPinned(int $uid, array $selected = [], array $condition = [], $params = [])
        {
                $useritems = DBA::select('user-item', ['iid'], ['uid' => $uid, 'pinned' => true]);
                if (!DBA::isResult($useritems)) {
@@ -165,7 +167,25 @@ class Item extends BaseObject
                }
                DBA::close($useritems);
 
-               return self::selectThreadForUser($uid, $selected, ['iid' => $pinned]);
+               if (empty($pinned)) {
+                       return [];
+               }
+
+               if (empty($condition) || !is_array($condition)) {
+                       $condition = ['iid' => $pinned];
+               } else {
+                       reset($condition);
+                       $first_key = key($condition);
+                       if (!is_int($first_key)) {
+                               $condition['iid'] = $pinned;
+                       } else {
+                               $values_string = substr(str_repeat("?, ", count($pinned)), 0, -2);
+                               $condition[0] = '(' . $condition[0] . ") AND `iid` IN (" . $values_string . ")";
+                               $condition = array_merge($condition, $pinned);
+                       }
+               }
+
+               return self::selectThreadForUser($uid, $selected, $condition, $params);
        }
 
        /**
index 60dc6aa1b447074910eb3438b61da7dd8bf6974d..aab5918567fbab92582531c7967e1ced93bc32d1 100644 (file)
@@ -350,7 +350,7 @@ class Profile extends BaseModule
                $items = DBA::toArray($items_stmt);
 
                if ($pager->getStart() == 0 && !empty($a->profile['profile_uid'])) {
-                       $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri']);
+                       $pinned_items = Item::selectPinned($a->profile['profile_uid'], ['uri', 'pinned'], ['true' . $sql_extra]);
                        $pinned = Item::inArray($pinned_items);
                        $items = array_merge($items, $pinned);
                }
index f9119ee032676eb85ab1e292eb4f4c9fd25f8eb8..981bf76c7d6f576423265d9d4ac358f7da542065 100644 (file)
@@ -193,6 +193,8 @@ class Post extends BaseObject
                        if (DBA::isResult($parent)) {
                                $origin = $parent['origin'];
                        }
+               } elseif ($item['pinned']) {
+                       $pinned = L10n::t('pinned item');
                }
 
                if ($origin && ($item['id'] != $item['parent']) && ($item['network'] == Protocol::ACTIVITYPUB)) {
@@ -288,10 +290,6 @@ class Post extends BaseObject
 
                                if ($conv->getProfileOwner() == local_user() && ($item['uid'] != 0)) {
                                        if ($origin) {
-                                               if ($item['pinned']) {
-                                                       $pinned = L10n::t('pinned item');
-                                               }
-
                                                $ispinned = ($item['pinned'] ? 'pinned' : 'unpinned');
 
                                                $pin = [