diff --git a/appinfo/routes.php b/appinfo/routes.php index f30b9ffa..3645fcf2 100644 --- a/appinfo/routes.php +++ b/appinfo/routes.php @@ -116,8 +116,6 @@ return [ ['name' => 'Local#postLike', 'url' => '/api/v1/post/like', 'verb' => 'POST'], ['name' => 'Local#postUnlike', 'url' => '/api/v1/post/like', 'verb' => 'DELETE'], - ['name' => 'Local#postBoost', 'url' => '/api/v1/post/boost', 'verb' => 'POST'], - ['name' => 'Local#postUnboost', 'url' => '/api/v1/post/boost', 'verb' => 'DELETE'], ['name' => 'Local#actionFollow', 'url' => '/api/v1/current/follow', 'verb' => 'PUT'], ['name' => 'Local#actionUnfollow', 'url' => '/api/v1/current/follow', 'verb' => 'DELETE'], diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php index c8029a7b..045194cf 100644 --- a/lib/Controller/ApiController.php +++ b/lib/Controller/ApiController.php @@ -253,7 +253,10 @@ class ApiController extends Controller { if (!empty($status->getMediaIds())) { $post->setMedias( array_map(function (Document $document): MediaAttachment { - return $document->convertToMediaAttachment($this->urlGenerator); + return $document->convertToMediaAttachment( + $this->urlGenerator, + ACore::FORMAT_ACTIVITYPUB + ); }, $this->documentService->getMediaFromArray( $status->getMediaIds(), $this->viewer->getPreferredUsername() diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php index 7e95deb1..8c0c1b96 100644 --- a/lib/Db/StreamRequest.php +++ b/lib/Db/StreamRequest.php @@ -75,10 +75,15 @@ class StreamRequest extends StreamRequestBuilder { $qb = $this->saveStream($stream); if ($stream->getType() === Note::TYPE) { /** @var Note $stream */ + + $attachments = []; + foreach ($stream->getAttachments() as $item) { + $attachments[] = $item->asLocal(); // get attachment ready for local + } + $qb->setValue('hashtags', $qb->createNamedParameter(json_encode($stream->getHashtags()))) ->setValue( - 'attachments', $qb->createNamedParameter( - json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES) + 'attachments', $qb->createNamedParameter(json_encode($attachments, JSON_UNESCAPED_SLASHES) ) ); } diff --git a/lib/Model/ActivityPub/Object/Document.php b/lib/Model/ActivityPub/Object/Document.php index 4fd494f1..943bf9c8 100644 --- a/lib/Model/ActivityPub/Object/Document.php +++ b/lib/Model/ActivityPub/Object/Document.php @@ -369,9 +369,13 @@ class Document extends ACore implements JsonSerializable { /** * @return MediaAttachment */ - public function convertToMediaAttachment(?IURLGenerator $urlGenerator = null): MediaAttachment { + public function convertToMediaAttachment( + ?IURLGenerator $urlGenerator = null, + int $exportFormat = self::FORMAT_LOCAL + ): MediaAttachment { $media = new MediaAttachment(); - $media->setId((string)$this->getNid()); + $media->setId((string)$this->getNid()) + ->setExportFormat($exportFormat); $mime = ''; if (strpos($this->getMediaType(), '/')) { diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 274ae0b9..92e4e08b 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -702,11 +702,8 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { public function jsonSerialize(): array { $result = parent::jsonSerialize(); - $result['media_attachments'] = $this->getAttachments(); - -// if ($this->isCompleteDetails()) { -// $result['attachments'] = $this->getAttachments(); -// } +// $result['media_attachments'] = $this->getAttachments(); + $result['attachment'] = $this->getAttachments(); return $result; } diff --git a/lib/Model/Client/MediaAttachment.php b/lib/Model/Client/MediaAttachment.php index fba53f30..ef43958a 100644 --- a/lib/Model/Client/MediaAttachment.php +++ b/lib/Model/Client/MediaAttachment.php @@ -30,6 +30,8 @@ declare(strict_types=1); namespace OCA\Social\Model\Client; use JsonSerializable; +use OCA\Social\Model\ActivityPub\ACore; +use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Tools\Traits\TArrayTools; class MediaAttachment implements JsonSerializable { @@ -44,6 +46,7 @@ class MediaAttachment implements JsonSerializable { private ?AttachmentMeta $meta = null; private string $description = ''; private string $blurHash = ''; + private int $exportFormat = ACore::FORMAT_LOCAL; public function setId(string $id): self { $this->id = $id; @@ -136,6 +139,17 @@ class MediaAttachment implements JsonSerializable { } + public function setExportFormat(int $exportFormat): self { + $this->exportFormat = $exportFormat; + + return $this; + } + + public function getExportFormat(): int { + return $this->exportFormat; + } + + public function import(array $data): self { $this->setId($this->get('id', $data)); $this->setType($this->get('type', $data)); @@ -153,6 +167,14 @@ class MediaAttachment implements JsonSerializable { } public function jsonSerialize(): array { + if ($this->getExportFormat() === ACore::FORMAT_LOCAL) { + return $this->asLocal(); + } + + return $this->asDocument(); + } + + public function asLocal(): array { return array_filter( [ 'id' => $this->getId(), @@ -166,4 +188,24 @@ class MediaAttachment implements JsonSerializable { ] ); } + + /** + * quick implementation of converting MediaAttachment to Document. Can be improved. + * + * @return array + */ + public function asDocument(): array { + $original = $this->getMeta()->getOriginal(); + + return + [ + 'type' => Document::TYPE, + 'mediaType' => '', + 'url' => $this->getUrl(), + 'name' => null, + 'blurhash' => $this->getBlurHash(), + 'width' => ($original === null) ? 0 : $original->getWidth() ?? 0, + 'height' => ($original === null) ? 0 : $original->getHeight() ?? 0 + ]; + } } diff --git a/lib/Service/BoostService.php b/lib/Service/BoostService.php index 668d5393..eefaf3ac 100644 --- a/lib/Service/BoostService.php +++ b/lib/Service/BoostService.php @@ -120,7 +120,9 @@ class BoostService { throw new StreamNotFoundException('Stream is not Public'); } + $announce->setTo(ACore::CONTEXT_PUBLIC); $announce->addCc($actor->getFollowers()); + $announce->addcc($note->getAttributedTo()); $announce->setObjectId($note->getId()); $announce->setRequestToken($this->uuid()); diff --git a/lib/Service/PostService.php b/lib/Service/PostService.php index 27000306..96c28553 100644 --- a/lib/Service/PostService.php +++ b/lib/Service/PostService.php @@ -109,8 +109,6 @@ class PostService { $note->setAttachments($post->getMedias()); $note->setVisibility($post->getType()); -// $this->generateDocumentsFromAttachments($note, $post); - $this->streamService->replyTo($note, $post->getReplyTo()); $this->streamService->addRecipients($note, $post->getType(), $post->getTo()); $this->streamService->addHashtags($note, $post->getHashtags());