优化 刷新页面不在重复播报 离开和登录提示
This commit is contained in:
@@ -30,7 +30,8 @@ class ProcessUserLeave implements ShouldQueue
|
||||
public function __construct(
|
||||
public int $roomId,
|
||||
public User $user,
|
||||
public float $leaveTime
|
||||
public float $leaveTime,
|
||||
public string $outInfo = '正常退出了房间',
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -52,7 +53,7 @@ class ProcessUserLeave implements ShouldQueue
|
||||
// 记录退出时间和退出信息
|
||||
$this->user->update([
|
||||
'out_time' => now(),
|
||||
'out_info' => '正常退出了房间',
|
||||
'out_info' => $this->outInfo,
|
||||
]);
|
||||
|
||||
// 关闭该用户尚未结束的在职登录记录(结算在线时长)
|
||||
@@ -60,41 +61,25 @@ class ProcessUserLeave implements ShouldQueue
|
||||
|
||||
// 2. 发送离场播报
|
||||
$superLevel = (int) Sysparam::getValue('superlevel', '100');
|
||||
|
||||
[$leaveText, $color] = $broadcast->buildLeaveBroadcast($this->user);
|
||||
$vipPresencePayload = $broadcast->buildVipPresencePayload($this->user, 'leave');
|
||||
$leaveMsg = [
|
||||
'id' => $chatState->nextMessageId($this->roomId),
|
||||
'room_id' => $this->roomId,
|
||||
'from_user' => '进出播报',
|
||||
'to_user' => '大家',
|
||||
'content' => "<span style=\"color: {$color}; font-weight: bold;\">{$leaveText}</span>",
|
||||
'is_secret' => false,
|
||||
'font_color' => $color,
|
||||
'action' => empty($vipPresencePayload) ? 'system_welcome' : 'vip_presence',
|
||||
'welcome_user' => $this->user->username,
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
if ($this->user->user_level >= $superLevel) {
|
||||
// 管理员离场:系统公告
|
||||
$leaveMsg = [
|
||||
'id' => $chatState->nextMessageId($this->roomId),
|
||||
'room_id' => $this->roomId,
|
||||
'from_user' => '系统公告',
|
||||
'to_user' => '大家',
|
||||
'content' => "👋 管理员 【{$this->user->username}】 已离开聊天室。",
|
||||
'is_secret' => false,
|
||||
'font_color' => '#b91c1c',
|
||||
'action' => 'admin_welcome',
|
||||
'welcome_user' => $this->user->username,
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
} else {
|
||||
[$leaveText, $color] = $broadcast->buildLeaveBroadcast($this->user);
|
||||
$vipPresencePayload = $broadcast->buildVipPresencePayload($this->user, 'leave');
|
||||
$leaveMsg = [
|
||||
'id' => $chatState->nextMessageId($this->roomId),
|
||||
'room_id' => $this->roomId,
|
||||
'from_user' => '进出播报',
|
||||
'to_user' => '大家',
|
||||
'content' => "<span style=\"color: {$color}; font-weight: bold;\">{$leaveText}</span>",
|
||||
'is_secret' => false,
|
||||
'font_color' => $color,
|
||||
'action' => empty($vipPresencePayload) ? 'system_welcome' : 'vip_presence',
|
||||
'welcome_user' => $this->user->username,
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
];
|
||||
|
||||
// 会员离场时,把横幅与特效信息挂到消息体,前端才能展示专属离场效果。
|
||||
if (! empty($vipPresencePayload)) {
|
||||
$leaveMsg = array_merge($leaveMsg, $vipPresencePayload);
|
||||
}
|
||||
// 会员离场时,把横幅与特效信息挂到消息体,前端才能展示专属离场效果。
|
||||
if (! empty($vipPresencePayload)) {
|
||||
$leaveMsg = array_merge($leaveMsg, $vipPresencePayload);
|
||||
}
|
||||
|
||||
// 将播报存入 Redis 历史及广播
|
||||
|
||||
Reference in New Issue
Block a user