summaryrefslogtreecommitdiffstats
path: root/lib/Interfaces/Object
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Interfaces/Object')
-rw-r--r--lib/Interfaces/Object/AnnounceInterface.php80
-rw-r--r--lib/Interfaces/Object/DocumentInterface.php15
-rw-r--r--lib/Interfaces/Object/FollowInterface.php15
-rw-r--r--lib/Interfaces/Object/ImageInterface.php17
-rw-r--r--lib/Interfaces/Object/NoteInterface.php39
5 files changed, 151 insertions, 15 deletions
diff --git a/lib/Interfaces/Object/AnnounceInterface.php b/lib/Interfaces/Object/AnnounceInterface.php
index f7a661f5..4cbb095f 100644
--- a/lib/Interfaces/Object/AnnounceInterface.php
+++ b/lib/Interfaces/Object/AnnounceInterface.php
@@ -31,10 +31,14 @@ declare(strict_types=1);
namespace OCA\Social\Interfaces\Object;
+use daita\MySmallPhpTools\Exceptions\CacheItemNotFoundException;
+use daita\MySmallPhpTools\Traits\TArrayTools;
use Exception;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\InvalidOriginException;
use OCA\Social\Exceptions\ItemNotFoundException;
+use OCA\Social\Exceptions\ItemUnknownException;
+use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Interfaces\IActivityPubInterface;
use OCA\Social\Model\ActivityPub\ACore;
@@ -42,6 +46,7 @@ use OCA\Social\Model\ActivityPub\Activity\Undo;
use OCA\Social\Model\ActivityPub\Object\Announce;
use OCA\Social\Model\ActivityPub\Stream;
use OCA\Social\Model\StreamQueue;
+use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\MiscService;
use OCA\Social\Service\StreamQueueService;
@@ -54,12 +59,18 @@ use OCA\Social\Service\StreamQueueService;
class AnnounceInterface implements IActivityPubInterface {
+ use TArrayTools;
+
+
/** @var StreamRequest */
private $streamRequest;
/** @var StreamQueueService */
private $streamQueueService;
+ /** @var CacheActorService */
+ private $cacheActorService;
+
/** @var MiscService */
private $miscService;
@@ -69,14 +80,16 @@ class AnnounceInterface implements IActivityPubInterface {
*
* @param StreamRequest $streamRequest
* @param StreamQueueService $streamQueueService
+ * @param CacheActorService $cacheActorService
* @param MiscService $miscService
*/
public function __construct(
StreamRequest $streamRequest, StreamQueueService $streamQueueService,
- MiscService $miscService
+ CacheActorService $cacheActorService, MiscService $miscService
) {
$this->streamRequest = $streamRequest;
$this->streamQueueService = $streamQueueService;
+ $this->cacheActorService = $cacheActorService;
$this->miscService = $miscService;
}
@@ -137,7 +150,20 @@ class AnnounceInterface implements IActivityPubInterface {
public function save(ACore $item) {
/** @var Announce $item */
try {
- $this->streamRequest->getStreamById($item->getId());
+ $knownItem =
+ $this->streamRequest->getStreamByObjectId($item->getObjectId(), Announce::TYPE);
+
+ if ($item->hasActor()) {
+ $actor = $item->getActor();
+ } else {
+ $actor = $this->cacheActorService->getFromId($item->getActorId());
+ }
+
+ if (!$knownItem->hasCc($actor->getFollowers())) {
+ $knownItem->addCc($actor->getFollowers());
+ $this->streamRequest->update($knownItem);
+ }
+
} catch (StreamNotFoundException $e) {
$objectId = $item->getObjectId();
$item->addCacheItem($objectId);
@@ -153,8 +179,56 @@ class AnnounceInterface implements IActivityPubInterface {
/**
* @param ACore $item
*/
+ public function update(ACore $item) {
+ }
+
+
+ /**
+ * @param ACore $item
+ */
public function delete(ACore $item) {
- $this->streamRequest->deleteStreamById($item->getId(), Announce::TYPE);
+ try {
+ $knownItem =
+ $this->streamRequest->getStreamByObjectId($item->getObjectId(), Announce::TYPE);
+
+ $actor = $item->getActor();
+ $knownItem->removeCc($actor->getFollowers());
+
+ if (empty($knownItem->getCcArray())) {
+ $this->streamRequest->deleteStreamById($knownItem->getId(), Announce::TYPE);
+ } else {
+ $this->streamRequest->update($knownItem);
+ }
+ } catch (StreamNotFoundException $e) {
+ } catch (ItemUnknownException $e) {
+ } catch (SocialAppConfigException $e) {
+ }
+ }
+
+
+ /**
+ * @param ACore $item
+ * @param string $source
+ */
+ public function event(ACore $item, string $source) {
+ /** @var Stream $item */
+ switch ($source) {
+ case 'updateCache':
+ $objectId = $item->getObjectId();
+ try {
+ $cachedItem = $item->getCache()
+ ->getItem($objectId);
+ } catch (CacheItemNotFoundException $e) {
+ return;
+ }
+
+ $to = $this->get('attributedTo', $cachedItem->getObject(), '');
+ if ($to !== '') {
+ $this->streamRequest->updateAttributedTo($item->getId(), $to);
+ }
+
+ break;
+ }
}
}
diff --git a/lib/Interfaces/Object/DocumentInterface.php b/lib/Interfaces/Object/DocumentInterface.php
index b0e6efc5..99f04358 100644
--- a/lib/Interfaces/Object/DocumentInterface.php
+++ b/lib/Interfaces/Object/DocumentInterface.php
@@ -122,10 +122,25 @@ class DocumentInterface implements IActivityPubInterface {
/**
* @param ACore $item
*/
+ public function update(ACore $item) {
+ }
+
+
+ /**
+ * @param ACore $item
+ */
public function delete(ACore $item) {
// $this->cacheDocumentsRequest->delete($item);
}
+ /**
+ * @param ACore $item
+ * @param string $source
+ */
+ public function event(ACore $item, string $source) {
+ }
+
+
}
diff --git a/lib/Interfaces/Object/FollowInterface.php b/lib/Interfaces/Object/FollowInterface.php
index 6f45cf82..91609820 100644
--- a/lib/Interfaces/Object/FollowInterface.php
+++ b/lib/Interfaces/Object/FollowInterface.php
@@ -246,11 +246,26 @@ class FollowInterface implements IActivityPubInterface {
/**
* @param ACore $item
*/
+ public function update(ACore $item) {
+ }
+
+
+ /**
+ * @param ACore $item
+ */
public function delete(ACore $item) {
}
/**
+ * @param ACore $item
+ * @param string $source
+ */
+ public function event(ACore $item, string $source) {
+ }
+
+
+ /**
* @param Follow $follow
*
* @throws ItemUnknownException
diff --git a/lib/Interfaces/Object/ImageInterface.php b/lib/Interfaces/Object/ImageInterface.php
index 63b2e666..6f3f612d 100644
--- a/lib/Interfaces/Object/ImageInterface.php
+++ b/lib/Interfaces/Object/ImageInterface.php
@@ -100,10 +100,27 @@ class ImageInterface extends DocumentInterface implements IActivityPubInterface
/**
* @param ACore $item
*/
+ public function update(ACore $item) {
+ parent::update($item);
+ }
+
+
+ /**
+ * @param ACore $item
+ */
public function delete(ACore $item) {
parent::delete($item);
}
+ /**
+ * @param ACore $item
+ * @param string $source
+ */
+ public function event(ACore $item, string $source) {
+ parent::event($item, $source);
+ }
+
+
}
diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php
index 6db04f0d..18ac2122 100644
--- a/lib/Interfaces/Object/NoteInterface.php
+++ b/lib/Interfaces/Object/NoteInterface.php
@@ -109,6 +109,24 @@ class NoteInterface implements IActivityPubInterface {
/**
+ * @param ACore $activity
+ * @param ACore $item
+ *
+ * @throws InvalidOriginException
+ */
+ public function activity(Acore $activity, ACore $item) {
+ /** @var Note $item */
+
+ if ($activity->getType() === Create::TYPE) {
+ $activity->checkOrigin($item->getId());
+ $activity->checkOrigin($item->getAttributedTo());
+ $item->setActivityId($activity->getId());
+ $this->save($item);
+ }
+ }
+
+
+ /**
* @param ACore $note
*/
public function save(ACore $note) {
@@ -123,20 +141,9 @@ class NoteInterface implements IActivityPubInterface {
/**
- * @param ACore $activity
* @param ACore $item
- *
- * @throws InvalidOriginException
*/
- public function activity(Acore $activity, ACore $item) {
- /** @var Note $item */
-
- if ($activity->getType() === Create::TYPE) {
- $activity->checkOrigin($item->getId());
- $activity->checkOrigin($item->getAttributedTo());
- $item->setActivityId($activity->getId());
- $this->save($item);
- }
+ public function update(ACore $item) {
}
@@ -153,5 +160,13 @@ class NoteInterface implements IActivityPubInterface {
}
+ /**
+ * @param ACore $item
+ * @param string $source
+ */
+ public function event(ACore $item, string $source) {
+ }
+
+
}