Merge pull request #13175 from HankG/mastodon-api-reshare-fixes

Mastodon api reshare fixes
This commit is contained in:
Hypolite Petovan 2023-08-16 14:55:33 -04:00 committed by GitHub
commit 18c078f8c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 76 additions and 25 deletions

View File

@ -65,6 +65,11 @@ class Bookmark extends BaseApi
Item::update(['starred' => true], ['id' => $item['id']]); 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());
} }
} }

View File

@ -42,13 +42,18 @@ class Favourite extends BaseApi
DI::mstdnError()->UnprocessableEntity(); 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)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
Item::performActivity($item['id'], 'like', $uid); 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());
} }
} }

View File

@ -53,6 +53,11 @@ class Mute extends BaseApi
Post\ThreadUser::setIgnored($item['uri-id'], $uid, true); 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());
} }
} }

View File

@ -48,6 +48,11 @@ class Pin extends BaseApi
Post\Collection::add($item['uri-id'], Post\Collection::FEATURED, $item['author-id'], $uid); 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());
} }
} }

View File

@ -45,7 +45,7 @@ class Reblog extends BaseApi
DI::mstdnError()->UnprocessableEntity(); 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)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
@ -58,6 +58,11 @@ class Reblog extends BaseApi
Item::performActivity($item['id'], 'announce', $uid); 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());
} }
} }

View File

@ -65,6 +65,11 @@ class Unbookmark extends BaseApi
Item::update(['starred' => false], ['id' => $item['id']]); 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());
} }
} }

View File

@ -42,13 +42,18 @@ class Unfavourite extends BaseApi
DI::mstdnError()->UnprocessableEntity(); 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)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
Item::performActivity($item['id'], 'unlike', $uid); 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());
} }
} }

View File

@ -53,6 +53,11 @@ class Unmute extends BaseApi
Post\ThreadUser::setIgnored($item['uri-id'], $uid, false); 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());
} }
} }

View File

@ -48,6 +48,11 @@ class Unpin extends BaseApi
Post\Collection::remove($item['uri-id'], Post\Collection::FEATURED, $uid); 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());
} }
} }

View File

@ -44,7 +44,7 @@ class Unreblog extends BaseApi
DI::mstdnError()->UnprocessableEntity(); 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)) { if (!DBA::isResult($item)) {
DI::mstdnError()->RecordNotFound(); DI::mstdnError()->RecordNotFound();
} }
@ -64,6 +64,11 @@ class Unreblog extends BaseApi
Item::performActivity($item['id'], 'unannounce', $uid); 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());
} }
} }

View File

@ -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) 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->id = (string)$item['uri-id'];
$this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON); $this->created_at = DateTimeFormat::utc($item['created'], DateTimeFormat::JSON);
$this->edited_at = DateTimeFormat::utc($item['edited'], DateTimeFormat::JSON); $this->edited_at = DateTimeFormat::utc($item['edited'], DateTimeFormat::JSON);
@ -135,26 +136,26 @@ class Status extends BaseDataTransferObject
$this->uri = $item['uri']; $this->uri = $item['uri'];
$this->url = $item['plink'] ?? null; $this->url = $item['plink'] ?? null;
$this->replies_count = $counts->replies; $this->replies_count = $reblogged ? 0 : $counts->replies;
$this->reblogs_count = $counts->reblogs; $this->reblogs_count = $reblogged ? 0 : $counts->reblogs;
$this->favourites_count = $counts->favourites; $this->favourites_count = $reblogged ? 0 : $counts->favourites;
$this->favourited = $userAttributes->favourited; $this->favourited = $userAttributes->favourited;
$this->reblogged = $userAttributes->reblogged; $this->reblogged = $userAttributes->reblogged;
$this->muted = $userAttributes->muted; $this->muted = $userAttributes->muted;
$this->bookmarked = $userAttributes->bookmarked; $this->bookmarked = $userAttributes->bookmarked;
$this->pinned = $userAttributes->pinned; $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->reblog = $reblog;
$this->quote = $quote; $this->quote = $quote;
$this->application = $application->toArray(); $this->application = $application->toArray();
$this->account = $account->toArray(); $this->account = $account->toArray();
$this->media_attachments = $attachments; $this->media_attachments = $reblogged ? [] : $attachments;
$this->mentions = $mentions; $this->mentions = $reblogged ? [] : $mentions;
$this->tags = $tags; $this->tags = $reblogged ? [] : $tags;
$this->emojis = []; $this->emojis = $reblogged ? [] : [];
$this->card = $card->toArray() ?: null; $this->card = $reblogged ? null : ($card->toArray() ?: null);
$this->poll = $poll; $this->poll = $reblogged ? null : $poll;
$this->friendica = $friendica; $this->friendica = $reblogged ? null : $friendica;
} }
/** /**