summaryrefslogtreecommitdiffstats
path: root/lib/Model
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-01-04 18:34:19 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-02-05 15:10:24 -0100
commit47fa5d08f30836c5ddeb4a5952effb1f16df6fca (patch)
treeb0c0b6326ba96e87d1f0b7d7e54e7606049659b7 /lib/Model
parentcb7583c68c84de1d2e358c14db84f541d12ac7d4 (diff)
save hashtags and get from database
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Model')
-rw-r--r--lib/Model/ActivityPub/ACore.php2
-rw-r--r--lib/Model/ActivityPub/Item.php21
-rw-r--r--lib/Model/ActivityPub/Object/Note.php53
3 files changed, 69 insertions, 7 deletions
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 = '';
@@ -97,6 +100,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
*/
public function getAttributedTo(): string {
@@ -199,6 +221,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
*/
public function import(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;
}
}