Created a notifications page

This commit is contained in:
Ghostie 2025-01-11 14:20:19 -05:00
parent e31e7ff847
commit dca3116d2a
8 changed files with 119 additions and 15 deletions

View File

@ -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/(?<reverbid>[^/]+)/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;
}
}
```

View File

@ -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"]);

View File

@ -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"));
}
}

View File

@ -223,7 +223,7 @@ class TypeNote
$actor_exists->user->notify (new UserNotification(
"Mention",
$actor->id,
$actor_exists->id
$note->id
));
}
break;

View File

@ -66,6 +66,12 @@
<a href="#">&nbsp;Favs </a>
</li>
@auth
<li class="active">
<a href="{{ route ('users.notifications') }}">&nbsp;Notifications ({{ count (auth ()->user ()->unreadNotifications) }})</a>
</li>
@endauth
<li>
<a href="https://github.com/0xd011f4ce/OurSpace">&nbsp;Source </a>
</li>

View File

@ -45,9 +45,6 @@
@if (auth ()->check ())
<script>
const notification_sound = new Audio ("/resources/sounds/notification.mp3")
notification_sound.muted = true
notification_sound.play ()
notification_sound.muted = false
function register_echo ()
{

View File

@ -0,0 +1,56 @@
@extends ("partials.layout")
@section ("title", "Notifications")
@section ("content")
<div class="simple-container">
<h1>Notifications</h1>
<p>You have <b>{{ count ($user->unreadNotifications) }}</b> unread notifications</p>
<br>
<table border="1" width="100%">
<tr>
<th style="width: 100px">Actor</th>
<th>Content</th>
<th>Time</th>
<th>Read</th>
</tr>
@foreach ($processed_notifications as $notification)
<tr @if ($notification ['read_at'] == null) style="font-weight: bold" @endif>
<td>
<a href="{{ route ('users.show', [ 'user_name' => $notification ['actor']->local_actor_id ? $notification ['actor']->local_actor_id : $notification ['actor']->name ]) }}">
<p>{{ $notification ['actor']->name }}</p>
</a>
</td>
<td>
@if ($notification ['type'] == 'Follow')
<p>Followed you</p>
@elseif ($notification ['type'] == 'Unfollow')
<p>Unfollowed you</p>
@elseif ($notification ['type'] == 'Boost')
<p>Boosted this <b><a href="{{ route ('posts.show', ['note' => $notification['object']->id]) }}">post</a></b></p>
@elseif ($notification ['type'] == 'Like')
<p>Liked this <b><a href="{{ route ('posts.show', ['note' => $notification['object']->id]) }}">post</a></b></p>
@elseif ($notification ['type'] == 'Reply')
<p>Replied to this <b><a href="{{ route ('posts.show', ['note' => $notification['object']->id]) }}">post</a></b></p>
@elseif ($notification ['type'] == 'Mention')
<p>Mentioned you in this <b><a href="{{ route ('posts.show', ['note' => $notification['object']->id])}}">post</a></b></p>
@endif
</td>
<td>
<p>{{ $notification ['created_at']->diffForHumans () }}</p>
</td>
<td>
<input type="checkbox" @if ($notification ['read_at'] != null) checked @endif disabled>
</td>
</tr>
@endforeach
</table>
{{ $notifications->links ("pagination::default") }}
</div>
@endsection

View File

@ -26,6 +26,7 @@ Route::middleware ("update_online")->group (function () {
// user routes
Route::get ("/user/edit", [ ProfileController::class, "edit" ])->name ("users.edit")->middleware ("auth");
Route::post ("/user/edit", [ ProfileController::class, "update" ])->middleware ("auth");
Route::get ("/user/notifications", [ ProfileController::class, "notifications" ])->name ("users.notifications")->middleware ("auth");
Route::get ("/user/{user_name}/friends", [ ProfileController::class, "friends" ])->name ("users.friends");
Route::get ("/user/{user_name}", [ ProfileController::class, "show" ])->name ("users.show");