59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 文件功能:用户定向页面刷新广播事件
|
||
|
|
*
|
||
|
|
* 在任命或撤销职务成功后,向目标用户私有频道推送刷新指令,
|
||
|
|
* 确保对方页面上的权限按钮与职务状态及时同步。
|
||
|
|
*
|
||
|
|
* @author ChatRoom Laravel
|
||
|
|
*
|
||
|
|
* @version 1.0.0
|
||
|
|
*/
|
||
|
|
|
||
|
|
namespace App\Events;
|
||
|
|
|
||
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
||
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
||
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
|
||
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
||
|
|
use Illuminate\Queue\SerializesModels;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 类功能:向指定用户广播页面刷新请求。
|
||
|
|
*/
|
||
|
|
class UserBrowserRefreshRequested implements ShouldBroadcastNow
|
||
|
|
{
|
||
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 构造函数:记录目标用户与刷新说明。
|
||
|
|
*/
|
||
|
|
public function __construct(
|
||
|
|
public readonly int $targetUserId,
|
||
|
|
public readonly string $operator,
|
||
|
|
public readonly string $reason = '',
|
||
|
|
) {}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 广播频道:目标用户私有频道。
|
||
|
|
*/
|
||
|
|
public function broadcastOn(): PrivateChannel
|
||
|
|
{
|
||
|
|
return new PrivateChannel('user.'.$this->targetUserId);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 广播数据:供前端展示提示并执行刷新。
|
||
|
|
*
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function broadcastWith(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'operator' => $this->operator,
|
||
|
|
'reason' => $this->reason,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|