Skip to content

Commit

Permalink
Update StatusController, add interstitial logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dansup committed Dec 10, 2020
1 parent 342e7a5 commit 003caf7
Showing 1 changed file with 38 additions and 2 deletions.
40 changes: 38 additions & 2 deletions app/Http/Controllers/StatusController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Jobs\StatusPipeline\NewStatusPipeline;
use App\Jobs\StatusPipeline\StatusDelete;
use App\Jobs\SharePipeline\SharePipeline;
use App\AccountInterstitial;
use App\Media;
use App\Profile;
use App\Status;
Expand Down Expand Up @@ -162,14 +163,49 @@ public function delete(Request $request)

$status = Status::findOrFail($request->input('item'));

if ($status->profile_id === Auth::user()->profile->id || Auth::user()->is_admin == true) {
$user = Auth::user();

if($status->profile_id != $user->profile->id &&
$user->is_admin == true &&
$status->uri == null
) {
$media = $status->media;

$ai = new AccountInterstitial;
$ai->user_id = $status->profile->user_id;
$ai->type = 'post.removed';
$ai->view = 'account.moderation.post.removed';
$ai->item_type = 'App\Status';
$ai->item_id = $status->id;
$ai->has_media = (bool) $media->count();
$ai->blurhash = $media->count() ? $media->first()->blurhash : null;
$ai->meta = json_encode([
'caption' => $status->caption,
'created_at' => $status->created_at,
'type' => $status->type,
'url' => $status->url(),
'is_nsfw' => $status->is_nsfw,
'scope' => $status->scope,
'reblog' => $status->reblog_of_id,
'likes_count' => $status->likes_count,
'reblogs_count' => $status->reblogs_count,
]);
$ai->save();

$u = $status->profile->user;
$u->has_interstitial = true;
$u->save();
}

if ($status->profile_id == $user->profile->id || $user->is_admin == true) {
Cache::forget('profile:status_count:'.$status->profile_id);
StatusDelete::dispatch($status);
}

if($request->wantsJson()) {
return response()->json(['Status successfully deleted.']);
} else {
return redirect(Auth::user()->url());
return redirect($user->url());
}
}

Expand Down

0 comments on commit 003caf7

Please sign in to comment.