]> git.mxchange.org Git - friendica.git/commitdiff
Issue 11915: Show reshared posts for contacts
authorMichael <heluecht@pirati.ca>
Sun, 4 Dec 2022 21:57:58 +0000 (21:57 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 4 Dec 2022 21:57:58 +0000 (21:57 +0000)
src/Factory/Api/Mastodon/Status.php
src/Module/Api/Mastodon/Accounts/Statuses.php
src/Module/Profile/Status.php

index dba74b140743873c72502d488f5b05b7e938df21..533c95a33abb2258020c931764d4f43df0b45917 100644 (file)
@@ -86,7 +86,7 @@ class Status extends BaseFactory
         */
        public function createFromUriId(int $uriId, int $uid = 0, bool $reblog = true): \Friendica\Object\Api\Mastodon\Status
        {
-               $fields = ['uri-id', 'uid', 'author-id', 'author-uri-id', 'author-link', 'causer-uri-id', 'post-reason', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
+               $fields = ['uri-id', 'uid', 'author-id', 'causer-id', 'author-uri-id', 'author-link', 'causer-uri-id', 'post-reason', 'starred', 'app', 'title', 'body', 'raw-body', 'content-warning', 'question-id',
                        'created', 'network', 'thr-parent-id', 'parent-author-id', 'language', 'uri', 'plink', 'private', 'vid', 'gravity', 'featured', 'has-media', 'quote-uri-id'];
                $item = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
                if (!$item) {
@@ -97,9 +97,18 @@ class Status extends BaseFactory
                        throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
                }
 
-               $is_reshare = $reblog && !is_null($item['causer-uri-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT);
-
-               $account = $this->mstdnAccountFactory->createFromUriId($is_reshare ? $item['causer-uri-id']:$item['author-uri-id'], $uid);
+               if (($item['gravity'] == Item::GRAVITY_ACTIVITY) && ($item['vid'] == Verb::getID(Activity::ANNOUNCE))) {
+                       $is_reshare = true;
+                       $account    = $this->mstdnAccountFactory->createFromUriId($item['author-uri-id'], $uid);
+                       $uriId      = $item['thr-parent-id'];
+                       $item       = Post::selectFirst($fields, ['uri-id' => $uriId, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
+                       if (!$item) {
+                               throw new HTTPException\NotFoundException('Item with URI ID ' . $uriId . ' not found' . ($uid ? ' for user ' . $uid : '.'));
+                       }
+               } else {
+                       $is_reshare = $reblog && !is_null($item['causer-uri-id']) && ($item['causer-id'] != $item['author-id']) && ($item['post-reason'] == Item::PR_ANNOUNCEMENT);
+                       $account    = $this->mstdnAccountFactory->createFromUriId($is_reshare ? $item['causer-uri-id']:$item['author-uri-id'], $uid);
+               }
 
                $count_announce = Post::countPosts([
                        'thr-parent-id' => $uriId,
@@ -190,19 +199,13 @@ class Status extends BaseFactory
                        }
                }
 
-               if ($item['vid'] == Verb::getID(Activity::ANNOUNCE)) {
-                       $reshare       = $this->createFromUriId($item['thr-parent-id'], $uid)->toArray();
-                       $reshared_item = Post::selectFirst(['title', 'body'], ['uri-id' => $item['thr-parent-id'],'uid' => [0, $uid]]);
-                       $item['title'] = $reshared_item['title'] ?? $item['title'];
-                       $item['body']  = $reshared_item['body'] ?? $item['body'];
-               } else {
-                       $item['body']     = $this->contentItem->addSharedPost($item);
-                       $item['raw-body'] = $this->contentItem->addSharedPost($item, $item['raw-body']);
-                       $reshare = [];
-               }
+               $item['body']     = $this->contentItem->addSharedPost($item);
+               $item['raw-body'] = $this->contentItem->addSharedPost($item, $item['raw-body']);
 
                if ($is_reshare) {
                        $reshare = $this->createFromUriId($uriId, $uid, false)->toArray();
+               } else {
+                       $reshare = [];
                }
 
                return new \Friendica\Object\Api\Mastodon\Status($item, $account, $counts, $userAttributes, $sensitive, $application, $mentions, $tags, $card, $attachments, $reshare, $poll);
index 7de8699401dc14da7f7b96eeb710815e8c503376..b9bb63ae78bc0e487134dd667ef0390669a3cd24 100644 (file)
@@ -80,8 +80,15 @@ class Statuses extends BaseApi
                }
 
                if (!$request['pinned'] && !$request['only_media']) {
-                       $condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
-                               Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
+                       if ($request['exclude_replies']) {
+                               $condition = DBA::mergeConditions($condition, ["(`gravity` = ? OR (`gravity` = ? AND `vid` = ?))",
+                                       Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
+                       } else {
+                               $condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
+                                       Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
+                       }
+               } elseif ($request['exclude_replies']) {
+                       $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
                }
 
                if (!empty($request['max_id'])) {
@@ -97,16 +104,10 @@ class Statuses extends BaseApi
                        $params['order'] = ['uri-id'];
                }
 
-               if (($request['pinned'] || $request['only_media']) && $request['exclude_replies']) {
-                       $condition = DBA::mergeConditions($condition, ['gravity' => Item::GRAVITY_PARENT]);
-               }
-
                if ($request['pinned']) {
                        $items = DBA::select('collection-view', ['uri-id'], $condition, $params);
                } elseif ($request['only_media']) {
                        $items = DBA::select('media-view', ['uri-id'], $condition, $params);
-               } elseif ($request['exclude_replies']) {
-                       $items = Post::selectThreadForUser($uid, ['uri-id'], $condition, $params);
                } else {
                        $items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
                }
index 0a4a17e462e1b3deb9d0145235834105be2ef50c..2ffe91feb5541c5713691d4f8edfc14975dcc171 100644 (file)
@@ -173,7 +173,7 @@ class Status extends BaseProfile
 
                $condition = DBA::mergeConditions($condition, ["((`gravity` = ? AND `wall`) OR
                        (`gravity` = ? AND `vid` = ? AND `origin`
-                       AND `thr-parent-id` IN (SELECT `uri-id` FROM `post` WHERE `gravity` = ? AND `network` IN (?, ?))))",
+                       AND EXISTS(SELECT `uri-id` FROM `post` WHERE `uri-id` = `post-user-view`.`thr-parent-id` AND `gravity` = ? AND `network` IN (?, ?))))",
                        Item::GRAVITY_PARENT, Item::GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE), Item::GRAVITY_PARENT, Protocol::ACTIVITYPUB, Protocol::DFRN]);
 
                $condition = DBA::mergeConditions($condition, ['uid' => $profile['uid'], 'network' => Protocol::FEDERATED,