3 * @copyright Copyright (C) 2010-2021, 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\Logger;
25 use Friendica\Database\DBA;
26 use Friendica\Module\BaseApi;
28 use Friendica\Model\Contact;
29 use Friendica\Model\Post;
30 use Friendica\Network\HTTPException\BadRequestException;
33 * Returns a single status.
35 * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id
37 class Show extends BaseApi
39 public function rawContent()
41 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
42 $uid = BaseApi::getCurrentUserID();
44 if (empty($this->parameters['id'])) {
45 $id = intval($_REQUEST['id'] ?? 0);
47 $id = (int)$this->parameters['id'];
50 Logger::notice('API: api_statuses_show: ' . $id);
52 $conversation = !empty($_REQUEST['conversation']);
54 // try to fetch the item for the local user - or the public item, if there is no local one
55 $uri_item = Post::selectFirst(['uri-id'], ['id' => $id]);
56 if (!DBA::isResult($uri_item)) {
57 throw new BadRequestException(sprintf("There is no status with the id %d", $id));
60 $item = Post::selectFirst(['id'], ['uri-id' => $uri_item['uri-id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
61 if (!DBA::isResult($item)) {
62 throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $uri_item['uri-id']));
68 $condition = ['parent' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
69 $params = ['order' => ['id' => true]];
71 $condition = ['id' => $id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
75 $statuses = Post::selectForUser($uid, [], $condition, $params);
77 /// @TODO How about copying this to above methods which don't check $r ?
78 if (!DBA::isResult($statuses)) {
79 throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
82 $include_entities = strtolower(($_REQUEST['include_entities'] ?? 'false') == 'true');
85 while ($status = DBA::fetch($statuses)) {
86 $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
88 DBA::close($statuses);
91 $data = ['status' => $ret];
92 DI::apiResponse()->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
94 $data = ['status' => $ret[0]];
95 DI::apiResponse()->exit('status', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));