新增聊天室状态与功能快捷菜单
This commit is contained in:
@@ -19,20 +19,35 @@ namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\UserKicked;
|
||||
use App\Events\UserMuted;
|
||||
use App\Events\UserStatusUpdated;
|
||||
use App\Http\Requests\ChangePasswordRequest;
|
||||
use App\Http\Requests\UpdateChatPreferencesRequest;
|
||||
use App\Http\Requests\UpdateDailyStatusRequest;
|
||||
use App\Http\Requests\UpdateProfileRequest;
|
||||
use App\Models\Room;
|
||||
use App\Models\Sysparam;
|
||||
use App\Models\User;
|
||||
use App\Services\ChatStateService;
|
||||
use App\Services\ChatUserPresenceService;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Redis;
|
||||
|
||||
/**
|
||||
* 类功能:处理用户资料、聊天室偏好、当日状态与基础管理动作。
|
||||
*/
|
||||
class UserController extends Controller
|
||||
{
|
||||
/**
|
||||
* 构造用户控制器依赖。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly ChatStateService $chatState,
|
||||
private readonly ChatUserPresenceService $chatUserPresenceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* 查看其他用户资料片 (对应 USERinfo.ASP)
|
||||
*/
|
||||
@@ -230,6 +245,55 @@ class UserController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存聊天室当日状态,并同步当前在线名单显示。
|
||||
*/
|
||||
public function updateDailyStatus(UpdateDailyStatusRequest $request): JsonResponse
|
||||
{
|
||||
$user = Auth::user();
|
||||
$data = $request->validated();
|
||||
$roomId = (int) $data['room_id'];
|
||||
|
||||
// 仅允许当前确实在线的用户从聊天室内修改状态,避免离线脏请求写入。
|
||||
if (! $this->chatState->isUserInRoom($roomId, $user->username)) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => '请先进入聊天室后再设置状态。',
|
||||
], 422);
|
||||
}
|
||||
|
||||
if ($data['action'] === 'clear') {
|
||||
$user->update([
|
||||
'daily_status_key' => null,
|
||||
'daily_status_expires_at' => null,
|
||||
]);
|
||||
} else {
|
||||
// 状态有效期固定维持到当天结束,次日自动失效。
|
||||
$user->update([
|
||||
'daily_status_key' => $data['status_key'],
|
||||
'daily_status_expires_at' => now()->endOfDay(),
|
||||
]);
|
||||
}
|
||||
|
||||
$user->refresh();
|
||||
$presencePayload = $this->chatUserPresenceService->build($user);
|
||||
$roomIds = $this->chatState->getUserRooms($user->username);
|
||||
|
||||
foreach ($roomIds as $activeRoomId) {
|
||||
// 所有当前在线房间都刷新 Redis 载荷,确保头像、会员与状态显示口径一致。
|
||||
$this->chatState->userJoin((int) $activeRoomId, $user->username, $presencePayload);
|
||||
broadcast(new UserStatusUpdated((int) $activeRoomId, $user->username, $presencePayload));
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => $data['action'] === 'clear' ? '状态已清除。' : '状态已更新。',
|
||||
'data' => [
|
||||
'status' => $this->chatUserPresenceService->currentDailyStatus($user),
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码 (对应 chpasswd.asp)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user