kopia lustrzana https://github.com/nextcloud/social
adding hashtags on post creation
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/295/head
rodzic
f5da0c0e7e
commit
01ed889984
lib
Command
Controller
Model
|
@ -108,6 +108,10 @@ class NoteCreate extends Base {
|
|||
'type', 'y', InputOption::VALUE_OPTIONAL,
|
||||
'type: public (default), followers, unlisted, direct'
|
||||
)
|
||||
->addOption(
|
||||
'hashtag', 'g', InputOption::VALUE_OPTIONAL,
|
||||
'hashtag, without the leading #'
|
||||
)
|
||||
->addArgument('userid', InputArgument::REQUIRED, 'userId of the author')
|
||||
->addArgument('content', InputArgument::REQUIRED, 'content of the post')
|
||||
->setDescription('Create a new note');
|
||||
|
@ -125,6 +129,7 @@ class NoteCreate extends Base {
|
|||
$userId = $input->getArgument('userid');
|
||||
$content = $input->getArgument('content');
|
||||
$to = $input->getOption('to');
|
||||
$hashtag = $input->getOption('hashtag');
|
||||
$replyTo = $input->getOption('replyTo');
|
||||
$type = $input->getOption('type');
|
||||
|
||||
|
@ -134,6 +139,7 @@ class NoteCreate extends Base {
|
|||
$post->setType(($type === null) ? '' : $type);
|
||||
$post->setReplyTo(($replyTo === null) ? '' : $replyTo);
|
||||
$post->addTo(($to === null) ? '' : $to);
|
||||
$post->setHashtags(($hashtag === null) ? [] : [$hashtag]);
|
||||
|
||||
$token = $this->postService->createPost($post, $activity);
|
||||
|
||||
|
|
|
@ -147,6 +147,7 @@ class LocalController extends Controller {
|
|||
$post->setTo($this->getArray('to', $data, []));
|
||||
$post->addTo($this->get('to', $data, ''));
|
||||
$post->setType($this->get('type', $data, Note::TYPE_PUBLIC));
|
||||
$post->setHashtags($this->getArray('hashtags', $data, []));
|
||||
|
||||
/** @var ACore $activity */
|
||||
$token = $this->postService->createPost($post, $activity);
|
||||
|
|
|
@ -61,6 +61,9 @@ class Post implements JsonSerializable {
|
|||
/** @var string */
|
||||
private $type = '';
|
||||
|
||||
/** @var array */
|
||||
private $hashtags = [];
|
||||
|
||||
|
||||
/**
|
||||
* Post constructor.
|
||||
|
@ -148,6 +151,25 @@ class Post implements JsonSerializable {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHashtags(): array {
|
||||
return $this->hashtags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $hashtags
|
||||
*
|
||||
* @return Post
|
||||
*/
|
||||
public function setHashtags(array $hashtags): Post {
|
||||
$this->hashtags = $hashtags;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -212,7 +212,8 @@ class NoteService {
|
|||
$note->addTag(
|
||||
[
|
||||
'type' => 'Mention',
|
||||
'href' => $actor->getId()
|
||||
'href' => $actor->getId(),
|
||||
'name' => '@' . $account
|
||||
]
|
||||
);
|
||||
|
||||
|
@ -220,22 +221,49 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
|
|
|
@ -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());
|
||||
|
|
Ładowanie…
Reference in New Issue