diff options
Diffstat (limited to 'lib/Interfaces')
-rw-r--r-- | lib/Interfaces/Activity/AcceptInterface.php | 19 | ||||
-rw-r--r-- | lib/Interfaces/Activity/AddInterface.php | 16 | ||||
-rw-r--r-- | lib/Interfaces/Activity/BlockInterface.php | 16 | ||||
-rw-r--r-- | lib/Interfaces/Activity/CreateInterface.php | 16 | ||||
-rw-r--r-- | lib/Interfaces/Activity/DeleteInterface.php | 17 | ||||
-rw-r--r-- | lib/Interfaces/Activity/LikeInterface.php | 16 | ||||
-rw-r--r-- | lib/Interfaces/Activity/RejectInterface.php | 16 | ||||
-rw-r--r-- | lib/Interfaces/Activity/RemoveInterface.php | 15 | ||||
-rw-r--r-- | lib/Interfaces/Activity/UndoInterface.php | 15 | ||||
-rw-r--r-- | lib/Interfaces/Activity/UpdateInterface.php | 16 | ||||
-rw-r--r-- | lib/Interfaces/Actor/PersonInterface.php | 35 | ||||
-rw-r--r-- | lib/Interfaces/IActivityPubInterface.php | 19 | ||||
-rw-r--r-- | lib/Interfaces/Internal/SocialAppNotificationInterface.php | 24 | ||||
-rw-r--r-- | lib/Interfaces/Object/AnnounceInterface.php | 80 | ||||
-rw-r--r-- | lib/Interfaces/Object/DocumentInterface.php | 15 | ||||
-rw-r--r-- | lib/Interfaces/Object/FollowInterface.php | 15 | ||||
-rw-r--r-- | lib/Interfaces/Object/ImageInterface.php | 17 | ||||
-rw-r--r-- | lib/Interfaces/Object/NoteInterface.php | 39 |
18 files changed, 376 insertions, 30 deletions
diff --git a/lib/Interfaces/Activity/AcceptInterface.php b/lib/Interfaces/Activity/AcceptInterface.php index 5e3aa5fb..fc726028 100644 --- a/lib/Interfaces/Activity/AcceptInterface.php +++ b/lib/Interfaces/Activity/AcceptInterface.php @@ -98,12 +98,31 @@ class AcceptInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Activity/AddInterface.php b/lib/Interfaces/Activity/AddInterface.php index 706460ab..8aa7da89 100644 --- a/lib/Interfaces/Activity/AddInterface.php +++ b/lib/Interfaces/Activity/AddInterface.php @@ -101,9 +101,25 @@ class AddInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Activity/BlockInterface.php b/lib/Interfaces/Activity/BlockInterface.php index 4bc2f792..3fe46f94 100644 --- a/lib/Interfaces/Activity/BlockInterface.php +++ b/lib/Interfaces/Activity/BlockInterface.php @@ -101,9 +101,25 @@ class BlockInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Activity/CreateInterface.php b/lib/Interfaces/Activity/CreateInterface.php index e7a72d32..a625655b 100644 --- a/lib/Interfaces/Activity/CreateInterface.php +++ b/lib/Interfaces/Activity/CreateInterface.php @@ -101,9 +101,25 @@ class CreateInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Activity/DeleteInterface.php b/lib/Interfaces/Activity/DeleteInterface.php index 9b631f4d..6f86d8d0 100644 --- a/lib/Interfaces/Activity/DeleteInterface.php +++ b/lib/Interfaces/Activity/DeleteInterface.php @@ -128,14 +128,29 @@ class DeleteInterface implements IActivityPubInterface { /** * @param ACore $item */ + public function save(ACore $item) { + } + + + /** + * @param ACore $item + */ + public function update(ACore $item) { + } + + + /** + * @param ACore $item + */ public function delete(ACore $item) { } /** * @param ACore $item + * @param string $source */ - public function save(ACore $item) { + public function event(ACore $item, string $source) { } diff --git a/lib/Interfaces/Activity/LikeInterface.php b/lib/Interfaces/Activity/LikeInterface.php index d1e78abc..fba4a6e3 100644 --- a/lib/Interfaces/Activity/LikeInterface.php +++ b/lib/Interfaces/Activity/LikeInterface.php @@ -101,9 +101,25 @@ class LikeInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Activity/RejectInterface.php b/lib/Interfaces/Activity/RejectInterface.php index be46e6d3..6f21ba1a 100644 --- a/lib/Interfaces/Activity/RejectInterface.php +++ b/lib/Interfaces/Activity/RejectInterface.php @@ -101,9 +101,25 @@ class RejectInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Activity/RemoveInterface.php b/lib/Interfaces/Activity/RemoveInterface.php index ea5d44f5..c284109e 100644 --- a/lib/Interfaces/Activity/RemoveInterface.php +++ b/lib/Interfaces/Activity/RemoveInterface.php @@ -101,11 +101,26 @@ class RemoveInterface 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 ACore $activity * @param ACore $item */ diff --git a/lib/Interfaces/Activity/UndoInterface.php b/lib/Interfaces/Activity/UndoInterface.php index 7d55b7a0..5231312b 100644 --- a/lib/Interfaces/Activity/UndoInterface.php +++ b/lib/Interfaces/Activity/UndoInterface.php @@ -102,11 +102,26 @@ class UndoInterface 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 ACore $activity * @param ACore $item */ diff --git a/lib/Interfaces/Activity/UpdateInterface.php b/lib/Interfaces/Activity/UpdateInterface.php index 3be2c255..465a6968 100644 --- a/lib/Interfaces/Activity/UpdateInterface.php +++ b/lib/Interfaces/Activity/UpdateInterface.php @@ -101,9 +101,25 @@ class UpdateInterface 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 ACore $activity * @param ACore $item diff --git a/lib/Interfaces/Actor/PersonInterface.php b/lib/Interfaces/Actor/PersonInterface.php index 5e843b44..084b277d 100644 --- a/lib/Interfaces/Actor/PersonInterface.php +++ b/lib/Interfaces/Actor/PersonInterface.php @@ -126,6 +126,22 @@ class PersonInterface implements IActivityPubInterface { /** + * @param ACore $activity + * @param ACore $item + * + * @throws InvalidOriginException + */ + public function activity(Acore $activity, ACore $item) { + /** @var Person $item */ + $activity->checkOrigin($item->getId()); + + if ($activity->getType() === Update::TYPE) { + $this->updateActor($item, $activity); + } + } + + + /** * @param ACore $person */ public function save(ACore $person) { @@ -140,18 +156,9 @@ class PersonInterface implements IActivityPubInterface { /** - * @param ACore $activity * @param ACore $item - * - * @throws InvalidOriginException */ - public function activity(Acore $activity, ACore $item) { - /** @var Person $item */ - $activity->checkOrigin($item->getId()); - - if ($activity->getType() === Update::TYPE) { - $this->updateActor($item, $activity); - } + public function update(ACore $item) { } @@ -166,6 +173,14 @@ class PersonInterface implements IActivityPubInterface { /** + * @param ACore $item + * @param string $source + */ + public function event(ACore $item, string $source) { + } + + + /** * @param Person $actor * @param ACore $activity */ diff --git a/lib/Interfaces/IActivityPubInterface.php b/lib/Interfaces/IActivityPubInterface.php index d0dcc4c1..fe7f4d99 100644 --- a/lib/Interfaces/IActivityPubInterface.php +++ b/lib/Interfaces/IActivityPubInterface.php @@ -62,8 +62,8 @@ interface IActivityPubInterface { /** * @param string $id * - * @throws ItemNotFoundException * @return ACore + * @throws ItemNotFoundException */ public function getItemById(string $id): ACore; @@ -86,6 +86,23 @@ interface IActivityPubInterface { /** + * Update the current item. + * + * @param ACore $item + */ + public function update(ACore $item); + + + /** + * Event on the current item. + * + * @param ACore $item + * @param string $source + */ + public function event(ACore $item, string $source); + + + /** * Delete the current item. * * @param ACore $item diff --git a/lib/Interfaces/Internal/SocialAppNotificationInterface.php b/lib/Interfaces/Internal/SocialAppNotificationInterface.php index 0c05eb4c..ed4f5028 100644 --- a/lib/Interfaces/Internal/SocialAppNotificationInterface.php +++ b/lib/Interfaces/Internal/SocialAppNotificationInterface.php @@ -102,6 +102,14 @@ class SocialAppNotificationInterface implements IActivityPubInterface { /** + * @param ACore $activity + * @param ACore $item + */ + public function activity(Acore $activity, ACore $item) { + } + + + /** * @param ACore $notification */ public function save(ACore $notification) { @@ -113,16 +121,17 @@ class SocialAppNotificationInterface implements IActivityPubInterface { $notification->setPublished(date("c")); $notification->convertPublished(); - $this->miscService->log('Generating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1); + $this->miscService->log( + 'Generating notification: ' . json_encode($notification, JSON_UNESCAPED_SLASHES), 1 + ); $this->streamRequest->save($notification); } /** - * @param ACore $activity * @param ACore $item */ - public function activity(Acore $activity, ACore $item) { + public function update(ACore $item) { } @@ -132,5 +141,14 @@ class SocialAppNotificationInterface implements IActivityPubInterface { public function delete(ACore $item) { } + + /** + * @param ACore $item + * @param string $source + */ + public function event(ACore $item, string $source) { + } + + } 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) { + } + + } |