Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.11] Store Rewrite & Websockets #516

Open
wants to merge 27 commits into
base: release-0.11
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c0937d0
add frontend part of websocket libs
v1r0x Jun 20, 2024
eea7855
add example for basic public channel subscription and data updates
v1r0x Jun 20, 2024
ae43a08
replace third-party auth with laravel sanctum
v1r0x Jun 23, 2024
41e3290
setup test event system to test private channel broadcasting
v1r0x Jun 23, 2024
927de7a
several login and auth related fixes
v1r0x Jun 25, 2024
d37dcab
cleanup websocket test; add helpers
v1r0x Jun 25, 2024
fbd4dc3
Merge remote-tracking branch 'origin/master' into 0.11-feat-realtime
v1r0x Aug 29, 2024
728456d
update lock files; fix merge fails
v1r0x Aug 29, 2024
21d68ce
add active users to entitydetail
v1r0x Aug 30, 2024
5aeaa8f
beginning to replace vuex with pinia and test combination with websoc…
v1r0x Aug 30, 2024
b78e8c2
highlighted updated entity in tree; more migration vuex -> pinia
v1r0x Sep 16, 2024
8c9c37b
finish vuex migration
v1r0x Sep 23, 2024
c209253
use broadcast for event dispatching
v1r0x Sep 25, 2024
459471c
ui polishing
v1r0x Oct 9, 2024
9c618c5
restructure Notification model; add event emitters and handlers; rest…
v1r0x Oct 9, 2024
6da3660
Merge branch 'release-0.11' into 0.11-feat-realtime
v1r0x Oct 10, 2024
540ecd6
fix moderation
v1r0x Oct 10, 2024
609a066
fix merge error
v1r0x Oct 10, 2024
c824b24
add events to handle attribute value changes; introduce new dotindica…
v1r0x Nov 5, 2024
60ba4e3
remove update indicator from node component
v1r0x Nov 11, 2024
2171f44
update entity instead of a backup
v1r0x Nov 11, 2024
0cf9bb4
Merge branch 'release-0.11' into 0.11-feat-realtime
v1r0x Nov 11, 2024
9bb5307
minor fixes
v1r0x Nov 15, 2024
88552ab
Merge branch 'release-0.11' into 0.11-feat-realtime; fix and adjust t…
v1r0x Nov 26, 2024
70526fa
update workflow files
v1r0x Nov 27, 2024
2e88e45
revert reverb .env config
v1r0x Nov 27, 2024
902b39c
fix plugin stores
v1r0x Nov 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .env.phpunit
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ APP_ENV=testing
APP_KEY=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://localhost
APP_URL=http://localhost:8000
APP_FORCE_URL=false
FRONTEND_URL=http://localhost:5173
SESSION_DOMAIN=localhost
SANCTUM_STATEFUL_DOMAINS=localhost:8000,localhost:5173

DB_CONNECTION=testing
DB_HOST=localhost
Expand All @@ -16,3 +20,6 @@ BROADCAST_DRIVER=log
CACHE_DRIVER=array
SESSION_DRIVER=array
QUEUE_DRIVER=sync

VITE_APP_PATH=
VITE_APP_NAME='Spacialist Testing Instance'
3 changes: 1 addition & 2 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ jobs:
run: composer update
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate keys
- name: Generate key
run: |
php artisan key:generate
php artisan jwt:secret
- name: Run migrations
run: |
php artisan migrate
Expand Down
4 changes: 1 addition & 3 deletions app/AttributeTypes/EntityAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class EntityAttribute extends AttributeBase
protected static string $type = "entity";
protected static bool $inTable = true;
protected static ?string $field = 'entity_val';

// TODO: Do we still need this?
// protected static string $deleted_string = "error.deleted_entity";
protected static string $deleted_string = "error.deleted_entity";

