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
$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();

View File

@ -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();

View File

@ -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)),
));
}
}