diff options
Diffstat (limited to 'lib/Interfaces/Object/NoteInterface.php')
-rw-r--r-- | lib/Interfaces/Object/NoteInterface.php | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/lib/Interfaces/Object/NoteInterface.php b/lib/Interfaces/Object/NoteInterface.php index 27fccfe9..40fc0a67 100644 --- a/lib/Interfaces/Object/NoteInterface.php +++ b/lib/Interfaces/Object/NoteInterface.php @@ -48,24 +48,20 @@ use OCA\Social\Model\ActivityPub\Activity\Delete; use OCA\Social\Model\ActivityPub\Internal\SocialAppNotification; use OCA\Social\Model\ActivityPub\Object\Mention; use OCA\Social\Model\ActivityPub\Object\Note; +use OCA\Social\Model\ActivityPub\Stream; +use OCA\Social\Service\CacheActorService; use OCA\Social\Service\PushService; use OCA\Social\Tools\Traits\TArrayTools; class NoteInterface extends AbstractActivityPubInterface implements IActivityPubInterface { use TArrayTools; - private StreamRequest $streamRequest; - private CacheActorsRequest $cacheActorsRequest; - private PushService $pushService; - public function __construct( - StreamRequest $streamRequest, - CacheActorsRequest $cacheActorsRequest, - PushService $pushService + private StreamRequest $streamRequest, + private CacheActorsRequest $cacheActorsRequest, + private CacheActorService $cacheActorService, + private PushService $pushService ) { - $this->streamRequest = $streamRequest; - $this->cacheActorsRequest = $cacheActorsRequest; - $this->pushService = $pushService; } /** @@ -104,6 +100,7 @@ class NoteInterface extends AbstractActivityPubInterface implements IActivityPub try { $this->streamRequest->getStreamById($note->getId()); } catch (StreamNotFoundException $e) { + $note->setVisibility($this->estimateVisibility($note)); $this->streamRequest->save($note); $this->updateDetails($note); $this->generateNotification($note); @@ -167,4 +164,22 @@ class NoteInterface extends AbstractActivityPubInterface implements IActivityPub $notificationInterface->save($notification); } } + + + private function estimateVisibility(Note $note): string { + if (in_array(Stream::CONTEXT_PUBLIC, $note->getToAll())) { + return Stream::TYPE_PUBLIC; + } + + if (in_array(Stream::CONTEXT_PUBLIC, $note->getCcArray())) { + return Stream::TYPE_UNLISTED; + } + + $actor = $this->cacheActorService->getFromId($note->getAttributedTo()); + if (in_array($actor->getFollowers(), array_merge($note->getCcArray(), $note->getToAll()))) { + return Stream::TYPE_FOLLOWERS; + } + + return Stream::TYPE_DIRECT; + } } |