后端:
- FriendController:add/remove/status/index 四个接口
- FriendAdded / FriendRemoved 广播事件(私有频道)
- channels.php 注册 user.{username} 私有频道鉴权
- routes/web.php 注册好友路由
- ChatController::init() 修复 DutyLog 在 return 后执行的 bug
- ChatController::notifyFriendsOnline() 上线时悄悄话通知好友
前端:
- user-actions:写私信 → 加好友/删好友按钮(动态状态)
- toggleFriend() 方法 + fetchUser 后加载好友状态
- scripts:监听私有频道 FriendAdded/FriendRemoved
- showFriendToast() 右下角浮窗通知(5秒自动消失)
- global-dialog 加 fdSlideIn 动画
35 lines
1.4 KiB
PHP
35 lines
1.4 KiB
PHP
<?php
|
||
|
||
use Illuminate\Support\Facades\Broadcast;
|
||
|
||
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
||
return (int) $user->id === (int) $id;
|
||
});
|
||
|
||
// 聊天室房间 Presence Channel 鉴权与成员信息抓取
|
||
Broadcast::channel('room.{roomId}', function ($user, $roomId) {
|
||
// 这里未来可以增加判断:比如该房间是否被锁定,或者该用户是否在此房间的黑名单中
|
||
// 凡是通过了这个判断的人(返回一个数组),他就会成功建立 WebSocket,
|
||
// 且他的这个数组信息会被 Reverb 推送给这个房间内的所有其他人 (joining / here 事件)。
|
||
|
||
$superLevel = (int) \App\Models\Sysparam::getValue('superlevel', '100');
|
||
|
||
return [
|
||
'id' => $user->id,
|
||
'username' => $user->username,
|
||
'user_level' => $user->user_level,
|
||
'sex' => $user->sex,
|
||
'headface' => $user->headface, // 通过 accessor 读取 usersf,默认 1.gif
|
||
'vip_icon' => $user->vipIcon(),
|
||
'vip_name' => $user->vipName(),
|
||
'vip_color' => $user->isVip() ? ($user->vipLevel?->color ?? '') : '',
|
||
'is_admin' => $user->user_level >= $superLevel,
|
||
];
|
||
});
|
||
|
||
// 用户私有频道鉴权(好友通知:FriendAdded / FriendRemoved)
|
||
// 只有用户名匹配的本人才能订阅
|
||
Broadcast::channel('user.{username}', function ($user, string $username) {
|
||
return $user->username === $username;
|
||
});
|