Use correct category for favorites

pull/37/head
Varun Patil 2022-09-11 20:03:04 -07:00
parent 435d096ed3
commit e8774b2aa4
3 changed files with 15 additions and 13 deletions

View File

@ -67,11 +67,11 @@ trait TimelineQueryDay {
)); ));
// Filter by UID // Filter by UID
$query->andWhere($query->expr()->eq('uid', $query->createNamedParameter($user))); $query->andWhere($query->expr()->eq('m.uid', $query->createNamedParameter($user)));
// Apply all transformations // Apply all transformations
foreach ($queryTransforms as &$transform) { foreach ($queryTransforms as &$transform) {
$transform($query); $transform($query, $user);
} }
$rows = $query->executeQuery()->fetchAll(); $rows = $query->executeQuery()->fetchAll();

View File

@ -62,11 +62,11 @@ trait TimelineQueryDays {
)); ));
// Filter by user // Filter by user
$query->andWhere($query->expr()->eq('uid', $query->createNamedParameter($user))); $query->andWhere($query->expr()->eq('m.uid', $query->createNamedParameter($user)));
// Apply all transformations // Apply all transformations
foreach ($queryTransforms as &$transform) { foreach ($queryTransforms as &$transform) {
$transform($query); $transform($query, $user);
} }
$rows = $query->executeQuery()->fetchAll(); $rows = $query->executeQuery()->fetchAll();

View File

@ -4,16 +4,18 @@ declare(strict_types=1);
namespace OCA\Memories\Db; namespace OCA\Memories\Db;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\ITags;
trait TimelineQueryFavorites { trait TimelineQueryFavorites {
public function transformFavoriteFilter(IQueryBuilder $query) { public function transformFavoriteFilter(IQueryBuilder $query, string $userId) {
// TODO: 2 is not guaranteed to be the favorites tag id // Inner join will filter only the favorites
// use OCP\ITags; instead $query->innerJoin('m', 'vcategory_to_object', 'vco', $query->expr()->eq('vco.objid', 'm.fileid'));
$query->innerJoin('m', 'vcategory_to_object', 'c',
$query->expr()->andX( // Get the favorites category only
$query->expr()->eq('c.objid', 'm.fileid'), $query->innerJoin('vco', 'vcategory', 'vc', $query->expr()->andX(
$query->expr()->eq('c.categoryid', $query->createNamedParameter(2, IQueryBuilder::PARAM_INT)), $query->expr()->eq('vc.id', 'vco.categoryid'),
$query->expr()->eq('c.type', $query->createNamedParameter('files')), $query->expr()->eq('vc.uid', $query->createNamedParameter($userId)),
)); $query->expr()->eq('vc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)),
));
} }
} }