From: Michael Date: Sun, 4 Dec 2022 21:57:58 +0000 (+0000) Subject: Issue 11915: Show reshared posts for contacts X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=4f98d2c74a5a71e57baa69818e0958ec1da3e9f7;p=friendica.git Issue 11915: Show reshared posts for contacts --- diff --git a/src/Factory/Api/Mastodon/Status.php b/src/Factory/Api/Mastodon/Status.php index dba74b1407..533c95a33a 100644 --- a/src/Factory/Api/Mastodon/Status.php +++ b/src/Factory/Api/Mastodon/Status.php @@ -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); diff --git a/src/Module/Api/Mastodon/Accounts/Statuses.php b/src/Module/Api/Mastodon/Accounts/Statuses.php index 7de8699401..b9bb63ae78 100644 --- a/src/Module/Api/Mastodon/Accounts/Statuses.php +++ b/src/Module/Api/Mastodon/Accounts/Statuses.php @@ -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); } diff --git a/src/Module/Profile/Status.php b/src/Module/Profile/Status.php index 0a4a17e462..2ffe91feb5 100644 --- a/src/Module/Profile/Status.php +++ b/src/Module/Profile/Status.php @@ -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,