Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
alpha1
Maxence Lange 2018-11-20 21:38:36 -01:00
rodzic 75826b04eb
commit a05dfc5879
5 zmienionych plików z 48 dodań i 42 usunięć

Wyświetl plik

@ -36,7 +36,8 @@ return [
['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{postId}', 'verb' => 'GET'],
['name' => 'Local#newPost', 'url' => '/api/v1/post', 'verb' => 'POST'],
['name' => 'Local#postCreate', 'url' => '/api/v1/post', 'verb' => 'POST'],
['name' => 'Local#postDelete', 'url' => '/api/v1/post', 'verb' => 'GET'],
['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'],

Wyświetl plik

@ -34,6 +34,7 @@ use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\Post;
use OCA\Social\Service\ActivityPub\FollowService;
use OCA\Social\Service\ActivityPub\NoteService;
@ -121,7 +122,7 @@ class LocalController extends Controller {
*
* @return DataResponse
*/
public function newPost(array $data): DataResponse {
public function postCreate(array $data): DataResponse {
try {
$post = new Post($this->userId);
$post->setContent($this->get('content', $data, ''));
@ -134,7 +135,38 @@ class LocalController extends Controller {
return $this->success($result);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}
/**
* Create a new post.
*
* // TODO: Delete the NoCSRF check
*
* @NoCSRFRequired
* @NoAdminRequired
* @NoSubAdminRequired
*
* @param string $id
*
* @return DataResponse
*/
public function postDelete(string $id): DataResponse {
try {
$note = $this->noteService->getNoteById($id);
$actor = $this->actorService->getActorFromUserId($this->userId);
if ($note->getAttributedTo() !== $actor->getId()) {
throw new InvalidResourceException('user have no rights');
}
$this->noteService->delete($note);
return $this->success();
} catch (Exception $e) {
return $this->fail($e);
}
}
@ -159,7 +191,7 @@ class LocalController extends Controller {
return $this->success($posts);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}
@ -178,7 +210,7 @@ class LocalController extends Controller {
return $this->success($posts);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}
@ -201,7 +233,7 @@ class LocalController extends Controller {
return $this->success(['accounts' => $accounts]);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}
@ -225,7 +257,7 @@ class LocalController extends Controller {
return $this->success([]);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}
@ -249,7 +281,7 @@ class LocalController extends Controller {
return $this->success([]);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}
@ -272,7 +304,7 @@ class LocalController extends Controller {
return $this->success(['actor' => $actor]);
} catch (Exception $e) {
return $this->fail($e->getMessage());
return $this->fail($e);
}
}

Wyświetl plik

@ -31,7 +31,6 @@ namespace OCA\Social\Db;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Cache\CacheActor;
use OCA\Social\Model\ActivityPub\Person;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
@ -58,16 +57,14 @@ class CacheActorsRequest extends CacheActorsRequestBuilder {
* insert cache about an Actor in database.
*
* @param Person $actor
* @param bool $local
*
* @return int
*/
public function save(Person $actor, bool $local = false): int {
public function save(Person $actor): int {
$qb = $this->getCacheActorsInsertSql();
$qb->setValue('id', $qb->createNamedParameter($actor->getId()))
->setValue('account', $qb->createNamedParameter($actor->getAccount()))
->setValue('local', $qb->createNamedParameter(($local) ? '1' : '0'))
->setValue('local', $qb->createNamedParameter(($actor->isLocal()) ? '1' : '0'))
->setValue('following', $qb->createNamedParameter($actor->getFollowing()))
->setValue('followers', $qb->createNamedParameter($actor->getFollowers()))
->setValue('inbox', $qb->createNamedParameter($actor->getInbox()))

Wyświetl plik

@ -94,6 +94,7 @@ class NotesRequest extends NotesRequestBuilder {
->setValue('attributed_to', $qb->createNamedParameter($note->getAttributedTo()))
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
->setValue('source', $qb->createNamedParameter($note->getSource()))
->setValue('local', $qb->createNamedParameter(($note->isLocal()) ? '1' : '0'))
->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
@ -111,7 +112,7 @@ class NotesRequest extends NotesRequestBuilder {
* @return Note
* @throws NoteNotFoundException
*/
public function getFromId(string $id): Note {
public function getNoteById(string $id): Note {
if ($id === '') {
throw new NoteNotFoundException();
};

Wyświetl plik

@ -84,10 +84,6 @@ class Person extends ACore implements JsonSerializable {
/** @var string */
private $featured = '';
/** @var bool */
private $local = false;
/**
* Person constructor.
*
@ -342,25 +338,6 @@ class Person extends ACore implements JsonSerializable {
}
/**
* @return bool
*/
public function isLocal(): bool {
return $this->local;
}
/**
* @param bool $local
*
* @return Person
*/
public function setLocal(bool $local): Person {
$this->local = $local;
return $this;
}
/**
* @param array $data
*/
@ -377,8 +354,7 @@ class Person extends ACore implements JsonSerializable {
->setFollowing($this->get('following', $data, ''))
->setSharedInbox($this->get('shared_inbox', $data, ''))
->setFeatured($this->get('featured', $data, ''))
->setCreation($this->getInt('creation', $data, 0))
->setLocal(($this->getInt('local', $data, 0) === 1));
->setCreation($this->getInt('creation', $data, 0));
// if ($this->getPreferredUsername() === '') {
// $this->setType('Invalid');
@ -410,8 +386,7 @@ class Person extends ACore implements JsonSerializable {
'id' => $this->getId() . '#main-key',
'owner' => $this->getId(),
'publicKeyPem' => $this->getPublicKey()
],
'local' => $this->isLocal()
]
]
);
}