diff --git a/src/Module/Api/Mastodon/Statuses/Bookmark.php b/src/Module/Api/Mastodon/Statuses/Bookmark.php index 59c61f991..7f32c9a43 100644 --- a/src/Module/Api/Mastodon/Statuses/Bookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Bookmark.php @@ -65,6 +65,11 @@ class Bookmark extends BaseApi Item::update(['starred' => true], ['id' => $item['id']]); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Favourite.php b/src/Module/Api/Mastodon/Statuses/Favourite.php index d1a68862c..3543a3ba8 100644 --- a/src/Module/Api/Mastodon/Statuses/Favourite.php +++ b/src/Module/Api/Mastodon/Statuses/Favourite.php @@ -42,13 +42,18 @@ class Favourite extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } Item::performActivity($item['id'], 'like', $uid); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Mute.php b/src/Module/Api/Mastodon/Statuses/Mute.php index 1f00d39d0..a99cd6863 100644 --- a/src/Module/Api/Mastodon/Statuses/Mute.php +++ b/src/Module/Api/Mastodon/Statuses/Mute.php @@ -53,6 +53,11 @@ class Mute extends BaseApi Post\ThreadUser::setIgnored($item['uri-id'], $uid, true); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Pin.php b/src/Module/Api/Mastodon/Statuses/Pin.php index 33a0116eb..5d9a18113 100644 --- a/src/Module/Api/Mastodon/Statuses/Pin.php +++ b/src/Module/Api/Mastodon/Statuses/Pin.php @@ -48,6 +48,11 @@ class Pin extends BaseApi Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(),$isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Reblog.php b/src/Module/Api/Mastodon/Statuses/Reblog.php index f1922d727..98cbd417d 100644 --- a/src/Module/Api/Mastodon/Statuses/Reblog.php +++ b/src/Module/Api/Mastodon/Statuses/Reblog.php @@ -45,7 +45,7 @@ class Reblog extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -58,6 +58,11 @@ class Reblog extends BaseApi Item::performActivity($item['id'], 'announce', $uid); } - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unbookmark.php b/src/Module/Api/Mastodon/Statuses/Unbookmark.php index f95fd9445..556db2b4b 100644 --- a/src/Module/Api/Mastodon/Statuses/Unbookmark.php +++ b/src/Module/Api/Mastodon/Statuses/Unbookmark.php @@ -65,6 +65,11 @@ class Unbookmark extends BaseApi Item::update(['starred' => false], ['id' => $item['id']]); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unfavourite.php b/src/Module/Api/Mastodon/Statuses/Unfavourite.php index a3760b454..99358be55 100644 --- a/src/Module/Api/Mastodon/Statuses/Unfavourite.php +++ b/src/Module/Api/Mastodon/Statuses/Unfavourite.php @@ -42,13 +42,18 @@ class Unfavourite extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['id', 'uri-id'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } Item::performActivity($item['id'], 'unlike', $uid); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unmute.php b/src/Module/Api/Mastodon/Statuses/Unmute.php index 2285422ca..b6d9c2b19 100644 --- a/src/Module/Api/Mastodon/Statuses/Unmute.php +++ b/src/Module/Api/Mastodon/Statuses/Unmute.php @@ -53,6 +53,11 @@ class Unmute extends BaseApi Post\ThreadUser::setIgnored($item['uri-id'], $uid, false); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unpin.php b/src/Module/Api/Mastodon/Statuses/Unpin.php index c80582d15..75b1d6fa5 100644 --- a/src/Module/Api/Mastodon/Statuses/Unpin.php +++ b/src/Module/Api/Mastodon/Statuses/Unpin.php @@ -48,6 +48,11 @@ class Unpin extends BaseApi Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid); - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Module/Api/Mastodon/Statuses/Unreblog.php b/src/Module/Api/Mastodon/Statuses/Unreblog.php index 54a18823a..6730e0fb5 100644 --- a/src/Module/Api/Mastodon/Statuses/Unreblog.php +++ b/src/Module/Api/Mastodon/Statuses/Unreblog.php @@ -44,7 +44,7 @@ class Unreblog extends BaseApi DI::mstdnError()->UnprocessableEntity(); } - $item = Post::selectOriginalForUser($uid, ['id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); + $item = Post::selectOriginalForUser($uid, ['id', 'uri-id', 'network'], ['uri-id' => $this->parameters['id'], 'uid' => [$uid, 0]]); if (!DBA::isResult($item)) { DI::mstdnError()->RecordNotFound(); } @@ -64,6 +64,11 @@ class Unreblog extends BaseApi Item::performActivity($item['id'], 'unannounce', $uid); } - System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes())->toArray()); + // @TODO Remove once mstdnStatus()->createFromUriId is fixed so that it returns posts not reshared posts if given an ID to an original post that has been reshared + // Introduced in this PR: https://github.com/friendica/friendica/pull/13175 + // Issue tracking the behavior of createFromUriId: https://github.com/friendica/friendica/issues/13350 + $isReblog = $item['uri-id'] != $this->parameters['id']; + + System::jsonExit(DI::mstdnStatus()->createFromUriId($this->parameters['id'], $uid, self::appSupportsQuotes(), $isReblog)->toArray()); } } diff --git a/src/Object/Api/Mastodon/Status.php b/src/Object/Api/Mastodon/Status.php index 0a02a4854..122e62f9c 100644 --- a/src/Object/Api/Mastodon/Status.php +++ b/src/Object/Api/Mastodon/Status.php @@ -109,6 +109,7 @@ class Status extends BaseDataTransferObject */ public function __construct(array $item, Account $account, Counts $counts, UserAttributes $userAttributes, bool $sensitive, Application $application, array $mentions, array $tags, Card $card, array $attachments, array $in_reply, array $reblog, FriendicaExtension $friendica, array $quote = null, array $poll = null) { + $reblogged = !empty($reblog); $this->id = (string)$item['uri-id']; $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON); $this->edited_at = DateTimeFormat::utc($item['edited'], DateTimeFormat::JSON); @@ -135,26 +136,26 @@ class Status extends BaseDataTransferObject $this->uri = $item['uri']; $this->url = $item['plink'] ?? null; - $this->replies_count = $counts->replies; - $this->reblogs_count = $counts->reblogs; - $this->favourites_count = $counts->favourites; + $this->replies_count = $reblogged ? 0 : $counts->replies; + $this->reblogs_count = $reblogged ? 0 : $counts->reblogs; + $this->favourites_count = $reblogged ? 0 : $counts->favourites; $this->favourited = $userAttributes->favourited; $this->reblogged = $userAttributes->reblogged; $this->muted = $userAttributes->muted; $this->bookmarked = $userAttributes->bookmarked; $this->pinned = $userAttributes->pinned; - $this->content = BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::MASTODON_API); + $this->content = $reblogged ? '' : BBCode::convertForUriId($item['uri-id'], BBCode::setMentionsToNicknames($item['raw-body'] ?? $item['body']), BBCode::MASTODON_API); $this->reblog = $reblog; $this->quote = $quote; $this->application = $application->toArray(); $this->account = $account->toArray(); - $this->media_attachments = $attachments; - $this->mentions = $mentions; - $this->tags = $tags; - $this->emojis = []; - $this->card = $card->toArray() ?: null; - $this->poll = $poll; - $this->friendica = $friendica; + $this->media_attachments = $reblogged ? [] : $attachments; + $this->mentions = $reblogged ? [] : $mentions; + $this->tags = $reblogged ? [] : $tags; + $this->emojis = $reblogged ? [] : []; + $this->card = $reblogged ? null : ($card->toArray() ?: null); + $this->poll = $reblogged ? null : $poll; + $this->friendica = $reblogged ? null : $friendica; } /**