diff options
27 files changed, 318 insertions, 198 deletions
diff --git a/composer.json b/composer.json index 2a6532ba..bc4315ce 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ } }, "require": { - "daita/my-small-php-tools": "dev-master#ca9c257dd640576c072cb50282e15ae51147cfc2", + "daita/my-small-php-tools": "dev-master", "gumlet/php-image-resize": "2.0.*", "friendica/json-ld": "^1.0" }, diff --git a/composer.lock b/composer.lock index c951dbec..302f8fc2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a5fe26ce64e01c6e8e2687e75ff674fb", + "content-hash": "773474981fdf7ef0b2f1bcf58cf1b2ec", "packages": [ { "name": "daita/my-small-php-tools", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/daita/my-small-php-tools.git", - "reference": "ca9c257dd640576c072cb50282e15ae51147cfc2" + "reference": "aeed155a9c0cf79153bc9703d1792b0361162dd3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/ca9c257dd640576c072cb50282e15ae51147cfc2", - "reference": "ca9c257dd640576c072cb50282e15ae51147cfc2", + "url": "https://api.github.com/repos/daita/my-small-php-tools/zipball/aeed155a9c0cf79153bc9703d1792b0361162dd3", + "reference": "aeed155a9c0cf79153bc9703d1792b0361162dd3", "shasum": "" }, "require": { @@ -40,7 +40,7 @@ } ], "description": "My small PHP Tools", - "time": "2020-09-29T15:30:16+00:00" + "time": "2020-12-01T00:47:38+00:00" }, { "name": "friendica/json-ld", @@ -1003,23 +1003,23 @@ }, { "name": "sebastian/code-unit-reverse-lookup", - "version": "1.0.1", + "version": "1.0.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18" + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", - "reference": "4419fcdb5eabb9caa61a27c7a1db532a6b55dd18", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/1de8cd5c010cb153fcd68b8d0f64606f523f7619", + "reference": "1de8cd5c010cb153fcd68b8d0f64606f523f7619", "shasum": "" }, "require": { - "php": "^5.6 || ^7.0" + "php": ">=5.6" }, "require-dev": { - "phpunit/phpunit": "^5.7 || ^6.0" + "phpunit/phpunit": "^8.5" }, "type": "library", "extra": { @@ -1044,7 +1044,13 @@ ], "description": "Looks up which function or method a line of code belongs to", "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", - "time": "2017-03-04T06:30:41+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T08:15:22+00:00" }, { "name": "sebastian/comparator", @@ -1214,20 +1220,20 @@ }, { "name": "sebastian/exporter", - "version": "3.1.2", + "version": "3.1.3", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e" + "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/68609e1261d215ea5b21b7987539cbfbe156ec3e", - "reference": "68609e1261d215ea5b21b7987539cbfbe156ec3e", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/6b853149eab67d4da22291d36f5b0631c0fd856e", + "reference": "6b853149eab67d4da22291d36f5b0631c0fd856e", "shasum": "" }, "require": { - "php": "^7.0", + "php": ">=7.0", "sebastian/recursion-context": "^3.0" }, "require-dev": { @@ -1277,7 +1283,13 @@ "export", "exporter" ], - "time": "2019-09-14T09:02:43+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:47:53+00:00" }, { "name": "sebastian/global-state", @@ -1332,20 +1344,20 @@ }, { "name": "sebastian/object-enumerator", - "version": "3.0.3", + "version": "3.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-enumerator.git", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5" + "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/7cfd9e65d11ffb5af41198476395774d4c8a84c5", - "reference": "7cfd9e65d11ffb5af41198476395774d4c8a84c5", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", + "reference": "e67f6d32ebd0c749cf9d1dbd9f226c727043cdf2", "shasum": "" }, "require": { - "php": "^7.0", + "php": ">=7.0", "sebastian/object-reflector": "^1.1.1", "sebastian/recursion-context": "^3.0" }, @@ -1375,24 +1387,30 @@ ], "description": "Traverses array structures and object graphs to enumerate all referenced objects", "homepage": "https://github.com/sebastianbergmann/object-enumerator/", - "time": "2017-08-03T12:35:26+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:40:27+00:00" }, { "name": "sebastian/object-reflector", - "version": "1.1.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/object-reflector.git", - "reference": "773f97c67f28de00d397be301821b06708fca0be" + "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/773f97c67f28de00d397be301821b06708fca0be", - "reference": "773f97c67f28de00d397be301821b06708fca0be", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", + "reference": "9b8772b9cbd456ab45d4a598d2dd1a1bced6363d", "shasum": "" }, "require": { - "php": "^7.0" + "php": ">=7.0" }, "require-dev": { "phpunit/phpunit": "^6.0" @@ -1420,24 +1438,30 @@ ], "description": "Allows reflection of object attributes, including inherited and non-public ones", "homepage": "https://github.com/sebastianbergmann/object-reflector/", - "time": "2017-03-29T09:07:27+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:37:18+00:00" }, { "name": "sebastian/recursion-context", - "version": "3.0.0", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/recursion-context.git", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8" + "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", - "reference": "5b0cd723502bac3b006cbf3dbf7a1e3fcefe4fa8", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/367dcba38d6e1977be014dc4b22f47a484dac7fb", + "reference": "367dcba38d6e1977be014dc4b22f47a484dac7fb", "shasum": "" }, "require": { - "php": "^7.0" + "php": ">=7.0" }, "require-dev": { "phpunit/phpunit": "^6.0" @@ -1459,21 +1483,27 @@ ], "authors": [ { - "name": "Jeff Welch", - "email": "whatthejeff@gmail.com" - }, - { "name": "Sebastian Bergmann", "email": "sebastian@phpunit.de" }, { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { "name": "Adam Harvey", "email": "aharvey@php.net" } ], "description": "Provides functionality to recursively process PHP variables", "homepage": "http://www.github.com/sebastianbergmann/recursion-context", - "time": "2017-03-03T06:23:57+00:00" + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2020-11-30T07:34:24+00:00" }, { "name": "sebastian/resource-operations", @@ -1562,16 +1592,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.18.1", + "version": "v1.19.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" + "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", - "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/aed596913b70fae57be53d86faa2e9ef85a2297b", + "reference": "aed596913b70fae57be53d86faa2e9ef85a2297b", "shasum": "" }, "require": { @@ -1583,7 +1613,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.18-dev" + "dev-main": "1.19-dev" }, "thanks": { "name": "symfony/polyfill", @@ -1634,7 +1664,7 @@ "type": "tidelift" } ], - "time": "2020-07-14T12:35:20+00:00" + "time": "2020-10-23T09:01:57+00:00" }, { "name": "theseer/tokenizer", @@ -8,6 +8,8 @@ OC.L10N.register( "Notifications" : "Известувања", "Profile" : "Профил", "Public" : "Јавна", + "posts" : "објави", + "No results found" : "Нема пронајдено резултати", "Reply" : "Одговор", "Hello" : "Здраво", "Close" : "Затвори", diff --git a/l10n/mk.json b/l10n/mk.json index 25e90db7..435c2534 100644 --- a/l10n/mk.json +++ b/l10n/mk.json @@ -6,6 +6,8 @@ "Notifications" : "Известувања", "Profile" : "Профил", "Public" : "Јавна", + "posts" : "објави", + "No results found" : "Нема пронајдено резултати", "Reply" : "Одговор", "Hello" : "Здраво", "Close" : "Затвори", @@ -77,6 +77,7 @@ OC.L10N.register( "User not found" : "Пользователь не найден", "Sorry, we could not find the account of {userId}" : "Не удалось найти пользователя {userId}", "Nextcloud becomes part of the federated social networks!" : "Nextcloud становится частью Федерации Социальных Сетей!", + "We automatically created a Social account for you. Your Social ID is the same as your Federated Cloud ID:" : "Мы автоматически создали для вас учетную запись в Social. Ваш Social ID совпадает с вашим ID Federated Cloud:", "Since you are new to Social, start by following the official Nextcloud account so you don't miss any news" : "Начните с подписки на официальный аккаунт Nextcloud чтобы не пропустить ничего", "Follow Nextcloud on mastodon.xyz" : "Следите за Nextcloud на сайте mastodon.xyz" }, diff --git a/l10n/ru.json b/l10n/ru.json index 61a5fd4a..5dc69d20 100644 --- a/l10n/ru.json +++ b/l10n/ru.json @@ -75,6 +75,7 @@ "User not found" : "Пользователь не найден", "Sorry, we could not find the account of {userId}" : "Не удалось найти пользователя {userId}", "Nextcloud becomes part of the federated social networks!" : "Nextcloud становится частью Федерации Социальных Сетей!", + "We automatically created a Social account for you. Your Social ID is the same as your Federated Cloud ID:" : "Мы автоматически создали для вас учетную запись в Social. Ваш Social ID совпадает с вашим ID Federated Cloud:", "Since you are new to Social, start by following the official Nextcloud account so you don't miss any news" : "Начните с подписки на официальный аккаунт Nextcloud чтобы не пропустить ничего", "Follow Nextcloud on mastodon.xyz" : "Следите за Nextcloud на сайте mastodon.xyz" },"pluralForm" :"nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);" diff --git a/lib/Command/Timeline.php b/lib/Command/Timeline.php index d8334b34..8330afd0 100644 --- a/lib/Command/Timeline.php +++ b/lib/Command/Timeline.php @@ -169,12 +169,12 @@ class Timeline extends ExtendedBase { break; case 'local': - $stream = $this->streamRequest->getTimelineGlobal(0, $this->count, true); + $stream = $this->streamRequest->getTimelineGlobal_dep(0, $this->count, true); $this->outputStreams($stream); break; case 'global': - $stream = $this->streamRequest->getTimelineGlobal(0, $this->count, false); + $stream = $this->streamRequest->getTimelineGlobal_dep(0, $this->count, false); $this->outputStreams($stream); break; diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index 1138bc64..0462b3da 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -30,6 +30,7 @@ declare(strict_types=1); namespace OCA\Social\Controller; +use daita\MySmallPhpTools\Traits\Nextcloud\nc20\TNC20Logger; use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse; use daita\MySmallPhpTools\Traits\TAsync; use daita\MySmallPhpTools\Traits\TStringTools; @@ -65,6 +66,7 @@ class ActivityPubController extends Controller { use TNCDataResponse; use TStringTools; use TAsync; +use TNC20Logger; /** @var SocialPubController */ @@ -246,10 +248,9 @@ class ActivityPubController extends Controller { * @return Response */ public function inbox(string $username): Response { - try { $body = file_get_contents('php://input'); - $this->miscService->log('[<<] inbox: ' . $body, 1); + $this->debug('[<<] inbox', ['body' => $body]); $requestTime = 0; $origin = $this->signatureService->checkRequest($this->request, $body, $requestTime); diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index 1b4be8a7..a0b7bc0a 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -261,14 +261,17 @@ class ApiController extends Controller { * * @param string $timeline * @param int $limit - * + * @param int $max_id + * @param int $min_id * @return DataResponse */ - public function timelines(string $timeline, int $limit = 20): 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); try { $this->initViewer(true); diff --git a/lib/Controller/OAuthController.php b/lib/Controller/OAuthController.php index 3f46cdc9..23a22c88 100644 --- a/lib/Controller/OAuthController.php +++ b/lib/Controller/OAuthController.php @@ -268,6 +268,7 @@ class OAuthController extends Controller { ], Http::STATUS_OK ); } catch (Exception $e) { + $this->miscService->log($e->getMessage() . ' ' . get_class($e)); return new DataResponse(['error' => $e->getMessage()], Http::STATUS_UNAUTHORIZED); } } diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php index 7e5ec825..6b4c677b 100644 --- a/lib/Db/StreamRequest.php +++ b/lib/Db/StreamRequest.php @@ -412,7 +412,7 @@ class StreamRequest extends StreamRequestBuilder { * * @return Stream[] * @throws DateTimeException - * @deprecated - use GetTimeline() + * @deprecated - use getTimelineHome() */ public function getTimelineHome_dep( int $since = 0, int $limit = 5, int $format = Stream::FORMAT_ACTIVITYPUB @@ -521,6 +521,37 @@ class StreamRequest extends StreamRequestBuilder { return $this->getStreamsFromRequest($qb); } + /** + * Should returns: + * * All local public/federated posts + * + * @param TimelineOptions $options + * + * @return Stream[] + * @throws DateTimeException + */ + public function getTimelinePublic(TimelineOptions $options): array { + $qb = $this->getStreamSelectSql($options->getFormat()); + $qb->paginate($options); + + $qb->limitToLocal($options->isLocal()); + $qb->limitToType(Note::TYPE); + + $qb->linkToCacheActors('ca', 's.attributed_to_prim'); + $qb->leftJoinStreamAction(); + + $qb->selectDestFollowing('sd', ''); + $qb->innerJoinSteamDest('recipient', 'id_prim', 'sd', 's'); + $qb->limitToDest(ACore::CONTEXT_PUBLIC, 'recipient', 'to', 'sd'); + + $result = $this->getStreamsFromRequest($qb); + if ($options->isInverted()) { + $result = array_reverse($result); + } + + return $result; + } + /** * Should returns: @@ -532,8 +563,9 @@ class StreamRequest extends StreamRequestBuilder { * * @return Stream[] * @throws DateTimeException + * @deprecated - use getTimelinePublic() */ - public function getTimelineGlobal(int $since = 0, int $limit = 5, bool $localOnly = true + public function getTimelineGlobal_dep(int $since = 0, int $limit = 5, bool $localOnly = true ): array { $qb = $this->getStreamSelectSql(); $qb->limitPaginate($since, $limit); diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index ee8bfcb7..2e00e0dc 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -61,6 +61,7 @@ class ACore extends Item implements JsonSerializable { const AS_USERNAME = 5; const AS_ACCOUNT = 6; const AS_STRING = 7; + const AS_CONTENT = 8; const AS_TAGS = 10; const FORMAT_ACTIVITYPUB = 1; @@ -559,14 +560,16 @@ class ACore extends Item implements JsonSerializable { return $value; case self::AS_STRING: - // try to preserve some whitespace from the html tags - $value = preg_replace("/\<br *\/?\>/", "\n", $value); - $value = preg_replace("/\<\/?p>/", "\n", $value); - $value = strip_tags($value); $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5); - return trim($value); + return $value; + + case self::AS_CONTENT: + $value = strip_tags($value, ['a', 'p', 'span', 'br']); + $value = html_entity_decode($value, ENT_QUOTES | ENT_HTML5); + + return $value; case self::AS_USERNAME: $value = strip_tags($value); @@ -654,6 +657,12 @@ class ACore extends Item implements JsonSerializable { $this->setLocal(($this->getInt('local', $data, 0) === 1)); } + /** + * @param array $data + */ + public function importFromCache(array $data) { + $this->import($data); + } /** * @param int $format diff --git a/lib/Model/ActivityPub/Actor/Person.php b/lib/Model/ActivityPub/Actor/Person.php index f9f3b5c3..e55030ec 100644 --- a/lib/Model/ActivityPub/Actor/Person.php +++ b/lib/Model/ActivityPub/Actor/Person.php @@ -741,7 +741,7 @@ class Person extends ACore implements IQueryRow, JsonSerializable { $result = [ "username" => $this->getPreferredUsername(), - "acct" => $this->getPreferredUsername(), + "acct" => $this->getAccount(), "display_name" => $this->getDisplayName(), "locked" => $this->isLocked(), "bot" => $this->isBot(), diff --git a/lib/Model/ActivityPub/Object/Announce.php b/lib/Model/ActivityPub/Object/Announce.php index a13e5b6a..0d4eab15 100644 --- a/lib/Model/ActivityPub/Object/Announce.php +++ b/lib/Model/ActivityPub/Object/Announce.php @@ -33,6 +33,7 @@ namespace OCA\Social\Model\ActivityPub\Object; use Exception; use JsonSerializable; +use OCA\Social\AP; use OCA\Social\Model\ActivityPub\ACore; use OCA\Social\Model\ActivityPub\Stream; @@ -72,26 +73,25 @@ class Announce extends Stream implements JsonSerializable { $this->setAttributedTo($this->getActorId()); } - - /** - * @param array $data - * - * @throws Exception - */ - public function importFromDatabase(array $data) { - parent::importFromDatabase($data); - } - - /** * @return array */ - public function jsonSerialize(): array { - $result = parent::jsonSerialize(); - //$result['actor'] = $this->getAttributedTo(); + public function exportAsLocal(): array { + $result = parent::exportAsLocal(); + + if ($this->hasCache()) { + $cache = $this->getCache(); + if ($object = $cache->getItem($this->getObjectId())) { + $object = $object->getObject(); + /** @var Stream $item */ + $item = AP::$activityPub->getItemFromType($this->get('type', $object, Stream::TYPE)); + $item->importFromCache($object); + $result['reblog'] = $item->exportAsLocal(); + $result['content'] = $item->getContent(); + } + } return $result; } - } diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 88dd1fdd..68b187a7 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -36,6 +36,7 @@ use daita\MySmallPhpTools\Model\CacheItem; use DateTime; use Exception; use JsonSerializable; +use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\StreamAction; use OCA\Social\Traits\TDetails; |