save hashtags and get from database

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/295/head
Maxence Lange 2019-01-04 18:34:19 -01:00
rodzic cb7583c68c
commit 47fa5d08f3
5 zmienionych plików z 72 dodań i 10 usunięć

Wyświetl plik

@ -87,6 +87,7 @@ class NotesRequest extends NotesRequestBuilder {
)
->setValue('content', $qb->createNamedParameter($note->getContent()))
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
->setValue('hashtags', $qb->createNamedParameter(json_encode($note->getHashtags())))
->setValue('published', $qb->createNamedParameter($note->getPublished()))
->setValue(
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)

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.hashtags', '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

@ -559,7 +559,7 @@ class ACore extends Item implements JsonSerializable {
$this->setPublished($this->validate(self::AS_DATE, 'published', $data, ''));
$this->setActorId($this->validate(self::AS_ID, 'actor', $data, ''));
$this->setObjectId($this->validate(self::AS_ID, 'object', $data, ''));
$this->setTags($this->validateArray(self::AS_TAGS, 'tags', $data, []));
$this->setTags($this->validateArray(self::AS_TAGS, 'tag', $data, []));
}

Wyświetl plik

@ -30,6 +30,7 @@ declare(strict_types=1);
namespace OCA\Social\Model\ActivityPub;
use daita\MySmallPhpTools\Traits\TArrayTools;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Model\InstancePath;
@ -37,6 +38,9 @@ use OCA\Social\Model\InstancePath;
class Item {
use TArrayTools;
/** @var string */
private $urlSocial = '';
@ -502,10 +506,23 @@ class Item {
}
/**
* @param string $type
*
* @return array
*/
public function getTags(): array {
return $this->tags;
public function getTags(string $type = ''): array {
if ($type === '') {
return $this->tags;
}
$result = [];
foreach ($this->tags as $tag) {
if ($this->get('type', $tag, '') === $type) {
$result[] = $tag;
}
}
return $result;
}
/**

Wyświetl plik

@ -49,6 +49,9 @@ class Note extends ACore implements JsonSerializable {
/** @var string */
private $content = '';
/** @var array */
private $hashtags = [];
/** @var string */
private $attributedTo = '';
@ -96,6 +99,25 @@ class Note extends ACore implements JsonSerializable {
}
/**
* @return array
*/
public function getHashtags(): array {
return $this->hashtags;
}
/**
* @param array $hashtags
*
* @return Note
*/
public function setHashtags(array $hashtags): Note {
$this->hashtags = $hashtags;
return $this;
}
/**
* @return string
*/
@ -198,6 +220,20 @@ class Note extends ACore implements JsonSerializable {
}
/**
*
*/
public function fillHashtags() {
$tags = $this->getTags('Hashtag');
$hashtags = [];
foreach ($tags as $tag) {
$hashtags[] = $tag['name'];
}
$this->setHashtags($hashtags);
}
/**
* @param array $data
*/
@ -210,6 +246,8 @@ class Note extends ACore implements JsonSerializable {
$this->setConversation($this->validate(ACore::AS_ID, 'conversation', $data, ''));
$this->setContent($this->get('content', $data, ''));
$this->convertPublished();
$this->fillHashtags();
}
@ -226,6 +264,7 @@ class Note extends ACore implements JsonSerializable {
$this->setPublishedTime($dTime->getTimestamp());
$this->setAttributedTo($this->validate(self::AS_ID, 'attributed_to', $data, ''));
$this->setInReplyTo($this->validate(self::AS_ID, 'in_reply_to', $data));
$this->setHashtags($this->getArray('hashtags', $data, []));
}
@ -235,16 +274,22 @@ class Note extends ACore implements JsonSerializable {
public function jsonSerialize(): array {
$this->addEntryInt('publishedTime', $this->getPublishedTime());
return array_merge(
$result = array_merge(
parent::jsonSerialize(),
[
'content' => $this->getContent(),
'content' => $this->getContent(),
'attributedTo' => $this->getUrlSocial() . $this->getAttributedTo(),
'inReplyTo' => $this->getInReplyTo(),
'sensitive' => $this->isSensitive(),
'inReplyTo' => $this->getInReplyTo(),
'sensitive' => $this->isSensitive(),
'conversation' => $this->getConversation()
]
);
if ($this->isCompleteDetails()) {
$result['hashtags'] = $this->getHashtags();
}
return $result;
}
}