Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/51/head
Maxence Lange 2018-11-22 10:46:11 -01:00
rodzic 3e79734512
commit 6a06fd22b1
4 zmienionych plików z 98 dodań i 43 usunięć

Wyświetl plik

@ -12,11 +12,13 @@ return [
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
['name' => 'Navigation#test', 'url' => '/test', 'verb' => 'GET'],
['name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET',
'requirements' => ['path' => '.+'], 'defaults' => ['path' => '']
[
'name' => 'Navigation#timeline', 'url' => '/timeline/{path}', 'verb' => 'GET',
'requirements' => ['path' => '.+'], 'defaults' => ['path' => '']
],
['name' => 'Navigation#account', 'url' => '/account/{path}', 'verb' => 'GET',
'requirements' => ['path' => '.+'], 'defaults' => ['path' => '']
[
'name' => 'Navigation#account', 'url' => '/account/{path}', 'verb' => 'GET',
'requirements' => ['path' => '.+'], 'defaults' => ['path' => '']
],
// ['name' => 'Navigation#public', 'url' => '/{username}', 'verb' => 'GET'],
@ -36,16 +38,21 @@ return [
['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET'],
['name' => 'Local#streamHome', 'url' => '/api/v1/stream/home', 'verb' => 'GET'],
['name' => 'Local#streamTimeline', 'url' => '/api/v1/stream/timeline', 'verb' => 'GET'],
['name' => 'Local#streamFederated', 'url' => '/api/v1/stream/federated', 'verb' => 'GET'],
['name' => 'Local#streamDirect', 'url' => '/api/v1/stream/direct', 'verb' => 'GET'],
['name' => 'Local#postCreate', 'url' => '/api/v1/post', 'verb' => 'POST'],
['name' => 'Local#postDelete', 'url' => '/api/v1/post', 'verb' => 'DELETE'],
['name' => 'Local#timeline', 'url' => '/api/v1/timeline', 'verb' => 'GET'],
['name' => 'Local#direct', 'url' => '/api/v1/direct', 'verb' => 'PUT'],
['name' => 'Local#accountsSearch', 'url' => '/api/v1/accounts/search', 'verb' => 'GET'],
['name' => 'Local#accountFollow', 'url' => '/api/v1/account/follow', 'verb' => 'PUT'],
['name' => 'Local#accountUnfollow', 'url' => '/api/v1/account/follow', 'verb' => 'DELETE'],
['name' => 'Local#actorInfo', 'url' => '/api/v1/actor/info', 'verb' => 'GET'],
['name' => 'Config#setCloudAddress', 'url' => '/api/v1/config/cloudAddress', 'verb' => 'POST'],
[
'name' => 'Config#setCloudAddress', 'url' => '/api/v1/config/cloudAddress',
'verb' => 'POST'
],
]
]
];

Wyświetl plik

@ -30,12 +30,11 @@ declare(strict_types=1);
namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RequestException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\Post;
use OCA\Social\Service\ActivityPub\FollowService;
@ -45,7 +44,6 @@ use OCA\Social\Service\ActorService;
use OCA\Social\Service\MiscService;
use OCA\Social\Service\PostService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\DataResponse;
use OCP\IRequest;
@ -135,7 +133,7 @@ class LocalController extends Controller {
$post->setType($this->get('type', $data, NoteService::TYPE_PUBLIC));
/** @var ACore $activity */
$result = $this->postService->createPost($post, $activity);
$this->postService->createPost($post, $activity);
return $this->directSuccess($activity->getObject());
} catch (Exception $e) {
@ -175,8 +173,6 @@ class LocalController extends Controller {
/**
* Get timeline
*
* // TODO: Delete the NoCSRF check
*
* @NoCSRFRequired
@ -185,9 +181,11 @@ class LocalController extends Controller {
*
* @return DataResponse
*/
public function timeline($since = 0, $limit = 5): DataResponse {
public function streamHome(): DataResponse {
try {
$posts = $this->noteService->getTimeline((int)$since, (int)$limit);
$actor = $this->actorService->getActorFromUserId($this->userId);
$posts = $this->noteService->getHomeNotesForActor($actor);
return $this->success($posts);
} catch (Exception $e) {
@ -197,16 +195,68 @@ class LocalController extends Controller {
/**
* // TODO: Delete the NoCSRF check
*
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubAdminRequired
*
* @return DataResponse
*/
public function direct(): DataResponse {
public function streamDirect(): DataResponse {
try {
$actor = $this->actorService->getActorFromUserId($this->userId);
$posts = $this->noteService->getNotesForActor($actor);
$posts = $this->noteService->getDirectNotesForActor($actor);
return $this->success($posts);
} catch (Exception $e) {
return $this->fail($e);
}
}
/**
* Get timeline
*
* // TODO: Delete the NoCSRF check
*
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubAdminRequired
*
* @param int $since
* @param int $limit
*
* @return DataResponse
*/
public function streamTimeline(int $since = 0, int $limit = 5): DataResponse {
try {
$posts = $this->noteService->getLocalTimeline($since, $limit);
return $this->success($posts);
} catch (Exception $e) {
return $this->fail($e);
}
}
/**
* Get timeline
*
* // TODO: Delete the NoCSRF check
*
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubAdminRequired
*
* @param int $since
* @param int $limit
*
* @return DataResponse
*/
public function streamFederated(int $since = 0, int $limit = 5): DataResponse {
try {
$posts = $this->noteService->getFederatedTimeline($since, $limit);
return $this->success($posts);
} catch (Exception $e) {

Wyświetl plik

@ -287,19 +287,6 @@ class NoteService implements ICoreService {
}
// /**
// * @param Note $note
// */
// private function assignInstances(Note $note) {
// $note->addInstancePath(new InstancePath($note->getTo()));
// $all = array_merge($note->getToArray(), $note->getCcArray(), $note->getBccArray());
// foreach ($all as $uri) {
// $note->addInstancePath(new InstancePath($uri));
// }
// $note->addInstancePath(new InstancePath($note->getInReplyTo()));
// }
/**
* @param ACore $item
*/
@ -321,13 +308,12 @@ class NoteService implements ICoreService {
/**
* @param string $userId
* @param Person $actor
*
* @return Note[]
*/
public function getTimeline(int $since = 0, int $limit = 5): array {
return $this->notesRequest->getPublicNotes($since, $limit);
// return $result;
public function getHomeNotesForActor(Person $actor): array {
return $this->notesRequest->getHomeNotesForActorId($actor->getId());
}
@ -336,19 +322,31 @@ class NoteService implements ICoreService {
*
* @return Note[]
*/
public function getNotesForActor(Person $actor): array {
$privates = $this->getPrivateNotesForActor($actor);
return $privates;
public function getDirectNotesForActor(Person $actor): array {
return $this->notesRequest->getDirectNotesForActorId($actor->getId());
}
/**
* @param Person $actor
* @param int $since
* @param int $limit
*
* @return Note[]
*/
private function getPrivateNotesForActor(Person $actor): array {
return $this->notesRequest->getNotesForActorId($actor->getId());
public function getLocalTimeline(int $since = 0, int $limit = 5): array {
return $this->notesRequest->getPublicNotes($since, $limit, true);
}
/**
* @param int $since
* @param int $limit
*
* @return Note[]
*/
public function getFederatedTimeline(int $since = 0, int $limit = 5): array {
return $this->notesRequest->getPublicNotes($since, $limit, false);
}
}

Wyświetl plik

@ -62,7 +62,7 @@ const actions = {
if (typeof sinceTimestamp === 'undefined') {
sinceTimestamp = Date.parse(state.since) / 1000
}
return axios.get(OC.generateUrl('apps/social/api/v1/timeline?limit=5&since=' + sinceTimestamp)).then((response) => {
return axios.get(OC.generateUrl('apps/social/api/v1/stream/timeline?limit=5&since=' + sinceTimestamp)).then((response) => {
if (response.status === -1) {
throw response.message
}