Update comment url structure

This commit is contained in:
Daniel Supernault 2018-06-04 00:07:40 -06:00
parent aaf94d56cc
commit 2a73150586
4 changed files with 10 additions and 4 deletions

View file

@ -10,10 +10,10 @@ use App\{Comment, Profile, Status};
class CommentController extends Controller class CommentController extends Controller
{ {
public function show(Request $request, $username, int $id) public function show(Request $request, $username, int $id, int $cid)
{ {
$user = Profile::whereUsername($username)->firstOrFail(); $user = Profile::whereUsername($username)->firstOrFail();
$status = Status::whereProfileId($user->id)->whereNotNull('in_reply_to_id')->findOrFail($id); $status = Status::whereProfileId($user->id)->whereInReplyToId($id)->findOrFail($cid);
return view('status.reply', compact('user', 'status')); return view('status.reply', compact('user', 'status'));
} }

View file

@ -17,7 +17,7 @@ class StatusController extends Controller
->withCount('likes') ->withCount('likes')
->findOrFail($id); ->findOrFail($id);
if(!$status->media_path && $status->in_reply_to_id) { if(!$status->media_path && $status->in_reply_to_id) {
return view('status.reply', compact('user', 'status')); return redirect($status->url());
} }
return view('status.show', compact('user', 'status')); return view('status.show', compact('user', 'status'));
} }

View file

@ -32,7 +32,12 @@ class Status extends Model
{ {
$id = $this->id; $id = $this->id;
$username = $this->profile->username; $username = $this->profile->username;
return url(config('app.url') . "/p/{$username}/{$id}"); $path = config('app.url') . "/p/{$username}/{$id}";
if(!is_null($this->in_reply_to_id)) {
$pid = $this->in_reply_to_id;
$path = config('app.url') . "/p/{$username}/{$pid}/c/{$id}";
}
return url($path);
} }
public function mediaUrl() public function mediaUrl()

View file

@ -125,6 +125,7 @@ Route::domain(config('pixelfed.domain.app'))->group(function() {
Route::view('libraries', 'site.libraries')->name('site.libraries'); Route::view('libraries', 'site.libraries')->name('site.libraries');
}); });
Route::get('p/{username}/{id}/c/{cid}', 'CommentController@show');
Route::get('p/{username}/{id}', 'StatusController@show'); Route::get('p/{username}/{id}', 'StatusController@show');
Route::get('{username}/saved', 'ProfileController@savedBookmarks'); Route::get('{username}/saved', 'ProfileController@savedBookmarks');
Route::get('{username}/followers', 'ProfileController@followers'); Route::get('{username}/followers', 'ProfileController@followers');