kopia lustrzana https://github.com/nextcloud/social
Merge pull request #1632 from nextcloud/fix/noid/meta-in-statuses
add meta to attachmentspull/1633/head
commit
8d4ea5eec2
|
@ -57,6 +57,12 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
|
||||||
->setValue('parent_id_prim', $qb->createNamedParameter($qb->prim($document->getParentId())))
|
->setValue('parent_id_prim', $qb->createNamedParameter($qb->prim($document->getParentId())))
|
||||||
->setValue('public', $qb->createNamedParameter(($document->isPublic()) ? '1' : '0'));
|
->setValue('public', $qb->createNamedParameter(($document->isPublic()) ? '1' : '0'));
|
||||||
|
|
||||||
|
// generate Meta
|
||||||
|
$document->convertToMediaAttachment();
|
||||||
|
if ($document->getMeta() !== null) {
|
||||||
|
$qb->setValue('meta', $qb->createNamedParameter(json_encode($document->getMeta())));
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$qb->setValue(
|
$qb->setValue(
|
||||||
'creation',
|
'creation',
|
||||||
|
|
|
@ -62,8 +62,8 @@ class CacheDocumentsRequestBuilder extends CoreRequestBuilder {
|
||||||
$qb->select(
|
$qb->select(
|
||||||
'cd.nid', 'cd.id', 'cd.type', 'cd.parent_id', 'cd.account',
|
'cd.nid', 'cd.id', 'cd.type', 'cd.parent_id', 'cd.account',
|
||||||
'cd.media_type', 'cd.mime_type', 'cd.url', 'cd.local_copy', 'cd.public',
|
'cd.media_type', 'cd.mime_type', 'cd.url', 'cd.local_copy', 'cd.public',
|
||||||
'cd.error', 'cd.creation', 'cd.caching', 'cd.resized_copy', 'cd.blurhash',
|
'cd.error', 'cd.creation', 'cd.caching', 'cd.resized_copy', 'cd.meta',
|
||||||
'cd.description'
|
'cd.blurhash', 'cd.description'
|
||||||
)
|
)
|
||||||
->from(self::TABLE_CACHE_DOCUMENTS, 'cd');
|
->from(self::TABLE_CACHE_DOCUMENTS, 'cd');
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ class CoreRequestBuilder {
|
||||||
'url',
|
'url',
|
||||||
'local_copy',
|
'local_copy',
|
||||||
'resized_copy',
|
'resized_copy',
|
||||||
|
'meta',
|
||||||
'blurhash',
|
'blurhash',
|
||||||
'description',
|
'description',
|
||||||
'public',
|
'public',
|
||||||
|
|
|
@ -986,6 +986,13 @@ class Version1000Date20221118000001 extends SimpleMigrationStep {
|
||||||
'default' => ''
|
'default' => ''
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
$table->addColumn(
|
||||||
|
'meta', Types::TEXT,
|
||||||
|
[
|
||||||
|
'notnull' => true,
|
||||||
|
'default' => '[]'
|
||||||
|
]
|
||||||
|
);
|
||||||
$table->addColumn(
|
$table->addColumn(
|
||||||
'blurhash', Types::STRING,
|
'blurhash', Types::STRING,
|
||||||
[
|
[
|
||||||
|
|
|
@ -81,6 +81,16 @@ class Version1000Date20230217000002 extends SimpleMigrationStep {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$table->hasColumn('meta')) {
|
||||||
|
$table->addColumn(
|
||||||
|
'meta', Types::TEXT,
|
||||||
|
[
|
||||||
|
'notnull' => true,
|
||||||
|
'default' => '[]'
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
if (!$table->hasColumn('blurhash')) {
|
if (!$table->hasColumn('blurhash')) {
|
||||||
$table->addColumn(
|
$table->addColumn(
|
||||||
'blurhash', Types::STRING,
|
'blurhash', Types::STRING,
|
||||||
|
|
|
@ -57,6 +57,7 @@ class Document extends ACore implements JsonSerializable {
|
||||||
private string $localCopy = '';
|
private string $localCopy = '';
|
||||||
private string $resizedCopy = '';
|
private string $resizedCopy = '';
|
||||||
private string $blurHash = '';
|
private string $blurHash = '';
|
||||||
|
private ?AttachmentMeta $meta = null;
|
||||||
private string $description = '';
|
private string $description = '';
|
||||||
private int $caching = 0;
|
private int $caching = 0;
|
||||||
private bool $public = false;
|
private bool $public = false;
|
||||||
|
@ -193,6 +194,16 @@ class Document extends ACore implements JsonSerializable {
|
||||||
return $this->blurHash;
|
return $this->blurHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setMeta(AttachmentMeta $meta): self {
|
||||||
|
$this->meta = $meta;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMeta(): ?AttachmentMeta {
|
||||||
|
return $this->meta;
|
||||||
|
}
|
||||||
|
|
||||||
public function setDescription(string $description): self {
|
public function setDescription(string $description): self {
|
||||||
$this->description = $description;
|
$this->description = $description;
|
||||||
|
|
||||||
|
@ -326,6 +337,12 @@ class Document extends ACore implements JsonSerializable {
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->get('meta', $data) !== '') {
|
||||||
|
$meta = new AttachmentMeta();
|
||||||
|
$meta->import($this->getArray('meta', $data));
|
||||||
|
$this->setMeta($meta);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -375,12 +392,16 @@ class Document extends ACore implements JsonSerializable {
|
||||||
$media->setRemoteUrl($this->getUrl());
|
$media->setRemoteUrl($this->getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
$meta = new AttachmentMeta();
|
if ($this->getMeta() === null) {
|
||||||
$meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize()))
|
$meta = new AttachmentMeta();
|
||||||
->setSmall(new AttachmentMetaDim($this->getResizedCopySize()))
|
$meta->setOriginal(new AttachmentMetaDim($this->getLocalCopySize()))
|
||||||
->setFocus(new AttachmentMetaFocus(0, 0));
|
->setSmall(new AttachmentMetaDim($this->getResizedCopySize()))
|
||||||
|
->setFocus(new AttachmentMetaFocus(0, 0));
|
||||||
|
|
||||||
$media->setMeta($meta)
|
$this->setMeta($meta);
|
||||||
|
}
|
||||||
|
|
||||||
|
$media->setMeta($this->getMeta())
|
||||||
->setDescription($this->getDescription())
|
->setDescription($this->getDescription())
|
||||||
->setBlurHash($this->getBlurHash());
|
->setBlurHash($this->getBlurHash());
|
||||||
|
|
||||||
|
|
|
@ -204,6 +204,23 @@ class AttachmentMeta implements JsonSerializable {
|
||||||
return $this->blurHash;
|
return $this->blurHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function import(array $data): self {
|
||||||
|
$original = new AttachmentMetaDim();
|
||||||
|
$original->import($this->getArray('original', $data));
|
||||||
|
$this->setOriginal($original);
|
||||||
|
|
||||||
|
$small = new AttachmentMetaDim();
|
||||||
|
$small->import($this->getArray('small', $data));
|
||||||
|
$this->setSmall($small);
|
||||||
|
|
||||||
|
$focus = new AttachmentMetaFocus($this->getInt('focus.x', $data), $this->getInt('focus.y', $data));
|
||||||
|
$this->setFocus($focus);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
return array_filter(
|
return array_filter(
|
||||||
[
|
[
|
||||||
|
|
|
@ -30,8 +30,11 @@ declare(strict_types=1);
|
||||||
namespace OCA\Social\Model\Client;
|
namespace OCA\Social\Model\Client;
|
||||||
|
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
use OCA\Social\Tools\Traits\TArrayTools;
|
||||||
|
|
||||||
class AttachmentMetaDim implements JsonSerializable {
|
class AttachmentMetaDim implements JsonSerializable {
|
||||||
|
use TArrayTools;
|
||||||
|
|
||||||
private ?int $width = null;
|
private ?int $width = null;
|
||||||
private ?int $height = null;
|
private ?int $height = null;
|
||||||
private string $size = '';
|
private string $size = '';
|
||||||
|
@ -40,7 +43,11 @@ class AttachmentMetaDim implements JsonSerializable {
|
||||||
private ?float $bitrate = null;
|
private ?float $bitrate = null;
|
||||||
private ?float $frameRate = null;
|
private ?float $frameRate = null;
|
||||||
|
|
||||||
public function __construct(array $dim) {
|
public function __construct(array $dim = []) {
|
||||||
|
if (sizeof($dim) !== 2) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$width = (int)$dim[0];
|
$width = (int)$dim[0];
|
||||||
$height = (int)$dim[1];
|
$height = (int)$dim[1];
|
||||||
|
|
||||||
|
@ -122,6 +129,18 @@ class AttachmentMetaDim implements JsonSerializable {
|
||||||
return $this->frameRate;
|
return $this->frameRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function import(array $data): self {
|
||||||
|
$this->setWidth($this->getInt('width', $data))
|
||||||
|
->setHeight($this->getInt('height', $data))
|
||||||
|
->setSize($this->get('size', $data))
|
||||||
|
->setAspect($this->getFloat('aspect', $data))
|
||||||
|
->setDuration($this->getInt('duration', $data))
|
||||||
|
->setBitrate($this->getInt('bitrate', $data))
|
||||||
|
->setFrameRate($this->getFloat('frame_rate', $data));
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
return array_filter(
|
return array_filter(
|
||||||
[
|
[
|
||||||
|
|
|
@ -32,10 +32,10 @@ namespace OCA\Social\Model\Client;
|
||||||
use JsonSerializable;
|
use JsonSerializable;
|
||||||
|
|
||||||
class AttachmentMetaFocus implements JsonSerializable {
|
class AttachmentMetaFocus implements JsonSerializable {
|
||||||
private ?float $x;
|
private float $x;
|
||||||
private ?float $y;
|
private float $y;
|
||||||
|
|
||||||
public function __construct(?float $x = null, ?float $y = null) {
|
public function __construct(float $x = 0, float $y = 0) {
|
||||||
$this->x = $x;
|
$this->x = $x;
|
||||||
$this->y = $y;
|
$this->y = $y;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ class AttachmentMetaFocus implements JsonSerializable {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getX(): ?float {
|
public function getX(): float {
|
||||||
return $this->x;
|
return $this->x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,16 +56,14 @@ class AttachmentMetaFocus implements JsonSerializable {
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getY(): ?float {
|
public function getY(): float {
|
||||||
return $this->y;
|
return $this->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function jsonSerialize(): array {
|
public function jsonSerialize(): array {
|
||||||
return array_filter(
|
return [
|
||||||
[
|
'x' => $this->getX(),
|
||||||
'x' => $this->getX(),
|
'y' => $this->getY()
|
||||||
'y' => $this->getY()
|
];
|
||||||
]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ class PostService {
|
||||||
$token = $this->activityService->createActivity($actor, $note, $activity);
|
$token = $this->activityService->createActivity($actor, $note, $activity);
|
||||||
$this->accountService->cacheLocalActorDetailCount($actor);
|
$this->accountService->cacheLocalActorDetailCount($actor);
|
||||||
|
|
||||||
$this->miscService->log('Activity: ' . json_encode($activity));
|
$this->logger->debug('Activity: ' . json_encode($activity));
|
||||||
|
|
||||||
return $activity;
|
return $activity;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue