修复在线名单职务图标显示
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use Illuminate\Support\Facades\Broadcast;
|
use Illuminate\Support\Facades\Broadcast;
|
||||||
|
|
||||||
|
// 用户私有频道:仅允许用户本人订阅自己的通知频道。
|
||||||
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
Broadcast::channel('App.Models.User.{id}', function ($user, $id) {
|
||||||
return (int) $user->id === (int) $id;
|
return (int) $user->id === (int) $id;
|
||||||
});
|
});
|
||||||
@@ -19,6 +20,9 @@ Broadcast::channel('room.{roomId}', function ($user, $roomId) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$superLevel = (int) \App\Models\Sysparam::getValue('superlevel', '100');
|
$superLevel = (int) \App\Models\Sysparam::getValue('superlevel', '100');
|
||||||
|
// 预加载当前在职职务,供右侧在线名单直接显示职务图标与名称。
|
||||||
|
$activePosition = $user->activePosition()->with('position.department')->first();
|
||||||
|
$position = $activePosition?->position;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'id' => $user->id,
|
'id' => $user->id,
|
||||||
@@ -30,6 +34,9 @@ Broadcast::channel('room.{roomId}', function ($user, $roomId) {
|
|||||||
'vip_name' => $user->vipName(),
|
'vip_name' => $user->vipName(),
|
||||||
'vip_color' => $user->isVip() ? ($user->vipLevel?->color ?? '') : '',
|
'vip_color' => $user->isVip() ? ($user->vipLevel?->color ?? '') : '',
|
||||||
'is_admin' => $user->user_level >= $superLevel,
|
'is_admin' => $user->user_level >= $superLevel,
|
||||||
|
'position_icon' => $position?->icon ?? '',
|
||||||
|
'position_name' => $position?->name ?? '',
|
||||||
|
'department_name' => $position?->department?->name ?? '',
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -124,6 +124,31 @@ class ChatControllerTest extends TestCase
|
|||||||
$this->assertFalse($channelCallback($user, (string) $room->id));
|
$this->assertFalse($channelCallback($user, (string) $room->id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 测试聊天室 Presence 频道会返回当前在职职务图标与名称。
|
||||||
|
*/
|
||||||
|
public function test_room_presence_channel_returns_active_position_payload(): void
|
||||||
|
{
|
||||||
|
$room = Room::create([
|
||||||
|
'room_name' => 'posbadge',
|
||||||
|
'door_open' => true,
|
||||||
|
]);
|
||||||
|
$user = $this->createUserWithPositionPermissions([]);
|
||||||
|
$position = $user->activePosition()->with('position.department')->first()?->position;
|
||||||
|
$channelCallback = Broadcast::driver()->getChannels()->get('room.{roomId}');
|
||||||
|
|
||||||
|
$this->assertIsCallable($channelCallback);
|
||||||
|
|
||||||
|
$this->actingAs($user)->get(route('chat.room', $room->id));
|
||||||
|
|
||||||
|
$authorizedPayload = $channelCallback($user, (string) $room->id);
|
||||||
|
|
||||||
|
$this->assertIsArray($authorizedPayload);
|
||||||
|
$this->assertSame('🛡️', $authorizedPayload['position_icon'] ?? null);
|
||||||
|
$this->assertSame($position?->name, $authorizedPayload['position_name'] ?? null);
|
||||||
|
$this->assertSame($position?->department?->name, $authorizedPayload['department_name'] ?? null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 测试主干默认聊天室页面不会渲染虚拟形象挂载点和配置。
|
* 测试主干默认聊天室页面不会渲染虚拟形象挂载点和配置。
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user