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\GNUSocial\Statusnet;
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 conversation
35 class Conversation extends BaseApi
37 protected function rawContent(array $request = [])
39 BaseApi::checkAllowedScope(BaseApi::SCOPE_READ);
40 $uid = BaseApi::getCurrentUserID();
43 $id = $this->getRequestValue($this->parameters, 'id', 0);
44 $since_id = $this->getRequestValue($request, 'since_id', 0, 0);
45 $max_id = $this->getRequestValue($request, 'max_id', 0, 0);
46 $count = $this->getRequestValue($request, 'count', 20, 1, 100);
47 $page = $this->getRequestValue($request, 'page', 1, 1);
48 $include_entities = $this->getRequestValue($request, 'include_entities', false);
50 $start = max(0, ($page - 1) * $count);
53 $id = $request['id'] ?? 0;
56 Logger::info(BaseApi::LOG_PREFIX . '{subaction}', ['module' => 'api', 'action' => 'conversation', 'subaction' => 'show', 'id' => $id]);
58 // try to fetch the item for the local user - or the public item, if there is no local one
59 $item = Post::selectFirst(['parent-uri-id'], ['id' => $id]);
60 if (!DBA::isResult($item)) {
61 throw new BadRequestException("There is no status with the id $id.");
64 $parent = Post::selectFirst(['id'], ['uri-id' => $item['parent-uri-id'], 'uid' => [0, $uid]], ['order' => ['uid' => true]]);
65 if (!DBA::isResult($parent)) {
66 throw new BadRequestException("There is no status with this id.");
71 $condition = ["`parent` = ? AND `uid` IN (0, ?) AND `gravity` IN (?, ?) AND `id` > ?",
72 $id, $uid, GRAVITY_PARENT, GRAVITY_COMMENT, $since_id];
75 $condition[0] .= " AND `id` <= ?";
76 $condition[] = $max_id;
79 $params = ['order' => ['id' => true], 'limit' => [$start, $count]];
80 $statuses = Post::selectForUser($uid, [], $condition, $params);
82 if (!DBA::isResult($statuses)) {
83 throw new BadRequestException("There is no status with id $id.");
87 while ($status = DBA::fetch($statuses)) {
88 $ret[] = DI::twitterStatus()->createFromUriId($status['uri-id'], $status['uid'], $include_entities)->toArray();
90 DBA::close($statuses);
92 $this->response->exit('statuses', ['status' => $ret], $this->parameters['extension'] ?? null, Contact::getPublicIdByUserId($uid));