TimelineController.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Auth, Cache;
  4. use App\Follower;
  5. use App\Profile;
  6. use App\Status;
  7. use App\User;
  8. use App\UserFilter;
  9. use Illuminate\Http\Request;
  10. class TimelineController extends Controller
  11. {
  12. public function __construct()
  13. {
  14. $this->middleware('auth');
  15. $this->middleware('twofactor');
  16. }
  17. public function local(Request $request)
  18. {
  19. $this->validate($request,[
  20. 'page' => 'nullable|integer|max:20'
  21. ]);
  22. // TODO: Use redis for timelines
  23. // $timeline = Timeline::build()->local();
  24. $pid = Auth::user()->profile->id;
  25. $private = Profile::whereIsPrivate(true)->where('id', '!=', $pid)->pluck('id');
  26. $filters = UserFilter::whereUserId($pid)
  27. ->whereFilterableType('App\Profile')
  28. ->whereIn('filter_type', ['mute', 'block'])
  29. ->pluck('filterable_id')->toArray();
  30. $filtered = array_merge($private->toArray(), $filters);
  31. $timeline = Status::whereHas('media')
  32. ->whereNotIn('profile_id', $filtered)
  33. ->whereNull('in_reply_to_id')
  34. ->whereNull('reblog_of_id')
  35. ->whereVisibility('public')
  36. ->withCount(['comments', 'likes'])
  37. ->orderBy('created_at', 'desc')
  38. ->simplePaginate(10);
  39. $type = 'local';
  40. return view('timeline.template', compact('timeline', 'type'));
  41. }
  42. }