moving Person $actor around instead of $actorId

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/143/head
Maxence Lange 2018-12-06 18:18:12 -01:00
rodzic 296f8b3540
commit c41c43c529
4 zmienionych plików z 23 dodań i 17 usunięć

Wyświetl plik

@ -208,7 +208,7 @@ class LocalController extends Controller {
public function streamHome($since = 0, int $limit = 5): DataResponse { public function streamHome($since = 0, int $limit = 5): DataResponse {
try { try {
$this->initViewer(true); $this->initViewer(true);
$posts = $this->noteService->getStreamHome($this->viewer->getId(), $since, $limit); $posts = $this->noteService->getStreamHome($this->viewer, $since, $limit);
return $this->success($posts); return $this->success($posts);
} catch (Exception $e) { } catch (Exception $e) {
@ -259,7 +259,7 @@ class LocalController extends Controller {
public function streamDirect(int $since = 0, int $limit = 5): DataResponse { public function streamDirect(int $since = 0, int $limit = 5): DataResponse {
try { try {
$this->initViewer(); $this->initViewer();
$posts = $this->noteService->getStreamDirect($this->viewer->getId(), $since, $limit); $posts = $this->noteService->getStreamDirect($this->viewer, $since, $limit);
return $this->success($posts); return $this->success($posts);
} catch (Exception $e) { } catch (Exception $e) {

Wyświetl plik

@ -33,6 +33,7 @@ namespace OCA\Social\Db;
use DateTime; use DateTime;
use OCA\Social\Exceptions\NoteNotFoundException; use OCA\Social\Exceptions\NoteNotFoundException;
use OCA\Social\Model\ActivityPub\Note; use OCA\Social\Model\ActivityPub\Note;
use OCA\Social\Model\ActivityPub\Person;
use OCA\Social\Service\ActivityService; use OCA\Social\Service\ActivityService;
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
use OCA\Social\Service\MiscService; use OCA\Social\Service\MiscService;
@ -160,16 +161,16 @@ class NotesRequest extends NotesRequestBuilder {
* * Own posts, * * Own posts,
* * Followed accounts * * Followed accounts
* *
* @param string $actorId * @param Person $actor
* @param int $since * @param int $since
* @param int $limit * @param int $limit
* *
* @return array * @return array
*/ */
public function getStreamHome(string $actorId, int $since = 0, int $limit = 5): array { public function getStreamHome(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getNotesSelectSql(); $qb = $this->getNotesSelectSql();
$this->rightJoinFollowing($qb, $actorId); $this->joinFollowing($qb, $actor);
$this->limitPaginate($qb, $since, $limit); $this->limitPaginate($qb, $since, $limit);
$this->leftJoinCacheActors($qb, 'attributed_to'); $this->leftJoinCacheActors($qb, 'attributed_to');
@ -218,17 +219,21 @@ class NotesRequest extends NotesRequestBuilder {
* * Private message. * * Private message.
* - group messages. * - group messages.
* *
* @param string $actorId * @param Person $actor
* @param int $since * @param int $since
* @param int $limit * @param int $limit
* *
* @return array * @return array
*/ */
public function getStreamDirect(string $actorId, int $since = 0, int $limit = 5): array { public function getStreamDirect(Person $actor, int $since = 0, int $limit = 5): array {
$qb = $this->getNotesSelectSql(); $qb = $this->getNotesSelectSql();
$this->limitPaginate($qb, $since, $limit); $this->limitPaginate($qb, $since, $limit);
$this->limitToRecipient($qb, $actor->getId(), true);
$this->filterToRecipient($qb, ActivityService::TO_PUBLIC);
$this->filterToRecipient($qb, $actor->getFollowers());
$this->leftJoinCacheActors($qb, 'attributed_to'); $this->leftJoinCacheActors($qb, 'attributed_to');
$this->limitToRecipient($qb, $actorId, true);
$notes = []; $notes = [];
$cursor = $qb->execute(); $cursor = $qb->execute();

Wyświetl plik

@ -35,7 +35,9 @@ use DateTime;
use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Query\QueryBuilder;
use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Note; use OCA\Social\Model\ActivityPub\Note;
use OCA\Social\Model\ActivityPub\Person;
use OCA\Social\Model\InstancePath; use OCA\Social\Model\InstancePath;
use OCP\DB\QueryBuilder\ICompositeExpression;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
class NotesRequestBuilder extends CoreRequestBuilder { class NotesRequestBuilder extends CoreRequestBuilder {
@ -124,9 +126,9 @@ class NotesRequestBuilder extends CoreRequestBuilder {
/** /**
* @param IQueryBuilder $qb * @param IQueryBuilder $qb
* @param string $actorId * @param Person $actor
*/ */
protected function rightJoinFollowing(IQueryBuilder $qb, string $actorId = '') { protected function joinFollowing(IQueryBuilder $qb, Person $actor) {
if ($qb->getType() !== QueryBuilder::SELECT) { if ($qb->getType() !== QueryBuilder::SELECT) {
return; return;
} }

Wyświetl plik

@ -350,15 +350,14 @@ class NoteService implements ICoreService {
/** /**
* @param string $actorId * @param Person $actor
*
* @param int $since * @param int $since
* @param int $limit * @param int $limit
* *
* @return Note[] * @return Note[]
*/ */
public function getStreamHome(string $actorId, int $since = 0, int $limit = 5): array { public function getStreamHome(Person $actor, int $since = 0, int $limit = 5): array {
return $this->notesRequest->getStreamHome($actorId, $since, $limit); return $this->notesRequest->getStreamHome($actor, $since, $limit);
} }
@ -375,14 +374,14 @@ class NoteService implements ICoreService {
/** /**
* @param string $actorId * @param Person $actor
* @param int $since * @param int $since
* @param int $limit * @param int $limit
* *
* @return Note[] * @return Note[]
*/ */
public function getStreamDirect(string $actorId, int $since = 0, int $limit = 5): array { public function getStreamDirect(Person $actor, int $since = 0, int $limit = 5): array {
return $this->notesRequest->getStreamDirect($actorId, $since, $limit); return $this->notesRequest->getStreamDirect($actor, $since, $limit);
} }