修正房主不显示自己信息的问题

This commit is contained in:
mtvpls
2025-12-07 21:35:39 +08:00
parent d729be9177
commit c38d1bbdad
2 changed files with 8 additions and 7 deletions
@@ -25,7 +25,6 @@ export default function ChatFloatingWindow() {
useEffect(() => { useEffect(() => {
const roomId = watchRoom?.currentRoom?.id || null; const roomId = watchRoom?.currentRoom?.id || null;
if (roomId !== currentRoomIdRef.current) { if (roomId !== currentRoomIdRef.current) {
console.log('[ChatFloatingWindow] Room changed:', currentRoomIdRef.current, '->', roomId);
currentRoomIdRef.current = roomId; currentRoomIdRef.current = roomId;
lastMessageCountRef.current = 0; lastMessageCountRef.current = 0;
setUnreadCount(0); setUnreadCount(0);
@@ -66,15 +65,10 @@ export default function ChatFloatingWindow() {
if (currentCount > lastMessageCountRef.current) { if (currentCount > lastMessageCountRef.current) {
// 有新消息 // 有新消息
const newMessageCount = currentCount - lastMessageCountRef.current; const newMessageCount = currentCount - lastMessageCountRef.current;
console.log('[ChatFloatingWindow] New messages:', newMessageCount, 'isOpen:', isOpenRef.current, 'isMinimized:', isMinimizedRef.current);
if (!isOpenRef.current && !isMinimizedRef.current) { if (!isOpenRef.current && !isMinimizedRef.current) {
// 只有在聊天窗口完全关闭时才增加未读计数 // 只有在聊天窗口完全关闭时才增加未读计数
setUnreadCount(prev => { setUnreadCount(prev => prev + newMessageCount);
const newCount = prev + newMessageCount;
console.log('[ChatFloatingWindow] Updating unread count:', prev, '->', newCount);
return newCount;
});
} }
} }
lastMessageCountRef.current = currentCount; lastMessageCountRef.current = currentCount;
+7
View File
@@ -107,6 +107,13 @@ export function useWatchRoom(onRoomDeleted?: (data?: { reason?: string }) => voi
if (response.success && response.room) { if (response.success && response.room) {
setCurrentRoom(response.room); setCurrentRoom(response.room);
setIsOwner(true); setIsOwner(true);
// 创建房间时,手动设置房主的成员信息
setMembers([{
id: sock.id!,
name: data.userName,
isOwner: true,
lastHeartbeat: Date.now(),
}]);
storeRoomInfo({ storeRoomInfo({
roomId: response.room.id, roomId: response.room.id,
roomName: response.room.name, roomName: response.room.name,