TimelineController.php 2.3 KB

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