summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-05-06 13:32:31 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-05-06 13:32:31 -0100
commit8174167e482481b4d687281103b92bf172d7f856 (patch)
tree7bd28ecfe4d10707b1eeca9d3965f0216452dfb1
parent76997d0cd5c351e1e7afe2f067c08e536a862447 (diff)
cleaning and renaming
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--lib/AP.php43
-rw-r--r--lib/Controller/LocalController.php2
-rw-r--r--lib/Controller/NavigationController.php3
-rw-r--r--lib/Db/NotesRequest.php138
-rw-r--r--lib/Db/NotesRequestBuilder.php2
-rw-r--r--lib/Exceptions/ActivityCantBeVerifiedException.php4
-rw-r--r--lib/Interfaces/Internal/SocialAppNotificationInterface.php2
-rw-r--r--lib/Model/ActivityPub/Internal/SocialAppNotification.php9
-rw-r--r--lib/Model/ActivityPub/Stream.php9
-rw-r--r--lib/Service/CheckService.php6
-rw-r--r--lib/Service/NoteService.php12
-rw-r--r--lib/webfinger.php7
-rw-r--r--tests/bootstrap.php2
13 files changed, 128 insertions, 111 deletions
diff --git a/lib/AP.php b/lib/AP.php
index e11fb9dc..75d1d1d8 100644
--- a/lib/AP.php
+++ b/lib/AP.php
@@ -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->configService = \OC::$server->query(ConfigService::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::$activityPub = $ap;
} catch (QueryException $e) {
- \OC::$server->getLogger()
- ->logException($e);
+ OC::$server->getLogger()
+ ->logException($e);
}
}
diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php
index 17606ef7..5f68a7fe 100644
--- a/lib/Controller/LocalController.php
+++ b/lib/Controller/LocalController.php
@@ -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) {
diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php
index 2621c7c0..6b58aae2 100644
--- a/lib/Controller/NavigationController.php
+++ b/lib/Controller/NavigationController.php
@@ -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()
]
diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php
index b64daf46..5a8bb8c1 100644
--- a/lib/Db/NotesRequest.php
+++ b/lib/Db/NotesRequest.php
@@ -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
@@ -107,42 +142,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());
diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php
index 151842cd..8caa7846 100644
--- a/lib/Db/NotesRequestBuilder.php
+++ b/lib/Db/NotesRequestBuilder.php
@@ -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();
diff --git a/lib/Exceptions/ActivityCantBeVerifiedException.php b/lib/Exceptions/ActivityCantBeVerifiedException.php
index 9fe5f222..fdb5c079 100644
--- a/lib/Exceptions/ActivityCantBeVerifiedException.php
+++ b/lib/Exceptions/ActivityCantBeVerifiedException.php
@@ -2,7 +2,9 @@
namespace OCA\Social\Exceptions;
-class ActivityCantBeVerifiedException extends \Exception {
+use Exception;
+
+class ActivityCantBeVerifiedException extends Exception {
}
diff --git a/lib/Interfaces/Internal/SocialAppNotificationInterface.php b/lib/Interfaces/Internal/SocialAppNotificationInterface.php
index d8fdf1fc..eb766310 100644
--- a/lib/Interfaces/Internal/SocialAppNotificationInterface.php
+++ b/lib/Interfaces/Internal/SocialAppNotificationInterface.php
@@ -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);
}
diff --git a/lib/Model/ActivityPub/Internal/SocialAppNotification.php b/lib/Model/ActivityPub/Internal/SocialAppNotification.php
index 489de9f4..c76965d1 100644
--- a/lib/Model/ActivityPub/Internal/SocialAppNotification.php
+++ b/lib/Model/ActivityPub/Internal/SocialAppNotification.php
@@ -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);
diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php
index dc0ff248..42ac756b 100644
--- a/lib/Model/ActivityPub/Stream.php
+++ b/lib/Model/ActivityPub/Stream.php
@@ -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));
diff --git a/lib/Service/CheckService.php b/lib/Service/CheckService.php
index ff3960b5..47a4a133 100644
--- a/lib/Service/CheckService.php
+++ b/lib/Service/CheckService.php
@@ -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;
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index 934d53f9..3ebdf223 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -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());
}
diff --git a/lib/webfinger.php b/lib/webfinger.php
index 7794abad..f4f1f426 100644
--- a/lib/webfinger.php
+++ b/lib/webfinger.php
@@ -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();
diff --git a/tests/bootstrap.php b/tests/bootstrap.php
index 56afd432..0db0e40a 100644
--- a/tests/bootstrap.php
+++ b/tests/bootstrap.php
@@ -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();