feat: Manage socket connection lifecycle based on authentication status and ensure chat screen joins rooms only when socket is connected.
This commit is contained in:
@@ -37,8 +37,17 @@ class _ChatScreenState extends ConsumerState<ChatScreen> {
|
||||
notifier.setActiveConversation(widget.conversationId);
|
||||
notifier.loadMessages(widget.conversationId);
|
||||
notifier.markAsRead(widget.conversationId);
|
||||
// Join socket room for real-time updates
|
||||
_socket.joinConversation(widget.conversationId);
|
||||
// Join socket room for real-time updates (socket is connected at auth time)
|
||||
if (_socket.isConnected) {
|
||||
_socket.joinConversation(widget.conversationId);
|
||||
} else {
|
||||
// Wait for socket connection then join
|
||||
_socket.onConnectionChange.first.then((connected) {
|
||||
if (connected && mounted) {
|
||||
_socket.joinConversation(widget.conversationId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
_scrollController.addListener(_onScroll);
|
||||
_messageController.addListener(_onTextChanged);
|
||||
|
||||
Reference in New Issue
Block a user