status creation from mastodon client

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/1517/head
Maxence Lange 2022-11-21 15:48:39 -01:00
rodzic 72be817000
commit b32fa07f9c
10 zmienionych plików z 357 dodań i 103 usunięć

Wyświetl plik

@ -81,6 +81,7 @@ return [
['name' => 'Api#savedSearches', 'url' => '/api/saved_searches/list.json', 'verb' => 'GET'],
['name' => 'Api#timelines', 'url' => '/api/v1/timelines/{timeline}/', 'verb' => 'GET'],
['name' => 'Api#notifications', 'url' => '/api/v1/notifications', 'verb' => 'GET'],
['name' => 'Api#statusNew', 'url' => '/api/v1/statuses', 'verb' => 'POST'],
// Api for local front-end
// TODO: front-end should be using the new ApiController

142
composer.lock wygenerowano
Wyświetl plik

@ -352,16 +352,16 @@
},
{
"name": "composer/pcre",
"version": "3.0.2",
"version": "3.1.0",
"source": {
"type": "git",
"url": "https://github.com/composer/pcre.git",
"reference": "4482b6409ca6bfc2af043a5711cd21ac3e7a8dfb"
"reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/pcre/zipball/4482b6409ca6bfc2af043a5711cd21ac3e7a8dfb",
"reference": "4482b6409ca6bfc2af043a5711cd21ac3e7a8dfb",
"url": "https://api.github.com/repos/composer/pcre/zipball/4bff79ddd77851fe3cdd11616ed3f92841ba5bd2",
"reference": "4bff79ddd77851fe3cdd11616ed3f92841ba5bd2",
"shasum": ""
},
"require": {
@ -403,7 +403,7 @@
],
"support": {
"issues": "https://github.com/composer/pcre/issues",
"source": "https://github.com/composer/pcre/tree/3.0.2"
"source": "https://github.com/composer/pcre/tree/3.1.0"
},
"funding": [
{
@ -419,7 +419,7 @@
"type": "tidelift"
}
],
"time": "2022-11-03T20:24:16+00:00"
"time": "2022-11-17T09:50:14+00:00"
},
{
"name": "composer/semver",
@ -1171,12 +1171,12 @@
"source": {
"type": "git",
"url": "https://github.com/nextcloud-deps/ocp.git",
"reference": "81fabae31c9bb142d5d0d4d52384fe98d757ab49"
"reference": "d1f996e8d03a10184d48a0120282886b3f7806f7"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/81fabae31c9bb142d5d0d4d52384fe98d757ab49",
"reference": "81fabae31c9bb142d5d0d4d52384fe98d757ab49",
"url": "https://api.github.com/repos/nextcloud-deps/ocp/zipball/d1f996e8d03a10184d48a0120282886b3f7806f7",
"reference": "d1f996e8d03a10184d48a0120282886b3f7806f7",
"shasum": ""
},
"require": {
@ -1207,20 +1207,20 @@
"issues": "https://github.com/nextcloud-deps/ocp/issues",
"source": "https://github.com/nextcloud-deps/ocp/tree/master"
},
"time": "2022-11-04T00:49:09+00:00"
"time": "2022-11-10T00:44:20+00:00"
},
{
"name": "nikic/php-parser",
"version": "v4.15.1",
"version": "v4.15.2",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900"
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0ef6c55a3f47f89d7a374e6f835197a0b5fcf900",
"reference": "0ef6c55a3f47f89d7a374e6f835197a0b5fcf900",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"reference": "f59bbe44bf7d96f24f3e2b4ddc21cd52c1d2adbc",
"shasum": ""
},
"require": {
@ -1261,9 +1261,9 @@
],
"support": {
"issues": "https://github.com/nikic/PHP-Parser/issues",
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.1"
"source": "https://github.com/nikic/PHP-Parser/tree/v4.15.2"
},
"time": "2022-09-04T07:30:47+00:00"
"time": "2022-11-12T15:38:23+00:00"
},
{
"name": "openlss/lib-array2xml",
@ -1596,16 +1596,16 @@
},
{
"name": "phpunit/php-code-coverage",
"version": "9.2.18",
"version": "9.2.19",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
"reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a"
"reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/12fddc491826940cf9b7e88ad9664cf51f0f6d0a",
"reference": "12fddc491826940cf9b7e88ad9664cf51f0f6d0a",
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/c77b56b63e3d2031bd8997fcec43c1925ae46559",
"reference": "c77b56b63e3d2031bd8997fcec43c1925ae46559",
"shasum": ""
},
"require": {
@ -1661,7 +1661,7 @@
],
"support": {
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.18"
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.19"
},
"funding": [
{
@ -1669,7 +1669,7 @@
"type": "github"
}
],
"time": "2022-10-27T13:35:33+00:00"
"time": "2022-11-18T07:47:47+00:00"
},
{
"name": "phpunit/php-file-iterator",
@ -3703,16 +3703,16 @@
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4"
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
"reference": "6fd1b9a79f6e3cf65f9e679b23af304cd9e010d4",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a",
"shasum": ""
},
"require": {
@ -3727,7 +3727,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -3765,7 +3765,7 @@
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0"
},
"funding": [
{
@ -3781,20 +3781,20 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:49:31+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "433d05519ce6990bf3530fba6957499d327395c2"
"reference": "511a08c03c1960e08a883f4cffcacd219b758354"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/433d05519ce6990bf3530fba6957499d327395c2",
"reference": "433d05519ce6990bf3530fba6957499d327395c2",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354",
"reference": "511a08c03c1960e08a883f4cffcacd219b758354",
"shasum": ""
},
"require": {
@ -3806,7 +3806,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -3846,7 +3846,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.27.0"
},
"funding": [
{
@ -3862,20 +3862,20 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:49:31+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "219aa369ceff116e673852dce47c3a41794c14bd"
"reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/219aa369ceff116e673852dce47c3a41794c14bd",
"reference": "219aa369ceff116e673852dce47c3a41794c14bd",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6",
"reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6",
"shasum": ""
},
"require": {
@ -3887,7 +3887,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -3930,7 +3930,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0"
},
"funding": [
{
@ -3946,20 +3946,20 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:49:31+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e"
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e",
"reference": "9344f9cb97f3b19424af1a21a3b0e75b0a7d8d7e",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"shasum": ""
},
"require": {
@ -3974,7 +3974,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -4013,7 +4013,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0"
},
"funding": [
{
@ -4029,20 +4029,20 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:49:31+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-php73",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php73.git",
"reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85"
"reference": "9e8ecb5f92152187c4799efd3c96b78ccab18ff9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/e440d35fa0286f77fb45b79a03fedbeda9307e85",
"reference": "e440d35fa0286f77fb45b79a03fedbeda9307e85",
"url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/9e8ecb5f92152187c4799efd3c96b78ccab18ff9",
"reference": "9e8ecb5f92152187c4799efd3c96b78ccab18ff9",
"shasum": ""
},
"require": {
@ -4051,7 +4051,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -4092,7 +4092,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php73/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-php73/tree/v1.27.0"
},
"funding": [
{
@ -4108,20 +4108,20 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:49:31+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-php80",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php80.git",
"reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace"
"reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/cfa0ae98841b9e461207c13ab093d76b0fa7bace",
"reference": "cfa0ae98841b9e461207c13ab093d76b0fa7bace",
"url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936",
"reference": "7a6ff3f1959bb01aefccb463a0f2cd3d3d2fd936",
"shasum": ""
},
"require": {
@ -4130,7 +4130,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -4175,7 +4175,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php80/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-php80/tree/v1.27.0"
},
"funding": [
{
@ -4191,20 +4191,20 @@
"type": "tidelift"
}
],
"time": "2022-05-10T07:21:04+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-php81",
"version": "v1.26.0",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-php81.git",
"reference": "13f6d1271c663dc5ae9fb843a8f16521db7687a1"
"reference": "707403074c8ea6e2edaf8794b0157a0bfa52157a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/13f6d1271c663dc5ae9fb843a8f16521db7687a1",
"reference": "13f6d1271c663dc5ae9fb843a8f16521db7687a1",
"url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/707403074c8ea6e2edaf8794b0157a0bfa52157a",
"reference": "707403074c8ea6e2edaf8794b0157a0bfa52157a",
"shasum": ""
},
"require": {
@ -4213,7 +4213,7 @@
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.26-dev"
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
@ -4254,7 +4254,7 @@
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-php81/tree/v1.26.0"
"source": "https://github.com/symfony/polyfill-php81/tree/v1.27.0"
},
"funding": [
{
@ -4270,7 +4270,7 @@
"type": "tidelift"
}
],
"time": "2022-05-24T11:49:31+00:00"
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/process",

Wyświetl plik

@ -91,6 +91,7 @@ class Timeline extends ExtendedBase {
$this->setName('social:stream')
->addArgument('userId', InputArgument::REQUIRED, 'viewer')
->addArgument('timeline', InputArgument::REQUIRED, 'timeline')
->addOption('local', '', InputOption::VALUE_NONE, 'public')
->addOption('count', '', InputOption::VALUE_REQUIRED, 'number of elements', '5')
->addOption('min_id', '', InputOption::VALUE_REQUIRED, 'min_id', 0)
->addOption('max_id', '', InputOption::VALUE_REQUIRED, 'max_id', 0)
@ -133,10 +134,12 @@ class Timeline extends ExtendedBase {
->setMaxId(intval($input->getOption('max_id')));
try {
$options->setTimeline($input->getArgument('timeline'));
if ($input->getOption('local')) {
$options->setLocal(true);
}
$options->setTimeline($timeline = $input->getArgument('timeline'));
$this->outputStreams($this->streamRequest->getTimeline($options));
} catch (UnknownTimelineException $e) {
echo $input->getArgument('timeline');
$this->displayUnsupportedStream($options);
}

Wyświetl plik

@ -30,7 +30,6 @@ declare(strict_types=1);
namespace OCA\Social\Controller;
use OCA\Social\Tools\Traits\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountDoesNotExistException;
@ -41,19 +40,23 @@ use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\Client\Options\TimelineOptions;
use OCA\Social\Model\Client\SocialClient;
use OCA\Social\Model\Client\Status;
use OCA\Social\Model\Post;
use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\ClientService;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\FollowService;
use OCA\Social\Service\InstanceService;
use OCA\Social\Service\MiscService;
use OCA\Social\Service\PostService;
use OCA\Social\Service\StreamService;
use OCA\Social\Tools\Traits\TNCDataResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
use OCP\IUserSession;
use Psr\Log\LoggerInterface;
/**
* Class ApiController
@ -64,35 +67,45 @@ class ApiController extends Controller {
use TNCDataResponse;
private IUserSession $userSession;
private LoggerInterface $logger;
private InstanceService $instanceService;
private ClientService $clientService;
private AccountService $accountService;
private CacheActorService $cacheActorService;
private FollowService $followService;
private StreamService $streamService;
private PostService $postService;
private ConfigService $configService;
private MiscService $miscService;
private string $bearer = '';
private ?SocialClient $client = null;
private ?Person $viewer = null;
public function __construct(
IRequest $request, IUserSession $userSession, InstanceService $instanceService,
ClientService $clientService, AccountService $accountService, CacheActorService $cacheActorService,
FollowService $followService, StreamService $streamService, ConfigService $configService,
MiscService $miscService
IRequest $request,
IUserSession $userSession,
LoggerInterface $logger,
InstanceService $instanceService,
ClientService $clientService,
AccountService $accountService,
CacheActorService $cacheActorService,
FollowService $followService,
StreamService $streamService,
PostService $postService,
ConfigService $configService
) {
parent::__construct(Application::APP_NAME, $request);
$this->userSession = $userSession;
$this->logger = $logger;
$this->instanceService = $instanceService;
$this->clientService = $clientService;
$this->accountService = $accountService;
$this->cacheActorService = $cacheActorService;
$this->followService = $followService;
$this->streamService = $streamService;
$this->postService = $postService;
$this->configService = $configService;
$this->miscService = $miscService;
$authHeader = trim($this->request->getHeader('Authorization'));
if (strpos($authHeader, ' ')) {
@ -211,26 +224,68 @@ class ApiController extends Controller {
}
/**
* @PublicPage
* @NoCSRFRequired
*
* @return DataResponse
*/
public function statusNew(): DataResponse {
try {
$this->initViewer(true);
$input = file_get_contents('php://input');
$this->logger->debug('[ApiController] newStatus: ' . $input);
$status = new Status();
$status->import($this->convertInput($input));
$post = new Post($this->accountService->getActorFromUserId($this->currentSession()));
$post->setContent($status->getStatus());
$post->setType($status->getVisibility());
$activity = $this->postService->createPost($post);
$activity->setExportFormat(ACore::FORMAT_LOCAL);
return new DataResponse($activity, Http::STATUS_OK);
} catch (Exception $e) {
$this->logger->warning('issues while statusNew', ['exception' => $e]);
return new DataResponse(['error' => $e->getMessage()], Http::STATUS_BAD_REQUEST);
}
}
/**
* @NoCSRFRequired
* @PublicPage
*
* @param string $timeline
* @param bool $local
* @param int $limit
* @param int $max_id
* @param int $min_id
*
* @return DataResponse
*/
public function timelines(string $timeline, int $limit = 20, int $max_id = 0, int $min_id = 0): DataResponse {
$options = new TimelineOptions($this->request);
$options->setFormat(Stream::FORMAT_LOCAL);
$options->setTimeline($timeline);
$options->setLimit($limit);
$options->setMaxId($max_id);
$options->setMinId($min_id);
public function timelines(
string $timeline,
bool $local = false,
int $limit = 20,
int $max_id = 0,
int $min_id = 0
): DataResponse {
try {
$this->initViewer(true);
$options = new TimelineOptions($this->request);
$options->setFormat(ACore::FORMAT_LOCAL);
$options->setTimeline($timeline);
$options->setLocal($local);
$options->setLimit($limit);
$options->setMaxId($max_id);
$options->setMinId($min_id);
$posts = $this->streamService->getTimeline($options);
return new DataResponse($posts, Http::STATUS_OK);
@ -251,8 +306,8 @@ class ApiController extends Controller {
try {
$userId = $this->currentSession();
$this->miscService->log(
'[ApiController] initViewer: ' . $userId . ' (bearer=' . $this->bearer . ')', 0
$this->logger->debug(
'[ApiController] initViewer: ' . $userId . ' (bearer=' . $this->bearer . ')'
);
$account = $this->accountService->getActorFromUserId($userId);
@ -274,6 +329,32 @@ class ApiController extends Controller {
}
private function convertInput(string $input): array {
$contentType = $this->request->getHeader('Content-Type');
$pos = strpos($contentType, ';');
if ($pos > 0) {
$contentType = substr($contentType, 0, $pos);
}
switch ($contentType) {
case 'application/json':
return json_decode($input, true);
case 'application/x-www-form-urlencoded':
return $this->request->getParams();
default: // in case of no header ...
$result = json_decode($input, true);
if (is_array($result)) {
return $result;
}
return $this->request->getParams();
}
}
/**
* @return string
* @throws AccountDoesNotExistException

Wyświetl plik

@ -313,7 +313,7 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
* @param bool $local
*/
public function limitToLocal(bool $local) {
$this->limitToDBField('local', ($local) ? '1' : '0');
$this->limitToDBFieldInt('local', ($local) ? 1 : 0);
}

Wyświetl plik

@ -188,15 +188,23 @@ class StreamRequest extends StreamRequestBuilder {
/**
* @param string $id
* @param bool $asViewer
* @param int $format
*
* @return Stream
* @throws StreamNotFoundException
*/
public function getStreamById(string $id, bool $asViewer = false): Stream {
public function getStreamById(
string $id,
bool $asViewer = false,
int $format = ACore::FORMAT_ACTIVITYPUB
): Stream {
if ($id === '') {
throw new StreamNotFoundException();
};
$qb = $this->getStreamSelectSql();
$qb = $this->getStreamSelectSql($format);
$qb->limitToIdPrim($qb->prim($id));
$qb->linkToCacheActors('ca', 's.attributed_to_prim');
@ -340,11 +348,6 @@ class StreamRequest extends StreamRequestBuilder {
$result = $this->getTimelineDirect($options);
break;
case 'public':
$options->setLocal(false);
$result = $this->getTimelinePublic($options);
break;
case 'local':
$options->setLocal(true);
$result = $this->getTimelinePublic($options);
break;

Wyświetl plik

@ -56,7 +56,6 @@ class TimelineOptions extends CoreOptions implements JsonSerializable {
public static array $availableTimelines = [
'home',
'local',
'public'
];

Wyświetl plik

@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
/**
* Nextcloud - Social Support
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2022, Maxence Lange <maxence@artificial-owl.com>
* @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 <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Social\Model\Client;
use OCA\Social\Tools\Traits\TArrayTools;
class Status implements \JsonSerializable {
use TArrayTools;
private string $contentType = '';
private bool $sensitive = false;
private string $visibility = '';
private string $spoilerText = '';
private string $status = '';
//"media_ids": [],
public function __construct() {
}
/**
* @param string $contentType
*
* @return Status
*/
public function setContentType(string $contentType): self {
$this->contentType = $contentType;
return $this;
}
/**
* @return string
*/
public function getContentType(): string {
return $this->contentType;
}
/**
* @param bool $sensitive
*
* @return Status
*/
public function setSensitive(bool $sensitive): self {
$this->sensitive = $sensitive;
return $this;
}
/**
* @return bool
*/
public function isSensitive(): bool {
return $this->sensitive;
}
/**
* @param string $visibility
*
* @return Status
*/
public function setVisibility(string $visibility): self {
$this->visibility = $visibility;
return $this;
}
/**
* @return string
*/
public function getVisibility(): string {
return $this->visibility;
}
/**
* @param string $spoilerText
*
* @return Status
*/
public function setSpoilerText(string $spoilerText): self {
$this->spoilerText = $spoilerText;
return $this;
}
/**
* @return string
*/
public function getSpoilerText(): string {
return $this->spoilerText;
}
/**
* @param string $status
*
* @return Status
*/
public function setStatus(string $status): self {
$this->status = $status;
return $this;
}
/**
* @return string
*/
public function getStatus(): string {
return $this->status;
}
public function import(array $data): self {
$this->setContentType($this->get('content_type', $data));
$this->setSensitive($this->getBool('sensitive', $data));
$this->setVisibility($this->get('visibility', $data));
$this->setSpoilerText($this->get('spoiler_text', $data));
$this->setStatus($this->get('status', $data));
return $this;
}
public function jsonSerialize(): array {
return [
'contentType' => $this->getContentType(),
'sensitive' => $this->isSensitive(),
'visibility' => $this->getVisibility(),
'spoilerText' => $this->getSpoilerText(),
'status' => $this->getStatus()
];
}
}

Wyświetl plik

@ -97,7 +97,7 @@ class PostService {
* @throws StreamNotFoundException
* @throws UnauthorizedFediverseException
*/
public function createPost(Post $post, &$token = ''): ACore {
public function createPost(Post $post, string &$token = ''): ACore {
$this->fixRecipientAndHashtags($post);
$note = new Note();

Wyświetl plik

@ -370,8 +370,12 @@ class StreamService {
* @return Stream
* @throws StreamNotFoundException
*/
public function getStreamById(string $id, bool $asViewer = false): Stream {
return $this->streamRequest->getStreamById($id, $asViewer);
public function getStreamById(
string $id,
bool $asViewer = false,
int $format = ACore::FORMAT_ACTIVITYPUB
): Stream {
return $this->streamRequest->getStreamById($id, $asViewer, $format);
}