kopia lustrzana https://github.com/nextcloud/social
rodzic
3e79734512
commit
6a06fd22b1
|
@ -12,11 +12,13 @@ return [
|
||||||
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
|
['name' => 'Navigation#navigate', 'url' => '/', 'verb' => 'GET'],
|
||||||
['name' => 'Navigation#test', 'url' => '/test', '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'],
|
// ['name' => 'Navigation#public', 'url' => '/{username}', 'verb' => 'GET'],
|
||||||
|
|
||||||
|
@ -36,16 +38,21 @@ return [
|
||||||
|
|
||||||
['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET'],
|
['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#postCreate', 'url' => '/api/v1/post', 'verb' => 'POST'],
|
||||||
['name' => 'Local#postDelete', 'url' => '/api/v1/post', 'verb' => 'DELETE'],
|
['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#accountsSearch', 'url' => '/api/v1/accounts/search', 'verb' => 'GET'],
|
||||||
['name' => 'Local#accountFollow', 'url' => '/api/v1/account/follow', 'verb' => 'PUT'],
|
['name' => 'Local#accountFollow', 'url' => '/api/v1/account/follow', 'verb' => 'PUT'],
|
||||||
['name' => 'Local#accountUnfollow', 'url' => '/api/v1/account/follow', 'verb' => 'DELETE'],
|
['name' => 'Local#accountUnfollow', 'url' => '/api/v1/account/follow', 'verb' => 'DELETE'],
|
||||||
['name' => 'Local#actorInfo', 'url' => '/api/v1/actor/info', 'verb' => 'GET'],
|
['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'
|
||||||
|
],
|
||||||
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
|
@ -30,12 +30,11 @@ declare(strict_types=1);
|
||||||
namespace OCA\Social\Controller;
|
namespace OCA\Social\Controller;
|
||||||
|
|
||||||
|
|
||||||
use daita\MySmallPhpTools\Traits\TArrayTools;
|
|
||||||
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
|
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
|
||||||
|
use daita\MySmallPhpTools\Traits\TArrayTools;
|
||||||
use Exception;
|
use Exception;
|
||||||
use OCA\Social\AppInfo\Application;
|
use OCA\Social\AppInfo\Application;
|
||||||
use OCA\Social\Exceptions\InvalidResourceException;
|
use OCA\Social\Exceptions\InvalidResourceException;
|
||||||
use OCA\Social\Exceptions\RequestException;
|
|
||||||
use OCA\Social\Model\ActivityPub\ACore;
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
use OCA\Social\Model\Post;
|
use OCA\Social\Model\Post;
|
||||||
use OCA\Social\Service\ActivityPub\FollowService;
|
use OCA\Social\Service\ActivityPub\FollowService;
|
||||||
|
@ -45,7 +44,6 @@ use OCA\Social\Service\ActorService;
|
||||||
use OCA\Social\Service\MiscService;
|
use OCA\Social\Service\MiscService;
|
||||||
use OCA\Social\Service\PostService;
|
use OCA\Social\Service\PostService;
|
||||||
use OCP\AppFramework\Controller;
|
use OCP\AppFramework\Controller;
|
||||||
use OCP\AppFramework\Http;
|
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
|
|
||||||
|
@ -135,7 +133,7 @@ class LocalController extends Controller {
|
||||||
$post->setType($this->get('type', $data, NoteService::TYPE_PUBLIC));
|
$post->setType($this->get('type', $data, NoteService::TYPE_PUBLIC));
|
||||||
|
|
||||||
/** @var ACore $activity */
|
/** @var ACore $activity */
|
||||||
$result = $this->postService->createPost($post, $activity);
|
$this->postService->createPost($post, $activity);
|
||||||
|
|
||||||
return $this->directSuccess($activity->getObject());
|
return $this->directSuccess($activity->getObject());
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -175,8 +173,6 @@ class LocalController extends Controller {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get timeline
|
|
||||||
*
|
|
||||||
* // TODO: Delete the NoCSRF check
|
* // TODO: Delete the NoCSRF check
|
||||||
*
|
*
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
|
@ -185,9 +181,11 @@ class LocalController extends Controller {
|
||||||
*
|
*
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function timeline($since = 0, $limit = 5): DataResponse {
|
public function streamHome(): DataResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$posts = $this->noteService->getTimeline((int)$since, (int)$limit);
|
$actor = $this->actorService->getActorFromUserId($this->userId);
|
||||||
|
$posts = $this->noteService->getHomeNotesForActor($actor);
|
||||||
|
|
||||||
return $this->success($posts);
|
return $this->success($posts);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
@ -197,16 +195,68 @@ class LocalController extends Controller {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* // TODO: Delete the NoCSRF check
|
||||||
|
*
|
||||||
|
* @NoCSRFRequired
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoSubAdminRequired
|
* @NoSubAdminRequired
|
||||||
*
|
*
|
||||||
* @return DataResponse
|
* @return DataResponse
|
||||||
*/
|
*/
|
||||||
public function direct(): DataResponse {
|
public function streamDirect(): DataResponse {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$actor = $this->actorService->getActorFromUserId($this->userId);
|
$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);
|
return $this->success($posts);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
|
|
|
@ -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
|
* @param ACore $item
|
||||||
*/
|
*/
|
||||||
|
@ -321,13 +308,12 @@ class NoteService implements ICoreService {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $userId
|
* @param Person $actor
|
||||||
*
|
*
|
||||||
* @return Note[]
|
* @return Note[]
|
||||||
*/
|
*/
|
||||||
public function getTimeline(int $since = 0, int $limit = 5): array {
|
public function getHomeNotesForActor(Person $actor): array {
|
||||||
return $this->notesRequest->getPublicNotes($since, $limit);
|
return $this->notesRequest->getHomeNotesForActorId($actor->getId());
|
||||||
// return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -336,19 +322,31 @@ class NoteService implements ICoreService {
|
||||||
*
|
*
|
||||||
* @return Note[]
|
* @return Note[]
|
||||||
*/
|
*/
|
||||||
public function getNotesForActor(Person $actor): array {
|
public function getDirectNotesForActor(Person $actor): array {
|
||||||
$privates = $this->getPrivateNotesForActor($actor);
|
return $this->notesRequest->getDirectNotesForActorId($actor->getId());
|
||||||
|
|
||||||
return $privates;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Person $actor
|
* @param int $since
|
||||||
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return Note[]
|
* @return Note[]
|
||||||
*/
|
*/
|
||||||
private function getPrivateNotesForActor(Person $actor): array {
|
public function getLocalTimeline(int $since = 0, int $limit = 5): array {
|
||||||
return $this->notesRequest->getNotesForActorId($actor->getId());
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,7 +62,7 @@ const actions = {
|
||||||
if (typeof sinceTimestamp === 'undefined') {
|
if (typeof sinceTimestamp === 'undefined') {
|
||||||
sinceTimestamp = Date.parse(state.since) / 1000
|
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) {
|
if (response.status === -1) {
|
||||||
throw response.message
|
throw response.message
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue