Merge branch 'stCyr_fixHashtags' of https://github.com/StCyr/social into stCyr_fixHashtags

pull/666/head
Cyrille Bollu 2019-08-01 15:44:08 +02:00
commit 889eaa9115
7 zmienionych plików z 29 dodań i 18 usunięć

Wyświetl plik

@ -810,7 +810,7 @@ class LocalController extends Controller {
}
try {
$tags = $this->hashtagService->searchHashtags($search);
$tags = $this->hashtagService->searchHashtags($search, false);
return $this->success(['tags' => $tags, 'exact' => $match]);
} catch (Exception $e) {

Wyświetl plik

@ -37,7 +37,6 @@ use Doctrine\DBAL\Query\QueryBuilder;
use Exception;
use OC\DB\SchemaWrapper;
use OCA\Social\AP;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Actor\Person;
@ -307,10 +306,13 @@ class CoreRequestBuilder {
*
* @param IQueryBuilder $qb
* @param string $hashtag
* @param bool $all
*/
protected function searchInHashtag(IQueryBuilder &$qb, string $hashtag) {
protected function searchInHashtag(IQueryBuilder &$qb, string $hashtag, bool $all = false) {
$dbConn = $this->dbConnection;
$this->searchInDBField($qb, 'hashtag', '%' . $dbConn->escapeLikeParameter($hashtag) . '%');
$this->searchInDBField(
$qb, 'hashtag', (($all) ? '%' : '') . $dbConn->escapeLikeParameter($hashtag) . '%'
);
}

Wyświetl plik

@ -118,12 +118,13 @@ class HashtagsRequest extends HashtagsRequestBuilder {
/**
* @param string $hashtag
* @param bool $all
*
* @return array
*/
public function searchHashtags(string $hashtag): array {
public function searchHashtags(string $hashtag, bool $all): array {
$qb = $this->getHashtagsSelectSql();
$this->searchInHashtag($qb, $hashtag);
$this->searchInHashtag($qb, $hashtag, $all);
$this->limitResults($qb, 25);
$hashtags = [];

Wyświetl plik

@ -36,6 +36,8 @@ use OCA\Social\Db\HashtagsRequest;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\DateTimeException;
use OCA\Social\Exceptions\HashtagDoesNotExistException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Model\ActivityPub\Object\Note;
use OCA\Social\Model\ActivityPub\Stream;
@ -100,6 +102,8 @@ class HashtagService {
/**
* @return int
* @throws DateTimeException
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
public function manageHashtags(): int {
$current = $this->hashtagsRequest->getAll();
@ -146,11 +150,12 @@ class HashtagService {
/**
* @param string $hashtag
* @param bool $all
*
* @return array
*/
public function searchHashtags(string $hashtag): array {
return $this->hashtagsRequest->searchHashtags($hashtag);
public function searchHashtags(string $hashtag, bool $all = false): array {
return $this->hashtagsRequest->searchHashtags($hashtag, $all);
}
@ -159,6 +164,8 @@ class HashtagService {
*
* @return Stream[]
* @throws DateTimeException
* @throws ItemUnknownException
* @throws SocialAppConfigException
*/
private function getTrendSince(int $timestamp): array {
$result = [];

Wyświetl plik

@ -139,7 +139,7 @@ class SearchService {
}
try {
$hashtags = $this->hashtagService->searchHashtags($search);
$hashtags = $this->hashtagService->searchHashtags($search, true);
$result['result'] = $hashtags;
} catch (Exception $e) {
}

Wyświetl plik

@ -386,7 +386,7 @@ export default {
},
values: (text, cb) => {
let users = []
if (text.length < 1) {
cb(users)
}
@ -419,7 +419,7 @@ export default {
return item.original.value
},
selectTemplate: function(item) {
let tag = '';
let tag = ''
// item is undefined if selectTemplate is called from a noMatchTemplate menu
if (typeof item === 'undefined') {
tag = this.currentMentionTextSnapshot
@ -431,7 +431,7 @@ export default {
},
values: (text, cb) => {
let tags = []
if (text.length < 1) {
cb(tags)
}
@ -439,14 +439,14 @@ export default {
if (result.data.result.exact) {
tags.push({
key: result.data.result.exact,
value: result.data.result.exact,
value: result.data.result.exact
})
}
for (var i in result.data.result.tags) {
let tag = result.data.result.tags[i]
tags.push({
key: tag.hashtag,
value: tag.hashtag,
value: tag.hashtag
})
}
cb(tags)
@ -455,12 +455,13 @@ export default {
}
],
noMatchTemplate() {
if (this.current.collection.trigger === "#")
if (this.current.collection.trigger === '#') {
if (this.current.mentionText === '') {
return undefined
} else {
return '<li data-index="0">#' + this.current.mentionText + '</li>';
return '<li data-index="0">#' + this.current.mentionText + '</li>'
}
}
}
},
menuOpened: false

Wyświetl plik

@ -141,8 +141,8 @@ export default {
mangleHashtags(msg) {
// Replace hashtag's href parameter with local ones
this.item.hashtags.forEach(tag => {
let patt = new RegExp("#" + tag, "gi")
msg = msg.replace( patt, function(matched) {
let patt = new RegExp('#' + tag, 'gi')
msg = msg.replace(patt, function(matched) {
var a = '<a href="' + OC.generateUrl('/apps/social/timeline/tags/' + matched.substring(1)) + '">' + matched + '</a>'
return a
})