diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2023-04-08 11:31:19 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2023-04-08 11:31:19 -0100 |
commit | eef10d9a83c80b6f2467229b7ec52ae6b56d8234 (patch) | |
tree | 26a65828c71cb18aea2e55bd5a934db369f5ffe3 /lib | |
parent | 961f8c021ef30394a03580298beac1073ac6c5ca (diff) |
improve relationships
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Db/FollowsRequest.php | 4 | ||||
-rw-r--r-- | lib/Service/FollowService.php | 43 |
2 files changed, 24 insertions, 23 deletions
diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index 920fe44b..1b4ac09d 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -136,8 +136,8 @@ class FollowsRequest extends FollowsRequestBuilder { */ public function getByPersons(string $actorId, string $remoteActorId): Follow { $qb = $this->getFollowsSelectSql(); - $this->limitToActorId($qb, $actorId); - $this->limitToObjectId($qb, $remoteActorId); + $qb->limitToActorIdPrim($qb->prim($actorId)); + $qb->limitToObjectIdPrim($qb->prim($remoteActorId)); return $this->getFollowFromRequest($qb); } diff --git a/lib/Service/FollowService.php b/lib/Service/FollowService.php index cab69ab0..27aba151 100644 --- a/lib/Service/FollowService.php +++ b/lib/Service/FollowService.php @@ -304,42 +304,43 @@ class FollowService { $actorNids[$actor->getNid()] = $actor->getId(); } - $follows = $this->followsRequest->getFollows(array_values($actorNids)); foreach ($actorNids as $actorNid => $actorId) { if ($actorNid === $this->viewer->getNid()) { continue; // ignore current session } - // might be resource heavy, need to be checked/optimized ? - $relationships[] = $this->generateRelationship($actorNid, $actorId, $follows); + $relationships[] = $this->generateRelationship($actorNid, $this->viewer->getId(), $actorId); } return $relationships; } /** - * @param int $objectNid - * @param string $objectId - * @param Follow[] $follows + * @param int $nid + * @param string $viewerId + * @param string $actorId * * @return Relationship */ - private function generateRelationship(int $objectNid, string $objectId, array $follows): Relationship { - $relationship = new Relationship($objectNid); - - foreach ($follows as $follow) { - if ($follow->getType() === Follow::TYPE) { - if ($follow->getObjectId() === $objectId) { - if ($follow->isAccepted()) { - $relationship->setFollowing(true); - } else { - $relationship->setRequested(true); - } - } - if ($follow->getActorId() === $objectId && $follow->isAccepted()) { - $relationship->setFollowedBy(true); - } + private function generateRelationship(int $nid, string $viewerId, string $actorId): Relationship { + $relationship = new Relationship($nid); + + try { + $follow = $this->followsRequest->getByPersons($viewerId, $actorId); + if ($follow->isAccepted()) { + $relationship->setFollowing(true); + } else { + $relationship->setRequested(true); + } + } catch (FollowNotFoundException $e) { + } + + try { + $follow = $this->followsRequest->getByPersons($actorId, $viewerId); + if ($follow->isAccepted()) { + $relationship->setFollowedBy(true); } + } catch (FollowNotFoundException $e) { } return $relationship; |