2018-04-16 01:18:59 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2018-06-01 03:12:27 +00:00
|
|
|
use Auth, Cache;
|
|
|
|
use App\Jobs\StatusPipeline\NewStatusPipeline;
|
2018-04-16 01:18:59 +00:00
|
|
|
use Illuminate\Http\Request;
|
2018-04-19 05:56:46 +00:00
|
|
|
use App\{Media, Profile, Status, User};
|
|
|
|
use Vinkla\Hashids\Facades\Hashids;
|
2018-04-16 01:18:59 +00:00
|
|
|
|
|
|
|
class StatusController extends Controller
|
|
|
|
{
|
2018-06-01 03:12:27 +00:00
|
|
|
public function show(Request $request, $username, int $id)
|
2018-04-19 05:56:46 +00:00
|
|
|
{
|
2018-06-01 20:21:24 +00:00
|
|
|
/*
|
|
|
|
* Load all required data
|
|
|
|
*/
|
|
|
|
$user = Profile::whereUsername($username)->with('avatar')->firstOrFail();
|
|
|
|
$status = Status::whereProfileId($user->id)->with(['firstMedia', 'comments', 'comments.profile'])->findOrFail($id);
|
|
|
|
|
|
|
|
// avoid calling the same profile in the blade template
|
|
|
|
$status->profile = $user;
|
|
|
|
|
|
|
|
// load a count non-relationship; this seems to be the most sane solution.
|
|
|
|
$status->likesCount;
|
|
|
|
/*
|
|
|
|
* End load all required data
|
|
|
|
*/
|
|
|
|
|
2018-06-01 03:12:27 +00:00
|
|
|
if(!$status->media_path && $status->in_reply_to_id) {
|
|
|
|
return view('status.reply', compact('user', 'status'));
|
|
|
|
}
|
2018-04-19 05:56:46 +00:00
|
|
|
return view('status.show', compact('user', 'status'));
|
|
|
|
}
|
|
|
|
|
2018-04-17 01:24:42 +00:00
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
if(Auth::check() == false)
|
2018-06-01 20:21:24 +00:00
|
|
|
{
|
|
|
|
abort(403);
|
2018-04-17 01:24:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$user = Auth::user();
|
|
|
|
|
|
|
|
$this->validate($request, [
|
2018-06-01 03:12:27 +00:00
|
|
|
'photo' => 'required|image|max:15000',
|
2018-04-17 01:24:42 +00:00
|
|
|
'caption' => 'string|max:150'
|
|
|
|
]);
|
2018-06-01 03:12:27 +00:00
|
|
|
|
|
|
|
$monthHash = hash('sha1', date('Y') . date('m'));
|
2018-04-17 01:24:42 +00:00
|
|
|
$userHash = hash('sha1', $user->id . (string) $user->created_at);
|
|
|
|
$storagePath = "public/m/{$monthHash}/{$userHash}";
|
|
|
|
$path = $request->photo->store($storagePath);
|
|
|
|
$profile = $user->profile;
|
|
|
|
|
|
|
|
$status = new Status;
|
|
|
|
$status->profile_id = $profile->id;
|
|
|
|
$status->caption = $request->caption;
|
|
|
|
$status->save();
|
|
|
|
|
|
|
|
$media = new Media;
|
|
|
|
$media->status_id = $status->id;
|
|
|
|
$media->profile_id = $profile->id;
|
|
|
|
$media->user_id = $user->id;
|
|
|
|
$media->media_path = $path;
|
|
|
|
$media->size = $request->file('photo')->getClientSize();
|
|
|
|
$media->mime = $request->file('photo')->getClientMimeType();
|
|
|
|
$media->save();
|
2018-06-01 03:12:27 +00:00
|
|
|
NewStatusPipeline::dispatch($status, $media);
|
|
|
|
|
|
|
|
// TODO: Parse Caption
|
|
|
|
// TODO: Send to subscribers
|
2018-06-01 20:21:24 +00:00
|
|
|
|
2018-04-19 05:56:46 +00:00
|
|
|
return redirect($status->url());
|
2018-04-17 01:24:42 +00:00
|
|
|
}
|
2018-04-16 01:18:59 +00:00
|
|
|
}
|