diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-12-05 09:05:21 -0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-05 09:05:21 -0100 |
commit | 5c6081f2cc2bbff141ae6ea439e4af190e04046a (patch) | |
tree | d0b9444f7c0e7413b7a794e90e857d975671d70a /lib/Controller | |
parent | 523e2304392d9247f5e7872ab8ea11230174b66e (diff) | |
parent | c3bd113694ef1e50f811684f8a71e9132ed10733 (diff) |
Merge pull request #134 from nextcloud-gmbh/fix-timeline
Timeline, followers & account public messages
Diffstat (limited to 'lib/Controller')
-rw-r--r-- | lib/Controller/ActivityPubController.php | 14 | ||||
-rw-r--r-- | lib/Controller/LocalController.php | 88 |
2 files changed, 73 insertions, 29 deletions
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index b4cc6de5..ce92a2e5 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -170,7 +170,7 @@ class ActivityPubController extends Controller { try { $body = file_get_contents('php://input'); - $this->miscService->log('Shared Inbox: ' . $body, 0); + $this->miscService->log('[<<] shared-inbox: ' . $body, 1); $origin = $this->activityService->checkRequest($this->request); @@ -205,7 +205,7 @@ class ActivityPubController extends Controller { try { $body = file_get_contents('php://input'); - $this->miscService->log('Inbox: ' . $body, 0); + $this->miscService->log('[<<] inbox: ' . $body, 1); $origin = $this->activityService->checkRequest($this->request); @@ -323,6 +323,16 @@ class ActivityPubController extends Controller { // uncomment this line to display the result that would be return to an ActivityPub service (TEST) // return true; + // TODO - cleaner to being able to parse: + // - 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' + // - 'application/activity+json, application/ld+json' + $accept = explode(',', $this->request->getHeader('Accept')); + $accept = array_map('trim', $accept); + + if (in_array('application/ld+json', $accept)) { + return true; + } + if ($this->request->getHeader('Accept') === 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"') { return true; diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index a1c564b4..2e31350a 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -33,12 +33,11 @@ namespace OCA\Social\Controller; use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse; use daita\MySmallPhpTools\Traits\TArrayTools; use Exception; -use OC\User\NoUserException; use OCA\Social\AppInfo\Application; -use OCA\Social\Exceptions\AccountAlreadyExistsException; -use OCA\Social\Exceptions\ActorDoesNotExistException; +use OCA\Social\Exceptions\AccountDoesNotExistException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Model\ActivityPub\Person; use OCA\Social\Model\Post; use OCA\Social\Service\ActivityPub\DocumentService; use OCA\Social\Service\ActivityPub\FollowService; @@ -51,7 +50,6 @@ use OCP\AppFramework\Controller; use OCP\AppFramework\Http; use OCP\AppFramework\Http\DataResponse; use OCP\AppFramework\Http\FileDisplayResponse; -use OCP\AppFramework\Http\NotFoundResponse; use OCP\AppFramework\Http\Response; use OCP\IRequest; @@ -93,6 +91,10 @@ class LocalController extends Controller { private $miscService; + /** @var Person */ + private $viewer; + + /** * LocalController constructor. * @@ -204,10 +206,36 @@ class LocalController extends Controller { * @return DataResponse */ public function streamHome($since = 0, int $limit = 5): DataResponse { + try { + $this->initViewer(true); + $posts = $this->noteService->getStreamHome($this->viewer->getId(), $since, $limit); + + return $this->success($posts); + } catch (Exception $e) { + return $this->fail($e); + } + } + + /** + * // TODO: Delete the NoCSRF check + * + * @NoCSRFRequired + * @NoAdminRequired + * @NoSubAdminRequired + * + * @param string $username + * @param int $since + * @param int $limit + * + * @return DataResponse + */ + public function streamAccount(string $username, $since = 0, int $limit = 5): DataResponse { try { - $actor = $this->actorService->getActorFromUserId($this->userId); - $posts = $this->noteService->getHomeNotesForActor($actor, $since, $limit); + $this->initViewer(); + + $account = $this->actorService->getActor($username); + $posts = $this->noteService->getStreamAccount($account->getId(), $since, $limit); return $this->success($posts); } catch (Exception $e) { @@ -229,10 +257,9 @@ class LocalController extends Controller { * @return DataResponse */ public function streamDirect(int $since = 0, int $limit = 5): DataResponse { - try { - $actor = $this->actorService->getActorFromUserId($this->userId); - $posts = $this->noteService->getDirectNotesForActor($actor, $since, $limit); + $this->initViewer(); + $posts = $this->noteService->getStreamDirect($this->viewer->getId(), $since, $limit); return $this->success($posts); } catch (Exception $e) { @@ -257,7 +284,7 @@ class LocalController extends Controller { */ public function streamTimeline(int $since = 0, int $limit = 5): DataResponse { try { - $posts = $this->noteService->getLocalTimeline($since, $limit); + $posts = $this->noteService->getStreamLocalTimeline($since, $limit); return $this->success($posts); } catch (Exception $e) { @@ -281,7 +308,7 @@ class LocalController extends Controller { */ public function streamFederated(int $since = 0, int $limit = 5): DataResponse { try { - $posts = $this->noteService->getFederatedTimeline($since, $limit); + $posts = $this->noteService->getStreamGlobalTimeline($since, $limit); return $this->success($posts); } catch (Exception $e) { @@ -368,9 +395,9 @@ class LocalController extends Controller { * @return DataResponse */ public function currentFollowers(): DataResponse { - $this->initViewer(); - try { + $this->initViewer(); + $actor = $this->actorService->getActorFromUserId($this->userId); $followers = $this->followService->getFollowers($actor); @@ -389,9 +416,9 @@ class LocalController extends Controller { * @return DataResponse */ public function currentFollowing(): DataResponse { - $this->initViewer(); - try { + $this->initViewer(); + $actor = $this->actorService->getActorFromUserId($this->userId); $followers = $this->followService->getFollowing($actor); @@ -415,9 +442,8 @@ class LocalController extends Controller { * @return DataResponse */ public function accountInfo(string $username): DataResponse { - $this->initViewer(); - try { + $this->initViewer(); $actor = $this->actorService->getActor($username); $actor = $this->personService->getFromLocalAccount($actor->getPreferredUsername()); @@ -462,9 +488,10 @@ class LocalController extends Controller { * @return DataResponse */ public function accountFollowing(string $username): DataResponse { - $this->initViewer(); try { + $this->initViewer(); + $actor = $this->actorService->getActor($username); $following = $this->followService->getFollowing($actor); @@ -488,9 +515,9 @@ class LocalController extends Controller { * @return DataResponse */ public function globalAccountInfo(string $account): DataResponse { - $this->initViewer(); - try { + $this->initViewer(); + $actor = $this->personService->getFromAccount($account); return $this->success(['account' => $actor]); @@ -513,9 +540,8 @@ class LocalController extends Controller { * @return DataResponse */ public function globalActorInfo(string $id): DataResponse { - $this->initViewer(); - try { + $this->initViewer(); $actor = $this->personService->getFromId($id); return $this->success(['actor' => $actor]); @@ -617,14 +643,22 @@ class LocalController extends Controller { /** - * @throws Exception + * + * @param bool $exception + * + * @throws AccountDoesNotExistException */ - private function initViewer() { + private function initViewer(bool $exception = false) { try { - $viewer = $this->actorService->getActorFromUserId($this->userId, true); - $this->followService->setViewerId($viewer->getId()); - $this->personService->setViewerId($viewer->getId()); + $this->viewer = $this->actorService->getActorFromUserId($this->userId, true); + + $this->followService->setViewerId($this->viewer->getId()); + $this->personService->setViewerId($this->viewer->getId()); + $this->noteService->setViewerId($this->viewer->getId()); } catch (Exception $e) { + if ($exception) { + throw new AccountDoesNotExistException(); + } } } |