leaveChat method

void leaveChat(
  1. String receiverId
)

Leaves the current chat but maintains the socket connection

Implementation

void leaveChat(String receiverId) {
  // Only update state if we're actually in this chat
  if (_receiverId == receiverId) {
    _log('Leaving chat with: $receiverId');

    // Clear the current receiver ID but don't disconnect socket
    _receiverId = '';

    // Stop typing indicator if it was active
    sendTypingIndicator(false);

    // Emit an event to the server that we've left this chat
    if (_socket != null && _socket!.connected) {
      final userId = ChatConfig.instance.userId;
      if (userId != null) {
        _socket!
            .emit('leave_chat', {'userId': userId, 'partnerId': receiverId});
      }
    }

    // Force refresh chat room list
    loadChatRooms();
  }
}