diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index e5635d1db..79f2d1c80 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -3,7 +3,7 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; -use Auth, Cache; +use Auth, Cache, Redis; use App\{Notification, Profile, User}; class AccountController extends Controller @@ -15,8 +15,33 @@ class AccountController extends Controller public function notifications(Request $request) { - $user = Auth::user(); - $profile = $user->profile; - return view('account.activity', compact('profile')); + $profile = Auth::user()->profile; + $notifications = $this->fetchNotifications($profile->id); + return view('account.activity', compact('profile', 'notifications')); + } + + public function fetchNotifications($id) + { + $key = config('cache.prefix') . ":user.{$id}.notifications"; + $redis = Redis::connection(); + $notifications = $redis->lrange($key, 0, 30); + if(empty($notifications)) { + $notifications = Notification::whereProfileId($id) + ->orderBy('id','desc')->take(30)->get(); + } else { + $notifications = $this->hydrateNotifications($notifications); + } + + return $notifications; + } + + public function hydrateNotifications($keys) + { + $prefix = 'notification.'; + $notifications = []; + foreach($keys as $key) { + $notifications[] = Cache::get($prefix . $key); + } + return $notifications; } } diff --git a/app/Notification.php b/app/Notification.php index 107f0ad10..4102ba56e 100644 --- a/app/Notification.php +++ b/app/Notification.php @@ -6,5 +6,15 @@ use Illuminate\Database\Eloquent\Model; class Notification extends Model { - // + + public function actor() + { + return $this->belongsTo(Profile::class, 'actor_id', 'id'); + } + + public function profile() + { + return $this->belongsTo(Profile::class, 'profile_id', 'id'); + } + } diff --git a/resources/assets/sass/custom.scss b/resources/assets/sass/custom.scss index 48c4f611d..0a0a549b6 100644 --- a/resources/assets/sass/custom.scss +++ b/resources/assets/sass/custom.scss @@ -76,4 +76,13 @@ body, button, input, textarea { .no-caret.dropdown-toggle::after { display:none; +} + +.notification-page .profile-link { + color: #212529; + font-weight: bold; +} + +.notification-page .list-group-item:first-child { + border-top: none; } \ No newline at end of file diff --git a/resources/views/account/activity.blade.php b/resources/views/account/activity.blade.php new file mode 100644 index 000000000..ebf4fe9b7 --- /dev/null +++ b/resources/views/account/activity.blade.php @@ -0,0 +1,29 @@ +@extends('layouts.app') + +@section('content') +
+
+ +
+
+@endsection \ No newline at end of file