kopia lustrzana https://github.com/nextcloud/social
fix mention based on content
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>pull/977/head
rodzic
2194c11b76
commit
0da568f56b
|
@ -411,7 +411,9 @@ class Item {
|
|||
* @return Item
|
||||
*/
|
||||
public function addToArray(string $to): Item {
|
||||
$this->toArray[] = $to;
|
||||
if (!in_array($to, $this->toArray)) {
|
||||
$this->toArray[] = $to;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -113,7 +113,7 @@ class Note extends Stream implements JsonSerializable {
|
|||
if (substr($hashtag, 0, 1) === '#') {
|
||||
$hashtag = substr($hashtag, 1);
|
||||
}
|
||||
$hashtags[] = $hashtag;
|
||||
$hashtags[] = trim($hashtag);
|
||||
}
|
||||
|
||||
$this->setHashtags($hashtags);
|
||||
|
|
|
@ -94,7 +94,8 @@ class Post implements JsonSerializable {
|
|||
* @return Post
|
||||
*/
|
||||
public function addTo(string $to): Post {
|
||||
if ($to !== '') {
|
||||
$to = trim($to);
|
||||
if ($to !== '' && !in_array($to, $this->to)) {
|
||||
$this->to[] = $to;
|
||||
}
|
||||
|
||||
|
@ -175,6 +176,14 @@ class Post implements JsonSerializable {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function addHashtag(string $hashtag): Post {
|
||||
$hashtag = trim($hashtag);
|
||||
if ($hashtag !== '' && !in_array($hashtag, $this->hashtags)) {
|
||||
$this->hashtags[] = $hashtag;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
|
|
|
@ -31,6 +31,11 @@ namespace OCA\Social\Service;
|
|||
|
||||
|
||||
use daita\MySmallPhpTools\Exceptions\MalformedArrayException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestContentException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use Exception;
|
||||
use OCA\Social\AP;
|
||||
use OCA\Social\Exceptions\CacheContentMimeTypeException;
|
||||
|
@ -38,11 +43,6 @@ use OCA\Social\Exceptions\InvalidOriginException;
|
|||
use OCA\Social\Exceptions\InvalidResourceException;
|
||||
use OCA\Social\Exceptions\ItemUnknownException;
|
||||
use OCA\Social\Exceptions\RedundancyLimitException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestContentException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestNetworkException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultNotJsonException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestResultSizeException;
|
||||
use daita\MySmallPhpTools\Exceptions\RequestServerException;
|
||||
use OCA\Social\Exceptions\SocialAppConfigException;
|
||||
use OCA\Social\Exceptions\StreamNotFoundException;
|
||||
use OCA\Social\Exceptions\UnauthorizedFediverseException;
|
||||
|
@ -119,6 +119,8 @@ class PostService {
|
|||
* @throws UnauthorizedFediverseException
|
||||
*/
|
||||
public function createPost(Post $post, &$token = ''): ACore {
|
||||
$this->fixRecipientAndHashtags($post);
|
||||
|
||||
$note = new Note();
|
||||
$actor = $post->getActor();
|
||||
$this->streamService->assignItem($note, $actor, $post->getType());
|
||||
|
@ -192,5 +194,22 @@ class PostService {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Post $post
|
||||
*/
|
||||
public function fixRecipientAndHashtags(Post $post) {
|
||||
preg_match_all('/(?!\b)@([^\s]+)/', $post->getContent(), $matchesTo);
|
||||
preg_match_all('/(?!\b)#([^\s]+)/', $post->getContent(), $matchesHash);
|
||||
|
||||
foreach ($matchesTo[1] as $to) {
|
||||
$post->addTo($to);
|
||||
}
|
||||
|
||||
foreach ($matchesHash[1] as $hash) {
|
||||
$post->addHashtag($hash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ class StreamService {
|
|||
}
|
||||
|
||||
try {
|
||||
$actor = $this->cacheActorService->getFromAccount($account);
|
||||
$actor = $this->cacheActorService->getFromAccount($account, true);
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ class StreamService {
|
|||
if ($type === Stream::TYPE_DIRECT) {
|
||||
$instancePath->setPriority(InstancePath::PRIORITY_HIGH);
|
||||
$stream->addToArray($actor->getId());
|
||||
$stream->setFilterDuplicate(true);
|
||||
$stream->setFilterDuplicate(true); // TODO: really needed ?
|
||||
} else {
|
||||
$stream->addCc($actor->getId());
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue