added the signup notification

This commit is contained in:
Ghostie 2025-01-11 14:51:17 -05:00
parent dca3116d2a
commit c0ad0c46d6
9 changed files with 118 additions and 15 deletions

View File

@ -220,6 +220,7 @@ WantedBy=multi-user.target
``` ```
```ini ```ini
# /lib/systemd/system/ourspace-ws.service
[Unit] [Unit]
Description=OurSpace WebSockets Service Description=OurSpace WebSockets Service
@ -233,8 +234,21 @@ ExecStart=/usr/bin/php /var/www/html/ourspace/artisan reverb:start
WantedBy=multi-user.target WantedBy=multi-user.target
``` ```
Now reload the systemd daemon:
```bash
sudo systemctl daemon-reload
```
Finally, enable and start both services, and your OurSpace instance will be ready to be used! Finally, enable and start both services, and your OurSpace instance will be ready to be used!
Aditionally, if you want to start multiple instances of the queue workers (which is ideal) you can name the service like `/lib/systemd/system/ourspace-queue@.service` and you can enable and manage them like this:
```bash
sudo systemctl enable ourspace-queue\{1..6} # enables 6 services
sudo systemctl start ourspace-queue\{1..6} # starts 6 services
```
## TODO: ## TODO:
For a list of planned features and improvements, please refer to the [TODO](TODO.md) file. For a list of planned features and improvements, please refer to the [TODO](TODO.md) file.

View File

@ -0,0 +1,28 @@
<?php
namespace App\Events;
use App\Models\User;
use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
class UserSignedUp
{
use Dispatchable, InteractsWithSockets, SerializesModels;
public User $user;
/**
* Create a new event instance.
*/
public function __construct(User $user)
{
$this->user = $user;
}
}

View File

@ -42,15 +42,17 @@ class HomeController extends Controller
if (request ()->get ("posts") == "latest") if (request ()->get ("posts") == "latest")
{ {
$notes = Note::latest ()->where ("in_reply_to", null)->take (10)->get (); $notes = Note::latest ();
} }
else else
{ {
$notes = Note::withCount ([ "get_likes" => function ($query) { $notes = Note::withCount ([ "get_likes" => function ($query) {
$query->where ("created_at", ">=", now ()->subDay ()); $query->where ("created_at", ">=", now ()->subDay ());
}])->where ("in_reply_to", null)->orderBy ("get_likes_count", "desc")->take (8)->get (); }])->where ("in_reply_to", null)->orderBy ("get_likes_count", "desc");
} }
$notes = $notes->paginate (10);
return view ("browse", compact ("users", "popular_hashtags", "notes")); return view ("browse", compact ("users", "popular_hashtags", "notes"));
} }

View File

@ -57,7 +57,7 @@ class ProfileController extends Controller
$incoming_fields = $request->validate ([ $incoming_fields = $request->validate ([
"avatar" => "image|max:4096", "avatar" => "image|max:4096",
"song" => "file|mimes:audio/mpeg,mp3|max:1024", "song" => "file|mimes:audio/mpeg,mp3|max:4096",
"bio" => "sometimes|nullable|string", "bio" => "sometimes|nullable|string",
"about_you" => "sometimes|nullable|string", "about_you" => "sometimes|nullable|string",
"status" => "sometimes|nullable|string", "status" => "sometimes|nullable|string",
@ -188,6 +188,10 @@ class ProfileController extends Controller
$object = Actor::find ($data["object"]); $object = Actor::find ($data["object"]);
break; break;
case "Signup":
$object = User::find ($data ["object"]);
break;
case "Like": case "Like":
case "Reply": case "Reply":
case "Boost": case "Boost":

View File

@ -7,6 +7,8 @@ use App\Models\Actor;
use App\Actions\ActionsFriends; use App\Actions\ActionsFriends;
use App\Events\UserSignedUp;
use Illuminate\Http\Request; use Illuminate\Http\Request;
class UserController extends Controller class UserController extends Controller
@ -30,14 +32,9 @@ class UserController extends Controller
]); ]);
$user = User::create ($incoming_fields); $user = User::create ($incoming_fields);
$actor = new Actor ();
$actor->create_from_user ($user);
auth ()->login ($user);
// create a friendship between the new user and the admin UserSignedUp::dispatch ($user);
$admin = User::where ("is_admin", 1)->first (); auth ()->login ($user);
if ($admin)
ActionsFriends::force_friendship ($user, $admin);
return redirect ()->route ("home")->with ("success", "You have successfuly signed up!"); return redirect ()->route ("home")->with ("success", "You have successfuly signed up!");
} }

View File

@ -0,0 +1,48 @@
<?php
namespace App\Listeners;
use App\Models\User;
use App\Models\Actor;
use App\Actions\ActionsFriends;
use App\Events\UserSignedUp;
use App\Notifications\UserNotification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;
class UserSignedUpListener
{
/**
* Create the event listener.
*/
public function __construct()
{
//
}
/**
* Handle the event.
*/
public function handle(UserSignedUp $event): void
{
$actor = new Actor ();
$actor->create_from_user ($event->user);
// create a friendship between the new user and the admin
$admin = User::where ("is_admin", 1)->first ();
if ($admin)
{
ActionsFriends::force_friendship ($event->user, $admin);
$admin->notify (new UserNotification(
"Signup",
$actor->id,
$event->user->id
));
}
}
}

View File

@ -53,5 +53,7 @@
@endforeach @endforeach
</tbody> </tbody>
</table> </table>
{{ $notes->links("pagination::default") }}
</div> </div>
@endsection @endsection

View File

@ -19,13 +19,21 @@
@foreach ($processed_notifications as $notification) @foreach ($processed_notifications as $notification)
<tr @if ($notification ['read_at'] == null) style="font-weight: bold" @endif> <tr @if ($notification ['read_at'] == null) style="font-weight: bold" @endif>
<td> <td>
<a href="{{ route ('users.show', [ 'user_name' => $notification ['actor']->local_actor_id ? $notification ['actor']->local_actor_id : $notification ['actor']->name ]) }}"> @if ($notification ['type'] == 'Signup')
<p>{{ $notification ['actor']->name }}</p> <a href="{{ route ('users.show', [ 'user_name' => $notification ['object']->actor->preferredUsername ]) }}">
</a> <p>{{ $notification ['object']->actor->preferredUsername }}</p>
</a>
@else
<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>
@endif
</td> </td>
<td> <td>
@if ($notification ['type'] == 'Follow') @if ($notification ['type'] == 'Signup')
<p>Joined Ourspace! Say something!!</p>
@elseif ($notification ['type'] == 'Follow')
<p>Followed you</p> <p>Followed you</p>
@elseif ($notification ['type'] == 'Unfollow') @elseif ($notification ['type'] == 'Unfollow')
<p>Unfollowed you</p> <p>Unfollowed you</p>

View File

@ -40,7 +40,7 @@
<script> <script>
let music = document.getElementById ('music'); let music = document.getElementById ('music');
music.volume = 0.1; music.volume = 0.075;
music.play () music.play ()
</script> </script>
@endif @endif