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\Logger;
25 use Friendica\Database\DBA;
26 use Friendica\Module\BaseApi;
28 use Friendica\Model\Contact;
29 use Friendica\Model\Item;
30 use Friendica\Model\Post;
31 use Friendica\Network\HTTPException\BadRequestException;
34 * Returns a single status.
36 * @see https://developer.twitter.com/en/docs/tweets/post-and-engage/api-reference/get-statuses-show-id
38 class Show extends BaseApi
40 protected function rawContent(array $request = [])
42 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
43 $uid = BaseApi::getCurrentUserID();
45 $id = $this->getRequestValue($request, 'id', 0);
46 $id = $this->getRequestValue($this->parameters, 'id', $id);
48 throw new BadRequestException('An id is missing.');
51 Logger::notice('API: api_statuses_show: ' . $id);
53 $conversation = !empty($request['conversation']);
55 // try to fetch the item for the local user - or the public item, if there is no local one
56 $item = Post::selectFirst(['id'], ['uri-id' => $id, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
57 if (!DBA::isResult($item)) {
58 throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $id));
61 $item_id = $item['id'];
64 $condition = ['parent' => $item_id, 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
65 $params = ['order' => ['uri-id' => true]];
67 $condition = ['id' => $item_id, 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]];
71 $statuses = Post::selectForUser($uid, [], $condition, $params);
73 /// @TODO How about copying this to above methods which don't check $r ?
74 if (!DBA::isResult($statuses)) {
75 throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
78 $include_entities = $this->getRequestValue($request, 'include_entities', false);
81 while ($status = DBA::fetch($statuses)) {
82 $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
84 DBA::close($statuses);
87 $data = ['status' => $ret];
88 $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
90 $data = ['status' => $ret[0]];
91 $this->response->exit('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));