TimelineController.php 1.9 KB

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