Merge pull request #1517 from nextcloud/enh/noid/statuses-creation

status creation from mastodon client
pull/1536/head
Maxence Lange 2022-11-22 16:28:06 -01:00 zatwierdzone przez GitHub
commit a21c75796f
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
27 zmienionych plików z 442 dodań i 190 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

@ -58,8 +58,8 @@ class Fediverse extends Base {
parent::configure();
$this->setName('social:fediverse')
->addOption(
'type', 't', InputArgument::OPTIONAL,
'Change the type of access management', ''
'type', 't', InputArgument::OPTIONAL,
'Change the type of access management', ''
)
->addArgument('action', InputArgument::OPTIONAL, 'add/remove/test address', '')
->addArgument('address', InputArgument::OPTIONAL, 'address/host', '')

Wyświetl plik

@ -119,10 +119,10 @@ class MigrateAlpha3 extends Base {
$this->setName('social:migrate:alpha3')
->setDescription('Trying to migrate old data to Alpha3')
->addOption(
'remove-migrated-tables', '', InputOption::VALUE_NONE, 'Remove old table once copy is done'
'remove-migrated-tables', '', InputOption::VALUE_NONE, 'Remove old table once copy is done'
)
->addOption(
'force-remove-old-tables', '', InputOption::VALUE_NONE, 'Force remove old tables'
'force-remove-old-tables', '', InputOption::VALUE_NONE, 'Force remove old tables'
);
}

Wyświetl plik

@ -96,18 +96,18 @@ class NoteCreate extends Base {
parent::configure();
$this->setName('social:note:create')
->addOption(
'replyTo', 'r', InputOption::VALUE_OPTIONAL, 'in reply to an existing thread'
'replyTo', 'r', InputOption::VALUE_OPTIONAL, 'in reply to an existing thread'
)
->addOption(
'to', 't', InputOption::VALUE_OPTIONAL, 'mentioning people'
'to', 't', InputOption::VALUE_OPTIONAL, 'mentioning people'
)
->addOption(
'type', 'y', InputOption::VALUE_OPTIONAL,
'type: public (default), followers, unlisted, direct'
'type', 'y', InputOption::VALUE_OPTIONAL,
'type: public (default), followers, unlisted, direct'
)
->addOption(
'hashtag', 'g', InputOption::VALUE_OPTIONAL,
'hashtag, without the leading #'
'hashtag', 'g', InputOption::VALUE_OPTIONAL,
'hashtag, without the leading #'
)
->addArgument('user_id', InputArgument::REQUIRED, 'userId of the author')
->addArgument('content', InputArgument::REQUIRED, 'content of the post')

Wyświetl plik

@ -73,7 +73,7 @@ class QueueStatus extends Base {
parent::configure();
$this->setName('social:queue:status')
->addOption(
'token', 't', InputOption::VALUE_OPTIONAL, 'token of a request'
'token', 't', InputOption::VALUE_OPTIONAL, 'token of a request'
)
->setDescription('Return status on the request queue');
}

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

@ -179,28 +179,28 @@ class OAuthController extends Controller {
string $response_type,
string $scope = 'read'
): Response {
$user = $this->userSession->getUser();
$user = $this->userSession->getUser();
// check actor exists
$this->accountService->getActorFromUserId($user->getUID());
// check actor exists
$this->accountService->getActorFromUserId($user->getUID());
if ($response_type !== 'code') {
throw new ClientNotFoundException('invalid response type');
}
if ($response_type !== 'code') {
throw new ClientNotFoundException('invalid response type');
}
// check client exists in db
$client = $this->clientService->getFromClientId($client_id);
$this->initialState->provideInitialState('appName', $client->getAppName());
// check client exists in db
$client = $this->clientService->getFromClientId($client_id);
$this->initialState->provideInitialState('appName', $client->getAppName());
return new TemplateResponse(Application::APP_NAME, 'oauth2', [
'request' =>
[
'clientId' => $client_id,
'redirectUri' => $redirect_uri,
'responseType' => $response_type,
'scope' => $scope
]
]);
return new TemplateResponse(Application::APP_NAME, 'oauth2', [
'request' =>
[
'clientId' => $client_id,
'redirectUri' => $redirect_uri,
'responseType' => $response_type,
'scope' => $scope
]
]);
}

Wyświetl plik

@ -53,13 +53,13 @@ class ActorsRequest extends ActorsRequestBuilder {
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
->setValue('avatar_version', $qb->createNamedParameter($actor->getAvatarVersion()))
->setValue(
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
)
->setValue('public_key', $qb->createNamedParameter($actor->getPublicKey()))
->setValue('private_key', $qb->createNamedParameter($actor->getPrivateKey()))
->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$qb->executeStatement();

Wyświetl plik

@ -121,7 +121,7 @@ class ActorsRequestBuilder extends CoreRequestBuilder {
->setLocal(true)
->setAvatarVersion($this->getInt('avatar_version', $data, -1))
->setAccount(
$actor->getPreferredUsername() . '@' . $this->configService->getSocialAddress()
$actor->getPreferredUsername() . '@' . $this->configService->getSocialAddress()
);
$actor->setUrlSocial($root)
->setUrl($actor->getId());

Wyświetl plik

@ -59,7 +59,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
->setValue('featured', $qb->createNamedParameter($actor->getFeatured()))
->setValue('url', $qb->createNamedParameter($actor->getUrl()))
->setValue(
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
)
->setValue('name', $qb->createNamedParameter($actor->getName()))
->setValue('summary', $qb->createNamedParameter($actor->getSummary()))
@ -112,7 +112,7 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
->set('featured', $qb->createNamedParameter($actor->getFeatured()))
->set('url', $qb->createNamedParameter($actor->getUrl()))
->set(
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
'preferred_username', $qb->createNamedParameter($actor->getPreferredUsername())
)
->set('name', $qb->createNamedParameter($actor->getName()))
->set('summary', $qb->createNamedParameter($actor->getSummary()))

Wyświetl plik

@ -56,7 +56,7 @@ class ClientRequest extends ClientRequestBuilder {
$qb->setValue('app_name', $qb->createNamedParameter($client->getAppName()))
->setValue('app_website', $qb->createNamedParameter($client->getAppWebsite()))
->setValue(
'app_redirect_uris', $qb->createNamedParameter(json_encode($client->getAppRedirectUris()))
'app_redirect_uris', $qb->createNamedParameter(json_encode($client->getAppRedirectUris()))
)
->setValue('app_client_id', $qb->createNamedParameter($client->getAppClientId()))
->setValue('app_client_secret', $qb->createNamedParameter($client->getAppClientSecret()))

Wyświetl plik

@ -1054,8 +1054,8 @@ class CoreRequestBuilder {
->selectAlias($prefix . '_f.follow_id', $prefix . '_follow_id')
->selectAlias($prefix . '_f.creation', $prefix . '_creation')
->leftJoin(
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_FOLLOWS, $prefix . '_f',
$andX
$this->defaultSelectAlias, CoreRequestBuilder::TABLE_FOLLOWS, $prefix . '_f',
$andX
);
}

Wyświetl plik

@ -66,9 +66,9 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
->setValue('author', $qb->createNamedParameter($queue->getAuthor()))
->setValue('activity', $qb->createNamedParameter($queue->getActivity()))
->setValue(
'instance', $qb->createNamedParameter(
json_encode($queue->getInstance(), JSON_UNESCAPED_SLASHES)
)
'instance', $qb->createNamedParameter(
json_encode($queue->getInstance(), JSON_UNESCAPED_SLASHES)
)
)
->setValue('priority', $qb->createNamedParameter($queue->getPriority()))
->setValue('status', $qb->createNamedParameter($queue->getStatus()))
@ -133,8 +133,8 @@ class RequestQueueRequest extends RequestQueueRequestBuilder {
$qb = $this->getRequestQueueUpdateSql();
$qb->set('status', $qb->createNamedParameter(RequestQueue::STATUS_RUNNING))
->set(
'last',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
'last',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$this->limitToId($qb, $queue->getId());
$this->limitToStatus($qb, RequestQueue::STATUS_STANDBY);

Wyświetl plik

@ -183,8 +183,8 @@ class SocialCrossQueryBuilder extends SocialCoreQueryBuilder {
->selectAlias('cd.error', 'cachedocument_error')
->selectAlias('cd.creation', 'cachedocument_creation')
->leftJoin(
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_DOCUMENTS, 'cd',
$expr->eq($func->lower($pf . '.' . $fieldDocumentId), $func->lower('cd.id'))
$this->getDefaultSelectAlias(), CoreRequestBuilder::TABLE_CACHE_DOCUMENTS, 'cd',
$expr->eq($func->lower($pf . '.' . $fieldDocumentId), $func->lower('cd.id'))
);
}

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

@ -56,9 +56,9 @@ class StreamActionsRequest extends StreamActionsRequestBuilder {
->setValue('stream_id', $qb->createNamedParameter($action->getStreamId()))
->setValue('stream_id_prim', $qb->createNamedParameter($this->prim($action->getStreamId())))
->setValue(
'values', $qb->createNamedParameter(
json_encode($values, JSON_UNESCAPED_SLASHES)
)
'values', $qb->createNamedParameter(
json_encode($values, JSON_UNESCAPED_SLASHES)
)
)
->setValue('liked', $qb->createNamedParameter(($liked) ? 1 : 0))
->setValue('boosted', $qb->createNamedParameter(($boosted) ? 1 : 0))

Wyświetl plik

@ -110,8 +110,8 @@ class StreamQueueRequest extends StreamQueueRequestBuilder {
$qb = $this->getStreamQueueUpdateSql();
$qb->set('status', $qb->createNamedParameter(StreamQueue::STATUS_RUNNING))
->set(
'last',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
'last',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$this->limitToId($qb, $queue->getId());
$this->limitToStatus($qb, StreamQueue::STATUS_STANDBY);

Wyświetl plik

@ -77,9 +77,9 @@ class StreamRequest extends StreamRequestBuilder {
/** @var Note $stream */
$qb->setValue('hashtags', $qb->createNamedParameter(json_encode($stream->getHashtags())))
->setValue(
'attachments', $qb->createNamedParameter(
json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES)
)
'attachments', $qb->createNamedParameter(
json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES)
)
);
}
@ -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;
@ -732,19 +735,19 @@ class StreamRequest extends StreamRequestBuilder {
->setValue('subtype', $qb->createNamedParameter($stream->getSubType()))
->setValue('to', $qb->createNamedParameter($stream->getTo()))
->setValue(
'to_array', $qb->createNamedParameter(
json_encode($stream->getToArray(), JSON_UNESCAPED_SLASHES)
)
'to_array', $qb->createNamedParameter(
json_encode($stream->getToArray(), JSON_UNESCAPED_SLASHES)
)
)
->setValue(
'cc', $qb->createNamedParameter(
json_encode($stream->getCcArray(), JSON_UNESCAPED_SLASHES)
)
'cc', $qb->createNamedParameter(
json_encode($stream->getCcArray(), JSON_UNESCAPED_SLASHES)
)
)
->setValue(
'bcc', $qb->createNamedParameter(
json_encode($stream->getBccArray(), JSON_UNESCAPED_SLASHES)
)
'bcc', $qb->createNamedParameter(
json_encode($stream->getBccArray(), JSON_UNESCAPED_SLASHES)
)
)
->setValue('content', $qb->createNamedParameter($stream->getContent()))
->setValue('summary', $qb->createNamedParameter($stream->getSummary()))
@ -760,13 +763,13 @@ class StreamRequest extends StreamRequestBuilder {
->setValue('details', $qb->createNamedParameter(json_encode($stream->getDetailsAll())))
->setValue('cache', $qb->createNamedParameter($cache))
->setValue(
'filter_duplicate',
$qb->createNamedParameter(($stream->isFilterDuplicate()) ? '1' : '0')
'filter_duplicate',
$qb->createNamedParameter(($stream->isFilterDuplicate()) ? '1' : '0')
)
->setValue(
'instances', $qb->createNamedParameter(
json_encode($stream->getInstancePaths(), JSON_UNESCAPED_SLASHES)
)
'instances', $qb->createNamedParameter(
json_encode($stream->getInstancePaths(), JSON_UNESCAPED_SLASHES)
)
)
->setValue('local', $qb->createNamedParameter(($stream->isLocal()) ? '1' : '0'));
@ -777,8 +780,8 @@ class StreamRequest extends StreamRequestBuilder {
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
)
->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
} catch (Exception $e) {
}

Wyświetl plik

@ -92,10 +92,10 @@ class StreamRequestBuilder extends CoreRequestBuilder {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->selectDistinct('s.id')
->addSelect(
's.nid', 's.type', 's.subtype', 's.to', 's.to_array', 's.cc', 's.bcc', 's.content',
's.summary', 's.attachments', 's.published', 's.published_time', 's.cache',
's.object_id', 's.attributed_to', 's.in_reply_to', 's.source', 's.local',
's.instances', 's.creation', 's.filter_duplicate', 's.details', 's.hashtags'
's.nid', 's.type', 's.subtype', 's.to', 's.to_array', 's.cc', 's.bcc', 's.content',
's.summary', 's.attachments', 's.published', 's.published_time', 's.cache',
's.object_id', 's.attributed_to', 's.in_reply_to', 's.source', 's.local',
's.instances', 's.creation', 's.filter_duplicate', 's.details', 's.hashtags'
)
->from(self::TABLE_STREAM, 's');

Wyświetl plik

@ -45,8 +45,6 @@ use OCP\Migration\SimpleMigrationStep;
* @package OCA\Social\Migration
*/
class Version1000Date20221118000001 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`

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);
}

Wyświetl plik

@ -71,12 +71,12 @@ trait TNCLogger {
$this->logger()
->log(
$level,
$message,
[
'app' => $this->setup('app'),
'exception' => $t
]
$level,
$message,
[
'app' => $this->setup('app'),
'exception' => $t
]
);
}
@ -111,12 +111,12 @@ trait TNCLogger {
$this->logger()
->log(
$level,
$message,
[
'app' => $this->setup('app'),
'exception' => $e
]
$level,
$message,
[
'app' => $this->setup('app'),
'exception' => $e
]
);
}