TimelineController.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Follower;
  4. use App\Profile;
  5. use App\Status;
  6. use App\User;
  7. use App\UserFilter;
  8. use Auth;
  9. class TimelineController extends Controller
  10. {
  11. public function __construct()
  12. {
  13. $this->middleware('auth');
  14. $this->middleware('twofactor');
  15. }
  16. public function personal()
  17. {
  18. $pid = Auth::user()->profile->id;
  19. // TODO: Use redis for timelines
  20. $following = Follower::whereProfileId($pid)->pluck('following_id');
  21. $following->push($pid);
  22. $filtered = UserFilter::whereUserId($pid)
  23. ->whereFilterableType('App\Profile')
  24. ->whereIn('filter_type', ['mute', 'block'])
  25. ->pluck('filterable_id');
  26. $timeline = Status::whereIn('profile_id', $following)
  27. ->whereNotIn('profile_id', $filtered)
  28. ->orderBy('created_at', 'desc')
  29. ->withCount(['comments', 'likes'])
  30. ->simplePaginate(20);
  31. $type = 'personal';
  32. return view('timeline.template', compact('timeline', 'type'));
  33. }
  34. public function local()
  35. {
  36. // TODO: Use redis for timelines
  37. // $timeline = Timeline::build()->local();
  38. $pid = Auth::user()->profile->id;
  39. $filtered = UserFilter::whereUserId($pid)
  40. ->whereFilterableType('App\Profile')
  41. ->whereIn('filter_type', ['mute', 'block'])
  42. ->pluck('filterable_id');
  43. $private = Profile::whereIsPrivate(true)->pluck('id');
  44. $filtered = $filtered->merge($private);
  45. $timeline = Status::whereHas('media')
  46. ->whereNotIn('profile_id', $filtered)
  47. ->whereNull('in_reply_to_id')
  48. ->whereNull('reblog_of_id')
  49. ->whereVisibility('public')
  50. ->withCount(['comments', 'likes'])
  51. ->orderBy('created_at', 'desc')
  52. ->simplePaginate(20);
  53. $type = 'local';
  54. return view('timeline.template', compact('timeline', 'type'));
  55. }
  56. }