TimelineController.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. ->whereVisibility('public')
  29. ->orderBy('created_at', 'desc')
  30. ->withCount(['comments', 'likes'])
  31. ->simplePaginate(20);
  32. $type = 'personal';
  33. return view('timeline.template', compact('timeline', 'type'));
  34. }
  35. public function local()
  36. {
  37. // TODO: Use redis for timelines
  38. // $timeline = Timeline::build()->local();
  39. $pid = Auth::user()->profile->id;
  40. $filtered = UserFilter::whereUserId($pid)
  41. ->whereFilterableType('App\Profile')
  42. ->whereIn('filter_type', ['mute', 'block'])
  43. ->pluck('filterable_id');
  44. $private = Profile::whereIsPrivate(true)->pluck('id');
  45. $filtered = $filtered->merge($private);
  46. $timeline = Status::whereHas('media')
  47. ->whereNotIn('profile_id', $filtered)
  48. ->whereNull('in_reply_to_id')
  49. ->whereNull('reblog_of_id')
  50. ->whereVisibility('public')
  51. ->withCount(['comments', 'likes'])
  52. ->orderBy('created_at', 'desc')
  53. ->simplePaginate(20);
  54. $type = 'local';
  55. return view('timeline.template', compact('timeline', 'type'));
  56. }
  57. }