TimelineController.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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('created_at', '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. ->whereVisibility('public')
  49. ->withCount(['comments', 'likes'])
  50. ->orderBy('created_at', 'desc')
  51. ->simplePaginate(20);
  52. $type = 'local';
  53. return view('timeline.template', compact('timeline', 'type'));
  54. }
  55. }