get stream for hashtag

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/295/head
Maxence Lange 2019-01-04 18:42:58 -01:00
rodzic 47fa5d08f3
commit c7d1da1f53
4 zmienionych plików z 71 dodań i 1 usunięć

Wyświetl plik

@ -59,6 +59,7 @@ return [
['name' => 'Local#streamHome', 'url' => '/api/v1/stream/home', 'verb' => 'GET'],
['name' => 'Local#streamNotifications', 'url' => '/api/v1/stream/notifications', 'verb' => 'GET'],
['name' => 'Local#streamTimeline', 'url' => '/api/v1/stream/timeline', 'verb' => 'GET'],
['name' => 'Local#streamTag', 'url' => '/api/v1/stream/tag/{hashtag}/', 'verb' => 'GET'],
['name' => 'Local#streamFederated', 'url' => '/api/v1/stream/federated', 'verb' => 'GET'],
['name' => 'Local#streamDirect', 'url' => '/api/v1/stream/direct', 'verb' => 'GET'],
['name' => 'Local#streamAccount', 'url' => '/api/v1/account/{username}/stream', 'verb' => 'GET'],

Wyświetl plik

@ -295,6 +295,30 @@ class LocalController extends Controller {
}
}
/**
* Get timeline
*
* @NoCSRFRequired
* @NoAdminRequired
*
* @param int $since
* @param int $limit
*
* @return DataResponse
*/
public function streamTag(string $hashtag, int $since = 0, int $limit = 5): DataResponse {
try {
$posts = $this->noteService->getStreamLocalTag($hashtag, $since, $limit);
return $this->success($posts);
} catch (Exception $e) {
return $this->fail($e);
}
}
/**
* Get timeline
*

Wyświetl plik

@ -87,7 +87,7 @@ class NotesRequest extends NotesRequestBuilder {
)
->setValue('content', $qb->createNamedParameter($note->getContent()))
->setValue('summary', $qb->createNamedParameter($note->getSummary()))
->setValue('hashtags', $qb->createNamedParameter(json_encode($note->getHashtags())))
->setValue('hashtags', $qb->createNamedParameter(json_encode($note->getHashtags())))
->setValue('published', $qb->createNamedParameter($note->getPublished()))
->setValue(
'published_time', $qb->createNamedParameter($dTime, IQueryBuilder::PARAM_DATE)
@ -307,6 +307,39 @@ class NotesRequest extends NotesRequestBuilder {
}
/**
* Should returns:
* - All public post related to a tag (not yet)
* - direct message related to a tag (not yet)
* - message to followers related to a tag (not yet)
*
* @param string $hashtag
* @param int $since
* @param int $limit
*
* @return array
*/
public function getStreamTag(string $hashtag, int $since = 0, int $limit = 5): array {
$qb = $this->getNotesSelectSql();
// // TODO: LIMIT TO NOTE RELATED TO THE VIEWER+PUBLIC
$this->limitPaginate($qb, $since, $limit);
$qb->andWhere($this->exprValueWithinJsonFormat($qb, 'hashtags', '#' . $hashtag));
$this->leftJoinCacheActors($qb, 'attributed_to');
$notes = [];
$cursor = $qb->execute();
while ($data = $cursor->fetch()) {
$notes[] = $this->parseNotesSelectSql($data);
}
$cursor->closeCursor();
return $notes;
}
/**
* @param string $id
*/

Wyświetl plik

@ -383,6 +383,18 @@ class NoteService {
}
/**
* @param string $hashtag
* @param int $since
* @param int $limit
*
* @return Note[]
*/
public function getStreamLocalTag(string $hashtag, int $since = 0, int $limit = 5): array {
return $this->notesRequest->getStreamTag($hashtag, $since, $limit);
}
/**
* @param int $since
* @param int $limit