summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2023-04-03 09:20:20 -0100
committerGitHub <noreply@github.com>2023-04-03 09:20:20 -0100
commit33de5114d72840b20716e5cd2e8c75266e0e9950 (patch)
tree6be7b7d60fcbf1243332a4301364c49063fcddcf /lib
parent91a793c9f9d02177c9db6ed172b6758e6f30772f (diff)
parent37bbde39e4e6149bd70f7243df46c8a23ebfae35 (diff)
Merge pull request #1709 from nextcloud/fix/noid/boost-attachment
federation and attachments
Diffstat (limited to 'lib')
-rw-r--r--lib/Controller/ApiController.php5
-rw-r--r--lib/Db/StreamRequest.php9
-rw-r--r--lib/Model/ActivityPub/Object/Document.php8
-rw-r--r--lib/Model/ActivityPub/Stream.php7
-rw-r--r--lib/Model/Client/MediaAttachment.php42
-rw-r--r--lib/Service/BoostService.php2
-rw-r--r--lib/Service/PostService.php2
7 files changed, 63 insertions, 12 deletions
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 6d093352..bd29ba6b 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 fe9cfaf7..18ca8c53 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());