summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2023-06-19 21:01:30 -0100
committerMaxence Lange <maxence@artificial-owl.com>2023-06-19 21:01:39 -0100
commit3d17efaf19b279bcfcbc4e951730bfba26c9ac3c (patch)
tree32a0ac0c2167451faeeafa5c2b9391eb0568d76b
parentf1529e386609ec74637c160872bd9f08e8732283 (diff)
visibility on remote statusenh/noid/visibility-on-remote
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
-rw-r--r--lib/Interfaces/Object/NoteInterface.php35
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;
+ }
}