Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/730/head
Maxence Lange 2019-09-13 20:56:40 -01:00
rodzic de841d1826
commit ea34bc6e70
15 zmienionych plików z 75 dodań i 64 usunięć

Wyświetl plik

@ -60,7 +60,6 @@ return [
['name' => 'OStatus#followRemote', 'url' => '/api/v1/ostatus/followRemote/{local}', 'verb' => 'GET'],
['name' => 'OStatus#getLink', 'url' => '/api/v1/ostatus/link/{local}/{account}', 'verb' => 'GET'],
// should it be moved to NavigationController ?
['name' => 'SocialPub#displayPost', 'url' => '/@{username}/{token}', 'verb' => 'GET'],
['name' => 'Local#streamHome', 'url' => '/api/v1/stream/home', 'verb' => 'GET'],

Wyświetl plik

@ -38,6 +38,8 @@ use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\FediverseService;
@ -131,6 +133,7 @@ class ActivityPubController extends Controller {
*
* @return Response
* @throws UrlCloudException
* @throws SocialAppConfigException
*/
public function actor(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
@ -162,6 +165,7 @@ class ActivityPubController extends Controller {
*
* @return Response
* @throws UrlCloudException
* @throws SocialAppConfigException
*/
public function actorAlias(string $username): Response {
return $this->actor($username);
@ -281,6 +285,7 @@ class ActivityPubController extends Controller {
*
* @return Response
* @throws UrlCloudException
* @throws SocialAppConfigException
*/
public function followers(string $username): Response {
@ -311,6 +316,7 @@ class ActivityPubController extends Controller {
*
* @return Response
* @throws UrlCloudException
* @throws SocialAppConfigException
*/
public function following(string $username): Response {
if (!$this->checkSourceActivityStreams()) {
@ -328,11 +334,13 @@ class ActivityPubController extends Controller {
* @PublicPage
*
* @param string $username
* @param $postId
* @param string $postId
*
* @return Response
* @throws SocialAppConfigException
* @throws StreamNotFoundException
*/
public function displayPost($username, $postId) {
public function displayPost(string $username, string $postId) {
if (!$this->checkSourceActivityStreams()) {
return $this->socialPubController->displayPost($username, $postId);
}

Wyświetl plik

@ -27,6 +27,7 @@ declare(strict_types=1);
*
*/
namespace OCA\Social\Controller;
@ -130,10 +131,10 @@ class LocalController extends Controller {
* @param MiscService $miscService
*/
public function __construct(
IRequest $request, $userId, AccountService $accountService,
CacheActorService $cacheActorService, HashtagService $hashtagService,
FollowService $followService,
PostService $postService, StreamService $streamService, SearchService $searchService,
IRequest $request, $userId, AccountService $accountService, CacheActorService $cacheActorService,
HashtagService $hashtagService,
FollowService $followService, PostService $postService, StreamService $streamService,
SearchService $searchService,
BoostService $boostService, LikeService $likeService, DocumentService $documentService,
MiscService $miscService
) {

Wyświetl plik

@ -261,6 +261,7 @@ class NavigationController extends Controller {
*
* @return TemplateResponse
* @throws UrlCloudException
* @throws SocialAppConfigException
*/
public function timeline(string $path = ''): TemplateResponse {
return $this->navigate();
@ -276,6 +277,7 @@ class NavigationController extends Controller {
*
* @return TemplateResponse
* @throws UrlCloudException
* @throws SocialAppConfigException
*/
public function account(string $path = ''): TemplateResponse {
return $this->navigate();

Wyświetl plik

@ -48,6 +48,12 @@ use OCP\AppFramework\Http\TemplateResponse;
use OCP\IL10N;
use OCP\IRequest;
/**
* Class SocialPubController
*
* @package OCA\Social\Controller
*/
class SocialPubController extends Controller {
@ -193,7 +199,7 @@ class SocialPubController extends Controller {
* Display the navigation page of the Social app.
*
* @NoCSRFRequired
* @NoAdminRequired
* @PublicPage
*
* @param string $username
* @param string $token

Wyświetl plik

@ -43,20 +43,6 @@ use OCP\IDBConnection;
class ActorsRequest extends ActorsRequestBuilder {
/**
* ActorsRequest constructor.
*
* @param IDBConnection $connection
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IDBConnection $connection, ConfigService $configService, MiscService $miscService
) {
parent::__construct($connection, $configService, $miscService);
}
/**
* create a new Person in the database.
*

Wyświetl plik

@ -35,29 +35,13 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Exception;
use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
class CacheActorsRequest extends CacheActorsRequestBuilder {
const CACHE_TTL = 60 * 24; // 1d
/**
* CacheActorsRequest constructor.
*
* @param IDBConnection $connection
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IDBConnection $connection, ConfigService $configService, MiscService $miscService
) {
parent::__construct($connection, $configService, $miscService);
}
/**
* insert cache about an Actor in database.

Wyświetl plik

@ -31,16 +31,17 @@ declare(strict_types=1);
namespace OCA\Social\Db;
use daita\MySmallPhpTools\IQueryRow;
use DateInterval;
use DateTime;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OC\DB\SchemaWrapper;
use OC\SystemConfig;
use OCA\Social\AP;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Exceptions\RowNotFoundException;
use OCA\Social\IQueryRow;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Follow;
@ -50,6 +51,7 @@ use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\ILogger;
/**
@ -123,6 +125,20 @@ class CoreRequestBuilder {
}
// /**
// * @return SocialQueryBuilder
// */
// public function getQueryBuilder(): SocialQueryBuilder {
// $qb = new SocialQueryBuilder(
// $this->dbConnection,
// $this->config,
// $this->logger
// );
//
// return $qb;
// }
/**
* @param Person $viewer
*/
@ -515,7 +531,7 @@ class CoreRequestBuilder {
$dTime->setTimestamp($since);
$this->limitToDBFieldDateTime($qb, 'published_time', $dTime);
}
} catch (\Exception $e) {
} catch (Exception $e) {
throw new DateTimeException();
}
@ -1190,7 +1206,7 @@ class CoreRequestBuilder {
* @return IQueryRow
* @throws RowNotFoundException
*/
public function getRowFromRequest(IQueryBuilder $qb, callable $method): IQueryRow {
public function getRow(IQueryBuilder $qb, callable $method): IQueryRow {
$cursor = $qb->execute();
$data = $cursor->fetch();
$cursor->closeCursor();
@ -1206,9 +1222,9 @@ class CoreRequestBuilder {
* @param IQueryBuilder $qb
* @param callable $method
*
* @return array
* @return IQueryRow[]
*/
public function getRowsFromRequest(IQueryBuilder $qb, callable $method): array {
public function getRows(IQueryBuilder $qb, callable $method): array {
$rows = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {

Wyświetl plik

@ -28,30 +28,31 @@ declare(strict_types=1);
*/
namespace OCA\Social;
namespace OCA\Social\Db;
use OCA\Social\Exceptions\ItemAlreadyExistsException;
use OCA\Social\Exceptions\ItemNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
use daita\MySmallPhpTools\Db\ExtendedQueryBuilder;
/**
* Interface IQueryRow
* Class SocialQueryBuilder
*
* TODO: MOVE THIS TO MyPhpTools
*
* @package OCA\Social\Service
* @package OCA\Push\Db
*/
interface IQueryRow {
class SocialQueryBuilder extends ExtendedQueryBuilder {
/**
* import data to feed the model.
* Limit the request to the Type
*
* @param array $data
* @param string $type
*
* @return SocialQueryBuilder
*/
public function import(array $data);
public function limitToType(string $type): self {
$this->limitToDBField('type', $type, false);
return $this;
}
}

Wyświetl plik

@ -47,10 +47,7 @@ use OCA\Social\Model\ActivityPub\Object\Document;
use OCA\Social\Model\ActivityPub\Object\Like;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
/**

Wyświetl plik

@ -458,7 +458,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
protected function getStreamFromRequest(IQueryBuilder $qb): Stream {
/** @var Stream $result */
try {
$result = $this->getRowFromRequest($qb, [$this, 'parseStreamSelectSql']);
$result = $this->getRow($qb, [$this, 'parseStreamSelectSql']);
} catch (RowNotFoundException $e) {
throw new StreamNotFoundException($e->getMessage());
}
@ -474,7 +474,7 @@ class StreamRequestBuilder extends CoreRequestBuilder {
*/
public function getStreamsFromRequest(IQueryBuilder $qb): array {
/** @var Stream[] $result */
$result = $this->getRowsFromRequest($qb, [$this, 'parseStreamSelectSql']);
$result = $this->getRows($qb, [$this, 'parseStreamSelectSql']);
return $result;
}

Wyświetl plik

@ -30,16 +30,21 @@ declare(strict_types=1);
namespace OCA\Social\Model\ActivityPub;
use daita\MySmallPhpTools\IQueryRow;
use daita\MySmallPhpTools\Model\Cache;
use daita\MySmallPhpTools\Model\CacheItem;
use DateTime;
use Exception;
use JsonSerializable;
use OCA\Social\IQueryRow;
use OCA\Social\Model\StreamAction;
use OCA\Social\Traits\TDetails;
/**
* Class Stream
*
* @package OCA\Social\Model\ActivityPub
*/
class Stream extends ACore implements IQueryRow, JsonSerializable {
@ -397,8 +402,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
[
'content' => $this->getContent(),
'attributedTo' => ($this->getAttributedTo() !== '') ? $this->getUrlSocial()
. $this->getAttributedTo(
) : '',
. $this->getAttributedTo() : '',
'inReplyTo' => $this->getInReplyTo(),
'sensitive' => $this->isSensitive(),
'conversation' => $this->getConversation()

Wyświetl plik

@ -72,6 +72,10 @@ class FediverseService {
* @throws SocialAppConfigException
*/
public function authorized(string $address): bool {
if ($address === '') {
throw new UnauthorizedFediverseException('Empty Origin');
}
if ($this->getAccessType() ===
$this->configService->accessTypeList['BLACKLIST']
&& !$this->isListed($address)) {

Wyświetl plik

@ -262,6 +262,8 @@ class SignatureService {
throw new SignatureIsGoneException();
} catch (SignatureException $e) {
}
return '';
}

Wyświetl plik

@ -383,6 +383,7 @@ class StreamService {
*
* @return Stream
* @throws StreamNotFoundException
* @throws SocialAppConfigException
*/
public function getStreamById(string $id, bool $asViewer = false): Stream {
return $this->streamRequest->getStreamById($id, $asViewer);