]> git.mxchange.org Git - friendica.git/blobdiff - include/conversation.php
Merge pull request #8670 from MrPetovan/bug/8626-attach-empty-data
[friendica.git] / include / conversation.php
index 0ae8dd14a129f3f64cde7d3ef1cfb4e19968a730..0eb94181f019fa5ad5c69d313a9b57291ac0f1f8 100644 (file)
@@ -22,7 +22,6 @@
 use Friendica\App;
 use Friendica\Content\ContactSelector;
 use Friendica\Content\Feature;
-use Friendica\Content\Pager;
 use Friendica\Content\Text\BBCode;
 use Friendica\Core\Hook;
 use Friendica\Core\Logger;
@@ -34,7 +33,7 @@ use Friendica\DI;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Profile;
-use Friendica\Model\Term;
+use Friendica\Model\Tag;
 use Friendica\Object\Post;
 use Friendica\Object\Thread;
 use Friendica\Protocol\Activity;
@@ -377,17 +376,17 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                . "<script> var profile_uid = " . $_SESSION['uid']
                                . "; var netargs = '" . substr(DI::args()->getCommand(), 8)
                                . '?f='
-                               . (!empty($_GET['cid'])    ? '&cid='    . rawurlencode($_GET['cid'])    : '')
-                               . (!empty($_GET['search']) ? '&search=' . rawurlencode($_GET['search']) : '')
-                               . (!empty($_GET['star'])   ? '&star='   . rawurlencode($_GET['star'])   : '')
-                               . (!empty($_GET['order'])  ? '&order='  . rawurlencode($_GET['order'])  : '')
-                               . (!empty($_GET['bmark'])  ? '&bmark='  . rawurlencode($_GET['bmark'])  : '')
-                               . (!empty($_GET['liked'])  ? '&liked='  . rawurlencode($_GET['liked'])  : '')
-                               . (!empty($_GET['conv'])   ? '&conv='   . rawurlencode($_GET['conv'])   : '')
-                               . (!empty($_GET['nets'])   ? '&nets='   . rawurlencode($_GET['nets'])   : '')
-                               . (!empty($_GET['cmin'])   ? '&cmin='   . rawurlencode($_GET['cmin'])   : '')
-                               . (!empty($_GET['cmax'])   ? '&cmax='   . rawurlencode($_GET['cmax'])   : '')
-                               . (!empty($_GET['file'])   ? '&file='   . rawurlencode($_GET['file'])   : '')
+                               . (!empty($_GET['contactid']) ? '&contactid=' . rawurlencode($_GET['contactid']) : '')
+                               . (!empty($_GET['search'])    ? '&search='    . rawurlencode($_GET['search'])    : '')
+                               . (!empty($_GET['star'])      ? '&star='      . rawurlencode($_GET['star'])      : '')
+                               . (!empty($_GET['order'])     ? '&order='     . rawurlencode($_GET['order'])     : '')
+                               . (!empty($_GET['bmark'])     ? '&bmark='     . rawurlencode($_GET['bmark'])     : '')
+                               . (!empty($_GET['liked'])     ? '&liked='     . rawurlencode($_GET['liked'])     : '')
+                               . (!empty($_GET['conv'])      ? '&conv='      . rawurlencode($_GET['conv'])      : '')
+                               . (!empty($_GET['nets'])      ? '&nets='      . rawurlencode($_GET['nets'])      : '')
+                               . (!empty($_GET['cmin'])      ? '&cmin='      . rawurlencode($_GET['cmin'])      : '')
+                               . (!empty($_GET['cmax'])      ? '&cmax='      . rawurlencode($_GET['cmax'])      : '')
+                               . (!empty($_GET['file'])      ? '&file='      . rawurlencode($_GET['file'])      : '')
 
                                . "'; </script>\r\n";
                }
@@ -527,7 +526,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                        $profile_name = $item['author-link'];
                                }
 
-                               $tags = Term::populateTagsFromItem($item);
+                               $tags = Tag::populateFromItem($item);
 
                                $author = ['uid' => 0, 'id' => $item['author-id'],
                                        'network' => $item['author-network'], 'url' => $item['author-link']];
@@ -770,20 +769,12 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
 
        $items = [];
 
-       foreach ($parents AS $parent) {
-               $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) ",
-                       $parent['uri'], $uid];
-               if ($block_authors) {
-                       $condition[0] .= "AND NOT `author`.`hidden`";
-               }
-
-               $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
+       $follow = Item::activityToIndex(Activity::FOLLOW);
 
-               $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
-
-               if (count($comments) != 0) {
-                       $items = array_merge($items, $comments);
-               }
+       foreach ($parents AS $parent) {
+               $condition = ["`item`.`parent-uri` = ? AND `item`.`uid` IN (0, ?) AND (`activity` != ? OR `activity` IS NULL)",
+                       $parent['uri'], $uid, $follow];
+               $items = conversation_fetch_items($parent, $items, $condition, $block_authors, $params);
        }
 
        foreach ($items as $index => $item) {
@@ -797,6 +788,31 @@ function conversation_add_children(array $parents, $block_authors, $order, $uid)
        return $items;
 }
 
+/**
+ * Fetch conversation items
+ *
+ * @param array $parent
+ * @param array $items
+ * @param array $condition
+ * @param boolean $block_authors
+ * @param array $params
+ * @return array
+ */
+function conversation_fetch_items(array $parent, array $items, array $condition, bool $block_authors, array $params) {
+       if ($block_authors) {
+               $condition[0] .= "AND NOT `author`.`hidden`";
+       }
+
+       $thread_items = Item::selectForUser(local_user(), array_merge(Item::DISPLAY_FIELDLIST, ['contact-uid', 'gravity']), $condition, $params);
+
+       $comments = conversation_fetch_comments($thread_items, $parent['pinned'] ?? false);
+
+       if (count($comments) != 0) {
+               $items = array_merge($items, $comments);
+       }
+       return $items;
+}
+
 function item_photo_menu($item) {
        $sub_link = '';
        $poke_link = '';
@@ -837,15 +853,15 @@ function item_photo_menu($item) {
 
        if (!empty($pcid)) {
                $contact_url = 'contact/' . $pcid;
-               $posts_link = 'contact/' . $pcid . '/posts';
-               $block_link = 'contact/' . $pcid . '/block';
-               $ignore_link = 'contact/' . $pcid . '/ignore';
+               $posts_link  = $contact_url . '/posts';
+               $block_link  = $contact_url . '/block';
+               $ignore_link = $contact_url . '/ignore';
        }
 
        if ($cid && !$item['self']) {
-               $poke_link = 'poke?c=' . $cid;
                $contact_url = 'contact/' . $cid;
-               $posts_link = 'contact/' . $cid . '/posts';
+               $poke_link   = $contact_url . '/poke';
+               $posts_link  = $contact_url . '/posts';
 
                if (in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA])) {
                        $pm_url = 'message/new/' . $cid;