修复悄悄话文字颜色及不能发数字0的问题
This commit is contained in:
@@ -362,7 +362,7 @@ class ChatController extends Controller
|
|||||||
|
|
||||||
// 1. 过滤净化消息体
|
// 1. 过滤净化消息体
|
||||||
$pureContent = $this->filter->filter($data['content'] ?? '');
|
$pureContent = $this->filter->filter($data['content'] ?? '');
|
||||||
if (empty($pureContent)) {
|
if ($pureContent === '') {
|
||||||
return response()->json(['status' => 'error', 'message' => '消息内容不能为空或不合法。'], 422);
|
return response()->json(['status' => 'error', 'message' => '消息内容不能为空或不合法。'], 422);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class MessageFilterService
|
|||||||
*/
|
*/
|
||||||
public function filter(string $content): string
|
public function filter(string $content): string
|
||||||
{
|
{
|
||||||
if (empty($content)) {
|
if ($content === '') {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -725,7 +725,8 @@
|
|||||||
const verbStr = msg.action ?
|
const verbStr = msg.action ?
|
||||||
buildActionStr(msg.action, fromHtml, toHtml, '悄悄说') :
|
buildActionStr(msg.action, fromHtml, toHtml, '悄悄说') :
|
||||||
`${fromHtml}对${toHtml}悄悄说:`;
|
`${fromHtml}对${toHtml}悄悄说:`;
|
||||||
html = `<span class="msg-secret">${headImg}${verbStr}${msg.content}</span>`;
|
html =
|
||||||
|
`${headImg}<span class="msg-secret">${verbStr}</span><span class="msg-content" style="color: ${fontColor}; font-style: italic;">${msg.content}</span>`;
|
||||||
}
|
}
|
||||||
} else if (msg.to_user && msg.to_user !== '大家') {
|
} else if (msg.to_user && msg.to_user !== '大家') {
|
||||||
// 对特定对象说话
|
// 对特定对象说话
|
||||||
|
|||||||
@@ -67,6 +67,39 @@ class ChatControllerTest extends TestCase
|
|||||||
$this->assertTrue($found, 'Message not found in Redis');
|
$this->assertTrue($found, 'Message not found in Redis');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_can_send_zero_message_content(): void
|
||||||
|
{
|
||||||
|
$room = Room::create(['room_name' => 'test_send_zero']);
|
||||||
|
$user = User::factory()->create();
|
||||||
|
|
||||||
|
$this->actingAs($user)->get(route('chat.room', $room->id));
|
||||||
|
|
||||||
|
$response = $this->actingAs($user)->postJson(route('chat.send', $room->id), [
|
||||||
|
'to_user' => '大家',
|
||||||
|
'content' => '0',
|
||||||
|
'is_secret' => false,
|
||||||
|
'font_color' => '#000000',
|
||||||
|
'action' => '',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$response->assertOk();
|
||||||
|
$response->assertJson(['status' => 'success']);
|
||||||
|
|
||||||
|
$messages = Redis::lrange("room:{$room->id}:messages", 0, -1);
|
||||||
|
$found = false;
|
||||||
|
|
||||||
|
foreach ($messages as $msgJson) {
|
||||||
|
$msg = json_decode($msgJson, true);
|
||||||
|
|
||||||
|
if ($msg['from_user'] === $user->username && $msg['content'] === '0') {
|
||||||
|
$found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertTrue($found, 'Zero message not found in Redis');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_can_trigger_heartbeat()
|
public function test_can_trigger_heartbeat()
|
||||||
{
|
{
|
||||||
$room = Room::create(['room_name' => 'test_hb']);
|
$room = Room::create(['room_name' => 'test_hb']);
|
||||||
|
|||||||
Reference in New Issue
Block a user