summaryrefslogtreecommitdiffstats
path: root/lib/Db
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2018-12-04 07:27:56 -0100
committerMaxence Lange <maxence@artificial-owl.com>2018-12-04 07:27:56 -0100
commit0ce9d6fa6cf4852ed34bc0f00801b012803167c2 (patch)
tree89d204884fba102a8a64d34cfbce69efcf4c1085 /lib/Db
parentc45cfe6b497cc92db806fd6f8b51f3560eac3b08 (diff)
Details also when displaying followers of an account
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib/Db')
-rw-r--r--lib/Db/CacheActorsRequestBuilder.php30
-rw-r--r--lib/Db/CoreRequestBuilder.php52
-rw-r--r--lib/Db/FollowsRequest.php3
-rw-r--r--lib/Db/FollowsRequestBuilder.php3
4 files changed, 54 insertions, 34 deletions
diff --git a/lib/Db/CacheActorsRequestBuilder.php b/lib/Db/CacheActorsRequestBuilder.php
index d00bbd5c..dc037646 100644
--- a/lib/Db/CacheActorsRequestBuilder.php
+++ b/lib/Db/CacheActorsRequestBuilder.php
@@ -125,35 +125,5 @@ class CacheActorsRequestBuilder extends CoreRequestBuilder {
}
- protected function leftJoinDetails(IQueryBuilder $qb) {
- $viewerId = $this->getViewerId();
- if ($viewerId !== '') {
- $this->leftJoinFollowAsViewer($qb, 'id', $viewerId, true, 'as_follower');
- $this->leftJoinFollowAsViewer($qb, 'id', $viewerId, false, 'as_followed');
- }
- }
-
-
- protected function assignDetails(Person $actor, array $data) {
- if ($this->getViewerId() !== '') {
-
- try {
- $this->parseFollowLeftJoin($data, 'as_follower');
- $actor->addDetailBool('following', true);
- } catch (InvalidResourceException $e) {
- $actor->addDetailBool('following', false);
- }
-
- try {
- $this->parseFollowLeftJoin($data, 'as_followed');
- $actor->addDetailBool('followed', true);
- } catch (InvalidResourceException $e) {
- $actor->addDetailBool('followed', false);
- }
-
- $actor->setCompleteDetails(true);
- }
- }
-
}
diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php
index b021a5a6..e31ec5b5 100644
--- a/lib/Db/CoreRequestBuilder.php
+++ b/lib/Db/CoreRequestBuilder.php
@@ -657,20 +657,27 @@ class CoreRequestBuilder {
/**
* @param IQueryBuilder $qb
* @param string $fieldActorId
- * @param string $viewerId
* @param bool $asFollower
* @param string $prefix
+ * @param string $pf
*/
protected function leftJoinFollowAsViewer(
- IQueryBuilder &$qb, string $fieldActorId, string $viewerId, bool $asFollower = true,
- string $prefix = 'follow'
+ IQueryBuilder &$qb, string $fieldActorId, bool $asFollower = true,
+ string $prefix = 'follow', string $pf = ''
) {
if ($qb->getType() !== QueryBuilder::SELECT) {
return;
}
+ $viewerId = $this->getViewerId();
+ if ($viewerId === '') {
+ return;
+ }
+
$expr = $qb->expr();
- $pf = $this->defaultSelectAlias;
+ if ($pf === '') {
+ $pf = $this->defaultSelectAlias;
+ }
$andX = $expr->andX();
if ($asFollower === true) {
@@ -722,6 +729,43 @@ class CoreRequestBuilder {
}
+ /**
+ * @param IQueryBuilder $qb
+ * @param string $fieldActorId
+ * @param string $pf
+ */
+ protected function leftJoinDetails(
+ IQueryBuilder $qb, string $fieldActorId = 'id', string $pf = ''
+ ) {
+ $this->leftJoinFollowAsViewer($qb, $fieldActorId, true, 'as_follower', $pf);
+ $this->leftJoinFollowAsViewer($qb, $fieldActorId, false, 'as_followed', $pf);
+ }
+
+
+ /**
+ * @param Person $actor
+ * @param array $data
+ */
+ protected function assignDetails(Person $actor, array $data) {
+ if ($this->getViewerId() !== '') {
+
+ try {
+ $this->parseFollowLeftJoin($data, 'as_follower');
+ $actor->addDetailBool('following', true);
+ } catch (InvalidResourceException $e) {
+ $actor->addDetailBool('following', false);
+ }
+
+ try {
+ $this->parseFollowLeftJoin($data, 'as_followed');
+ $actor->addDetailBool('followed', true);
+ } catch (InvalidResourceException $e) {
+ $actor->addDetailBool('followed', false);
+ }
+
+ $actor->setCompleteDetails(true);
+ }
+ }
}
diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php
index f6f27732..4861b878 100644
--- a/lib/Db/FollowsRequest.php
+++ b/lib/Db/FollowsRequest.php
@@ -34,6 +34,7 @@ namespace OCA\Social\Db;
use daita\MySmallPhpTools\Traits\TArrayTools;
use DateTime;
use OCA\Social\Exceptions\FollowDoesNotExistException;
+use OCA\Social\Exceptions\InvalidResourceException;
use OCA\Social\Model\ActivityPub\Follow;
use OCP\DB\QueryBuilder\IQueryBuilder;
@@ -173,6 +174,7 @@ class FollowsRequest extends FollowsRequestBuilder {
$qb = $this->getFollowsSelectSql();
$this->limitToOBjectId($qb, $actorId);
$this->leftJoinCacheActors($qb, 'actor_id');
+ $this->leftJoinDetails($qb, 'id', 'ca');
$qb->orderBy('creation', 'desc');
$follows = [];
@@ -195,6 +197,7 @@ class FollowsRequest extends FollowsRequestBuilder {
$qb = $this->getFollowsSelectSql();
$this->limitToActorId($qb, $actorId);
$this->leftJoinCacheActors($qb, 'object_id');
+ $this->leftJoinDetails($qb, 'id', 'ca');
$qb->orderBy('creation', 'desc');
$follows = [];
diff --git a/lib/Db/FollowsRequestBuilder.php b/lib/Db/FollowsRequestBuilder.php
index 0f50b37e..25c0686a 100644
--- a/lib/Db/FollowsRequestBuilder.php
+++ b/lib/Db/FollowsRequestBuilder.php
@@ -132,6 +132,9 @@ class FollowsRequestBuilder extends CoreRequestBuilder {
try {
$actor = $this->parseCacheActorsLeftJoin($data);
+ $actor->setCompleteDetails(true);
+ $this->assignDetails($actor, $data);
+
$follow->setCompleteDetails(true);
$follow->setActor($actor);
} catch (InvalidResourceException $e) {