SiteController.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App;
  4. use App\Follower;
  5. use App\Profile;
  6. use App\Status;
  7. use App\User;
  8. use App\UserFilter;
  9. use App\Util\Lexer\PrettyNumber;
  10. use Auth;
  11. use Cache;
  12. use Illuminate\Http\Request;
  13. class SiteController extends Controller
  14. {
  15. public function home()
  16. {
  17. if (Auth::check()) {
  18. return $this->homeTimeline();
  19. } else {
  20. return $this->homeGuest();
  21. }
  22. }
  23. public function homeGuest()
  24. {
  25. return view('site.index');
  26. }
  27. public function homeTimeline()
  28. {
  29. $pid = Auth::user()->profile->id;
  30. // TODO: Use redis for timelines
  31. $following = Cache::rememberForever("user:following:list:$pid", function() use($pid) {
  32. $following = Follower::whereProfileId($pid)->pluck('following_id');
  33. $following->push($pid);
  34. return $following->toArray();
  35. });
  36. $filtered = Cache::rememberForever("user:filter:list:$pid", function() use($pid) {
  37. return UserFilter::whereUserId($pid)
  38. ->whereFilterableType('App\Profile')
  39. ->whereIn('filter_type', ['mute', 'block'])
  40. ->pluck('filterable_id')->toArray();
  41. });
  42. $timeline = Status::whereIn('profile_id', $following)
  43. ->whereNotIn('profile_id', $filtered)
  44. ->whereHas('media')
  45. ->whereVisibility('public')
  46. ->orderBy('created_at', 'desc')
  47. ->withCount(['comments', 'likes', 'shares'])
  48. ->simplePaginate(20);
  49. $type = 'personal';
  50. return view('timeline.template', compact('timeline', 'type'));
  51. }
  52. public function changeLocale(Request $request, $locale)
  53. {
  54. // todo: add other locales after pushing new l10n strings
  55. $locales = ['en'];
  56. if(in_array($locale, $locales)) {
  57. session()->put('locale', $locale);
  58. }
  59. return redirect()->back();
  60. }
  61. public function about()
  62. {
  63. return view('site.about');
  64. }
  65. public function language()
  66. {
  67. return view('site.language');
  68. }
  69. }