diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2018-11-30 20:31:32 -0100 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2018-12-03 07:14:39 +0100 |
commit | f9f2b07d7ea36db8e4e6c8403ed3378a5b60d48f (patch) | |
tree | c0a2182b460bb60bf9e4120142bc2bb82b9cd49d /lib/Db/FollowsRequest.php | |
parent | 3eafb16c4ed742bbae5da4e5a585e16c2f05638a (diff) |
Followers/Following
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Db/FollowsRequest.php')
-rw-r--r-- | lib/Db/FollowsRequest.php | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index fdcb04ff..01640058 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -32,8 +32,10 @@ namespace OCA\Social\Db; use daita\MySmallPhpTools\Traits\TArrayTools; +use DateTime; use OCA\Social\Exceptions\FollowDoesNotExistException; use OCA\Social\Model\ActivityPub\Follow; +use OCP\DB\QueryBuilder\IQueryBuilder; /** @@ -58,7 +60,11 @@ class FollowsRequest extends FollowsRequestBuilder { ->setValue('actor_id', $qb->createNamedParameter($follow->getActorId())) ->setValue('type', $qb->createNamedParameter($follow->getType())) ->setValue('object_id', $qb->createNamedParameter($follow->getObjectId())) - ->setValue('follow_id', $qb->createNamedParameter($follow->getFollowId())); + ->setValue('follow_id', $qb->createNamedParameter($follow->getFollowId())) + ->setValue( + 'creation', + $qb->createNamedParameter(new DateTime('now'), IQueryBuilder::PARAM_DATE) + ); $qb->execute(); } @@ -159,6 +165,50 @@ class FollowsRequest extends FollowsRequestBuilder { /** + * @param string $actorId + * + * @return Follow[] + */ + public function getFollowersByActorId(string $actorId): array { + $qb = $this->getFollowsSelectSql(); + $this->limitToOBjectId($qb, $actorId); + $this->leftJoinCacheActors($qb, 'actor_id'); + $qb->orderBy('creation', 'desc'); + + $follows = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $follows[] = $this->parseFollowsSelectSql($data); + } + $cursor->closeCursor(); + + return $follows; + } + + + /** + * @param string $actorId + * + * @return Follow[] + */ + public function getFollowingByActorId(string $actorId): array { + $qb = $this->getFollowsSelectSql(); + $this->limitToActorId($qb, $actorId); + $this->leftJoinCacheActors($qb, 'actor_id'); + $qb->orderBy('creation', 'desc'); + + $follows = []; + $cursor = $qb->execute(); + while ($data = $cursor->fetch()) { + $follows[] = $this->parseFollowsSelectSql($data); + } + $cursor->closeCursor(); + + return $follows; + } + + + /** * @param Follow $follow */ public function delete(Follow $follow) { |