]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/Conversation.php
Blanks replaced
[friendica.git] / src / Content / Conversation.php
index fd1701483b4945dc63b38ced340f00b84f735f03..04cdab4785e50b0e5efefbdddb322fe8b015e963 100644 (file)
@@ -37,6 +37,7 @@ use Friendica\Core\Theme;
 use Friendica\Database\DBA;
 use Friendica\Model\Contact;
 use Friendica\Model\Item as ItemModel;
+use Friendica\Model\Photo;
 use Friendica\Model\Post;
 use Friendica\Model\Tag;
 use Friendica\Model\User;
@@ -108,6 +109,8 @@ class Conversation
         */
        public function builtinActivityPuller(array $activity, array &$conv_responses)
        {
+               $thread_parent = $activity['thr-parent-row'] ?? [];
+
                foreach ($conv_responses as $mode => $v) {
                        $sparkle = '';
 
@@ -152,9 +155,8 @@ class Conversation
                                        $activity['thr-parent-id'] = $activity['parent-uri-id'];
                                }
 
-                               // Skip when the causer of the parent is the same than the author of the announce
-                               if (($verb == Activity::ANNOUNCE) && Post::exists(['uri-id' => $activity['thr-parent-id'],
-                                       'uid' => $activity['uid'], 'causer-id' => $activity['author-id'], 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]])) {
+                               // Skip when the causer of the parent is the same as the author of the announce
+                               if (($verb == Activity::ANNOUNCE) && !empty($thread_parent['causer-id'] && ($thread_parent['causer-id'] == $activity['author-id']))) {
                                        continue;
                                }
 
@@ -667,15 +669,15 @@ class Conversation
                                                'created_date'         => $item['created'],
                                                'uriid'                => $item['uri-id'],
                                                'network'              => $item['network'],
-                                               'network_name'         => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network']),
-                                               'network_icon'         => ContactSelector::networkToIcon($item['network'], $item['author-link']),
+                                               'network_name'         => ContactSelector::networkToName($item['author-network'], $item['author-link'], $item['network'], $item['author-gsid']),
+                                               'network_icon'         => ContactSelector::networkToIcon($item['network'], $item['author-link'], $item['author-gsid']),
                                                'linktitle'            => $this->l10n->t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
                                                'profile_url'          => $profile_link,
                                                'item_photo_menu_html' => $this->item->photoMenu($item, $formSecurityToken),
                                                'name'                 => $profile_name,
                                                'sparkle'              => $sparkle,
                                                'lock'                 => false,
-                                               'thumb'                => $this->baseURL->remove(Contact::getAvatarUrlForUrl($item['author-link'], $item['uid'], Proxy::SIZE_THUMB)),
+                                               'thumb'                => $this->baseURL->remove($this->item->getAuthorAvatar($item)),
                                                'title'                => $title,
                                                'body_html'            => $body_html,
                                                'tags'                 => $tags['tags'],
@@ -696,7 +698,7 @@ class Conversation
                                                'indent'               => '',
                                                'owner_name'           => '',
                                                'owner_url'            => '',
-                                               'owner_photo'          => $this->baseURL->remove(Contact::getAvatarUrlForUrl($item['owner-link'], $item['uid'], Proxy::SIZE_THUMB)),
+                                               'owner_photo'          => $this->baseURL->remove($this->item->getOwnerAvatar($item)),
                                                'plink'                => ItemModel::getPlink($item),
                                                'edpost'               => false,
                                                'pinned'               => $pinned,
@@ -809,12 +811,13 @@ class Conversation
        /**
         * Adds some information (Causer, post reason, direction) to the fetched post row.
         *
-        * @param array   $row      Post row
-        * @param array   $activity Contact data of the resharer
+        * @param array   $row        Post row
+        * @param array   $activity   Contact data of the resharer
+        * @param array   $thr_parent Thread parent row
         *
         * @return array items with parents and comments
         */
-       private function addRowInformation(array $row, array $activity)
+       private function addRowInformation(array $row, array $activity, array $thr_parent)
        {
                $this->profiler->startRecording('rendering');
 
@@ -889,6 +892,8 @@ class Conversation
                                break;
                }
 
+               $row['thr-parent-row'] = $thr_parent;
+
                $this->profiler->stopRecording();
                return $row;
        }
@@ -916,8 +921,6 @@ class Conversation
                        $max_comments = $this->config->get('system', 'max_display_comments', 1000);
                }
 
-               $params = ['order' => ['uri-id' => true, 'uid' => true]];
-
                $activities      = [];
                $uriids          = [];
                $commentcounter  = [];
@@ -951,6 +954,17 @@ class Conversation
                $condition = DBA::mergeConditions($condition,
                        ["`uid` IN (0, ?) AND (`vid` != ? OR `vid` IS NULL)", $uid, Verb::getID(Activity::FOLLOW)]);
 
+               $thread_parents = Post::select(['uri-id', 'causer-id'], $condition, ['order' => ['uri-id' => false, 'uid']]);
+
+               $thr_parent = [];
+
+               while ($row = Post::fetch($thread_parents)) {
+                       $thr_parent[$row['uri-id']] = $row;
+               }
+               DBA::close($thread_parents);
+
+               $params = ['order' => ['uri-id' => true, 'uid' => true]];
+
                $thread_items = Post::selectForUser($uid, array_merge(ItemModel::DISPLAY_FIELDLIST, ['featured', 'contact-uid', 'gravity', 'post-type', 'post-reason']), $condition, $params);
 
                $items = [];
@@ -968,7 +982,8 @@ class Conversation
                                        continue;
                                }
                        }
-                       $items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? []);
+
+                       $items[$row['uri-id']] = $this->addRowInformation($row, $activities[$row['uri-id']] ?? [], $thr_parent[$row['thr-parent-id']] ?? []);
                }
 
                DBA::close($thread_items);
@@ -1162,6 +1177,8 @@ class Conversation
                        usort($parents, [$this, 'sortThrReceived']);
                } elseif (stristr($order, 'commented')) {
                        usort($parents, [$this, 'sortThrCommented']);
+               } elseif (stristr($order, 'created')) {
+                       usort($parents, [$this, 'sortThrCreated']);
                }
 
                /*
@@ -1266,4 +1283,16 @@ class Conversation
        {
                return strcmp($b['commented'], $a['commented']);
        }
+
+       /**
+        * usort() callback to sort item arrays by the created key
+        *
+        * @param array $a
+        * @param array $b
+        * @return int
+        */
+       private function sortThrCreated(array $a, array $b)
+       {
+               return strcmp($b['created'], $a['created']);
+       }
 }