优化提醒
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Events\AppointmentAnnounced;
|
||||
use App\Events\MessageSent;
|
||||
use App\Jobs\SaveMessageJob;
|
||||
use App\Models\Position;
|
||||
use App\Models\User;
|
||||
use App\Services\AppointmentService;
|
||||
@@ -92,6 +94,17 @@ class ChatAppointmentController extends Controller
|
||||
departmentName: $position->department?->name ?? '',
|
||||
operatorName: $operator->username,
|
||||
));
|
||||
|
||||
// 给被任命用户补一条私聊提示,并复用右下角 toast 通知。
|
||||
$this->pushTargetToastMessage(
|
||||
roomId: (int) $roomId,
|
||||
targetUsername: $target->username,
|
||||
content: "✨ <b>{$operator->username}</b> 已任命你为 {$position->icon} {$position->name}。",
|
||||
title: '✨ 职务任命通知',
|
||||
toastMessage: "<b>{$operator->username}</b> 已任命你为 <b>{$position->icon} {$position->name}</b>。",
|
||||
color: '#a855f7',
|
||||
icon: '✨',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +149,17 @@ class ChatAppointmentController extends Controller
|
||||
operatorName: $operator->username,
|
||||
type: 'revoke',
|
||||
));
|
||||
|
||||
// 给被撤职用户补一条私聊提示,并复用右下角 toast 通知。
|
||||
$this->pushTargetToastMessage(
|
||||
roomId: (int) $roomId,
|
||||
targetUsername: $target->username,
|
||||
content: "📋 <b>{$operator->username}</b> 已撤销你的 {$posIcon} {$posName} 职务。",
|
||||
title: '📋 职务变动通知',
|
||||
toastMessage: "<b>{$operator->username}</b> 已撤销你的 <b>{$posIcon} {$posName}</b> 职务。",
|
||||
color: '#6b7280',
|
||||
icon: '📋',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,4 +168,41 @@ class ChatAppointmentController extends Controller
|
||||
'message' => $result['message'],
|
||||
], $result['ok'] ? 200 : 422);
|
||||
}
|
||||
|
||||
/**
|
||||
* 向目标用户补发一条系统私聊消息,并附带右下角 toast 配置。
|
||||
*/
|
||||
private function pushTargetToastMessage(
|
||||
int $roomId,
|
||||
string $targetUsername,
|
||||
string $content,
|
||||
string $title,
|
||||
string $toastMessage,
|
||||
string $color,
|
||||
string $icon,
|
||||
): void {
|
||||
$msg = [
|
||||
'id' => $this->chatState->nextMessageId($roomId),
|
||||
'room_id' => $roomId,
|
||||
'from_user' => '系统',
|
||||
'to_user' => $targetUsername,
|
||||
'content' => $content,
|
||||
'is_secret' => true,
|
||||
'font_color' => $color,
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
// 复用现有聊天 toast 机制,在右下角弹出职务变动提示。
|
||||
'toast_notification' => [
|
||||
'title' => $title,
|
||||
'message' => $toastMessage,
|
||||
'icon' => $icon,
|
||||
'color' => $color,
|
||||
'duration' => 10000,
|
||||
],
|
||||
];
|
||||
|
||||
$this->chatState->pushMessage($roomId, $msg);
|
||||
broadcast(new MessageSent($roomId, $msg));
|
||||
SaveMessageJob::dispatch($msg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user