TimelineController.php 1.9 KB

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