diff --git a/.editorconfig b/.editorconfig index 3c44241c..6b67635e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,7 +1,6 @@ root = true [*] -indent_style = space indent_size = 4 end_of_line = lf charset = utf-8 diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index 7a753d6a..4e6272f0 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -132,6 +132,18 @@ class CollectionController extends Controller $collection = Collection::whereProfileId($profileId)->findOrFail($collectionId); $count = $collection->items()->count(); + if($count) { + CollectionItem::whereCollectionId($collection->id) + ->get() + ->filter(function($col) { + return StatusService::get($col->object_id, false) == null; + }) + ->each(function($col) use($collectionId) { + CollectionService::removeItem($collectionId, $col->object_id); + $col->delete(); + }); + } + $max = config('pixelfed.max_collection_length'); if($count >= $max) { abort(400, 'You can only add '.$max.' posts per collection'); diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index e0dc2a71..64f5a1cb 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -5,6 +5,7 @@ namespace App\Jobs\StatusPipeline; use DB, Storage; use App\{ AccountInterstitial, + CollectionItem, MediaTag, Notification, Report, @@ -25,6 +26,7 @@ use GuzzleHttp\Pool; use GuzzleHttp\Client; use GuzzleHttp\Promise; use App\Util\ActivityPub\HttpSignature; +use App\Services\CollectionService; use App\Services\StatusService; use App\Services\MediaStorageService; @@ -89,6 +91,19 @@ class StatusDelete implements ShouldQueue $parent->save(); }); } + + DB::transaction(function() use($status) { + CollectionItem::whereObjectType('App\Status') + ->whereObjectId($status->id) + ->get() + ->each(function($col) { + $id = $col->collection_id; + $sid = $col->object_id; + $col->delete(); + CollectionService::removeItem($id, $sid); + }); + }); + DB::transaction(function() use($status) { $comments = Status::where('in_reply_to_id', $status->id)->get(); foreach ($comments as $comment) { diff --git a/app/Services/CollectionService.php b/app/Services/CollectionService.php index 33a3303f..215e8cf4 100644 --- a/app/Services/CollectionService.php +++ b/app/Services/CollectionService.php @@ -9,7 +9,7 @@ use Illuminate\Support\Facades\Redis; class CollectionService { - const CACHE_KEY = 'pf:services:collections:'; + const CACHE_KEY = 'pf:services:collections-v1:'; public static function getItems($id, $start = 0, $stop = 10) { @@ -41,6 +41,9 @@ class CollectionService return CollectionItem::whereCollectionId($id) ->orderBy('order') ->get() + ->filter(function($item) use($id) { + return StatusService::get($item->object_id) != null; + }) ->each(function($item) use ($id) { self::addItem($id, $item->object_id, $item->order); }) @@ -80,13 +83,14 @@ class CollectionService 'visibility' => $collection->visibility, 'title' => $collection->title, 'description' => $collection->description, - 'thumb' => self::getThumb($id), + 'thumb' => '/storage/no-preview.png', 'url' => $collection->url(), 'published_at' => $collection->published_at ]; }); if($collection) { + $collection['thumb'] = self::getThumb($id); $collection['post_count'] = self::count($id); }