进退完美
This commit is contained in:
1 parent
31bcbbf7ef
commit
b9fe675036
1 file changed
+17
-3
+17
-3
@@ -81,7 +81,23 @@ function createUserItem(user, isMe) {
|
||||
function handleClientList(idx, list, selfId) {
|
||||
const rd = roomsData[idx];
|
||||
if (!rd) return;
|
||||
// 更新在线用户列表和映射
|
||||
// 记录旧用户ID集合
|
||||
const oldUserIds = new Set((rd.userList || []).map(u => u.clientId));
|
||||
// 新用户ID集合
|
||||
const newUserIds = new Set(list.map(u => u.clientId));
|
||||
// 检查退出用户(旧有,新没有)
|
||||
if (rd.isInitialized) {
|
||||
for (const oldId of oldUserIds) {
|
||||
if (!newUserIds.has(oldId)) {
|
||||
const user = rd.userMap[oldId];
|
||||
const name = user ? (user.userName || user.username || user.name || 'Anonymous') : 'Anonymous';
|
||||
const msg = `${name}已退出`;
|
||||
rd.messages.push({ type: 'system', text: msg });
|
||||
if (activeRoomIndex === idx) addSystemMsg(msg, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 更新在线用户列表和映射
|
||||
rd.userList = list;
|
||||
rd.userMap = {};
|
||||
list.forEach(u => { rd.userMap[u.clientId] = u; });
|
||||
@@ -98,9 +114,7 @@ function handleClientList(idx, list, selfId) {
|
||||
// 基准用户集合
|
||||
rd.knownUserIds = new Set(list.map(u => u.clientId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 调整 handleClientSecured: 立即更新UI,仅在初始化完成后才处理加入提示
|
||||
function handleClientSecured(idx, user) {
|
||||
const rd = roomsData[idx];
|
||||
|
||||
Reference in new issue
Block a user