mirror of https://github.com/pixelfed/pixelfed.git
Add broadcast events for real time updates
This commit is contained in:
parent
5fe8ec5476
commit
cb202c9671
|
@ -0,0 +1,51 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use App\User;
|
||||
|
||||
class NewMention implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
protected $user;
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(User $user, $data)
|
||||
{
|
||||
$this->user = $user;
|
||||
$this->data = $data;
|
||||
}
|
||||
|
||||
public function broadcastAs()
|
||||
{
|
||||
return 'notification.new.mention';
|
||||
}
|
||||
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new PrivateChannel('App.User.' . $this->user->id);
|
||||
}
|
||||
|
||||
public function broadcastWith()
|
||||
{
|
||||
return ['id' => $this->user->id];
|
||||
}
|
||||
|
||||
public function via()
|
||||
{
|
||||
return 'broadcast';
|
||||
}
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
<?php
|
||||
|
||||
namespace App\Events\Notification;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Broadcasting\PresenceChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||||
use App\Status;
|
||||
use App\Transformer\Api\StatusTransformer;
|
||||
use League\Fractal;
|
||||
use League\Fractal\Serializer\ArraySerializer;
|
||||
use League\Fractal\Pagination\IlluminatePaginatorAdapter;
|
||||
|
||||
class NewPublicPost implements ShouldBroadcastNow
|
||||
{
|
||||
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||||
|
||||
protected $status;
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Status $status)
|
||||
{
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
public function broadcastAs()
|
||||
{
|
||||
return 'status';
|
||||
}
|
||||
|
||||
public function broadcastOn()
|
||||
{
|
||||
return new Channel('firehost.public');
|
||||
}
|
||||
|
||||
public function broadcastWith()
|
||||
{
|
||||
$resource = new Fractal\Resource\Item($this->status, new StatusTransformer());
|
||||
$res = $this->fractal->createData($resource)->toArray();
|
||||
return [
|
||||
'entity' => $res
|
||||
];
|
||||
}
|
||||
|
||||
public function via()
|
||||
{
|
||||
return 'broadcast';
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue