From dca3116d2abb924da47fee61af977fe8d5f1f181 Mon Sep 17 00:00:00 2001 From: Ghostie Date: Sat, 11 Jan 2025 14:20:19 -0500 Subject: [PATCH] Created a notifications page --- README.md | 15 ++--- .../AP/APInstanceInboxController.php | 2 +- app/Http/Controllers/ProfileController.php | 49 ++++++++++++++++ app/Types/TypeNote.php | 2 +- resources/views/partials/header.blade.php | 6 ++ resources/views/partials/layout.blade.php | 3 - resources/views/users/notifications.blade.php | 56 +++++++++++++++++++ routes/web.php | 1 + 8 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 resources/views/users/notifications.blade.php diff --git a/README.md b/README.md index 5f89449..35346eb 100644 --- a/README.md +++ b/README.md @@ -164,8 +164,8 @@ server { server_name ws.ourspace.lat; root /var/www/html/ourspace/public; - location / { - proxy_http_version 1.1; + location /app { + proxy_http_version 1.1; proxy_set_header Host $http_host; proxy_set_header Scheme $scheme; proxy_set_header SERVER_PORT $server_port; @@ -173,16 +173,11 @@ server { proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "Upgrade"; + proxy_read_timeout 300s; + proxy_connect_timeout 75s; - proxy_pass http://0.0.0.0:8080; - } - location ~ ^/apps/(?[^/]+)/events$ { # variable reverbid - proxy_pass http://0.0.0.0:8080/apps/$reverbid/events; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; + proxy_pass http://127.0.0.1:8080; } } ``` diff --git a/app/Http/Controllers/AP/APInstanceInboxController.php b/app/Http/Controllers/AP/APInstanceInboxController.php index 0aa201b..0d2252b 100644 --- a/app/Http/Controllers/AP/APInstanceInboxController.php +++ b/app/Http/Controllers/AP/APInstanceInboxController.php @@ -99,7 +99,7 @@ class APInstanceInboxController extends Controller $note_actor = $note_exists->get_actor ()->first (); if ($note_actor->user) { - $note_actor->user->notify (new UserNotification("Boost", $announcement_actor, $note_exists)); + $note_actor->user->notify (new UserNotification("Boost", $announcement_actor->id, $note_exists->id)); } return response ()->json (["status" => "ok"]); diff --git a/app/Http/Controllers/ProfileController.php b/app/Http/Controllers/ProfileController.php index d4949a3..ac04122 100644 --- a/app/Http/Controllers/ProfileController.php +++ b/app/Http/Controllers/ProfileController.php @@ -10,8 +10,10 @@ use Intervention\Image\Drivers\Gd\Driver; use App\Models\User; use App\Models\Actor; +use App\Models\Note; use App\Actions\ActionsUser; +use App\Helpers\PaginationHelper; class ProfileController extends Controller { @@ -161,4 +163,51 @@ class ProfileController extends Controller return view ("users.friends", compact ("actor", "user", "friends")); } + + public function notifications () + { + if (!auth ()->check ()) + return redirect ()->route ("login"); + + $user = auth ()->user (); + $unread_notifications = $user->notifications; + $notifications = PaginationHelper::paginate (collect ($unread_notifications), 20); + $processed_notifications = []; + + foreach ($notifications as $notification) + { + $data = $notification->data; + $type = $data ['type']; + $actor = Actor::find ($data["actor"]); + $object = null; + + switch ($type) + { + case "Follow": + case "Unfollow": + $object = Actor::find ($data["object"]); + break; + + case "Like": + case "Reply": + case "Boost": + case "Mention": + $object = Note::find ($data["object"]); + break; + } + + $processed_notifications[] = [ + "id"=> $notification->id, + "type" => $type, + "actor" => $actor, + "object" => $object, + "created_at" => $notification->created_at, + "read_at" => $notification->read_at + ]; + + $notification->markAsRead (); + } + + return view ("users.notifications", compact ("user", "notifications", "processed_notifications")); + } } diff --git a/app/Types/TypeNote.php b/app/Types/TypeNote.php index 3bb3c54..14a4a9e 100644 --- a/app/Types/TypeNote.php +++ b/app/Types/TypeNote.php @@ -223,7 +223,7 @@ class TypeNote $actor_exists->user->notify (new UserNotification( "Mention", $actor->id, - $actor_exists->id + $note->id )); } break; diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index 4ec5508..94acfdb 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -66,6 +66,12 @@  Favs + @auth +
  • +  Notifications ({{ count (auth ()->user ()->unreadNotifications) }}) +
  • + @endauth +
  •  Source
  • diff --git a/resources/views/partials/layout.blade.php b/resources/views/partials/layout.blade.php index ec2578a..5514170 100644 --- a/resources/views/partials/layout.blade.php +++ b/resources/views/partials/layout.blade.php @@ -45,9 +45,6 @@ @if (auth ()->check ())