kopia lustrzana https://github.com/nextcloud/social
federation and attachments
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/1709/head
rodzic
cbab0d3594
commit
37bbde39e4
|
@ -116,8 +116,6 @@ return [
|
||||||
|
|
||||||
['name' => 'Local#postLike', 'url' => '/api/v1/post/like', 'verb' => 'POST'],
|
['name' => 'Local#postLike', 'url' => '/api/v1/post/like', 'verb' => 'POST'],
|
||||||
['name' => 'Local#postUnlike', 'url' => '/api/v1/post/like', 'verb' => 'DELETE'],
|
['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#actionFollow', 'url' => '/api/v1/current/follow', 'verb' => 'PUT'],
|
||||||
['name' => 'Local#actionUnfollow', 'url' => '/api/v1/current/follow', 'verb' => 'DELETE'],
|
['name' => 'Local#actionUnfollow', 'url' => '/api/v1/current/follow', 'verb' => 'DELETE'],
|
||||||
|
|
|
@ -253,7 +253,10 @@ class ApiController extends Controller {
|
||||||
if (!empty($status->getMediaIds())) {
|
if (!empty($status->getMediaIds())) {
|
||||||
$post->setMedias(
|
$post->setMedias(
|
||||||
array_map(function (Document $document): MediaAttachment {
|
array_map(function (Document $document): MediaAttachment {
|
||||||
return $document->convertToMediaAttachment($this->urlGenerator);
|
return $document->convertToMediaAttachment(
|
||||||
|
$this->urlGenerator,
|
||||||
|
ACore::FORMAT_ACTIVITYPUB
|
||||||
|
);
|
||||||
}, $this->documentService->getMediaFromArray(
|
}, $this->documentService->getMediaFromArray(
|
||||||
$status->getMediaIds(),
|
$status->getMediaIds(),
|
||||||
$this->viewer->getPreferredUsername()
|
$this->viewer->getPreferredUsername()
|
||||||
|
|
|
@ -75,10 +75,15 @@ class StreamRequest extends StreamRequestBuilder {
|
||||||
$qb = $this->saveStream($stream);
|
$qb = $this->saveStream($stream);
|
||||||
if ($stream->getType() === Note::TYPE) {
|
if ($stream->getType() === Note::TYPE) {
|
||||||
/** @var Note $stream */
|
/** @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())))
|
$qb->setValue('hashtags', $qb->createNamedParameter(json_encode($stream->getHashtags())))
|
||||||
->setValue(
|
->setValue(
|
||||||
'attachments', $qb->createNamedParameter(
|
'attachments', $qb->createNamedParameter(json_encode($attachments, JSON_UNESCAPED_SLASHES)
|
||||||
json_encode($stream->getAttachments(), JSON_UNESCAPED_SLASHES)
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -369,9 +369,13 @@ class Document extends ACore implements JsonSerializable {
|
||||||
/**
|
/**
|
||||||
* @return MediaAttachment
|
* @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 = new MediaAttachment();
|
||||||
$media->setId((string)$this->getNid());
|
$media->setId((string)$this->getNid())
|
||||||
|
->setExportFormat($exportFormat);
|
||||||
|
|
||||||
$mime = '';
|
$mime = '';
|
||||||
if (strpos($this->getMediaType(), '/')) {
|
if (strpos($this->getMediaType(), '/')) {
|
||||||
|
|
|
@ -702,11 +702,8 @@ class Stream extends ACore implements IQueryRow, JsonSerializable {
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
$result = parent::jsonSerialize();
|
$result = parent::jsonSerialize();
|
||||||
|
|
||||||
$result['media_attachments'] = $this->getAttachments();
|
// $result['media_attachments'] = $this->getAttachments();
|
||||||
|
$result['attachment'] = $this->getAttachments();
|
||||||
// if ($this->isCompleteDetails()) {
|
|
||||||
// $result['attachments'] = $this->getAttachments();
|
|
||||||
// }
|
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ declare(strict_types=1);
|
||||||
namespace OCA\Social\Model\Client;
|
namespace OCA\Social\Model\Client;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
use OCA\Social\Model\ActivityPub\ACore;
|
||||||
|
use OCA\Social\Model\ActivityPub\Object\Document;
|
||||||
use OCA\Social\Tools\Traits\TArrayTools;
|
use OCA\Social\Tools\Traits\TArrayTools;
|
||||||
|
|
||||||
class MediaAttachment implements JsonSerializable {
|
class MediaAttachment implements JsonSerializable {
|
||||||
|
@ -44,6 +46,7 @@ class MediaAttachment implements JsonSerializable {
|
||||||
private ?AttachmentMeta $meta = null;
|
private ?AttachmentMeta $meta = null;
|
||||||
private string $description = '';
|
private string $description = '';
|
||||||
private string $blurHash = '';
|
private string $blurHash = '';
|
||||||
|
private int $exportFormat = ACore::FORMAT_LOCAL;
|
||||||
|
|
||||||
public function setId(string $id): self {
|
public function setId(string $id): self {
|
||||||
$this->id = $id;
|
$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 {
|
public function import(array $data): self {
|
||||||
$this->setId($this->get('id', $data));
|
$this->setId($this->get('id', $data));
|
||||||
$this->setType($this->get('type', $data));
|
$this->setType($this->get('type', $data));
|
||||||
|
@ -153,6 +167,14 @@ class MediaAttachment implements JsonSerializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
|
if ($this->getExportFormat() === ACore::FORMAT_LOCAL) {
|
||||||
|
return $this->asLocal();
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->asDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function asLocal(): array {
|
||||||
return array_filter(
|
return array_filter(
|
||||||
[
|
[
|
||||||
'id' => $this->getId(),
|
'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
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,9 @@ class BoostService {
|
||||||
throw new StreamNotFoundException('Stream is not Public');
|
throw new StreamNotFoundException('Stream is not Public');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$announce->setTo(ACore::CONTEXT_PUBLIC);
|
||||||
$announce->addCc($actor->getFollowers());
|
$announce->addCc($actor->getFollowers());
|
||||||
|
$announce->addcc($note->getAttributedTo());
|
||||||
|
|
||||||
$announce->setObjectId($note->getId());
|
$announce->setObjectId($note->getId());
|
||||||
$announce->setRequestToken($this->uuid());
|
$announce->setRequestToken($this->uuid());
|
||||||
|
|
|
@ -109,8 +109,6 @@ class PostService {
|
||||||
$note->setAttachments($post->getMedias());
|
$note->setAttachments($post->getMedias());
|
||||||
$note->setVisibility($post->getType());
|
$note->setVisibility($post->getType());
|
||||||
|
|
||||||
// $this->generateDocumentsFromAttachments($note, $post);
|
|
||||||
|
|
||||||
$this->streamService->replyTo($note, $post->getReplyTo());
|
$this->streamService->replyTo($note, $post->getReplyTo());
|
||||||
$this->streamService->addRecipients($note, $post->getType(), $post->getTo());
|
$this->streamService->addRecipients($note, $post->getType(), $post->getTo());
|
||||||
$this->streamService->addHashtags($note, $post->getHashtags());
|
$this->streamService->addHashtags($note, $post->getHashtags());
|
||||||
|
|
Ładowanie…
Reference in New Issue