Add VIP presence themes and custom greetings
This commit is contained in:
@@ -16,10 +16,10 @@ use App\Models\User;
|
||||
class RoomBroadcastService
|
||||
{
|
||||
/**
|
||||
* 构造函数注入 VIP 服务(用于获取 VIP 专属入场/离场模板)
|
||||
* 构造函数注入会员进退场主题服务。
|
||||
*/
|
||||
public function __construct(
|
||||
private readonly VipService $vipService,
|
||||
private readonly VipPresenceService $vipPresenceService,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -43,11 +43,12 @@ class RoomBroadcastService
|
||||
|
||||
// 有 VIP:优先用专属进入模板,无模板则随机词加前缀
|
||||
if ($user->isVip() && $user->vipLevel) {
|
||||
$color = $user->vipLevel->color ?: '#f59e0b';
|
||||
$template = $this->vipService->getJoinMessage($user);
|
||||
$theme = $this->vipPresenceService->buildJoinTheme($user);
|
||||
$color = $theme['color'] ?: '#f59e0b';
|
||||
$template = $theme['text'];
|
||||
|
||||
if ($template) {
|
||||
return [$template, $color];
|
||||
return [(string) $template, $color];
|
||||
}
|
||||
|
||||
$text = '【'.$user->vipIcon().' '.$user->vipName().'】'.$this->randomWelcomeMsg($user);
|
||||
@@ -80,11 +81,12 @@ class RoomBroadcastService
|
||||
|
||||
// 有 VIP:优先用专属离场模板,无模板则随机词加前缀
|
||||
if ($user->isVip() && $user->vipLevel) {
|
||||
$color = $user->vipLevel->color ?: '#f59e0b';
|
||||
$template = $this->vipService->getLeaveMessage($user);
|
||||
$theme = $this->vipPresenceService->buildLeaveTheme($user);
|
||||
$color = $theme['color'] ?: '#f59e0b';
|
||||
$template = $theme['text'];
|
||||
|
||||
if ($template) {
|
||||
return [$template, $color];
|
||||
return [(string) $template, $color];
|
||||
}
|
||||
|
||||
$text = '【'.$user->vipIcon().' '.$user->vipName().'】'.$this->randomLeaveMsg($user);
|
||||
@@ -149,4 +151,36 @@ class RoomBroadcastService
|
||||
|
||||
return $templates[array_rand($templates)];
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建会员进退场横幅与特效的前端载荷。
|
||||
*
|
||||
* @param string $type join|leave
|
||||
* @return array<string, string|null>
|
||||
*/
|
||||
public function buildVipPresencePayload(User $user, string $type): array
|
||||
{
|
||||
$theme = $type === 'join'
|
||||
? $this->vipPresenceService->buildJoinTheme($user)
|
||||
: $this->vipPresenceService->buildLeaveTheme($user);
|
||||
|
||||
if (empty($theme['enabled'])) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$text = trim((string) ($theme['text'] ?? ''));
|
||||
if ($text === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return [
|
||||
'presence_type' => $type,
|
||||
'presence_text' => $text,
|
||||
'presence_color' => (string) ($theme['color'] ?? ''),
|
||||
'presence_effect' => $theme['effect'] ? (string) $theme['effect'] : null,
|
||||
'presence_banner_style' => (string) ($theme['banner_style'] ?? ''),
|
||||
'presence_level_name' => (string) ($theme['level_name'] ?? ''),
|
||||
'presence_icon' => (string) ($theme['icon'] ?? ''),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user