3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Module\Api\Twitter\Statuses;
24 use Friendica\Core\Protocol;
25 use Friendica\Database\DBA;
27 use Friendica\Model\Item;
28 use Friendica\Model\Post;
29 use Friendica\Module\BaseApi;
30 use Friendica\Network\HTTPException\BadRequestException;
31 use Friendica\Network\HTTPException\ForbiddenException;
32 use Friendica\Network\HTTPException\InternalServerErrorException;
33 use Friendica\Protocol\Diaspora;
38 * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/post-statuses-retweet-id
40 class Retweet extends BaseApi
42 protected function post(array $request = [])
44 self::checkAllowedScope(self::SCOPE_WRITE);
45 $uid = self::getCurrentUserID();
47 $id = $this->getRequestValue($request, 'id', 0);
48 $id = $this->getRequestValue($this->parameters, 'id', $id);
50 throw new BadRequestException('An id is missing.');
53 $fields = ['id', 'uri-id', 'network', 'body', 'title', 'author-name', 'author-link', 'author-avatar', 'guid', 'created', 'plink'];
54 $item = Post::selectFirst($fields, ['uri-id' => $id, 'uid' => [0, $uid], 'private' => [Item::PUBLIC, Item::UNLISTED]], ['order' => ['uid' => true]]);
56 if (DBA::isResult($item) && !empty($item['body'])) {
57 if (in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::TWITTER])) {
58 if (!Item::performActivity($id, 'announce', $uid)) {
59 throw new InternalServerErrorException();
62 $item_id = $item['id'];
64 $item_id = Diaspora::performReshare($item['uri-id'], $uid);
67 throw new ForbiddenException();
70 $status_info = DI::twitterStatus()->createFromItemId($item_id, $uid)->toArray();
72 DI::apiResponse()->exit('statuses', ['status' => $status_info], $this->parameters['extension'] ?? null);