1515use App \Exceptions \Internal \LycheeInvalidArgumentException ;
1616use App \Exceptions \Internal \TimelineGranularityException ;
1717use App \Models \Photo ;
18+ use App \Policies \AlbumPolicy ;
1819use App \Policies \PhotoQueryPolicy ;
1920use App \Repositories \ConfigManager ;
2021use Illuminate \Database \Eloquent \Builder ;
2122use Illuminate \Support \Carbon ;
2223use Illuminate \Support \Collection ;
24+ use Illuminate \Support \Facades \Auth ;
2325use Illuminate \Support \Facades \DB ;
2426
2527class Timeline
@@ -42,6 +44,9 @@ public function __construct(
4244 */
4345 public function do (): Builder
4446 {
47+ $ user = Auth::user ();
48+ $ unlocked_album_ids = AlbumPolicy::getUnlockedAlbumIDs ();
49+
4550 $ order = $ this ->config_manager ->getValueAsEnum ('timeline_photos_order ' , ColumnSortingPhotoType::class);
4651
4752 // Safe default (should not be needed).
@@ -53,6 +58,8 @@ public function do(): Builder
5358
5459 return $ this ->photo_query_policy ->applySearchabilityFilter (
5560 query: Photo::query ()->with (['statistics ' , 'size_variants ' , 'statistics ' , 'palette ' , 'tags ' , 'rating ' ]),
61+ user: $ user ,
62+ unlocked_album_ids: $ unlocked_album_ids ,
5663 origin: null ,
5764 include_nsfw: !$ this ->config_manager ->getValueAsBool ('hide_nsfw_in_timeline ' )
5865 )->orderBy ($ order ->value , OrderSortingType::DESC ->value );
@@ -68,6 +75,9 @@ public function do(): Builder
6875 */
6976 public function countYoungerFromDate (Carbon $ date ): int
7077 {
78+ $ user = Auth::user ();
79+ $ unlocked_album_ids = AlbumPolicy::getUnlockedAlbumIDs ();
80+
7181 $ order = $ this ->config_manager ->getValueAsEnum ('timeline_photos_order ' , ColumnSortingPhotoType::class);
7282
7383 $ granularity = $ this ->config_manager ->getValueAsEnum ('timeline_photos_granularity ' , TimelinePhotoGranularity::class);
@@ -91,6 +101,8 @@ public function countYoungerFromDate(Carbon $date): int
91101 query: Photo::query ()
92102 ->where ($ order ->value , '>= ' , $ date_offset )
93103 ->whereNotNull ($ order ->value ),
104+ user: $ user ,
105+ unlocked_album_ids: $ unlocked_album_ids ,
94106 origin: null ,
95107 include_nsfw: !$ this ->config_manager ->getValueAsBool ('hide_nsfw_in_timeline ' )
96108 )->count ();
@@ -106,6 +118,9 @@ public function countYoungerFromDate(Carbon $date): int
106118 */
107119 public function countYoungerFromPhoto (Photo $ photo ): int
108120 {
121+ $ user = Auth::user ();
122+ $ unlocked_album_ids = AlbumPolicy::getUnlockedAlbumIDs ();
123+
109124 $ order = $ this ->config_manager ->getValueAsEnum ('timeline_photos_order ' , ColumnSortingPhotoType::class);
110125
111126 // Safe default (should not be needed).
@@ -125,6 +140,8 @@ public function countYoungerFromPhoto(Photo $photo): int
125140 second: 'photos. ' . $ order ->value
126141 )
127142 ->whereNotNull ('photos. ' . $ order ->value ),
143+ user: $ user ,
144+ unlocked_album_ids: $ unlocked_album_ids ,
128145 origin: null ,
129146 include_nsfw: !$ this ->config_manager ->getValueAsBool ('hide_nsfw_in_timeline ' )
130147 )->count ();
@@ -137,6 +154,9 @@ public function countYoungerFromPhoto(Photo $photo): int
137154 */
138155 public function dates (): Collection
139156 {
157+ $ user = Auth::user ();
158+ $ unlocked_album_ids = AlbumPolicy::getUnlockedAlbumIDs ();
159+
140160 $ order = $ this ->config_manager ->getValueAsEnum ('timeline_photos_order ' , ColumnSortingPhotoType::class);
141161
142162 // Safe default (should not be needed).
@@ -170,6 +190,8 @@ public function dates(): Collection
170190
171191 ->selectRaw (sprintf ($ formatter , $ order ->value , $ date_format ) . ' as date ' )
172192 ->whereNotNull ($ order ->value ),
193+ user: $ user ,
194+ unlocked_album_ids: $ unlocked_album_ids ,
173195 origin: null ,
174196 include_nsfw: !$ this ->config_manager ->getValueAsBool ('hide_nsfw_in_timeline ' )
175197 )->groupBy ('date ' )
0 commit comments