diff --git a/lib/Controller/AlbumsController.php b/lib/Controller/AlbumsController.php index 0507cd02..6bda003d 100644 --- a/lib/Controller/AlbumsController.php +++ b/lib/Controller/AlbumsController.php @@ -49,6 +49,17 @@ class AlbumsController extends ApiBase $list = array_merge($list, $this->timelineQuery->getAlbums($user->getUID(), true)); } + // Remove elements with duplicate album_id + $seenIds = []; + $list = array_filter($list, function ($item) use (&$seenIds) { + if (\in_array($item['album_id'], $seenIds, true)) { + return false; + } + $seenIds[] = $item['album_id']; + + return true; + }); + return new JSONResponse($list, Http::STATUS_OK); } diff --git a/lib/Db/TimelineQueryAlbums.php b/lib/Db/TimelineQueryAlbums.php index 7baa22e6..3fed6940 100644 --- a/lib/Db/TimelineQueryAlbums.php +++ b/lib/Db/TimelineQueryAlbums.php @@ -39,9 +39,10 @@ trait TimelineQueryAlbums $query->select('pa.*', $count)->from('photos_albums', 'pa'); if ($shared) { + $ids = $this->getSelfCollaborators($uid); $query->innerJoin('pa', $this->collaboratorsTable(), 'pc', $query->expr()->andX( $query->expr()->eq('pa.album_id', 'pc.album_id'), - $query->expr()->eq('pc.collaborator_id', $query->createNamedParameter($uid)), + $query->expr()->in('pc.collaborator_id', $query->createNamedParameter($ids, IQueryBuilder::PARAM_STR_ARRAY)), )); } else { $query->where( @@ -141,9 +142,10 @@ trait TimelineQueryAlbums )); // Join to shared album + $ids = $this->getSelfCollaborators($uid); $query->leftJoin('paf', $this->collaboratorsTable(), 'pc', $query->expr()->andX( $query->expr()->eq('pc.album_id', 'paf.album_id'), - $query->expr()->eq('pc.collaborator_id', $query->createNamedParameter($uid)), + $query->expr()->in('pc.collaborator_id', $query->createNamedParameter($ids, IQueryBuilder::PARAM_STR_ARRAY)), )); return $query->executeQuery()->fetchOne(); @@ -185,10 +187,11 @@ trait TimelineQueryAlbums // Check in collaborators instead $query = $this->connection->getQueryBuilder(); + $ids = $this->getSelfCollaborators($uid); $query->select('album_id')->from($this->collaboratorsTable())->where( $query->expr()->andX( $query->expr()->eq('album_id', $query->createNamedParameter($album['album_id'])), - $query->expr()->eq('collaborator_id', $query->createNamedParameter($uid)), + $query->expr()->in('collaborator_id', $query->createNamedParameter($ids, IQueryBuilder::PARAM_STR_ARRAY)), ) ); @@ -217,6 +220,20 @@ trait TimelineQueryAlbums return $fileIds; } + /** Get list of collaborator ids including user id and groups */ + private function getSelfCollaborators(string $uid) + { + // Get groups for the user + $groupManager = \OC::$server->get(\OCP\IGroupManager::class); + $user = \OC::$server->get(\OCP\IUserManager::class)->get($uid); + $groups = $groupManager->getUserGroupIds($user); + + // And albums shared with user + $groups[] = $uid; + + return $groups; + } + /** Get the name of the collaborators table */ private function collaboratorsTable() { diff --git a/src/services/dav/albums.ts b/src/services/dav/albums.ts index 27874eab..6ada889e 100644 --- a/src/services/dav/albums.ts +++ b/src/services/dav/albums.ts @@ -268,11 +268,7 @@ export function getAlbumFileInfos( : `/photos/${uid}/sharedalbums/${albumName} (${albumUser})`; return photos.map((photo) => { - const basename = - albumUser === uid - ? `${photo.fileid}-${photo.basename}` - : `${photo.fileid}-${albumName} (${albumUser})`; - + const basename = `${photo.fileid}-${photo.basename}`; return { fileid: photo.fileid, filename: `${collection}/${basename}`,