add attachment and parent_id field

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/352/head
Maxence Lange 2019-01-18 14:45:56 -01:00
rodzic 75feeaf24e
commit 059711f28a
5 zmienionych plików z 49 dodań i 5 usunięć

Wyświetl plik

@ -56,6 +56,7 @@ class CacheDocumentsRequest extends CacheDocumentsRequestBuilder {
->setValue('mime_type', $qb->createNamedParameter($document->getMimeType()))
->setValue('error', $qb->createNamedParameter($document->getError()))
->setValue('local_copy', $qb->createNamedParameter($document->getLocalCopy()))
->setValue('parent_id', $qb->createNamedParameter($document->getParentId()))
->setValue('public', $qb->createNamedParameter(($document->isPublic()) ? '1' : '0'))
->setValue(
'creation',

Wyświetl plik

@ -31,6 +31,7 @@ namespace OCA\Social\Db;
use DateTime;
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Model\ActivityPub\ACore;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -87,6 +88,11 @@ class NotesRequest extends NotesRequestBuilder {
)
->setValue('content', $qb->createNamedParameter($note->getContent()))
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
->setValue(
'attachments', $qb->createNamedParameter(
json_encode($note->getAttachments(), JSON_UNESCAPED_SLASHES)
)
)
->setValue('published', $qb->createNamedParameter($note->getPublished()))
->setValue(
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
@ -105,7 +111,10 @@ class NotesRequest extends NotesRequestBuilder {
$qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE)
);
$qb->execute();
try {
$qb->execute();
} catch (UniqueConstraintViolationException $e) {
}
}

Wyświetl plik

@ -82,9 +82,8 @@ class NotesRequestBuilder extends CoreRequestBuilder {
/** @noinspection PhpMethodParametersCountMismatchInspection */
$qb->select(
'sn.id', 'sn.type', 'sn.to', 'sn.to_array', 'sn.cc', 'sn.bcc', 'sn.content',
'sn.summary',
'sn.published', 'sn.published_time', 'sn.attributed_to', 'sn.in_reply_to', 'sn.source',
'sn.local', 'sn.instances', 'sn.creation'
'sn.summary', 'sn.attachments', 'sn.published', 'sn.published_time', 'sn.attributed_to',
'sn.in_reply_to', 'sn.source', 'sn.local', 'sn.instances', 'sn.creation'
)
->from(self::TABLE_SERVER_NOTES, 'sn');

Wyświetl plik

@ -100,6 +100,13 @@ class DocumentInterface implements IActivityPubInterface {
*/
public function save(ACore $item) {
/** @var Document $item */
if ($item->getParent()) {
$item->setParentId(
$item->getParent()
->getId()
);
}
$this->cacheDocumentsRequest->save($item);
}

Wyświetl plik

@ -66,6 +66,8 @@ class Document extends ACore implements JsonSerializable {
/** @var int */
private $error = 0;
/** @var string */
private $parentId = '';
/**
* Document constructor.
@ -155,6 +157,25 @@ class Document extends ACore implements JsonSerializable {
}
/**
* @return string
*/
public function getParentId(): string {
return $this->parentId;
}
/**
* @param string $parentId
*
* @return Document
*/
public function setParentId(string $parentId): Document {
$this->parentId = $parentId;
return $this;
}
/**
* @return int
*/
@ -220,6 +241,7 @@ class Document extends ACore implements JsonSerializable {
$this->setLocalCopy($this->get('local_copy', $data, ''));
$this->setMediaType($this->get('media_type', $data, ''));
$this->setMimeType($this->get('mime_type', $data, ''));
$this->setParentId($this->get('parent_id', $data, ''));
if ($this->get('caching', $data, '') === '') {
$this->setCaching(0);
@ -233,7 +255,7 @@ class Document extends ACore implements JsonSerializable {
* @return array
*/
public function jsonSerialize(): array {
return array_merge(
$result = array_merge(
parent::jsonSerialize(),
[
'mediaType' => $this->getMediaType(),
@ -241,6 +263,12 @@ class Document extends ACore implements JsonSerializable {
'localCopy' => $this->getLocalCopy()
]
);
if ($this->isCompleteDetails()) {
$result['parentId'] = $this->getParentId();
}
return $result;
}
}