This commit is contained in:
parent
24d9a945b3
commit
c2bcc86527
12 changed files with 252 additions and 83 deletions
|
|
@ -16,7 +16,7 @@
|
|||
} from '$lib/chat/chatStore';
|
||||
import { chatWebSocket } from '$lib/chat/chatWebSocket';
|
||||
import { chatLayout } from '$lib/stores/chatLayout';
|
||||
import { auth } from '$lib/stores/auth';
|
||||
import { auth, isAuthenticated } from '$lib/stores/auth';
|
||||
import {
|
||||
ttsEnabled,
|
||||
ttsSettings,
|
||||
|
|
@ -55,6 +55,7 @@
|
|||
let honkAudio = null;
|
||||
let honkSoundUrl = null;
|
||||
let mentionedMessageIds = new Set(); // Track which messages have already played honk
|
||||
let wasAuthenticated = false; // Track previous auth state for reconnect detection
|
||||
|
||||
$: isConnected = $connectionStatus === 'connected';
|
||||
|
||||
|
|
@ -63,6 +64,16 @@
|
|||
chatWebSocket.getParticipants();
|
||||
}
|
||||
|
||||
// Reconnect WebSocket when user logs in or registers while already connected as guest
|
||||
$: {
|
||||
const nowAuthenticated = $isAuthenticated;
|
||||
if (nowAuthenticated && !wasAuthenticated && isConnected) {
|
||||
console.log('[ChatPanel] Auth state changed to authenticated, reconnecting...');
|
||||
chatWebSocket.manualReconnect();
|
||||
}
|
||||
wasAuthenticated = nowAuthenticated;
|
||||
}
|
||||
|
||||
function toggleMenu() {
|
||||
showMenu = !showMenu;
|
||||
if (showMenu) {
|
||||
|
|
@ -192,11 +203,17 @@
|
|||
console.log('Chat connecting with realmId:', realmId, token ? '(authenticated)' : '(guest)');
|
||||
chatWebSocket.connect(realmId, token);
|
||||
|
||||
// Function to scroll to bottom
|
||||
// Function to scroll to newest messages (bottom for UP flow, top for DOWN flow)
|
||||
const scrollToBottom = () => {
|
||||
if (autoScroll && messagesContainer) {
|
||||
requestAnimationFrame(() => {
|
||||
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
||||
if ($chatLayout.messagesFromTop) {
|
||||
// column-reverse: newest at top, scroll to top
|
||||
messagesContainer.scrollTop = 0;
|
||||
} else {
|
||||
// normal: newest at bottom, scroll to bottom
|
||||
messagesContainer.scrollTop = messagesContainer.scrollHeight;
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
@ -257,7 +274,13 @@
|
|||
|
||||
function handleScroll() {
|
||||
const { scrollTop, scrollHeight, clientHeight } = messagesContainer;
|
||||
autoScroll = scrollTop + clientHeight >= scrollHeight - 50;
|
||||
if ($chatLayout.messagesFromTop) {
|
||||
// column-reverse: user at "newest" means scrollTop near 0
|
||||
autoScroll = scrollTop <= 50;
|
||||
} else {
|
||||
// normal: user at bottom means scrollTop + clientHeight near scrollHeight
|
||||
autoScroll = scrollTop + clientHeight >= scrollHeight - 50;
|
||||
}
|
||||
}
|
||||
|
||||
function handleDeleteMessage(messageId) {
|
||||
|
|
@ -640,7 +663,6 @@
|
|||
<ChatMessage
|
||||
{message}
|
||||
showHeader={message.showHeader ?? false}
|
||||
headerBelow={$chatLayout.messagesFromTop}
|
||||
currentUserId={$chatUserInfo.userId}
|
||||
currentUsername={$chatUserInfo.username}
|
||||
currentRealmId={realmId}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue