]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Replace dba::select(limit => 1) by dba::selectOne
[friendica.git] / include / conversation.php
index 0bc3bb0b2b1de14ab45f1b70596d642d84703716..746a8a89134cd9970230874b8b4952eb3bca2f87 100644 (file)
@@ -3,6 +3,7 @@
  * @file include/conversation.php
  */
 use Friendica\App;
+use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
@@ -628,7 +629,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                        $writable = false;
                }
 
-               if ($mode === 'network-new' || $mode === 'search' || $community_readonly) {
+               if (in_array($mode, ['network-new', 'search', 'contact-posts']) || $community_readonly) {
 
                        /*
                         * "New Item View" on network page or search page results
@@ -776,7 +777,7 @@ function conversation(App $a, $items, $mode, $update, $preview = false) {
                                        'id' => (($preview) ? 'P0' : $item['item_id']),
                                        'guid' => (($preview) ? 'Q0' : $item['guid']),
                                        'network' => $item['item_network'],
-                                       'network_name' => network_to_name($item['item_network'], $profile_link),
+                                       'network_name' => ContactSelector::networkToName($item['item_network'], $profile_link),
                                        'linktitle' => sprintf( t('View %s\'s profile @ %s'), $profile_name, ((strlen($item['author-link'])) ? $item['author-link'] : $item['url'])),
                                        'profile_url' => $profile_link,
                                        'item_photo_menu' => item_photo_menu($item),
@@ -919,6 +920,20 @@ function community_add_items($parents) {
                );
                $comments = dba::inArray($thread_items);
 
+               // Check if the original item is in the result.
+               // When commenting from the community page there can be incomplete threads
+               if (count($comments) > 0) {
+                       $parent_found = false;
+                       foreach ($comments as $comment) {
+                               if ($comment['uri'] == $comment['parent-uri']) {
+                                       $parent_found = true;
+                                       break;
+                               }
+                       }
+                       if (!$parent_found) {
+                               $comments = array();
+                       }
+               }
 
                if (count($comments) == 0) {
                        $thread_items = dba::p(item_query()." AND `item`.`uid` = 0
@@ -953,9 +968,8 @@ function best_link_url($item, &$sparkle, $url = '') {
        $clean_url = normalise_link($item['author-link']);
 
        if (local_user()) {
-               $r = dba::select('contact', array('id'),
-                       array('network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false),
-                       array('limit' => 1));
+               $r = dba::selectOne('contact', ['id'],
+                       ['network' => NETWORK_DFRN, 'uid' => local_user(), 'nurl' => normalise_link($clean_url), 'pending' => false]);
                if (DBM::is_result($r)) {
                        $best_url = 'redir/' . $r['id'];
                        $sparkle = true;
@@ -1005,7 +1019,7 @@ function item_photo_menu($item) {
        $cid = 0;
        $network = '';
        $rel = 0;
-       $r = dba::select('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])), array('limit' => 1));
+       $r = dba::selectOne('contact', array('id', 'network', 'rel'), array('uid' => local_user(), 'nurl' => normalise_link($item['author-link'])));
        if (DBM::is_result($r)) {
                $cid = $r['id'];
                $network = $r['network'];