kopia lustrzana https://github.com/nextcloud/social
save hashtags and get from database
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/295/head
rodzic
cb7583c68c
commit
47fa5d08f3
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
||||
|
|
|
|||
|
|
@ -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, []));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue