功能:好友面板昵称后显示在线离线状态

后端:
- ChatStateService 新增 getAllOnlineUsernames(),跨房间聚合在线用户名
- FriendController::index() 为每位好友/待回加用户附加 is_online 字段
- 在线好友自动排在列表前面

前端:
- 昵称后显示 🟢 在线 /  离线 徽标
- .fp-status-online 绿底绿字,.fp-status-offline 灰底灰字
This commit is contained in:
2026-03-03 17:42:47 +08:00
parent 36fbc9982c
commit 40fcce2db3
3 changed files with 75 additions and 14 deletions
+22
View File
@@ -119,6 +119,28 @@ class ChatStateService
return array_unique($roomIds);
}
/**
* 获取全局所有在线用户名(跨所有房间,去重)。
*
* 遍历所有活跃房间,合并用户名后去重,
* 用于好友面板在线状态标记。
*
* @return array<string>
*/
public function getAllOnlineUsernames(): array
{
$usernames = [];
foreach ($this->getAllActiveRoomIds() as $roomId) {
$key = "room:{$roomId}:users";
$users = Redis::hkeys($key); // 只取 key(用户名),不取 value
foreach ($users as $username) {
$usernames[] = $username;
}
}
return array_unique($usernames);
}
/**
* 将一条新发言推入 Redis 列表,并限制最大保留数量,防止内存泄漏。
*