Porównaj commity

...

2 Commity

Autor SHA1 Wiadomość Data
Maxence Lange 6ecea39aef
Merge 3d17efaf19 into 12a1870cef 2023-12-29 18:50:43 +03:00
Maxence Lange 3d17efaf19 visibility on remote status
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
2023-06-19 21:01:39 -01:00
1 zmienionych plików z 25 dodań i 10 usunięć

Wyświetl plik

@ -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;
}
}