2020-10-31 22:32:26 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2022-01-02 07:27:47 +00:00
|
|
|
* @copyright Copyright (C) 2010-2022, the Friendica project
|
2020-10-31 22:32:26 +00:00
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Friendica\Module\Api\Mastodon\Accounts;
|
|
|
|
|
|
|
|
use Friendica\Core\Protocol;
|
|
|
|
use Friendica\Core\System;
|
|
|
|
use Friendica\Database\DBA;
|
|
|
|
use Friendica\DI;
|
|
|
|
use Friendica\Model\Item;
|
2021-01-16 22:37:27 +00:00
|
|
|
use Friendica\Model\Post;
|
2020-11-01 11:01:57 +00:00
|
|
|
use Friendica\Model\Verb;
|
2020-10-31 22:32:26 +00:00
|
|
|
use Friendica\Module\BaseApi;
|
2020-11-01 11:01:57 +00:00
|
|
|
use Friendica\Protocol\Activity;
|
2020-10-31 22:32:26 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @see https://docs.joinmastodon.org/methods/accounts/
|
|
|
|
*/
|
|
|
|
class Statuses extends BaseApi
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
|
|
|
*/
|
2021-11-20 14:38:03 +00:00
|
|
|
protected function rawContent(array $request = [])
|
2020-10-31 22:32:26 +00:00
|
|
|
{
|
2021-06-08 08:28:14 +00:00
|
|
|
$uid = self::getCurrentUserID();
|
|
|
|
|
2021-11-14 22:19:25 +00:00
|
|
|
if (empty($this->parameters['id'])) {
|
2021-05-12 14:00:15 +00:00
|
|
|
DI::mstdnError()->UnprocessableEntity();
|
2020-10-31 22:32:26 +00:00
|
|
|
}
|
|
|
|
|
2021-11-14 22:19:25 +00:00
|
|
|
$id = $this->parameters['id'];
|
2020-10-31 22:32:26 +00:00
|
|
|
if (!DBA::exists('contact', ['id' => $id, 'uid' => 0])) {
|
|
|
|
DI::mstdnError()->RecordNotFound();
|
|
|
|
}
|
|
|
|
|
2021-11-28 12:22:27 +00:00
|
|
|
$request = $this->getRequest([
|
2021-05-18 19:26:46 +00:00
|
|
|
'only_media' => false, // Show only statuses with media attached? Defaults to false.
|
|
|
|
'max_id' => 0, // Return results older than this id
|
|
|
|
'since_id' => 0, // Return results newer than this id
|
|
|
|
'min_id' => 0, // Return results immediately newer than this id
|
|
|
|
'limit' => 20, // Maximum number of results to return. Defaults to 20.
|
|
|
|
'pinned' => false, // Only pinned posts
|
|
|
|
'exclude_replies' => false, // Don't show comments
|
2021-05-19 06:18:42 +00:00
|
|
|
'with_muted' => false, // Pleroma extension: return activities by muted (not by blocked!) users.
|
|
|
|
'exclude_reblogs' => false, // Undocumented parameter
|
|
|
|
'tagged' => false, // Undocumented parameter
|
2021-11-27 23:30:41 +00:00
|
|
|
], $request);
|
2021-05-18 19:26:46 +00:00
|
|
|
|
|
|
|
$params = ['order' => ['uri-id' => true], 'limit' => $request['limit']];
|
2020-10-31 22:32:26 +00:00
|
|
|
|
2022-06-10 22:38:46 +00:00
|
|
|
if ($request['pinned']) {
|
|
|
|
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED]];
|
|
|
|
} elseif (!$uid) {
|
2021-05-07 21:28:48 +00:00
|
|
|
$condition = ['author-id' => $id, 'private' => [Item::PUBLIC, Item::UNLISTED],
|
|
|
|
'uid' => 0, 'network' => Protocol::FEDERATED];
|
|
|
|
} else {
|
|
|
|
$condition = ["`author-id` = ? AND (`uid` = 0 OR (`uid` = ? AND NOT `global`))", $id, $uid];
|
|
|
|
}
|
2020-11-01 11:01:57 +00:00
|
|
|
|
2022-06-10 22:38:46 +00:00
|
|
|
if (!$request['pinned']) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["(`gravity` IN (?, ?) OR (`gravity` = ? AND `vid` = ?))",
|
|
|
|
GRAVITY_PARENT, GRAVITY_COMMENT, GRAVITY_ACTIVITY, Verb::getID(Activity::ANNOUNCE)]);
|
|
|
|
}
|
2020-10-31 22:32:26 +00:00
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if ($request['only_media']) {
|
2021-05-08 01:52:23 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` IN (SELECT `uri-id` FROM `post-media` WHERE `type` IN (?, ?, ?))",
|
|
|
|
Post\Media::AUDIO, Post\Media::IMAGE, Post\Media::VIDEO]);
|
|
|
|
}
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if (!empty($request['max_id'])) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` < ?", $request['max_id']]);
|
2020-10-31 22:32:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if (!empty($request['since_id'])) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['since_id']]);
|
2020-10-31 22:32:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if (!empty($request['min_id'])) {
|
|
|
|
$condition = DBA::mergeConditions($condition, ["`uri-id` > ?", $request['min_id']]);
|
2020-10-31 22:32:26 +00:00
|
|
|
$params['order'] = ['uri-id'];
|
|
|
|
}
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if ($request['exclude_replies']) {
|
2021-05-15 15:02:15 +00:00
|
|
|
$condition = DBA::mergeConditions($condition, ['gravity' => GRAVITY_PARENT]);
|
|
|
|
}
|
|
|
|
|
2022-06-10 22:38:46 +00:00
|
|
|
if ($request['pinned']) {
|
|
|
|
$items = DBA::select('collection-view', ['uri-id'], $condition, $params);
|
|
|
|
} else {
|
|
|
|
$items = Post::selectForUser($uid, ['uri-id'], $condition, $params);
|
|
|
|
}
|
2020-10-31 22:32:26 +00:00
|
|
|
|
|
|
|
$statuses = [];
|
2021-01-16 22:37:27 +00:00
|
|
|
while ($item = Post::fetch($items)) {
|
2021-06-16 15:02:33 +00:00
|
|
|
self::setBoundaries($item['uri-id']);
|
2021-05-07 21:28:48 +00:00
|
|
|
$statuses[] = DI::mstdnStatus()->createFromUriId($item['uri-id'], $uid);
|
2020-10-31 22:32:26 +00:00
|
|
|
}
|
|
|
|
DBA::close($items);
|
|
|
|
|
2021-05-18 19:26:46 +00:00
|
|
|
if (!empty($request['min_id'])) {
|
2021-12-05 06:22:04 +00:00
|
|
|
$statuses = array_reverse($statuses);
|
2020-10-31 22:32:26 +00:00
|
|
|
}
|
|
|
|
|
2021-06-16 15:02:33 +00:00
|
|
|
self::setLinkHeader();
|
2020-10-31 22:32:26 +00:00
|
|
|
System::jsonExit($statuses);
|
|
|
|
}
|
|
|
|
}
|