cleaning and renaming

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/282/head
Maxence Lange 2019-05-06 13:32:31 -01:00
rodzic 76997d0cd5
commit 8174167e48
13 zmienionych plików z 127 dodań i 110 usunięć

Wyświetl plik

@ -32,6 +32,7 @@ namespace OCA\Social;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OC;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\SocialAppConfigException;
@ -162,30 +163,30 @@ class AP {
public static function init() {
$ap = new AP();
try {
$ap->acceptInterface = \OC::$server->query(AcceptInterface::class);
$ap->addInterface = \OC::$server->query(AddInterface::class);
$ap->announceInterface = \OC::$server->query(AnnounceInterface::class);
$ap->blockInterface = \OC::$server->query(BlockInterface::class);
$ap->createInterface = \OC::$server->query(CreateInterface::class);
$ap->deleteInterface = \OC::$server->query(DeleteInterface::class);
$ap->documentInterface = \OC::$server->query(DocumentInterface::class);
$ap->followInterface = \OC::$server->query(FollowInterface::class);
$ap->imageInterface = \OC::$server->query(ImageInterface::class);
$ap->likeInterface = \OC::$server->query(LikeInterface::class);
$ap->noteInterface = \OC::$server->query(NoteInterface::class);
$ap->notificationInterface = \OC::$server->query(SocialAppNotificationInterface::class);
$ap->personInterface = \OC::$server->query(PersonInterface::class);
$ap->rejectInterface = \OC::$server->query(RejectInterface::class);
$ap->removeInterface = \OC::$server->query(RemoveInterface::class);
$ap->undoInterface = \OC::$server->query(UndoInterface::class);
$ap->updateInterface = \OC::$server->query(UpdateInterface::class);
$ap->acceptInterface = OC::$server->query(AcceptInterface::class);
$ap->addInterface = OC::$server->query(AddInterface::class);
$ap->announceInterface = OC::$server->query(AnnounceInterface::class);
$ap->blockInterface = OC::$server->query(BlockInterface::class);
$ap->createInterface = OC::$server->query(CreateInterface::class);
$ap->deleteInterface = OC::$server->query(DeleteInterface::class);
$ap->documentInterface = OC::$server->query(DocumentInterface::class);
$ap->followInterface = OC::$server->query(FollowInterface::class);
$ap->imageInterface = OC::$server->query(ImageInterface::class);
$ap->likeInterface = OC::$server->query(LikeInterface::class);
$ap->noteInterface = OC::$server->query(NoteInterface::class);
$ap->notificationInterface = OC::$server->query(SocialAppNotificationInterface::class);
$ap->personInterface = OC::$server->query(PersonInterface::class);
$ap->rejectInterface = OC::$server->query(RejectInterface::class);
$ap->removeInterface = OC::$server->query(RemoveInterface::class);
$ap->undoInterface = OC::$server->query(UndoInterface::class);
$ap->updateInterface = OC::$server->query(UpdateInterface::class);
$ap->configService = \OC::$server->query(ConfigService::class);
$ap->configService = OC::$server->query(ConfigService::class);
AP::$activityPub = $ap;
} catch (QueryException $e) {
\OC::$server->getLogger()
->logException($e);
OC::$server->getLogger()
->logException($e);
}
}

Wyświetl plik

@ -191,7 +191,7 @@ class LocalController extends Controller {
throw new InvalidResourceException('user have no rights');
}
$this->noteService->deleteLocalNote($note);
$this->noteService->deleteLocalItem($note);
return $this->success();
} catch (Exception $e) {

Wyświetl plik

@ -33,6 +33,7 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OC;
use OC\User\NoUserException;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountAlreadyExistsException;
@ -139,7 +140,7 @@ class NavigationController extends Controller {
'public' => false,
'firstrun' => false,
'setup' => false,
'isAdmin' => \OC::$server->getGroupManager()
'isAdmin' => OC::$server->getGroupManager()
->isAdmin($this->userId),
'cliUrl' => $this->getCliUrl()
]

Wyświetl plik

@ -34,13 +34,9 @@ use daita\MySmallPhpTools\Model\Cache;
use DateTime;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use Exception;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Exceptions\RedundancyLimitException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Service\ConfigService;
@ -78,17 +74,56 @@ class NotesRequest extends NotesRequestBuilder {
$qb->setValue(
'hashtags', $qb->createNamedParameter(json_encode($stream->getHashtags()))
)
->setValue(
'attachments', $qb->createNamedParameter(
json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES)
)
);
->setValue(
'attachments', $qb->createNamedParameter(
json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES)
)
);
}
$qb->execute();
}
//
//
// /**
// * Insert a new Note in the database.
// *
// * @param SocialAppNotification $notification
// *
// * @throws Exception
// */
// public function saveNotification(SocialAppNotification $notification) {
// $qb = $this->getNotesInsertSql();
// $qb->setValue('id', $qb->createNamedParameter($notification->getId()))
// ->setValue('type', $qb->createNamedParameter($notification->getType()))
// ->setValue('to', $qb->createNamedParameter($notification->getTo()))
// ->setValue('to_array', $qb->createNamedParameter(''))
// ->setValue('cc', $qb->createNamedParameter(''))
// ->setValue('bcc', $qb->createNamedParameter(''))
// ->setValue('content', $qb->createNamedParameter(''))
// ->setValue('summary', $qb->createNamedParameter($notification->getSummary()))
// ->setValue('published', $qb->createNamedParameter($notification->getPublished()))
// ->setValue(
// 'published_time',
// $qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
// )
// ->setValue('attributed_to', $qb->createNamedParameter($notification->getAttributedTo()))
// ->setValue('in_reply_to', $qb->createNamedParameter(''))
// ->setValue('source', $qb->createNamedParameter($notification->getSource()))
// ->setValue('instances', $qb->createNamedParameter(''))
// ->setValue('local', $qb->createNamedParameter(($notification->isLocal()) ? '1' : '0'))
// ->setValue(
// 'creation',
// $qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
// );
//
// $qb->execute();
// }
/**
* @param Stream $stream
* @param Cache $cache
@ -106,42 +141,6 @@ class NotesRequest extends NotesRequestBuilder {
}
/**
* Insert a new Note in the database.
*
* @param SocialAppNotification $notification
*
* @throws Exception
*/
public function saveNotification(SocialAppNotification $notification) {
$qb = $this->getNotesInsertSql();
$qb->setValue('id', $qb->createNamedParameter($notification->getId()))
->setValue('type', $qb->createNamedParameter($notification->getType()))
->setValue('to', $qb->createNamedParameter($notification->getTo()))
->setValue('to_array', $qb->createNamedParameter(''))
->setValue('cc', $qb->createNamedParameter(''))
->setValue('bcc', $qb->createNamedParameter(''))
->setValue('content', $qb->createNamedParameter(''))
->setValue('summary', $qb->createNamedParameter($notification->getSummary()))
->setValue('published', $qb->createNamedParameter($notification->getPublished()))
->setValue(
'published_time',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
)
->setValue('attributed_to', $qb->createNamedParameter($notification->getAttributedTo()))
->setValue('in_reply_to', $qb->createNamedParameter(''))
->setValue('source', $qb->createNamedParameter($notification->getSource()))
->setValue('instances', $qb->createNamedParameter(''))
->setValue('local', $qb->createNamedParameter(($notification->isLocal()) ? '1' : '0'))
->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$qb->execute();
}
/**
* @param string $id
* @param bool $asViewer
@ -186,10 +185,8 @@ class NotesRequest extends NotesRequestBuilder {
* @param string $id
*
* @return Stream
* @throws ItemUnknownException
* @throws NoteNotFoundException
* @throws RedundancyLimitException
* @throws SocialAppConfigException
* @throws Exception
*/
public function getNoteByActivityId(string $id): Stream {
if ($id === '') {
@ -219,9 +216,6 @@ class NotesRequest extends NotesRequestBuilder {
*
* @return Stream
* @throws NoteNotFoundException
* @throws ItemUnknownException
* @throws RedundancyLimitException
* @throws SocialAppConfigException
*/
public function getNoteByObjectId(Person $actor, string $type, string $objectId): Stream {
if ($objectId === '') {
@ -282,7 +276,7 @@ class NotesRequest extends NotesRequestBuilder {
$qb = $this->getNotesSelectSql();
$this->joinFollowing($qb, $actor);
$this->limitToType($qb, Note::TYPE);
// $this->limitToType($qb, Note::TYPE);
$this->limitPaginate($qb, $since, $limit);
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@ -353,7 +347,8 @@ class NotesRequest extends NotesRequestBuilder {
public function getStreamAccount(string $actorId, int $since = 0, int $limit = 5): array {
$qb = $this->getNotesSelectSql();
$this->limitPaginate($qb, $since, $limit);
$this->limitToType($qb, Note::TYPE);
// $this->limitToType($qb, Note::TYPE);
$this->limitToAttributedTo($qb, $actorId);
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->limitToRecipient($qb, ACore::CONTEXT_PUBLIC);
@ -389,7 +384,7 @@ class NotesRequest extends NotesRequestBuilder {
$qb = $this->getNotesSelectSql();
$this->limitPaginate($qb, $since, $limit);
$this->limitToType($qb, Note::TYPE);
// $this->limitToType($qb, Note::TYPE);
$this->limitToRecipient($qb, $actor->getId(), true);
$this->filterToRecipient($qb, ACore::CONTEXT_PUBLIC);
$this->filterToRecipient($qb, $actor->getFollowers());
@ -425,10 +420,12 @@ class NotesRequest extends NotesRequestBuilder {
): array {
$qb = $this->getNotesSelectSql();
$this->limitPaginate($qb, $since, $limit);
$this->limitToType($qb, Note::TYPE);
// $this->limitToType($qb, Note::TYPE);
if ($localOnly) {
$this->limitToLocal($qb, true);
}
$this->leftJoinCacheActors($qb, 'attributed_to');
$this->leftJoinStreamAction($qb);
@ -540,11 +537,14 @@ class NotesRequest extends NotesRequestBuilder {
* @param Stream $note
*
* @return IQueryBuilder
* @throws Exception
*/
public function saveStream(Stream $note): IQueryBuilder {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
try {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
} catch (Exception $e) {
}
$cache = '[]';
if ($note->gotCache()) {
@ -579,9 +579,6 @@ class NotesRequest extends NotesRequestBuilder {
->setValue('content', $qb->createNamedParameter($note->getContent()))
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
->setValue('published', $qb->createNamedParameter($note->getPublished()))
->setValue(
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
)
->setValue('attributed_to', $qb->createNamedParameter($attributedTo))
->setValue('in_reply_to', $qb->createNamedParameter($note->getInReplyTo()))
->setValue('source', $qb->createNamedParameter($note->getSource()))
@ -592,11 +589,20 @@ class NotesRequest extends NotesRequestBuilder {
json_encode($note->getInstancePaths(), JSON_UNESCAPED_SLASHES)
)
)
->setValue('local', $qb->createNamedParameter(($note->isLocal()) ? '1' : '0'))
->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
->setValue('local', $qb->createNamedParameter(($note->isLocal()) ? '1' : '0'));
try {
$dTime = new DateTime();
$dTime->setTimestamp($note->getPublishedTime());
$qb->setValue(
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
)
->setValue(
'creation',
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
} catch (Exception $e) {
}
$this->generatePrimaryKey($qb, $note->getId());

Wyświetl plik

@ -32,7 +32,6 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TArrayTools;
use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -362,7 +361,6 @@ class NotesRequestBuilder extends CoreRequestBuilder {
* @param array $data
*
* @return Stream
* @throws Exception
*/
protected function parseNotesSelectSql($data): Stream {
$item = new Stream();

Wyświetl plik

@ -2,7 +2,9 @@
namespace OCA\Social\Exceptions;
class ActivityCantBeVerifiedException extends \Exception {
use Exception;
class ActivityCantBeVerifiedException extends Exception {
}

Wyświetl plik

@ -111,7 +111,7 @@ class SocialAppNotificationInterface implements IActivityPubInterface {
}
$this->miscService->log('Generating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1);
$this->notesRequest->saveNotification($notification);
$this->notesRequest->save($notification);
}

Wyświetl plik

@ -30,11 +30,12 @@ declare(strict_types=1);
namespace OCA\Social\Model\ActivityPub\Internal;
use Exception;
use JsonSerializable;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Stream;
class SocialAppNotification extends ACore implements JsonSerializable {
class SocialAppNotification extends Stream implements JsonSerializable {
const TYPE = 'SocialAppNotification';
@ -54,6 +55,8 @@ class SocialAppNotification extends ACore implements JsonSerializable {
/**
* @param array $data
*
* @throws Exception
*/
public function import(array $data) {
parent::import($data);
@ -62,6 +65,8 @@ class SocialAppNotification extends ACore implements JsonSerializable {
/**
* @param array $data
*
* @throws Exception
*/
public function importFromDatabase(array $data) {
parent::importFromDatabase($data);

Wyświetl plik

@ -307,17 +307,18 @@ class Stream extends ACore implements JsonSerializable {
/**
* @param array $data
*
* @throws Exception
*/
public function importFromDatabase(array $data) {
parent::importFromDatabase($data);
$dTime = new DateTime($this->get('published_time', $data, 'yesterday'));
try {
$dTime = new DateTime($this->get('published_time', $data, 'yesterday'));
$this->setPublishedTime($dTime->getTimestamp());
} catch (Exception $e) {
}
$this->setActivityId($this->validate(self::AS_ID, 'activity_id', $data, ''));
$this->setContent($this->validate(self::AS_STRING, 'content', $data, ''));
$this->setPublishedTime($dTime->getTimestamp());
$this->setObjectId($this->validate(self::AS_ID, 'object_id', $data, ''));
$this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, ''));
$this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data));

Wyświetl plik

@ -26,6 +26,8 @@ namespace OCA\Social\Service;
use daita\MySmallPhpTools\Traits\TArrayTools;
use daita\MySmallPhpTools\Traits\TStringTools;
use Exception;
use GuzzleHttp\Exception\ClientException;
use OCA\Social\Db\FollowsRequest;
use OCA\Social\Model\ActivityPub\Object\Follow;
use OCP\AppFramework\Http;
@ -175,8 +177,8 @@ class CheckService {
return true;
}
} catch (\GuzzleHttp\Exception\ClientException $e) {
} catch (\Exception $e) {
} catch (ClientException $e) {
} catch (Exception $e) {
}
return false;

Wyświetl plik

@ -312,18 +312,18 @@ class NoteService {
/**
* @param Note $note
* @param Stream $item
*
* @throws Exception
*/
public function deleteLocalNote(Note $note) {
if (!$note->isLocal()) {
public function deleteLocalItem(Stream $item) {
if (!$item->isLocal()) {
return;
}
$note->setActorId($note->getAttributedTo());
$this->activityService->deleteActivity($note);
$this->notesRequest->deleteNoteById($note->getId());
$item->setActorId($item->getAttributedTo());
$this->activityService->deleteActivity($item);
$this->notesRequest->deleteNoteById($item->getId());
}

Wyświetl plik

@ -30,6 +30,7 @@ namespace OCA\Social;
use Exception;
use OC;
use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\ConfigService;
@ -43,7 +44,7 @@ if (!array_key_exists('resource', $_GET)) {
$subject = $_GET['resource'];
$urlGenerator = \OC::$server->getURLGenerator();
$urlGenerator = OC::$server->getURLGenerator();
list($type, $account) = explode(':', $subject, 2);
if ($type !== 'acct') {
@ -55,8 +56,8 @@ if ($type !== 'acct') {
list($username, $instance) = explode('@', $account);
try {
$cacheActorService = \OC::$server->query(CacheActorService::class);
$configService = \OC::$server->query(ConfigService::class);
$cacheActorService = OC::$server->query(CacheActorService::class);
$configService = OC::$server->query(ConfigService::class);
if ($configService->getCloudAddress(true) !== $instance) {
throw new Exception();

Wyświetl plik

@ -3,5 +3,5 @@
require_once __DIR__ . '/../../../tests/bootstrap.php';
require_once __DIR__.'/../vendor/autoload.php';
\OC_App::loadApp('social');
OC_App::loadApp('social');
OC_Hook::clear();