summaryrefslogtreecommitdiffstats
path: root/lib/Service
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-01-02 22:31:25 -0100
committerMaxence Lange <maxence@artificial-owl.com>2019-02-05 15:10:24 -0100
commit01ed889984f710371e65132110fabda875a6f2ad (patch)
tree82fe5d7cc764395aa03aa6c35708706fe16f779f /lib/Service
parentf5da0c0e7e9bb4bb23f390ca770036bd3f061818 (diff)
adding hashtags on post creation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Service')
-rw-r--r--lib/Service/NoteService.php38
-rw-r--r--lib/Service/PostService.php1
2 files changed, 34 insertions, 5 deletions
diff --git a/lib/Service/NoteService.php b/lib/Service/NoteService.php
index 8e444523..af3860f5 100644
--- a/lib/Service/NoteService.php
+++ b/lib/Service/NoteService.php
@@ -212,7 +212,8 @@ class NoteService {
$note->addTag(
[
'type' => 'Mention',
- 'href' => $actor->getId()
+ 'href' => $actor->getId(),
+ 'name' => '@' . $account
]
);
@@ -222,14 +223,30 @@ class NoteService {
/**
* @param Note $note
+ * @param string $hashtag
+ */
+ public function addHashtag(Note $note, string $hashtag) {
+ try {
+ $note->addTag(
+ [
+ 'type' => 'Hashtag',
+ 'href' => $this->configService->getCloudAddress() . '/tag/' . strtolower(
+ $hashtag
+ ),
+ 'name' => '#' . $hashtag
+ ]
+ );
+ } catch (SocialAppConfigException $e) {
+ }
+ }
+
+
+ /**
+ * @param Note $note
* @param string $type
* @param array $accounts
*/
public function addRecipients(Note $note, string $type, array $accounts) {
- if ($accounts === []) {
- return;
- }
-
foreach ($accounts as $account) {
$this->addRecipient($note, $type, $account);
}
@@ -238,6 +255,17 @@ class NoteService {
/**
* @param Note $note
+ * @param array $hashtags
+ */
+ public function addHashtags(Note $note, array $hashtags) {
+ foreach ($hashtags as $hashtag) {
+ $this->addHashtag($note, $hashtag);
+ }
+ }
+
+
+ /**
+ * @param Note $note
* @param string $replyTo
*
* @throws InvalidOriginException
diff --git a/lib/Service/PostService.php b/lib/Service/PostService.php
index 89c0f603..817ddc40 100644
--- a/lib/Service/PostService.php
+++ b/lib/Service/PostService.php
@@ -104,6 +104,7 @@ class PostService {
$this->noteService->replyTo($note, $post->getReplyTo());
$this->noteService->addRecipients($note, $post->getType(), $post->getTo());
+ $this->noteService->addHashtags($note, $post->getHashtags());
$result = $this->activityService->createActivity($post->getActor(), $note, $activity);
$this->accountService->cacheLocalActorDetailCount($post->getActor());