diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 9db10b90..b6e0780e 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -218,10 +218,10 @@ class CoreRequestBuilder { * * @param IQueryBuilder $qb * @param bool $accepted + * @param string $alias */ - protected function limitToAccepted(IQueryBuilder &$qb, bool $accepted) { - $this->limitToDBField($qb, 'accepted', ($accepted) ? '1' : '0'); - + protected function limitToAccepted(IQueryBuilder &$qb, bool $accepted, string $alias = '') { + $this->limitToDBField($qb, 'accepted', ($accepted) ? '1' : '0', true, $alias); } @@ -458,13 +458,37 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param string $field * @param int $value + * @param string $alias */ - protected function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) { + protected function limitToDBFieldInt( + IQueryBuilder &$qb, string $field, int $value, string $alias = '' + ) { + $expr = $this->exprLimitToDBFieldInt($qb, $field, $value, $alias); + $qb->andWhere($expr); + } + + + /** + * @param IQueryBuilder $qb + * @param string $field + * @param int $value + * @param string $alias + * + * @return string + */ + protected function exprLimitToDBFieldInt( + IQueryBuilder &$qb, string $field, int $value, string $alias = '' + ): string { $expr = $qb->expr(); - $pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : ''; + + $pf = ''; + if ($qb->getType() === QueryBuilder::SELECT) { + $pf = (($alias === '') ? $this->defaultSelectAlias : $alias) . '.'; + } $field = $pf . $field; - $qb->andWhere($expr->eq($field, $qb->createNamedParameter($value))); + + return $expr->eq($field, $qb->createNamedParameter($value)); } @@ -688,6 +712,7 @@ class CoreRequestBuilder { } $andX = $expr->andX(); + $andX->add($this->exprLimitToDBFieldInt($qb, 'accepted', 1, $prefix . '_f')); if ($asFollower === true) { $andX->add( $expr->eq( diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index 4861b878..708f2513 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -152,6 +152,7 @@ class FollowsRequest extends FollowsRequestBuilder { public function getByFollowId(string $followId): array { $qb = $this->getFollowsSelectSql(); $this->limitToFollowId($qb, $followId); + $this->limitToAccepted($qb, true); $this->leftJoinCacheActors($qb, 'actor_id'); $follows = []; @@ -173,6 +174,7 @@ class FollowsRequest extends FollowsRequestBuilder { public function getFollowersByActorId(string $actorId): array { $qb = $this->getFollowsSelectSql(); $this->limitToOBjectId($qb, $actorId); + $this->limitToAccepted($qb, true); $this->leftJoinCacheActors($qb, 'actor_id'); $this->leftJoinDetails($qb, 'id', 'ca'); $qb->orderBy('creation', 'desc'); @@ -196,6 +198,7 @@ class FollowsRequest extends FollowsRequestBuilder { public function getFollowingByActorId(string $actorId): array { $qb = $this->getFollowsSelectSql(); $this->limitToActorId($qb, $actorId); + $this->limitToAccepted($qb, true); $this->leftJoinCacheActors($qb, 'object_id'); $this->leftJoinDetails($qb, 'id', 'ca'); $qb->orderBy('creation', 'desc'); diff --git a/lib/Db/FollowsRequestBuilder.php b/lib/Db/FollowsRequestBuilder.php index 25c0686a..01e08442 100644 --- a/lib/Db/FollowsRequestBuilder.php +++ b/lib/Db/FollowsRequestBuilder.php @@ -83,7 +83,9 @@ class FollowsRequestBuilder extends CoreRequestBuilder { $qb = $this->dbConnection->getQueryBuilder(); /** @noinspection PhpMethodParametersCountMismatchInspection */ - $qb->select('f.id', 'f.type', 'f.actor_id', 'f.object_id', 'f.follow_id', 'f.creation') + $qb->select( + 'f.id', 'f.type', 'f.actor_id', 'f.object_id', 'f.follow_id', 'f.accepted', 'f.creation' + ) ->from(self::TABLE_SERVER_FOLLOWS, 'f'); $this->defaultSelectAlias = 'f'; diff --git a/lib/Db/NotesRequest.php b/lib/Db/NotesRequest.php index 36e3e930..cc3fd342 100644 --- a/lib/Db/NotesRequest.php +++ b/lib/Db/NotesRequest.php @@ -156,17 +156,22 @@ class NotesRequest extends NotesRequestBuilder { /** + * Should returns: + * * Own posts, + * * Followed accounts + * * @param string $actorId * @param int $since * @param int $limit * * @return array */ - public function getHomeNotesForActorId(string $actorId, int $since = 0, int $limit = 5): array { + public function getStreamHome(string $actorId, int $since = 0, int $limit = 5): array { $qb = $this->getNotesSelectSql(); $this->rightJoinFollowing($qb); $this->limitToActorId($qb, $actorId, 'f'); + $this->limitToAccepted($qb, true, 'f'); $qb->orWhere($this->exprLimitToDBField($qb, 'attributed_to', $actorId)); $this->limitPaginate($qb, $since, $limit); @@ -184,19 +189,20 @@ class NotesRequest extends NotesRequestBuilder { /** + * Should returns: + * * Private message. + * - group messages. + + * @param string $actorId * @param int $since * @param int $limit - * @param bool $localOnly * * @return array */ - public function getPublicNotes(int $since = 0, int $limit = 5, bool $localOnly = true): array { + public function getStreamDirect(string $actorId, int $since = 0, int $limit = 5): array { $qb = $this->getNotesSelectSql(); - $this->limitToRecipient($qb, ActivityService::TO_PUBLIC); + $this->limitToRecipient($qb, $actorId, true); $this->limitPaginate($qb, $since, $limit); - if ($localOnly) { - $this->limitToLocal($qb, true); - } $this->leftJoinCacheActors($qb, 'attributed_to'); $notes = []; @@ -211,17 +217,23 @@ class NotesRequest extends NotesRequestBuilder { /** - * @param string $actorId + * Should returns: + * - All local public/federated posts + * * @param int $since * @param int $limit + * @param bool $localOnly * * @return array */ - public function getDirectNotesForActorId(string $actorId, int $since = 0, int $limit = 5 + public function getStreamTimeline(int $since = 0, int $limit = 5, bool $localOnly = true ): array { $qb = $this->getNotesSelectSql(); - $this->limitToRecipient($qb, $actorId, true); + $this->limitToRecipient($qb, ActivityService::TO_PUBLIC); $this->limitPaginate($qb, $since, $limit); + if ($localOnly) { + $this->limitToLocal($qb, true); + } $this->leftJoinCacheActors($qb, 'attributed_to'); $notes = []; diff --git a/lib/Model/ActivityPub/Follow.php b/lib/Model/ActivityPub/Follow.php index 26546265..e6e22738 100644 --- a/lib/Model/ActivityPub/Follow.php +++ b/lib/Model/ActivityPub/Follow.php @@ -32,6 +32,7 @@ namespace OCA\Social\Model\ActivityPub; use JsonSerializable; +use OCA\Social\Exceptions\InvalidResourceEntryException; /** @@ -48,6 +49,9 @@ class Follow extends ACore implements JsonSerializable { /** @var string */ private $followId = ''; + /** @var bool */ + private $accepted = false; + /** * Follow constructor. @@ -80,8 +84,29 @@ class Follow extends ACore implements JsonSerializable { } + /** + * @return bool + */ + public function isAccepted(): bool { + return $this->accepted; + } + + /** + * @param bool $accepted + * + * @return Follow + */ + public function setAccepted(bool $accepted): Follow { + $this->accepted = $accepted; + + return $this; + } + + /** * @param array $data + * + * @throws InvalidResourceEntryException */ public function import(array $data) { parent::import($data); @@ -94,6 +119,7 @@ class Follow extends ACore implements JsonSerializable { public function importFromDatabase(array $data) { parent::importFromDatabase($data); + $this->setAccepted(($this->getInt('accepted', $data, 0) === 1) ? true : false); $this->setFollowId($this->get('follow_id', $data, '')); } @@ -105,6 +131,8 @@ class Follow extends ACore implements JsonSerializable { return array_merge( parent::jsonSerialize(), [ + 'follow_id' => $this->getFollowId(), + 'accepted' => $this->isAccepted() ] ); }