修复普通定向发言公屏可见
This commit is contained in:
@@ -568,9 +568,54 @@ class ChatControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试定向消息仅广播到发送方与接收方私有频道。
|
||||
* 测试历史消息会让旁观用户看到普通定向发言,但不会泄露悄悄话。
|
||||
*/
|
||||
public function test_targeted_message_event_uses_private_user_channels(): void
|
||||
public function test_room_history_keeps_non_secret_targeted_messages_visible_to_others(): void
|
||||
{
|
||||
$room = Room::create(['room_name' => 'histtg']);
|
||||
$sender = User::factory()->create(['username' => 'history-sender']);
|
||||
$receiver = User::factory()->create(['username' => 'history-receiver']);
|
||||
$observer = User::factory()->create(['username' => 'history-observer']);
|
||||
$chatState = app(\App\Services\ChatStateService::class);
|
||||
|
||||
$chatState->pushMessage($room->id, [
|
||||
'id' => 1,
|
||||
'room_id' => $room->id,
|
||||
'from_user' => $sender->username,
|
||||
'to_user' => $receiver->username,
|
||||
'content' => '公开对你说',
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
]);
|
||||
$chatState->pushMessage($room->id, [
|
||||
'id' => 2,
|
||||
'room_id' => $room->id,
|
||||
'from_user' => $sender->username,
|
||||
'to_user' => $receiver->username,
|
||||
'content' => '旁人不可见悄悄话',
|
||||
'is_secret' => true,
|
||||
'font_color' => '#000000',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$response = $this->actingAs($observer)->get(route('chat.room', $room->id));
|
||||
|
||||
$response->assertOk();
|
||||
$response->assertViewHas('historyMessages', function (array $messages): bool {
|
||||
$contents = collect($messages)->pluck('content');
|
||||
|
||||
return $contents->contains('公开对你说')
|
||||
&& ! $contents->contains('旁人不可见悄悄话');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试悄悄话消息仅广播到发送方与接收方私有频道。
|
||||
*/
|
||||
public function test_secret_message_event_uses_private_user_channels(): void
|
||||
{
|
||||
$sender = User::factory()->create(['username' => 'sender-user']);
|
||||
$receiver = User::factory()->create(['username' => 'receiver-user']);
|
||||
@@ -597,7 +642,30 @@ class ChatControllerTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试公共消息仍广播到房间 Presence 频道。
|
||||
* 测试普通定向消息仍广播到房间 Presence 频道。
|
||||
*/
|
||||
public function test_non_secret_targeted_message_event_uses_room_presence_channel(): void
|
||||
{
|
||||
$event = new MessageSent(3, [
|
||||
'room_id' => 3,
|
||||
'from_user' => 'tester',
|
||||
'to_user' => 'receiver-user',
|
||||
'content' => '公开对你说',
|
||||
'is_secret' => false,
|
||||
'font_color' => '#000000',
|
||||
'action' => '',
|
||||
'sent_at' => now()->toDateTimeString(),
|
||||
]);
|
||||
|
||||
$channels = $event->broadcastOn();
|
||||
|
||||
$this->assertCount(1, $channels);
|
||||
$this->assertInstanceOf(PresenceChannel::class, $channels[0]);
|
||||
$this->assertSame('presence-room.3', $channels[0]->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试对大家消息仍广播到房间 Presence 频道。
|
||||
*/
|
||||
public function test_public_message_event_still_uses_room_presence_channel(): void
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user