Skip to content

Commit

Permalink
Fixes to user filters on active user sidebar and people pages (#773)
Browse files Browse the repository at this point in the history
Co-authored-by: debounced <35878315+nobodyatroot@users.noreply.github.com>
  • Loading branch information
e-five256 and nobodyatroot committed May 15, 2024
1 parent 5431dc3 commit c0a65e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/Controller/Magazine/MagazinePeopleFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function __invoke(
$this->magazineRepository->findByActivity(),
fn ($val) => 'random' !== $val->name && $val !== $magazine
),
'local' => $this->userRepository->findPeople($magazine),
'federated' => $this->userRepository->findPeople($magazine, true),
'local' => $this->userRepository->findUsersForMagazine($magazine),
'federated' => $this->userRepository->findUsersForMagazine($magazine, true),
]
);
}
Expand Down
31 changes: 21 additions & 10 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public function findAudience(User $user): array
$dql =
'SELECT COUNT(u.id), u.apInboxUrl FROM '.User::class.' u WHERE u IN ('.
'SELECT IDENTITY(us.follower) FROM '.UserFollow::class.' us WHERE us.following = :user)'.
'AND u.apId IS NOT NULL AND u.isBanned = false AND u.apTimeoutAt IS NULL '.
'AND u.apId IS NOT NULL AND u.isBanned = false AND u.isDeleted = false AND u.apTimeoutAt IS NULL '.
'GROUP BY u.apInboxUrl';

$res = $this->getEntityManager()->createQuery($dql)
Expand Down Expand Up @@ -358,9 +358,12 @@ private function findUsersQueryBuilder(string $group, ?bool $recentlyActive = tr
{
$qb = $this->createQueryBuilder('u');

$qb->where('u.visibility = :visibility')
->setParameter('visibility', VisibilityInterface::VISIBILITY_VISIBLE);

if ($recentlyActive) {
$qb->where('u.lastActive >= :lastActive')
->setParameters(['lastActive' => (new \DateTime())->modify('-7 days')]);
$qb->andWhere('u.lastActive >= :lastActive')
->setParameter('lastActive', (new \DateTime())->modify('-7 days'));
}

switch ($group) {
Expand Down Expand Up @@ -489,13 +492,14 @@ public function findUsersSuggestions(string $query): array
->andWhere($qb->expr()->like('u.username', ':query'))
->orWhere($qb->expr()->like('u.email', ':query'))
->andWhere('u.isBanned = false')
->andWhere('u.isDeleted = false')
->setParameters(['query' => "{$query}%"])
->setMaxResults(5)
->getQuery()
->getResult();
}

public function findPeople(Magazine $magazine, ?bool $federated = false, $limit = 200, bool $limitTime = false): array
public function findUsersForMagazine(Magazine $magazine, ?bool $federated = false, $limit = 200, bool $limitTime = false, bool $requireAvatar = false): array
{
$conn = $this->_em->getConnection();
$timeWhere = $limitTime ? "AND created_at > now() - '30 days'::interval" : '';
Expand Down Expand Up @@ -529,10 +533,14 @@ public function findPeople(Magazine $magazine, ?bool $federated = false, $limit
$qb = $this->createQueryBuilder('u', 'u.id');
$qb->andWhere($qb->expr()->in('u.id', $user))
->andWhere('u.isBanned = false')
->andWhere('u.isDeleted = false')
->andWhere('u.visibility = :visibility')
->andWhere('u.apDeletedAt IS NULL')
->andWhere('u.apTimeoutAt IS NULL')
->andWhere('u.about IS NOT NULL')
->andWhere('u.avatar IS NOT NULL');
->andWhere('u.apTimeoutAt IS NULL');

if (true === $requireAvatar) {
$qb->andWhere('u.avatar IS NOT NULL');
}

if (null !== $federated) {
if ($federated) {
Expand All @@ -543,7 +551,8 @@ public function findPeople(Magazine $magazine, ?bool $federated = false, $limit
}
}

$qb->setMaxResults($limit);
$qb->setParameter('visibility', VisibilityInterface::VISIBILITY_VISIBLE)
->setMaxResults($limit);

try {
$users = $qb->getQuery()->getResult(); // @todo
Expand All @@ -567,11 +576,13 @@ public function findPeople(Magazine $magazine, ?bool $federated = false, $limit
public function findActiveUsers(Magazine $magazine = null)
{
if ($magazine) {
$results = $this->findPeople($magazine, null, 35, true);
$results = $this->findUsersForMagazine($magazine, null, 35, true, true);
} else {
$results = $this->createQueryBuilder('u')
->andWhere('u.lastActive >= :lastActive')
->andWhere('u.isBanned = false')
->andWhere('u.isDeleted = false')
->andWhere('u.visibility = :visibility')
->andWhere('u.apDeletedAt IS NULL')
->andWhere('u.apTimeoutAt IS NULL')
->andWhere('u.avatar IS NOT NULL');
Expand All @@ -581,7 +592,7 @@ public function findActiveUsers(Magazine $magazine = null)

$results = $results->join('u.avatar', 'a')
->orderBy('u.lastActive', 'DESC')
->setParameters(['lastActive' => (new \DateTime())->modify('-7 days')])
->setParameters(['lastActive' => (new \DateTime())->modify('-7 days'), 'visibility' => VisibilityInterface::VISIBILITY_VISIBLE])
->setMaxResults(35)
->getQuery()
->getResult();
Expand Down

0 comments on commit c0a65e1

Please sign in to comment.