Skip to content

Commit bacbdba

Browse files
committed
done
1 parent f24389b commit bacbdba

4 files changed

Lines changed: 36 additions & 25 deletions

File tree

app/Actions/Photo/Delete.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public function do(array $photo_ids, string|null $from_id, array $album_ids = []
134134
private function validateArguments(array $photo_ids, string|null $from_id, array $album_ids): void
135135
{
136136
match (true) {
137-
count($photo_ids) === 0 && count($album_ids) === 0 => throw new LycheeLogicException('At least one of the arguments [$photo_ids, $album_ids] must be set.'),
138137
count($photo_ids) !== 0 && count($album_ids) !== 0 => throw new LycheeLogicException('Only one of the arguments [$photo_ids, $album_ids] must be set.'),
139138
count($photo_ids) !== 0 && $from_id === null => throw new LycheeLogicException('The $from_id must be provided with the $photo_ids.'),
140139
count($album_ids) !== 0 && $from_id !== null => throw new LycheeLogicException('The $from_id must not be provided with the $album_ids.'),

app/Actions/Photo/Pipes/Shared/NotifyAlbums.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function handle(PhotoDTO $state, \Closure $next): PhotoDTO
2424
$count_albums = DB::table(PA::PHOTO_ALBUM)
2525
->where('photo_id', $state->getPhoto()->id)
2626
->count();
27+
2728
if ($count_albums > 0) {
2829
$notify = new Notify();
2930
$notify->do($state->getPhoto());

app/Actions/User/Notify.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88

99
namespace App\Actions\User;
1010

11+
use App\Constants\AccessPermissionConstants as APC;
12+
use App\Constants\PhotoAlbum as PA;
1113
use App\Exceptions\ConfigurationKeyMissingException;
1214
use App\Exceptions\Internal\QueryBuilderException;
15+
use App\Models\Album;
1316
use App\Models\Configs;
1417
use App\Models\Photo;
1518
use App\Models\User;
@@ -42,10 +45,16 @@ public function do(Photo $photo): void
4245
// Admin user is always notified
4346
$users = User::query()->where('may_administrate', '=', true)->get();
4447

45-
$album = $photo->album;
46-
if ($album !== null) {
47-
$users = $users->concat($album->shared_with);
48-
$users->push($album->owner);
48+
$albums = Album::query()->without(['thumbs', 'statistics', 'cover'])->join(PA::PHOTO_ALBUM, PA::ALBUM_ID, '=', 'album.id')
49+
->where(PA::PHOTO_ID, '=', $photo->id)
50+
->get();
51+
52+
if ($albums->count() > 0) {
53+
$shared_with = User::query()->join(APC::ACCESS_PERMISSIONS, APC::USER_ID, '=', 'user.id')
54+
->whereIn(APC::BASE_ALBUM_ID, $albums->pluck('id'))
55+
->get();
56+
$users->push(...$shared_with->all());
57+
$users->push(...$albums->map(fn ($a) => $a->owner)->all());
4958
}
5059

5160
$users = $users

app/Console/Commands/PhotosAddedNotification.php

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
namespace App\Console\Commands;
1010

11+
use App\Constants\PhotoAlbum as PA;
1112
use App\Mail\PhotosAdded;
13+
use App\Models\BaseAlbumImpl;
1214
use App\Models\Configs;
1315
use App\Models\Photo;
1416
use App\Models\User;
@@ -54,13 +56,6 @@ public function handle(): int
5456
->find($notification->data['id']);
5557

5658
if ($photo !== null) {
57-
if (!isset($photos[$photo->album_id])) {
58-
$photos[$photo->album_id] = [
59-
'name' => $photo->album->title,
60-
'photos' => [],
61-
];
62-
}
63-
6459
$thumb_url = $photo->size_variants->getThumb()?->url;
6560

6661
// Mail clients do not like relative paths.
@@ -69,19 +64,26 @@ public function handle(): int
6964
$thumb_url = URL::asset($thumb_url);
7065
}
7166

72-
// If the url config doesn't contain a trailing slash then add it
73-
if (str_ends_with(config('app.url'), '/')) {
74-
$trailing_slash = '';
75-
} else {
76-
$trailing_slash = '/';
77-
}
67+
BaseAlbumImpl::query()->join(PA::PHOTO_ALBUM, PA::ALBUM_ID, '=', 'base_albums.id')
68+
->where(PA::PHOTO_ID, '=', $photo->id)
69+
->get()
70+
->each(function (BaseAlbumImpl $album) use (&$photos, $photo, $thumb_url): void {
71+
$album_id = $album->id;
72+
$title = $album->title;
73+
74+
if (!isset($photos[$album_id])) {
75+
$photos[$album_id] = [
76+
'name' => $title,
77+
'photos' => [],
78+
];
79+
}
7880

79-
$photos[$photo->album_id]['photos'][$photo->id] = [
80-
'title' => $photo->title,
81-
'thumb' => $thumb_url,
82-
// TODO: Clean this up. There should be a better way to get the URL of a photo than constructing it manually
83-
'link' => config('app.url') . $trailing_slash . 'r/' . $photo->album_id . '/' . $photo->id,
84-
];
81+
$photos[$album_id]['photos'][$photo->id] = [
82+
'title' => $photo->title,
83+
'thumb' => $thumb_url,
84+
'link' => route('gallery', ['albumId' => $album_id, 'photoId' => $photo->id]),
85+
];
86+
});
8587
}
8688
}
8789

@@ -93,4 +95,4 @@ public function handle(): int
9395

9496
return 0;
9597
}
96-
}
98+
}

0 commit comments

Comments
 (0)