public static function parseImport(int|float|bool|string $data) : mixed {
// TODO: This does not check if the entity that is selected is actually valid!
Expand Down
45 changes: 45 additions & 0 deletions app/Console/Commands/TestWebsocket.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace App\Console\Commands;

use App\Events\TestEvent;
use Illuminate\Console\Command;

class TestWebsocket extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'app:test-websocket {message : Message to send}';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Sends a message using a predefined Event (using a public and private channel) to test websocket functionality';

/**
* Create a new command instance.
*
* @return void
*/
public function __construct() {
parent::__construct();
}

/**
* Execute the console command.
*/
public function handle()

Check warning on line 36 in app/Console/Commands/TestWebsocket.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/TestWebsocket.php#L36

Added line #L36 was not covered by tests
{
$message = $this->argument('message');

Check warning on line 38 in app/Console/Commands/TestWebsocket.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/TestWebsocket.php#L38

Added line #L38 was not covered by tests

TestEvent::dispatch($message);

Check warning on line 40 in app/Console/Commands/TestWebsocket.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/TestWebsocket.php#L40

Added line #L40 was not covered by tests

$this->info("Message \"$message\" successfully send to TestEvent!");
return 0;

Check warning on line 43 in app/Console/Commands/TestWebsocket.php

View check run for this annotation

Codecov / codecov/patch

app/Console/Commands/TestWebsocket.php#L42-L43

Added lines #L42 - L43 were not covered by tests
}
}
43 changes: 43 additions & 0 deletions app/Events/AttributeValueCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Events;

use App\AttributeValue;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class AttributeValueCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $value;

/**
* Create a new event instance.
*/
public function __construct(
public AttributeValue $attributeValue,
public User $user,
)
{
$this->attributeValue = $attributeValue;
$this->user = $user;
$this->value = $attributeValue->getValue();
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PresenceChannel('room.entity.' . $this->attributeValue->entity->id),
];
}
}
43 changes: 43 additions & 0 deletions app/Events/AttributeValueDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Events;

use App\AttributeValue;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class AttributeValueDeleted implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $value;

/**
* Create a new event instance.
*/
public function __construct(
public AttributeValue $attributeValue,
public User $user,
)
{
$this->attributeValue = $attributeValue;
$this->user = $user;
$this->value = $attributeValue->getValue();
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PresenceChannel('room.entity.' . $this->attributeValue->entity->id),
];
}
}
43 changes: 43 additions & 0 deletions app/Events/AttributeValueUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace App\Events;

use App\AttributeValue;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class AttributeValueUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

public $value;

/**
* Create a new event instance.
*/
public function __construct(
public AttributeValue $attributeValue,
public User $user,
)
{
$this->attributeValue = $attributeValue;
$this->user = $user;
$this->value = $attributeValue->getValue();
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PresenceChannel('room.entity.' . $this->attributeValue->entity->id),
];
}
}
40 changes: 40 additions & 0 deletions app/Events/BibliographyCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Events;

use App\Bibliography;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class BibliographyCreated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Bibliography $bibliography,
public User $user,
)
{
$this->bibliography = $bibliography;
$this->user = $user;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel.system'),
];
}
}
40 changes: 40 additions & 0 deletions app/Events/BibliographyDeleted.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Events;

use App\Bibliography;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class BibliographyDeleted implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Bibliography $bibliography,
public User $user,
)
{
$this->bibliography = $bibliography;
$this->user = $user;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel.system'),
];
}
}
40 changes: 40 additions & 0 deletions app/Events/BibliographyUpdated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Events;

use App\Bibliography;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class BibliographyUpdated implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Bibliography $bibliography,
public User $user,
)
{
$this->bibliography = $bibliography;
$this->user = $user;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
return [
new PrivateChannel('channel.system'),
];
}
}
51 changes: 51 additions & 0 deletions app/Events/CommentAdded.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php

namespace App\Events;

use App\Comment;
use App\User;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;

class CommentAdded implements ShouldBroadcast
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* Create a new event instance.
*/
public function __construct(
public Comment $comment,
public User $user,
)
{
$this->comment = $comment;
$this->user = $user;
}

/**
* Get the channels the event should broadcast on.
*
* @return array<int, \Illuminate\Broadcasting\Channel>
*/
public function broadcastOn(): array
{
if(isset($this->comment->commentable_type)) {
$room = sp_get_comment_room($this->comment->commentable_type);
} else {
$room = sp_get_comment_room(
Comment::find($this->comment->reply_to)->commentable_type
);
}

if(!isset($room)) return [];

$cid = $this->comment->commentable_id;
return [
new PresenceChannel("room.$room.$cid"),
];
}
}
Loading
Loading