diff --git a/lib/Db/TimelineQueryDay.php b/lib/Db/TimelineQueryDay.php index a3e29107..f212c13f 100644 --- a/lib/Db/TimelineQueryDay.php +++ b/lib/Db/TimelineQueryDay.php @@ -67,11 +67,11 @@ trait TimelineQueryDay { )); // 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 foreach ($queryTransforms as &$transform) { - $transform($query); + $transform($query, $user); } $rows = $query->executeQuery()->fetchAll(); diff --git a/lib/Db/TimelineQueryDays.php b/lib/Db/TimelineQueryDays.php index e9cea06e..d00aa138 100644 --- a/lib/Db/TimelineQueryDays.php +++ b/lib/Db/TimelineQueryDays.php @@ -62,11 +62,11 @@ trait TimelineQueryDays { )); // 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 foreach ($queryTransforms as &$transform) { - $transform($query); + $transform($query, $user); } $rows = $query->executeQuery()->fetchAll(); diff --git a/lib/Db/TimelineQueryFavorites.php b/lib/Db/TimelineQueryFavorites.php index c35b0249..56332d91 100644 --- a/lib/Db/TimelineQueryFavorites.php +++ b/lib/Db/TimelineQueryFavorites.php @@ -4,16 +4,18 @@ declare(strict_types=1); namespace OCA\Memories\Db; use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\ITags; trait TimelineQueryFavorites { - public function transformFavoriteFilter(IQueryBuilder $query) { - // TODO: 2 is not guaranteed to be the favorites tag id - // use OCP\ITags; instead - $query->innerJoin('m', 'vcategory_to_object', 'c', - $query->expr()->andX( - $query->expr()->eq('c.objid', 'm.fileid'), - $query->expr()->eq('c.categoryid', $query->createNamedParameter(2, IQueryBuilder::PARAM_INT)), - $query->expr()->eq('c.type', $query->createNamedParameter('files')), - )); + public function transformFavoriteFilter(IQueryBuilder $query, string $userId) { + // Inner join will filter only the favorites + $query->innerJoin('m', 'vcategory_to_object', 'vco', $query->expr()->eq('vco.objid', 'm.fileid')); + + // Get the favorites category only + $query->innerJoin('vco', 'vcategory', 'vc', $query->expr()->andX( + $query->expr()->eq('vc.id', 'vco.categoryid'), + $query->expr()->eq('vc.uid', $query->createNamedParameter($userId)), + $query->expr()->eq('vc.category', $query->createNamedParameter(ITags::TAG_FAVORITE)), + )); } } \ No newline at end of file