refactor: optimize socket connection handling, improve messaging cache management, and simplify SpecializationCard UI
This commit is contained in:
@@ -345,7 +345,9 @@ export function useMessaging(options: UseMessagingOptions = {}): UseMessagingRet
|
||||
async (conversationId: string) => {
|
||||
await messagesService.deleteConversation(conversationId);
|
||||
|
||||
// Remove from list
|
||||
// Remove from list and invalidate cache
|
||||
_cachedConversations = null;
|
||||
_cachedTimestamp = 0;
|
||||
setConversations((prev) => prev.filter((c) => c.id !== conversationId));
|
||||
|
||||
// Clear current if it was the deleted one
|
||||
@@ -592,9 +594,22 @@ export function useMessaging(options: UseMessagingOptions = {}): UseMessagingRet
|
||||
unsubscribeStatus();
|
||||
unsubscribeRead();
|
||||
unsubscribeDelivered();
|
||||
// Clean up typing timeout to prevent memory leak
|
||||
if (typingTimeoutRef.current) {
|
||||
clearTimeout(typingTimeoutRef.current);
|
||||
typingTimeoutRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [updateUserStatus]);
|
||||
|
||||
// Invalidate cache when session changes (logout/login)
|
||||
useEffect(() => {
|
||||
if (!isAuthenticated) {
|
||||
_cachedConversations = null;
|
||||
_cachedTimestamp = 0;
|
||||
}
|
||||
}, [isAuthenticated]);
|
||||
|
||||
// Auto-connect on mount
|
||||
useEffect(() => {
|
||||
if (autoConnect && isAuthenticated && !isInitializedRef.current) {
|
||||
|
||||
Reference in New Issue
Block a user