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\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 protected function rawContent(array $request = [])
41 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
42 $uid = BaseApi::getCurrentUserID();
44 $id = $this->getRequestValue($request, 'id', 0);
45 $id = $this->getRequestValue($this->parameters, 'id', $id);
47 throw new BadRequestException('An id is missing.');
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 $item = Post::selectFirst(['id'], ['uri-id' => $id, 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
56 if (!DBA::isResult($item)) {
57 throw new BadRequestException(sprintf("There is no status with the uri-id %d for the given user.", $id));
60 $item_id = $item['id'];
63 $condition = ['parent' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
64 $params = ['order' => ['uri-id' => true]];
66 $condition = ['id' => $item_id, 'gravity' => [GRAVITY_PARENT, GRAVITY_COMMENT]];
70 $statuses = Post::selectForUser($uid, [], $condition, $params);
72 /// @TODO How about copying this to above methods which don't check $r ?
73 if (!DBA::isResult($statuses)) {
74 throw new BadRequestException(sprintf("There is no status or conversation with the id %d.", $id));
77 $include_entities = $this->getRequestValue($request, 'include_entities', false);
80 while ($status = DBA::fetch($statuses)) {
81 $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
83 DBA::close($statuses);
86 $data = ['status' => $ret];
87 $this->response->exit('statuses', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));
89 $data = ['status' => $ret[0]];
90 $this->response->exit('status', $data, $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));