diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 306c85ff..af5bd63f 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -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) diff --git a/lib/Db/NotesRequestBuilder.php b/lib/Db/NotesRequestBuilder.php index 5d770ddd..c8c8868f 100644 --- a/lib/Db/NotesRequestBuilder.php +++ b/lib/Db/NotesRequestBuilder.php @@ -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'); diff --git a/lib/Model/ActivityPub/ACore.php b/lib/Model/ActivityPub/ACore.php index b11cec61..4f981840 100644 --- a/lib/Model/ActivityPub/ACore.php +++ b/lib/Model/ActivityPub/ACore.php @@ -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, [])); } diff --git a/lib/Model/ActivityPub/Item.php b/lib/Model/ActivityPub/Item.php index 2cc0beb5..f6f04af1 100644 --- a/lib/Model/ActivityPub/Item.php +++ b/lib/Model/ActivityPub/Item.php @@ -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; } /** diff --git a/lib/Model/ActivityPub/Object/Note.php b/lib/Model/ActivityPub/Object/Note.php index 0efb3ac4..71501f26 100644 --- a/lib/Model/ActivityPub/Object/Note.php +++ b/lib/Model/ActivityPub/Object/Note.php @@ -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; } }